add some comments
[apps/native/gear-racing-car.git] / inc / resource / resource_motor_driver_L298N.h
1 /*
2  * Copyright (c) 2017 Samsung Electronics Co., Ltd.
3  *
4  * Contact: Jeonghoon Park <jh1979.park@samsung.com>
5  *
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
9  *
10  * http://floralicense.org/license/
11  *
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.
17  */
18
19 #ifndef __RESOURCE_MOTOR_DRIVER_L298N_H__
20 #define __RESOURCE_MOTOR_DRIVER_L298N_H__
21
22 /**
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
27  */
28
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
32
33 #define DEFAULT_MOTOR2_PIN1 19
34 #define DEFAULT_MOTOR2_PIN2 16
35
36 #define DEFAULT_MOTOR3_PIN1 6
37 #define DEFAULT_MOTOR3_PIN2 12
38
39 #define DEFAULT_MOTOR4_PIN1 22
40 #define DEFAULT_MOTOR4_PIN2 23
41
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
47
48
49 /**
50  * @brief Enumeration for motor id.
51  */
52 typedef enum {
53         MOTOR_ID_1,
54         MOTOR_ID_2,
55         MOTOR_ID_3,
56         MOTOR_ID_4,
57         MOTOR_ID_MAX
58 } motor_id_e;
59
60 /**
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
65  *
66  * @return 0 on success, otherwise a negative error value
67  * @before resource_set_motor_driver_L298N_speed() : Optional
68  */
69 int resource_set_motor_driver_L298N_configuration(motor_id_e id,
70         unsigned int pin1, unsigned int pin2, unsigned en_ch);
71
72 /**
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
79  */
80 int resource_set_motor_driver_L298N_speed(motor_id_e id, int speed);
81
82 #endif /* __RESOURCE_MOTOR_DRIVER_L298N_H__ */