Loading...
Searching...
No Matches
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
91extern "C" {
92#endif
93
102#ifndef CONFIG_MOTOR_DRIVER_MAX
103#define CONFIG_MOTOR_DRIVER_MAX (2)
104#endif
110#define MOTOR_DRIVER_DEV(x) (x)
111
123
131
135typedef enum {
139
152
156typedef unsigned int motor_driver_t;
157
161typedef void (*motor_driver_cb_t)(const motor_driver_t motor_driver,
162 uint8_t motor_id,
163 int32_t pwm_duty_cycle);
164
179
188int motor_driver_init(const motor_driver_t motor_driver);
189
200int motor_set(const motor_driver_t motor_driver, uint8_t motor_id, \
201 int32_t pwm_duty_cycle);
202
212int motor_brake(const motor_driver_t motor_driver, uint8_t motor_id);
213
222void motor_enable(const motor_driver_t motor_driver, uint8_t motor_id);
223
232void 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 */
pwm_mode_t
Low-level GPIO peripheral driver interface definitions.
#define CONFIG_MOTOR_DRIVER_MAX
Maximum number of motors by motor driver.
int motor_brake(const motor_driver_t motor_driver, uint8_t motor_id)
Brake the motor of a given motor driver.
void(* motor_driver_cb_t)(const motor_driver_t motor_driver, uint8_t motor_id, int32_t pwm_duty_cycle)
Motor callback.
motor_direction_t
Describe DC motor direction states.
unsigned int motor_driver_t
Default motor driver type definition.
motor_driver_mode_t
Describe DC motor driver modes.
int motor_set(const motor_driver_t motor_driver, uint8_t motor_id, int32_t pwm_duty_cycle)
Set motor speed and direction.
void motor_disable(const motor_driver_t motor_driver, uint8_t motor_id)
Disable a motor of a given motor driver.
void motor_enable(const motor_driver_t motor_driver, uint8_t motor_id)
Enable a motor of a given motor driver.
int motor_driver_init(const motor_driver_t motor_driver)
Initialize DC motor driver board.
motor_driver_mode_brake_t
Describe DC motor driver brake modes.
@ MOTOR_CW
clockwise
@ MOTOR_CCW
counter clockwise
@ MOTOR_DRIVER_1_DIR
Single GPIO for direction, \ no BRAKE.
@ MOTOR_DRIVER_1_DIR_BRAKE
Single GPIO for direction, \ Single GPIO for BRAKE.
@ MOTOR_DRIVER_2_DIRS
2 GPIOS for direction, \ handling BRAKE
@ MOTOR_BRAKE_LOW
Low stage brake.
@ MOTOR_BRAKE_HIGH
High stage brake.
uint_fast8_t pwm_t
Default PWM type definition.
Definition pwm.h:92
Low-level PWM peripheral driver interface definitions.
Describe DC motor driver with PWM device and motors array.
uint32_t pwm_frequency
PWM device frequency.
pwm_mode_t pwm_mode
PWM mode.
motor_driver_mode_brake_t mode_brake
driver brake mode
motor_driver_cb_t cb
callback on motor_set
motor_driver_mode_t mode
driver mode
uint8_t nb_motors
number of moros
uint32_t pwm_resolution
PWM device resolution.
pwm_t pwm_dev
PWM device driving motors.
Describe DC motor with PWM channel and GPIOs.
uint8_t gpio_enable_invert
flag to set enable GPIO inverted mode
gpio_t gpio_dir0
GPIO to control rotation direction.
uint8_t gpio_brake_invert
flag to make brake active low
int pwm_channel
PWM channel the motor is connected to.
gpio_t gpio_enable
GPIO to enable/disable motor.
uint8_t gpio_dir_reverse
flag to reverse direction
gpio_t gpio_dir1_or_brake
GPIO to control rotation direction.