mirror of
https://github.com/RIOT-OS/RIOT.git
synced 2025-12-27 23:41:18 +01:00
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 <g.doffe@gmail.com>
This commit is contained in:
parent
f33b5097ce
commit
5f41e82ce2
@ -16,7 +16,6 @@
|
||||
*/
|
||||
|
||||
#include "cpu.h"
|
||||
#include "motor_driver.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
@ -51,78 +50,6 @@ extern "C" {
|
||||
#define LED4_PORT_NUM PORT_C
|
||||
/** @} */
|
||||
|
||||
/**
|
||||
* @name Describe DC motors with PWM channel and GPIOs
|
||||
* @{
|
||||
*/
|
||||
/** Motor driver config. Two driver with three and one motor attached respectively */
|
||||
static const motor_driver_config_t motor_driver_config[] = {
|
||||
{
|
||||
.pwm_dev = 1,
|
||||
.mode = MOTOR_DRIVER_1_DIR,
|
||||
.mode_brake = MOTOR_BRAKE_HIGH,
|
||||
.pwm_mode = PWM_LEFT,
|
||||
.pwm_frequency = 20000U,
|
||||
.pwm_resolution = 4200U,
|
||||
.nb_motors = 3,
|
||||
.motors = {
|
||||
{
|
||||
.pwm_channel = 1,
|
||||
.gpio_enable = 0,
|
||||
.gpio_dir0 = 0,
|
||||
.gpio_dir1_or_brake = 0,
|
||||
.gpio_dir_reverse = 0,
|
||||
.gpio_enable_invert = 0,
|
||||
.gpio_brake_invert = 0,
|
||||
},
|
||||
{
|
||||
.pwm_channel = 3,
|
||||
.gpio_enable = 0,
|
||||
.gpio_dir0 = 0,
|
||||
.gpio_dir1_or_brake = 0,
|
||||
.gpio_dir_reverse = 0,
|
||||
.gpio_enable_invert = 0,
|
||||
.gpio_brake_invert = 0,
|
||||
},
|
||||
{
|
||||
.pwm_channel = 0,
|
||||
.gpio_enable = 0,
|
||||
.gpio_dir0 = 0,
|
||||
.gpio_dir1_or_brake = 0,
|
||||
.gpio_dir_reverse = 0,
|
||||
.gpio_enable_invert = 0,
|
||||
.gpio_brake_invert = 0,
|
||||
},
|
||||
},
|
||||
.cb = NULL,
|
||||
},
|
||||
{
|
||||
.pwm_dev = 2,
|
||||
.mode = MOTOR_DRIVER_1_DIR,
|
||||
.mode_brake = MOTOR_BRAKE_HIGH,
|
||||
.pwm_mode = PWM_LEFT,
|
||||
.pwm_frequency = 20000U,
|
||||
.pwm_resolution = 4200U,
|
||||
.nb_motors = 1,
|
||||
.motors = {
|
||||
{
|
||||
.pwm_channel = 0,
|
||||
.gpio_enable = 0,
|
||||
.gpio_dir0 = 0,
|
||||
.gpio_dir1_or_brake = 0,
|
||||
.gpio_dir_reverse = 0,
|
||||
.gpio_enable_invert = 0,
|
||||
.gpio_brake_invert = 0,
|
||||
},
|
||||
},
|
||||
.cb = NULL,
|
||||
}
|
||||
};
|
||||
|
||||
/** Number of motor drivers */
|
||||
#define MOTOR_DRIVER_NUMOF ARRAY_SIZE(motor_driver_config)
|
||||
/** @} */
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
133
boards/bitcraze-crazyflie21-main/include/motor_driver_params.h
Normal file
133
boards/bitcraze-crazyflie21-main/include/motor_driver_params.h
Normal file
@ -0,0 +1,133 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2025 COGIP Robotics association
|
||||
* SPDX-License-Identifier: LGPL-2.1-only
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
/**
|
||||
* @ingroup boards_bitcraze_crazyflie21_main
|
||||
* @{
|
||||
*
|
||||
* @file
|
||||
* @brief Configuration for motor driver on Crazyflie 2.1
|
||||
*
|
||||
* @author Gilles DOFFE <g.doffe@gmail.com>
|
||||
*/
|
||||
|
||||
#include "board.h"
|
||||
#include "motor_driver.h"
|
||||
#include "saul_reg.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @name Motor driver configuration for Crazyflie 2.1
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief Motor driver 0 parameters (3 motors on PWM device 1)
|
||||
*/
|
||||
#define MOTOR_DRIVER_0_PARAMS \
|
||||
{ \
|
||||
.mode = MOTOR_DRIVER_1_DIR, \
|
||||
.pwm_dev = 1, \
|
||||
.pwm_mode = PWM_LEFT, \
|
||||
.pwm_frequency = 20000U, \
|
||||
.pwm_resolution = 4200U, \
|
||||
.brake_inverted = true, \
|
||||
.enable_inverted = false, \
|
||||
.nb_motors = 3, \
|
||||
.motors = { \
|
||||
{ \
|
||||
.pwm_channel = 1, \
|
||||
.gpio_enable = GPIO_UNDEF, \
|
||||
.gpio_dir0 = GPIO_UNDEF, \
|
||||
.gpio_dir1 = GPIO_UNDEF, \
|
||||
.gpio_dir_reverse = GPIO_UNDEF, \
|
||||
}, \
|
||||
{ \
|
||||
.pwm_channel = 3, \
|
||||
.gpio_enable = GPIO_UNDEF, \
|
||||
.gpio_dir0 = GPIO_UNDEF, \
|
||||
.gpio_dir1 = GPIO_UNDEF, \
|
||||
.gpio_dir_reverse = GPIO_UNDEF, \
|
||||
}, \
|
||||
{ \
|
||||
.pwm_channel = 0, \
|
||||
.gpio_enable = GPIO_UNDEF, \
|
||||
.gpio_dir0 = GPIO_UNDEF, \
|
||||
.gpio_dir1 = GPIO_UNDEF, \
|
||||
.gpio_dir_reverse = GPIO_UNDEF, \
|
||||
} \
|
||||
}, \
|
||||
.motor_set_post_cb = NULL \
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Motor driver 1 parameters (1 motor on PWM device 2)
|
||||
*/
|
||||
#define MOTOR_DRIVER_1_PARAMS \
|
||||
{ \
|
||||
.mode = MOTOR_DRIVER_1_DIR, \
|
||||
.pwm_dev = 2, \
|
||||
.pwm_mode = PWM_LEFT, \
|
||||
.pwm_frequency = 20000U, \
|
||||
.pwm_resolution = 4200U, \
|
||||
.brake_inverted = true, \
|
||||
.enable_inverted = false, \
|
||||
.nb_motors = 1, \
|
||||
.motors = { \
|
||||
{ \
|
||||
.pwm_channel = 0, \
|
||||
.gpio_enable = GPIO_UNDEF, \
|
||||
.gpio_dir0 = GPIO_UNDEF, \
|
||||
.gpio_dir1 = GPIO_UNDEF, \
|
||||
.gpio_dir_reverse = GPIO_UNDEF, \
|
||||
} \
|
||||
}, \
|
||||
.motor_set_post_cb = NULL \
|
||||
}
|
||||
|
||||
#ifndef MOTOR_DRIVER_PARAMS
|
||||
/**
|
||||
* @brief Motor driver configuration array
|
||||
*/
|
||||
# define MOTOR_DRIVER_PARAMS \
|
||||
MOTOR_DRIVER_0_PARAMS, \
|
||||
MOTOR_DRIVER_1_PARAMS
|
||||
#endif
|
||||
|
||||
#ifndef MOTOR_DRIVER_SAUL_INFO
|
||||
/**
|
||||
* @brief SAUL registry information for motor drivers
|
||||
*/
|
||||
# define MOTOR_DRIVER_SAUL_INFO \
|
||||
{ .name = "motor_driver_0" }, \
|
||||
{ .name = "motor_driver_1" }
|
||||
#endif
|
||||
/**@}*/
|
||||
|
||||
/**
|
||||
* @brief MOTOR_DRIVER configuration
|
||||
*/
|
||||
static const motor_driver_params_t motor_driver_params[] =
|
||||
{
|
||||
MOTOR_DRIVER_PARAMS,
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Additional meta information to keep in the SAUL registry
|
||||
*/
|
||||
static const saul_reg_info_t motor_driver_saul_info[] =
|
||||
{
|
||||
MOTOR_DRIVER_SAUL_INFO
|
||||
};
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
/** @} */
|
||||
Loading…
x
Reference in New Issue
Block a user