motor_driver_params.h
Go to the documentation of this file.
1 /*
2  * SPDX-FileCopyrightText: 2023 COGIP Robotics association
3  * SPDX-License-Identifier: LGPL-2.1-only
4  */
5 
6 #pragma once
7 
19 #include "board.h"
20 #include "motor_driver.h"
21 #include "saul_reg.h"
22 
23 #ifdef __cplusplus
24 extern "C" {
25 #endif
26 
32 #ifndef MOTOR_DRIVER_PARAM_MODE
34 # define MOTOR_DRIVER_PARAM_MODE MOTOR_DRIVER_1_DIR
35 #endif
36 #ifndef MOTOR_DRIVER_PARAM_BRAKE_INVERTED
38 # define MOTOR_DRIVER_PARAM_BRAKE_INVERTED false
39 #endif
40 #ifndef MOTOR_DRIVER_PARAM_ENABLE_INVERTED
42 # define MOTOR_DRIVER_PARAM_ENABLE_INVERTED false
43 #endif
44 #ifndef MOTOR_DRIVER_PARAM_PWM
46 # define MOTOR_DRIVER_PARAM_PWM 0
47 #endif
48 #ifndef MOTOR_DRIVER_PARAM_PWM_MODE
50 # define MOTOR_DRIVER_PARAM_PWM_MODE PWM_LEFT
51 #endif
52 #ifndef MOTOR_DRIVER_PARAM_PWM_FREQUENCY
54 # define MOTOR_DRIVER_PARAM_PWM_FREQUENCY 20000U
55 #endif
56 #ifndef MOTOR_DRIVER_PARAM_PWM_RESOLUTION
58 # define MOTOR_DRIVER_PARAM_PWM_RESOLUTION 100U
59 #endif
60 #ifndef MOTOR_DRIVER_PARAM_NB_MOTORS
62 # define MOTOR_DRIVER_PARAM_NB_MOTORS 2U
63 #endif
64 #ifndef MOTOR_DRIVER_PARAM_MOTOR_SET_POST_CALLBACK
66 # define MOTOR_DRIVER_PARAM_MOTOR_SET_POST_CALLBACK NULL
67 #endif
68 
69 /* Motor 1 */
70 #ifndef MOTOR_DRIVER_PARAM_MOTOR1_PWM_CHANNEL
72 # define MOTOR_DRIVER_PARAM_MOTOR1_PWM_CHANNEL 1U
73 #endif
74 #ifndef MOTOR_DRIVER_PARAM_MOTOR1_GPIO_ENABLE
76 # define MOTOR_DRIVER_PARAM_MOTOR1_GPIO_ENABLE GPIO_UNDEF
77 #endif
78 #ifndef MOTOR_DRIVER_PARAM_MOTOR1_GPIO_DIR0
80 # define MOTOR_DRIVER_PARAM_MOTOR1_GPIO_DIR0 GPIO_UNDEF
81 #endif
82 #ifndef MOTOR_DRIVER_PARAM_MOTOR1_GPIO_DIR1_OR_BRAKE
84 # define MOTOR_DRIVER_PARAM_MOTOR1_GPIO_DIR1_OR_BRAKE GPIO_UNDEF
85 #endif
86 #ifndef MOTOR_DRIVER_PARAM_MOTOR1_GPIO_DIR_REVERSE
88 # define MOTOR_DRIVER_PARAM_MOTOR1_GPIO_DIR_REVERSE 0
89 #endif
90 
91 /* Motor 2 */
92 #ifndef MOTOR_DRIVER_PARAM_MOTOR2_PWM_CHANNEL
94 # define MOTOR_DRIVER_PARAM_MOTOR2_PWM_CHANNEL 2U
95 #endif
96 #ifndef MOTOR_DRIVER_PARAM_MOTOR2_GPIO_ENABLE
98 # define MOTOR_DRIVER_PARAM_MOTOR2_GPIO_ENABLE GPIO_UNDEF
99 #endif
100 #ifndef MOTOR_DRIVER_PARAM_MOTOR2_GPIO_DIR0
102 # define MOTOR_DRIVER_PARAM_MOTOR2_GPIO_DIR0 GPIO_UNDEF
103 #endif
104 #ifndef MOTOR_DRIVER_PARAM_MOTOR2_GPIO_DIR1_OR_BRAKE
106 # define MOTOR_DRIVER_PARAM_MOTOR2_GPIO_DIR1_OR_BRAKE GPIO_UNDEF
107 #endif
108 #ifndef MOTOR_DRIVER_PARAM_MOTOR2_GPIO_DIR_REVERSE
110 # define MOTOR_DRIVER_PARAM_MOTOR2_GPIO_DIR_REVERSE 0
111 #endif
112 
113 #ifndef MOTOR_DRIVER_PARAMS
115 # define MOTOR_DRIVER_PARAMS \
116  { \
117  .mode = MOTOR_DRIVER_PARAM_MODE, \
118  .pwm_dev = MOTOR_DRIVER_PARAM_PWM, \
119  .pwm_mode = MOTOR_DRIVER_PARAM_PWM_MODE, \
120  .pwm_frequency = MOTOR_DRIVER_PARAM_PWM_FREQUENCY, \
121  .pwm_resolution = MOTOR_DRIVER_PARAM_PWM_RESOLUTION, \
122  .brake_inverted = MOTOR_DRIVER_PARAM_BRAKE_INVERTED, \
123  .enable_inverted = MOTOR_DRIVER_PARAM_ENABLE_INVERTED, \
124  .nb_motors = MOTOR_DRIVER_PARAM_NB_MOTORS, \
125  .motors = { \
126  { \
127  .pwm_channel = MOTOR_DRIVER_PARAM_MOTOR1_PWM_CHANNEL, \
128  .gpio_enable = MOTOR_DRIVER_PARAM_MOTOR1_GPIO_ENABLE, \
129  .gpio_dir0 = MOTOR_DRIVER_PARAM_MOTOR1_GPIO_DIR0, \
130  .gpio_dir1 = MOTOR_DRIVER_PARAM_MOTOR1_GPIO_DIR1_OR_BRAKE, \
131  .gpio_dir_reverse = MOTOR_DRIVER_PARAM_MOTOR1_GPIO_DIR_REVERSE, \
132  }, \
133  { \
134  .pwm_channel = MOTOR_DRIVER_PARAM_MOTOR2_PWM_CHANNEL, \
135  .gpio_enable = MOTOR_DRIVER_PARAM_MOTOR2_GPIO_ENABLE, \
136  .gpio_dir0 = MOTOR_DRIVER_PARAM_MOTOR2_GPIO_DIR0, \
137  .gpio_dir1 = MOTOR_DRIVER_PARAM_MOTOR2_GPIO_DIR1_OR_BRAKE, \
138  .gpio_dir_reverse = MOTOR_DRIVER_PARAM_MOTOR2_GPIO_DIR_REVERSE, \
139  } \
140  }, \
141  .motor_set_post_cb = MOTOR_DRIVER_PARAM_MOTOR_SET_POST_CALLBACK \
142  }
143 #endif
144 
145 /* SAUL */
146 #ifndef MOTOR_DRIVER_SAUL_INFO
148 # define MOTOR_DRIVER_SAUL_INFO { .name = "motor_driver" }
149 #endif
156 {
158 };
159 
164 {
166 };
167 
168 #ifdef __cplusplus
169 }
170 #endif
#define MOTOR_DRIVER_PARAMS
Default motor driver parameters.
static const saul_reg_info_t motor_driver_saul_info[]
Additional meta information to keep in the SAUL registry.
static const motor_driver_params_t motor_driver_params[]
MOTOR_DRIVER configuration.
#define MOTOR_DRIVER_SAUL_INFO
SAUL information.
High-level driver for DC motors.
SAUL registry interface definition.
Describe DC motor driver with PWM device and motors array.
Definition: motor_driver.h:167
Additional data to collect for each entry.
Definition: saul_reg.h:48