Skip to content

Commit 49b01c4

Browse files
authored
Merge pull request #20429 from cogip/rework_motor_driver
drivers/motor_driver: rework motor driver
2 parents 34ec109 + 22c6b2b commit 49b01c4

File tree

16 files changed

+675
-523
lines changed

16 files changed

+675
-523
lines changed

boards/bitcraze-crazyflie21-main/include/board.h

Lines changed: 0 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
*/
1717

1818
#include "cpu.h"
19-
#include "motor_driver.h"
2019

2120
#ifdef __cplusplus
2221
extern "C" {
@@ -51,78 +50,6 @@ extern "C" {
5150
#define LED4_PORT_NUM PORT_C
5251
/** @} */
5352

54-
/**
55-
* @name Describe DC motors with PWM channel and GPIOs
56-
* @{
57-
*/
58-
/** Motor driver config. Two driver with three and one motor attached respectively */
59-
static const motor_driver_config_t motor_driver_config[] = {
60-
{
61-
.pwm_dev = 1,
62-
.mode = MOTOR_DRIVER_1_DIR,
63-
.mode_brake = MOTOR_BRAKE_HIGH,
64-
.pwm_mode = PWM_LEFT,
65-
.pwm_frequency = 20000U,
66-
.pwm_resolution = 4200U,
67-
.nb_motors = 3,
68-
.motors = {
69-
{
70-
.pwm_channel = 1,
71-
.gpio_enable = 0,
72-
.gpio_dir0 = 0,
73-
.gpio_dir1_or_brake = 0,
74-
.gpio_dir_reverse = 0,
75-
.gpio_enable_invert = 0,
76-
.gpio_brake_invert = 0,
77-
},
78-
{
79-
.pwm_channel = 3,
80-
.gpio_enable = 0,
81-
.gpio_dir0 = 0,
82-
.gpio_dir1_or_brake = 0,
83-
.gpio_dir_reverse = 0,
84-
.gpio_enable_invert = 0,
85-
.gpio_brake_invert = 0,
86-
},
87-
{
88-
.pwm_channel = 0,
89-
.gpio_enable = 0,
90-
.gpio_dir0 = 0,
91-
.gpio_dir1_or_brake = 0,
92-
.gpio_dir_reverse = 0,
93-
.gpio_enable_invert = 0,
94-
.gpio_brake_invert = 0,
95-
},
96-
},
97-
.cb = NULL,
98-
},
99-
{
100-
.pwm_dev = 2,
101-
.mode = MOTOR_DRIVER_1_DIR,
102-
.mode_brake = MOTOR_BRAKE_HIGH,
103-
.pwm_mode = PWM_LEFT,
104-
.pwm_frequency = 20000U,
105-
.pwm_resolution = 4200U,
106-
.nb_motors = 1,
107-
.motors = {
108-
{
109-
.pwm_channel = 0,
110-
.gpio_enable = 0,
111-
.gpio_dir0 = 0,
112-
.gpio_dir1_or_brake = 0,
113-
.gpio_dir_reverse = 0,
114-
.gpio_enable_invert = 0,
115-
.gpio_brake_invert = 0,
116-
},
117-
},
118-
.cb = NULL,
119-
}
120-
};
121-
122-
/** Number of motor drivers */
123-
#define MOTOR_DRIVER_NUMOF ARRAY_SIZE(motor_driver_config)
124-
/** @} */
125-
12653
#ifdef __cplusplus
12754
}
12855
#endif
Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
/*
2+
* SPDX-FileCopyrightText: 2025 COGIP Robotics association
3+
* SPDX-License-Identifier: LGPL-2.1-only
4+
*/
5+
6+
#pragma once
7+
8+
/**
9+
* @ingroup boards_bitcraze_crazyflie21_main
10+
* @{
11+
*
12+
* @file
13+
* @brief Configuration for motor driver on Crazyflie 2.1
14+
*
15+
* @author Gilles DOFFE <[email protected]>
16+
*/
17+
18+
#include "board.h"
19+
#include "motor_driver.h"
20+
#include "saul_reg.h"
21+
22+
#ifdef __cplusplus
23+
extern "C" {
24+
#endif
25+
26+
/**
27+
* @name Motor driver configuration for Crazyflie 2.1
28+
* @{
29+
*/
30+
31+
/**
32+
* @brief Motor driver 0 parameters (3 motors on PWM device 1)
33+
*/
34+
#define MOTOR_DRIVER_0_PARAMS \
35+
{ \
36+
.mode = MOTOR_DRIVER_1_DIR, \
37+
.pwm_dev = 1, \
38+
.pwm_mode = PWM_LEFT, \
39+
.pwm_frequency = 20000U, \
40+
.pwm_resolution = 4200U, \
41+
.brake_inverted = true, \
42+
.enable_inverted = false, \
43+
.nb_motors = 3, \
44+
.motors = { \
45+
{ \
46+
.pwm_channel = 1, \
47+
.gpio_enable = GPIO_UNDEF, \
48+
.gpio_dir0 = GPIO_UNDEF, \
49+
.gpio_dir1 = GPIO_UNDEF, \
50+
.gpio_dir_reverse = GPIO_UNDEF, \
51+
}, \
52+
{ \
53+
.pwm_channel = 3, \
54+
.gpio_enable = GPIO_UNDEF, \
55+
.gpio_dir0 = GPIO_UNDEF, \
56+
.gpio_dir1 = GPIO_UNDEF, \
57+
.gpio_dir_reverse = GPIO_UNDEF, \
58+
}, \
59+
{ \
60+
.pwm_channel = 0, \
61+
.gpio_enable = GPIO_UNDEF, \
62+
.gpio_dir0 = GPIO_UNDEF, \
63+
.gpio_dir1 = GPIO_UNDEF, \
64+
.gpio_dir_reverse = GPIO_UNDEF, \
65+
} \
66+
}, \
67+
.motor_set_post_cb = NULL \
68+
}
69+
70+
/**
71+
* @brief Motor driver 1 parameters (1 motor on PWM device 2)
72+
*/
73+
#define MOTOR_DRIVER_1_PARAMS \
74+
{ \
75+
.mode = MOTOR_DRIVER_1_DIR, \
76+
.pwm_dev = 2, \
77+
.pwm_mode = PWM_LEFT, \
78+
.pwm_frequency = 20000U, \
79+
.pwm_resolution = 4200U, \
80+
.brake_inverted = true, \
81+
.enable_inverted = false, \
82+
.nb_motors = 1, \
83+
.motors = { \
84+
{ \
85+
.pwm_channel = 0, \
86+
.gpio_enable = GPIO_UNDEF, \
87+
.gpio_dir0 = GPIO_UNDEF, \
88+
.gpio_dir1 = GPIO_UNDEF, \
89+
.gpio_dir_reverse = GPIO_UNDEF, \
90+
} \
91+
}, \
92+
.motor_set_post_cb = NULL \
93+
}
94+
95+
#ifndef MOTOR_DRIVER_PARAMS
96+
/**
97+
* @brief Motor driver configuration array
98+
*/
99+
# define MOTOR_DRIVER_PARAMS \
100+
MOTOR_DRIVER_0_PARAMS, \
101+
MOTOR_DRIVER_1_PARAMS
102+
#endif
103+
104+
#ifndef MOTOR_DRIVER_SAUL_INFO
105+
/**
106+
* @brief SAUL registry information for motor drivers
107+
*/
108+
# define MOTOR_DRIVER_SAUL_INFO \
109+
{ .name = "motor_driver_0" }, \
110+
{ .name = "motor_driver_1" }
111+
#endif
112+
/**@}*/
113+
114+
/**
115+
* @brief MOTOR_DRIVER configuration
116+
*/
117+
static const motor_driver_params_t motor_driver_params[] =
118+
{
119+
MOTOR_DRIVER_PARAMS,
120+
};
121+
122+
/**
123+
* @brief Additional meta information to keep in the SAUL registry
124+
*/
125+
static const saul_reg_info_t motor_driver_saul_info[] =
126+
{
127+
MOTOR_DRIVER_SAUL_INFO
128+
};
129+
130+
#ifdef __cplusplus
131+
}
132+
#endif
133+
/** @} */

boards/common/native/drivers/native-qdec.c

Lines changed: 0 additions & 59 deletions
This file was deleted.

boards/common/native/include/board.h

Lines changed: 0 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,6 @@
2020

2121
#include <stdint.h>
2222

23-
/* RIOT includes */
24-
#include <motor_driver.h>
25-
2623
#ifdef __cplusplus
2724
extern "C" {
2825
#endif
@@ -142,74 +139,14 @@ void _native_LED_RED_TOGGLE(void);
142139
/** @} */
143140
#endif
144141

145-
#if MODULE_PERIPH_QDEC
146-
/**
147-
* @brief Simulate QDEC on motor_set() calls
148-
*
149-
* @param[in] motor_driver motor driver to which motor is attached
150-
* @param[in] motor_id motor ID on driver
151-
* @param[in] pwm_duty_cycle Signed PWM duty_cycle to set motor speed and direction
152-
*/
153-
void native_motor_driver_qdec_simulation( \
154-
const motor_driver_t motor_driver, uint8_t motor_id, \
155-
int32_t pwm_duty_cycle);
156-
157-
/* C++ standard do not support designated initializers */
158-
#if !(defined __cplusplus) && (defined MODULE_PERIPH_QDEC)
159-
160-
/**
161-
* @name Describe DC motors with PWM channel and GPIOs
162-
* @{
163-
*/
164-
static const motor_driver_config_t motor_driver_config[] = {
165-
{
166-
.pwm_dev = 0,
167-
.mode = MOTOR_DRIVER_1_DIR_BRAKE,
168-
.mode_brake = MOTOR_BRAKE_LOW,
169-
.pwm_mode = PWM_LEFT,
170-
.pwm_frequency = 20000U,
171-
.pwm_resolution = 1000U,
172-
.nb_motors = 2,
173-
.motors = {
174-
{
175-
.pwm_channel = 0,
176-
.gpio_enable = GPIO_PIN(0, 0),
177-
.gpio_dir0 = GPIO_PIN(0, 0),
178-
.gpio_dir1_or_brake = GPIO_PIN(0, 0),
179-
.gpio_dir_reverse = 0,
180-
.gpio_enable_invert = 0,
181-
.gpio_brake_invert = 0,
182-
},
183-
{
184-
.pwm_channel = 1,
185-
.gpio_enable = GPIO_PIN(0, 0),
186-
.gpio_dir0 = GPIO_PIN(0, 0),
187-
.gpio_dir1_or_brake = GPIO_PIN(0, 0),
188-
.gpio_dir_reverse = 1,
189-
.gpio_enable_invert = 0,
190-
.gpio_brake_invert = 0,
191-
},
192-
},
193-
.cb = native_motor_driver_qdec_simulation,
194-
},
195-
};
196-
197-
#define MOTOR_DRIVER_NUMOF ARRAY_SIZE(motor_driver_config)
198-
/** @} */
199-
#endif
200-
201142
/**
202143
* @name ztimer configuration
203144
* @{
204145
*/
205-
#define CONFIG_ZTIMER_USEC_TYPE ZTIMER_TYPE_PERIPH_TIMER
206-
#define CONFIG_ZTIMER_USEC_DEV TIMER_DEV(0)
207146
/* on native, anything can happen... */
208147
#define CONFIG_ZTIMER_USEC_MIN (64)
209148
/** @} */
210149

211-
#endif /* __cplusplus */
212-
213150
#ifdef __cplusplus
214151
}
215152
#endif

0 commit comments

Comments
 (0)