Loading...
Searching...
No Matches
motor_driver.h
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2018 Gilles DOFFE <g.doffe@gmail.com>
3 * SPDX-License-Identifier: LGPL-2.1-only
4 */
5
6#pragma once
7
80
81#include <stdbool.h>
82
83#include "periph/pwm.h"
84#include "periph/gpio.h"
85
86#ifdef __cplusplus
87extern "C" {
88#endif
89
98#ifndef CONFIG_MOTOR_DRIVER_MAX
99# define CONFIG_MOTOR_DRIVER_MAX (2)
100#endif
102
114
118typedef enum {
122
126typedef struct {
128 gpio_t gpio_enable;
129 gpio_t gpio_dir0;
130 union {
131 gpio_t gpio_dir1;
132 gpio_t gpio_brake;
133 };
135} motor_t;
136
141
145typedef void (*motor_set_post_cb_t)(const motor_driver_t *motor_driver,
146 uint8_t motor_id,
147 int32_t pwm_duty_cycle);
148
152typedef void (*motor_set_cb_t)(const motor_t *motor,
153 motor_direction_t direction);
154
158typedef void (*motor_brake_cb_t)(const motor_t *motor,
159 bool brake);
160
176
183
195
206int motor_set(const motor_driver_t *motor_driver, uint8_t motor_id, \
207 int32_t pwm_duty_cycle);
208
218int motor_brake(const motor_driver_t *motor_driver, uint8_t motor_id);
219
226void motor_enable(const motor_driver_t *motor_driver, uint8_t motor_id);
227
234void motor_disable(const motor_driver_t *motor_driver, uint8_t motor_id);
235
236#ifdef __cplusplus
237}
238#endif
239
pwm_mode_t
Low-level GPIO peripheral driver interface definitions.
#define CONFIG_MOTOR_DRIVER_MAX
Maximum number of motors by motor driver.
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.
int motor_driver_init(motor_driver_t *motor_driver, const motor_driver_params_t *params)
Initialize DC motor driver board.
motor_direction_t
Describe DC motor direction states.
struct _motor_driver_t motor_driver_t
Motor driver.
motor_driver_mode_t
Describe DC motor driver modes.
void motor_enable(const motor_driver_t *motor_driver, uint8_t motor_id)
Enable a motor of a given motor driver.
void(* motor_set_cb_t)(const motor_t *motor, motor_direction_t direction)
Motor set callback.
int motor_brake(const motor_driver_t *motor_driver, uint8_t motor_id)
Brake the motor of a given motor driver.
void(* motor_brake_cb_t)(const motor_t *motor, bool brake)
Motor brake callback.
void(* motor_set_post_cb_t)(const motor_driver_t *motor_driver, uint8_t motor_id, int32_t pwm_duty_cycle)
Motor callback.
@ 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
uint_fast8_t pwm_t
Default PWM type definition.
Definition pwm.h:91
Low-level PWM peripheral driver interface definitions.
Motor driver.
const motor_driver_params_t * params
parameters
Describe DC motor driver with PWM device and motors array.
motor_driver_mode_t mode
driver mode
motor_t motors[CONFIG_MOTOR_DRIVER_MAX]
motors array
uint8_t nb_motors
number of motors
pwm_t pwm_dev
PWM device driving motors.
pwm_mode_t pwm_mode
PWM mode.
bool enable_inverted
if false, enable high (1), low (0) otherwise
bool brake_inverted
if false, brake high (1), low (0) otherwise
motor_set_post_cb_t motor_set_post_cb
callback post to motor_set
uint32_t pwm_frequency
PWM device frequency.
uint32_t pwm_resolution
PWM device resolution.
Describe DC motor with PWM channel and GPIOs.
gpio_t gpio_dir0
GPIO to control direction.
int pwm_channel
PWM channel the motor is connected to.
gpio_t gpio_brake
GPIO to control brake.
gpio_t gpio_enable
GPIO to enable/disable motor.
gpio_t gpio_dir1
GPIO to control direction.
bool gpio_dir_reverse
flag to reverse direction