diff --git a/cmake/configs/nuttx_px4fmu-v5_default.cmake b/cmake/configs/nuttx_px4fmu-v5_default.cmake index 86a0c0a7d89..209ce42a3cc 100644 --- a/cmake/configs/nuttx_px4fmu-v5_default.cmake +++ b/cmake/configs/nuttx_px4fmu-v5_default.cmake @@ -17,7 +17,7 @@ set(config_module_list drivers/led drivers/px4fmu drivers/boards/px4fmu-v5 - drivers/rgbled + drivers/rgbled_pwm drivers/mpu6000 drivers/mpu9250 drivers/hmc5883 diff --git a/nuttx-configs/px4fmu-v5/nsh/defconfig b/nuttx-configs/px4fmu-v5/nsh/defconfig index 75b70ea38d7..1c64e9e1624 100644 --- a/nuttx-configs/px4fmu-v5/nsh/defconfig +++ b/nuttx-configs/px4fmu-v5/nsh/defconfig @@ -494,7 +494,7 @@ CONFIG_ARCH_BOARD="px4fmu-v5" # Common Board Options # CONFIG_ARCH_HAVE_LEDS=y -CONFIG_ARCH_LEDS=y +CONFIG_ARCH_LEDS=n CONFIG_ARCH_HAVE_BUTTONS=y # CONFIG_ARCH_BUTTONS is not set CONFIG_ARCH_HAVE_IRQBUTTONS=y diff --git a/src/drivers/boards/px4fmu-v5/board_config.h b/src/drivers/boards/px4fmu-v5/board_config.h index 6abb9d657c3..d005bde248a 100644 --- a/src/drivers/boards/px4fmu-v5/board_config.h +++ b/src/drivers/boards/px4fmu-v5/board_config.h @@ -248,6 +248,18 @@ __BEGIN_DECLS #define DIRECT_INPUT_TIMER_CHANNELS 6 +#define BOARD_HAS_LED_PWM +#define BOARD_LED_PWM_DRIVE_ACTIVE_LOW 1 + +#define LED_TIM3_CH1OUT /* PC6 T3C1 GREEN */ GPIO_TIM3_CH1OUT_3 +#define LED_TIM3_CH2OUT /* PC7 T3C2 BLUE */ GPIO_TIM3_CH2OUT_3 +#define LED_TIM3_CH4OUT /* PB1 T3C4 RED */ GPIO_TIM3_CH4OUT_1 + +#define LED_TIM5_CH1OUT /* PH10 T5C1 RED */ GPIO_TIM5_CH1OUT_2 +#define LED_TIM5_CH2OUT /* PH11 T5C2 GREEN */ GPIO_TIM5_CH2OUT_2 +#define LED_TIM5_CH3OUT /* PH12 T5C3 BLUE */ GPIO_TIM5_CH3OUT_2 + + /* User GPIOs * * GPIO0-5 are the PWM servo outputs. diff --git a/src/drivers/boards/px4fmu-v5/px4fmu_led.c b/src/drivers/boards/px4fmu-v5/px4fmu_led.c index d61cb1606c8..c6c44dd947a 100644 --- a/src/drivers/boards/px4fmu-v5/px4fmu_led.c +++ b/src/drivers/boards/px4fmu-v5/px4fmu_led.c @@ -77,7 +77,7 @@ static uint32_t g_ledmap[] = { #else -# define xlat(p) +# define xlat(p) (p) static uint32_t g_ledmap[] = { GPIO_LED_BLUE, // Indexed by LED_BLUE GPIO_LED_RED, // Indexed by LED_RED, LED_AMBER @@ -97,9 +97,9 @@ __EXPORT void led_init(void) static void phy_set_led(int led, bool state) { - /* Drive High to switch on */ + /* Drive Low to switch on */ - stm32_gpiowrite(g_ledmap[led], state); + stm32_gpiowrite(g_ledmap[led], !state); } static bool phy_get_led(int led) diff --git a/src/drivers/boards/px4fmu-v5/px4fmu_timer_config.c b/src/drivers/boards/px4fmu-v5/px4fmu_timer_config.c index 14e34c0904a..cf123a7b11c 100644 --- a/src/drivers/boards/px4fmu-v5/px4fmu_timer_config.c +++ b/src/drivers/boards/px4fmu-v5/px4fmu_timer_config.c @@ -124,3 +124,63 @@ __EXPORT const timer_io_channels_t timer_io_channels[MAX_TIMER_IO_CHANNELS] = { .masks = GTIM_SR_CC3IF | GTIM_SR_CC3OF } }; + +__EXPORT const struct io_timers_t led_pwm_timers[MAX_LED_TIMERS] = { + { + .base = STM32_TIM3_BASE, + .clock_register = STM32_RCC_APB1ENR, + .clock_bit = RCC_APB1ENR_TIM3EN, + .clock_freq = STM32_APB1_TIM3_CLKIN, + .vectorno = 0, + .first_channel_index = 0, + .last_channel_index = 2, + }, + { + .base = STM32_TIM5_BASE, + .clock_register = STM32_RCC_APB1ENR, + .clock_bit = RCC_APB1ENR_TIM5EN, + .clock_freq = STM32_APB1_TIM5_CLKIN, + .vectorno = 0, + .first_channel_index = 3, + .last_channel_index = 5, + } +}; + +__EXPORT const struct timer_io_channels_t led_pwm_channels[MAX_TIMER_LED_CHANNELS] = { + { + .gpio_out = LED_TIM3_CH4OUT, + .gpio_in = 0, + .timer_index = 0, + .timer_channel = 4, + }, + { + .gpio_out = LED_TIM3_CH1OUT, + .gpio_in = 0, + .timer_index = 0, + .timer_channel = 1, + }, + { + .gpio_out = LED_TIM3_CH2OUT, + .gpio_in = 0, + .timer_index = 0, + .timer_channel = 2, + }, + { + .gpio_out = LED_TIM5_CH1OUT, + .gpio_in = 0, + .timer_index = 1, + .timer_channel = 1, + }, + { + .gpio_out = LED_TIM5_CH2OUT, + .gpio_in = 0, + .timer_index = 1, + .timer_channel = 2, + }, + { + .gpio_out = LED_TIM5_CH3OUT, + .gpio_in = 0, + .timer_index = 1, + .timer_channel = 3, + } +};