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
83
84#include <stdbool.h>
85
86#include "periph/pwm.h"
87#include "periph/gpio.h"
88
89#ifdef __cplusplus
90extern "C" {
91#endif
92
101#ifndef CONFIG_MOTOR_DRIVER_MAX
102# define CONFIG_MOTOR_DRIVER_MAX (2)
103#endif
105
117
121typedef enum {
125
129typedef struct {
131 gpio_t gpio_enable;
132 gpio_t gpio_dir0;
133 union {
134 gpio_t gpio_dir1;
135 gpio_t gpio_brake;
136 };
138} motor_t;
139
144
148typedef void (*motor_set_post_cb_t)(const motor_driver_t *motor_driver,
149 uint8_t motor_id,
150 int32_t pwm_duty_cycle);
151
155typedef void (*motor_set_cb_t)(const motor_t *motor,
156 motor_direction_t direction);
157
161typedef void (*motor_brake_cb_t)(const motor_t *motor,
162 bool brake);
163
179
186
198
209int motor_set(const motor_driver_t *motor_driver, uint8_t motor_id, \
210 int32_t pwm_duty_cycle);
211
221int motor_brake(const motor_driver_t *motor_driver, uint8_t motor_id);
222
229void motor_enable(const motor_driver_t *motor_driver, uint8_t motor_id);
230
237void motor_disable(const motor_driver_t *motor_driver, uint8_t motor_id);
238
239#ifdef __cplusplus
240}
241#endif
242
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