motor_driver.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2018 Gilles DOFFE <g.doffe@gmail.com>
3  *
4  * This file is subject to the terms and conditions of the GNU Lesser
5  * General Public License v2.1. See the file LICENSE in the top level
6  * directory for more details.
7  */
8 
84 #ifndef MOTOR_DRIVER_H
85 #define MOTOR_DRIVER_H
86 
87 #include "periph/pwm.h"
88 #include "periph/gpio.h"
89 
90 #ifdef __cplusplus
91 extern "C" {
92 #endif
93 
97 #ifndef MOTOR_DRIVER_MAX
98 #define MOTOR_DRIVER_MAX (2)
99 #endif /* MOTOR_DRIVER_MAX */
100 
104 #define MOTOR_DRIVER_DEV(x) (x)
105 
109 typedef enum {
117 
121 typedef enum {
125 
129 typedef enum {
130  MOTOR_CW = 0,
131  MOTOR_CCW = 1,
133 
137 typedef struct {
139  gpio_t gpio_enable;
140  gpio_t gpio_dir0;
145 } motor_t;
146 
150 typedef unsigned int motor_driver_t;
151 
155 typedef void (*motor_driver_cb_t)(const motor_driver_t motor_driver,
156  uint8_t motor_id,
157  int32_t pwm_duty_cycle);
158 
162 typedef struct {
167  uint32_t pwm_frequency;
168  uint32_t pwm_resolution;
169  uint8_t nb_motors;
173 
182 int motor_driver_init(const motor_driver_t motor_driver);
183 
194 int motor_set(const motor_driver_t motor_driver, uint8_t motor_id, \
195  int32_t pwm_duty_cycle);
196 
206 int motor_brake(const motor_driver_t motor_driver, uint8_t motor_id);
207 
216 void motor_enable(const motor_driver_t motor_driver, uint8_t motor_id);
217 
226 void motor_disable(const motor_driver_t motor_driver, uint8_t motor_id);
227 
228 #ifdef __cplusplus
229 }
230 #endif
231 
232 #endif /* MOTOR_DRIVER_H */
233 
Describe DC motor with PWM channel and GPIOs.
Definition: motor_driver.h:137
High stage brake.
Definition: motor_driver.h:123
Low-level PWM peripheral driver interface definitions.
void motor_disable(const motor_driver_t motor_driver, uint8_t motor_id)
Disable a motor of a given motor driver.
#define MOTOR_DRIVER_MAX
Maximum number of motors by motor driver.
Definition: motor_driver.h:98
Single GPIO for direction, \ Single GPIO for BRAKE.
Definition: motor_driver.h:114
clockwise
Definition: motor_driver.h:130
gpio_t gpio_enable
GPIO to enable/disable motor.
Definition: motor_driver.h:139
motor_driver_cb_t cb
callback on motor_set
Definition: motor_driver.h:171
pwm_t pwm_dev
PWM device driving motors.
Definition: motor_driver.h:163
motor_driver_mode_brake_t
Describe DC motor driver brake modes.
Definition: motor_driver.h:121
Low-level GPIO peripheral driver interface definitions.
motor_driver_mode_t mode
driver mode
Definition: motor_driver.h:164
uint8_t nb_motors
number of moros
Definition: motor_driver.h:169
void motor_enable(const motor_driver_t motor_driver, uint8_t motor_id)
Enable a motor of a given motor driver.
Single GPIO for direction, \ no BRAKE.
Definition: motor_driver.h:112
int motor_set(const motor_driver_t motor_driver, uint8_t motor_id, int32_t pwm_duty_cycle)
Set motor speed and direction.
2 GPIOS for direction, \ handling BRAKE
Definition: motor_driver.h:110
unsigned int motor_driver_t
Default motor driver type definition.
Definition: motor_driver.h:150
counter clockwise
Definition: motor_driver.h:131
motor_driver_mode_brake_t mode_brake
driver brake mode
Definition: motor_driver.h:165
pwm_mode_t pwm_mode
PWM mode.
Definition: motor_driver.h:166
uint8_t gpio_enable_invert
flag to set enable GPIO inverted mode
Definition: motor_driver.h:143
motor_direction_t
Describe DC motor direction states.
Definition: motor_driver.h:129
gpio_t gpio_dir1_or_brake
GPIO to control rotation direction.
Definition: motor_driver.h:141
motor_driver_mode_t
Describe DC motor driver modes.
Definition: motor_driver.h:109
int motor_brake(const motor_driver_t motor_driver, uint8_t motor_id)
Brake the motor of a given motor driver.
int motor_driver_init(const motor_driver_t motor_driver)
Initialize DC motor driver board.
gpio_t gpio_dir0
GPIO to control rotation direction.
Definition: motor_driver.h:140
uint8_t gpio_dir_reverse
flag to reverse direction
Definition: motor_driver.h:142
pwm_mode_t
Definition: periph_cpu.h:137
Low stage brake.
Definition: motor_driver.h:122
uint32_t pwm_resolution
PWM device resolution.
Definition: motor_driver.h:168
uint8_t gpio_brake_invert
flag to make brake active low
Definition: motor_driver.h:144
uint32_t pwm_frequency
PWM device frequency.
Definition: motor_driver.h:167
int pwm_channel
PWM channel the motor is connected to.
Definition: motor_driver.h:138
unsigned int pwm_t
Default PWM type definition.
Definition: pwm.h:92
Describe DC motor driver with PWM device and motors array.
Definition: motor_driver.h:162
void(* motor_driver_cb_t)(const motor_driver_t motor_driver, uint8_t motor_id, int32_t pwm_duty_cycle)
Motor callback.
Definition: motor_driver.h:155