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 
102 #ifndef CONFIG_MOTOR_DRIVER_MAX
103 #define CONFIG_MOTOR_DRIVER_MAX (2)
104 #endif
105 
110 #define MOTOR_DRIVER_DEV(x) (x)
111 
115 typedef enum {
123 
127 typedef enum {
131 
135 typedef enum {
136  MOTOR_CW = 0,
137  MOTOR_CCW = 1,
139 
143 typedef struct {
145  gpio_t gpio_enable;
146  gpio_t gpio_dir0;
151 } motor_t;
152 
156 typedef unsigned int motor_driver_t;
157 
161 typedef void (*motor_driver_cb_t)(const motor_driver_t motor_driver,
162  uint8_t motor_id,
163  int32_t pwm_duty_cycle);
164 
168 typedef struct {
173  uint32_t pwm_frequency;
174  uint32_t pwm_resolution;
175  uint8_t nb_motors;
179 
188 int motor_driver_init(const motor_driver_t motor_driver);
189 
200 int motor_set(const motor_driver_t motor_driver, uint8_t motor_id, \
201  int32_t pwm_duty_cycle);
202 
212 int motor_brake(const motor_driver_t motor_driver, uint8_t motor_id);
213 
222 void motor_enable(const motor_driver_t motor_driver, uint8_t motor_id);
223 
232 void motor_disable(const motor_driver_t motor_driver, uint8_t motor_id);
233 
234 #ifdef __cplusplus
235 }
236 #endif
237 
238 #endif /* MOTOR_DRIVER_H */
239 
Describe DC motor with PWM channel and GPIOs.
Definition: motor_driver.h:143
High stage brake.
Definition: motor_driver.h:129
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.
Single GPIO for direction, \ Single GPIO for BRAKE.
Definition: motor_driver.h:120
clockwise
Definition: motor_driver.h:136
gpio_t gpio_enable
GPIO to enable/disable motor.
Definition: motor_driver.h:145
motor_driver_cb_t cb
callback on motor_set
Definition: motor_driver.h:177
pwm_t pwm_dev
PWM device driving motors.
Definition: motor_driver.h:169
motor_driver_mode_brake_t
Describe DC motor driver brake modes.
Definition: motor_driver.h:127
Low-level GPIO peripheral driver interface definitions.
motor_driver_mode_t mode
driver mode
Definition: motor_driver.h:170
uint8_t nb_motors
number of moros
Definition: motor_driver.h:175
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:118
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:116
unsigned int motor_driver_t
Default motor driver type definition.
Definition: motor_driver.h:156
counter clockwise
Definition: motor_driver.h:137
motor_driver_mode_brake_t mode_brake
driver brake mode
Definition: motor_driver.h:171
pwm_mode_t pwm_mode
PWM mode.
Definition: motor_driver.h:172
uint8_t gpio_enable_invert
flag to set enable GPIO inverted mode
Definition: motor_driver.h:149
motor_direction_t
Describe DC motor direction states.
Definition: motor_driver.h:135
#define CONFIG_MOTOR_DRIVER_MAX
Maximum number of motors by motor driver.
Definition: motor_driver.h:103
gpio_t gpio_dir1_or_brake
GPIO to control rotation direction.
Definition: motor_driver.h:147
motor_driver_mode_t
Describe DC motor driver modes.
Definition: motor_driver.h:115
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:146
uint8_t gpio_dir_reverse
flag to reverse direction
Definition: motor_driver.h:148
pwm_mode_t
Definition: periph_cpu.h:159
Low stage brake.
Definition: motor_driver.h:128
uint32_t pwm_resolution
PWM device resolution.
Definition: motor_driver.h:174
uint8_t gpio_brake_invert
flag to make brake active low
Definition: motor_driver.h:150
uint32_t pwm_frequency
PWM device frequency.
Definition: motor_driver.h:173
int pwm_channel
PWM channel the motor is connected to.
Definition: motor_driver.h:144
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:168
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:161