Skip to content

Commit 5f41e82

Browse files
committed
boards/crazyflie21: migrate to motor_driver_params.h
Migrate motor driver configuration from inline definition in board.h to the new board-specific motor_driver_params.h header file. The old approach defined motor_driver_config[] directly in board.h and unconditionally included motor_driver.h, causing compilation failures for applications that do not use the motor_driver module. This allows the motor driver header to be included only when the module is actually used, while board-specific parameters take precedence over driver defaults due to include path ordering. Configuration migrated: - Driver 0: PWM device 1, 3 motors (channels 1, 3, 0) - Driver 1: PWM device 2, 1 motor (channel 0) - Mode: MOTOR_DRIVER_1_DIR with inverted brake for both drivers Signed-off-by: Gilles DOFFE <[email protected]>
1 parent f33b509 commit 5f41e82

File tree

2 files changed

+133
-73
lines changed

2 files changed

+133
-73
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+
/** @} */

0 commit comments

Comments
 (0)