2 * Copyright (c) 2018 Samsung Electronics Co., Ltd.
4 * Contact: Jin Yoon <jinny.yoon@samsung.com>
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an AS IS BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
19 #include <peripheral_io.h>
22 #define SERVO_MOTOR_CHANNEL (0)
23 #define SERVO_MOTOR_DEFAULT_PERIOD 20.0
25 static peripheral_pwm_h g_pwm_h;
27 void resource_close_servo_motor(void)
30 peripheral_pwm_close(g_pwm_h);
35 int resource_set_servo_motor_value(double duty_cycle_ms)
39 if (duty_cycle_ms >= SERVO_MOTOR_DEFAULT_PERIOD) {
40 _E("Too large duty cycle");
45 ret = peripheral_pwm_open(0, SERVO_MOTOR_CHANNEL, &g_pwm_h);
46 if (ret != PERIPHERAL_ERROR_NONE) {
47 _E("failed to open servo motor with ch : %s", get_error_message(ret));
52 ret = peripheral_pwm_set_period(g_pwm_h, SERVO_MOTOR_DEFAULT_PERIOD * 1000 * 1000);
53 if (ret != PERIPHERAL_ERROR_NONE) {
54 _E("failed to set period : %s", get_error_message(ret));
58 ret = peripheral_pwm_set_duty_cycle(g_pwm_h, duty_cycle_ms * 1000 * 1000);
59 if (ret != PERIPHERAL_ERROR_NONE) {
60 _E("failed to set duty cycle : %s", get_error_message(ret));
64 ret = peripheral_pwm_set_enabled(g_pwm_h, true);
65 if (ret != PERIPHERAL_ERROR_NONE) {
66 _E("failed to enable : %s", get_error_message(ret));