2 * Copyright (c) 2017 Samsung Electronics Co., Ltd.
4 * Contact: Jeonghoon Park <jh1979.park@samsung.com>
6 * Licensed under the Flora License, Version 1.1 (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://floralicense.org/license/
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 #ifndef __RESOURCE_MOTOR_DRIVER_L298N_H__
20 #define __RESOURCE_MOTOR_DRIVER_L298N_H__
23 * This module is sample codes to handling DC motors in Tizen platform.
24 * HW is configured with L298N(motor driver) and PCA9685(PWM controller).
25 * To control motor, we use two GPIO pins of IoT board(e.g. RPi 3) connected
26 * with L298N and a PWM channel of PCA9685 connected with L298N
29 /* Default GPIO pins of raspberry pi 3 connected with IN pins of L298N */
30 #define DEFAULT_MOTOR1_PIN1 26
31 #define DEFAULT_MOTOR1_PIN2 20
33 #define DEFAULT_MOTOR2_PIN1 19
34 #define DEFAULT_MOTOR2_PIN2 16
36 #define DEFAULT_MOTOR3_PIN1 6
37 #define DEFAULT_MOTOR3_PIN2 12
39 #define DEFAULT_MOTOR4_PIN1 22
40 #define DEFAULT_MOTOR4_PIN2 23
42 /* Default channel numbers of PCA9685 with enable pins of L298N */
43 #define DEFAULT_MOTOR1_EN_CH 1
44 #define DEFAULT_MOTOR2_EN_CH 2
45 #define DEFAULT_MOTOR3_EN_CH 3
46 #define DEFAULT_MOTOR4_EN_CH 4
50 * @brief Enumeration for motor id.
61 * @param[in] id The motor id
62 * @param[in] pin1 The first pin number to control motor
63 * @param[in] pin2 The second pin number to control motor
64 * @param[in] en_ch The enable channnel number to control PWM signal
66 * @return 0 on success, otherwise a negative error value
67 * @before resource_set_motor_driver_L298N_speed() : Optional
69 int resource_set_motor_driver_L298N_configuration(motor_id_e id,
70 unsigned int pin1, unsigned int pin2, unsigned en_ch);
73 * @param[in] id The motor id
74 * @param[in] speed The speed to control motor, 0 to stop motor,
75 * positive value to rotate clockwise and higher value to rotate more fast
76 * negative value to rotate couterclockwise and lower value to rotate more fast
77 * @return 0 on success, otherwise a negative error value
78 * @before resource_set_motor_driver_L298N_speed() : Optional
80 int resource_set_motor_driver_L298N_speed(motor_id_e id, int speed);
82 #endif /* __RESOURCE_MOTOR_DRIVER_L298N_H__ */