From 78eaf18c8fba5d2c51e1e84e3c289ceb518e4359 Mon Sep 17 00:00:00 2001 From: Jeonghoon Park Date: Thu, 7 Dec 2017 17:38:43 +0900 Subject: [PATCH] add servo motor module --- CMakeLists.txt | 1 + inc/servo_motor.h | 26 ++++++++++++++++++++++++++ src/servo_motor.c | 43 +++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 70 insertions(+) create mode 100644 inc/servo_motor.h create mode 100644 src/servo_motor.c diff --git a/CMakeLists.txt b/CMakeLists.txt index bc5c2d9..73084d3 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -30,6 +30,7 @@ ADD_EXECUTABLE(${PROJECT_NAME} ${PROJECT_ROOT_DIR}/src/app.c ${PROJECT_ROOT_DIR}/src/log.c ${PROJECT_ROOT_DIR}/src/dc_motor.c + ${PROJECT_ROOT_DIR}/src/servo_motor.c ${PROJECT_ROOT_DIR}/src/pca9685.c ) diff --git a/inc/servo_motor.h b/inc/servo_motor.h new file mode 100644 index 0000000..4b927fb --- /dev/null +++ b/inc/servo_motor.h @@ -0,0 +1,26 @@ +/* + * Copyright (c) 2017 Samsung Electronics Co., Ltd. + * + * Contact: Jeonghoon Park + * + * Licensed under the Flora License, Version 1.1 (the License); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://floralicense.org/license/ + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an AS IS BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef __CAR_APP_SERVO_MOTOR_H__ +#define __CAR_APP_SERVO_MOTOR_H__ + +int servo_motor_init(void); +int servo_motor_fini(void); +int servo_motor_value_set(int motor_id, int value); + +#endif /* __CAR_APP_SERVO_MOTOR_H__ */ \ No newline at end of file diff --git a/src/servo_motor.c b/src/servo_motor.c new file mode 100644 index 0000000..444c91e --- /dev/null +++ b/src/servo_motor.c @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2017 Samsung Electronics Co., Ltd. + * + * Contact: Jeonghoon Park + * + * Licensed under the Flora License, Version 1.1 (the License); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://floralicense.org/license/ + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an AS IS BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "log.h" +#include "pca9685.h" + +int servo_motor_init(void) +{ + int ret = 0; + ret = pca9685_init(); + if (ret) { + _E("failed to init PCA9685"); + return -1; + } +} + +int servo_motor_fini(void) +{ + pca9685_fini(); + return 0; +} + +int servo_motor_value_set(int motor_id, int value) +{ + int ret = 0; + ret = pca9685_set_value_to_channel(motor_id, 0, value); + return ret; +} -- 2.7.4