From 99f19dd809d178fd0bcd739a8d9ad68329307814 Mon Sep 17 00:00:00 2001 From: Alessio Morale Date: Sat, 26 Apr 2014 19:48:44 +0200 Subject: [PATCH] OP-1312 Make WS2811 driver configurable. Now output pin may be chosen among all servo outputs and Flexi-io pins 3 and 4 (they are not used for PWM input/output) --- .../targets/boards/revolution/board_hw_defs.c | 81 +++++++++++++++++-- .../boards/revolution/firmware/pios_board.c | 8 +- shared/uavobjectdefinition/hwsettings.xml | 1 + 3 files changed, 81 insertions(+), 9 deletions(-) diff --git a/flight/targets/boards/revolution/board_hw_defs.c b/flight/targets/boards/revolution/board_hw_defs.c index 716d4745b..9a48b2cb8 100644 --- a/flight/targets/boards/revolution/board_hw_defs.c +++ b/flight/targets/boards/revolution/board_hw_defs.c @@ -1965,23 +1965,88 @@ const struct pios_usb_hid_cfg pios_usb_hid_cfg = { #ifdef PIOS_INCLUDE_WS2811 #include +#include #define PIOS_WS2811_TIM_DIVIDER (PIOS_PERIPHERAL_APB2_CLOCK / (800000 * PIOS_WS2811_TIM_PERIOD)) void DMA2_Stream1_IRQHandler(void) __attribute__((alias("PIOS_WS2811_irq_handler"))); -const struct pios_ws2811_pin_cfg pios_ws2811_pin_cfg = { - .gpio = GPIOA, - .gpioInit = { - .GPIO_Pin = GPIO_Pin_3, - .GPIO_Speed = GPIO_Speed_50MHz, - .GPIO_Mode = GPIO_Mode_OUT, - .GPIO_OType = GPIO_OType_PP, +const struct pios_ws2811_pin_cfg pios_ws2811_pin_cfg[] = { + [HWSETTINGS_WS2811LED_OUT_SERVOOUT1] = { + .gpio = GPIOB, + .gpioInit = { + .GPIO_Pin = GPIO_Pin_0, + .GPIO_Speed = GPIO_Speed_25MHz, + .GPIO_Mode = GPIO_Mode_OUT, + .GPIO_OType = GPIO_OType_PP, + }, + }, + [HWSETTINGS_WS2811LED_OUT_SERVOOUT2] = { + .gpio = GPIOB, + .gpioInit = { + .GPIO_Pin = GPIO_Pin_1, + .GPIO_Speed = GPIO_Speed_25MHz, + .GPIO_Mode = GPIO_Mode_OUT, + .GPIO_OType = GPIO_OType_PP, + }, + }, + [HWSETTINGS_WS2811LED_OUT_SERVOOUT3] = { + .gpio = GPIOA, + .gpioInit = { + .GPIO_Pin = GPIO_Pin_3, + .GPIO_Speed = GPIO_Speed_25MHz, + .GPIO_Mode = GPIO_Mode_OUT, + .GPIO_OType = GPIO_OType_PP, + }, + }, + [HWSETTINGS_WS2811LED_OUT_SERVOOUT4] = { + .gpio = GPIOA, + .gpioInit = { + .GPIO_Pin = GPIO_Pin_2, + .GPIO_Speed = GPIO_Speed_25MHz, + .GPIO_Mode = GPIO_Mode_OUT, + .GPIO_OType = GPIO_OType_PP, + }, + }, + [HWSETTINGS_WS2811LED_OUT_SERVOOUT5] = { + .gpio = GPIOA, + .gpioInit = { + .GPIO_Pin = GPIO_Pin_1, + .GPIO_Speed = GPIO_Speed_25MHz, + .GPIO_Mode = GPIO_Mode_OUT, + .GPIO_OType = GPIO_OType_PP, + }, + }, + [HWSETTINGS_WS2811LED_OUT_SERVOOUT6] = { + .gpio = GPIOA, + .gpioInit = { + .GPIO_Pin = GPIO_Pin_0, + .GPIO_Speed = GPIO_Speed_25MHz, + .GPIO_Mode = GPIO_Mode_OUT, + .GPIO_OType = GPIO_OType_PP, + }, + }, + [HWSETTINGS_WS2811LED_OUT_FLEXIPIN3] = { + .gpio = GPIOB, + .gpioInit = { + .GPIO_Pin = GPIO_Pin_12, + .GPIO_Speed = GPIO_Speed_25MHz, + .GPIO_Mode = GPIO_Mode_OUT, + .GPIO_OType = GPIO_OType_PP, + }, + }, + [HWSETTINGS_WS2811LED_OUT_FLEXIPIN4] = { + .gpio = GPIOB, + .gpioInit = { + .GPIO_Pin = GPIO_Pin_13, + .GPIO_Speed = GPIO_Speed_25MHz, + .GPIO_Mode = GPIO_Mode_OUT, + .GPIO_OType = GPIO_OType_PP, + }, }, }; const struct pios_ws2811_cfg pios_ws2811_cfg = { // master mode selection Note: configure TIM_CR2_MMS_2 master mode selection - .timer = TIM1, .timerInit = { .TIM_Prescaler = PIOS_WS2811_TIM_DIVIDER - 1, diff --git a/flight/targets/boards/revolution/firmware/pios_board.c b/flight/targets/boards/revolution/firmware/pios_board.c index fd31d4f1c..0c03f2a38 100644 --- a/flight/targets/boards/revolution/firmware/pios_board.c +++ b/flight/targets/boards/revolution/firmware/pios_board.c @@ -949,7 +949,13 @@ void PIOS_Board_Init(void) #ifdef PIOS_INCLUDE_WS2811 #include - PIOS_WS2811_Init(&pios_ws2811_cfg, &pios_ws2811_pin_cfg); + HwSettingsWS2811LED_OutOptions ws2811_pin_settings; + HwSettingsWS2811LED_OutGet(&ws2811_pin_settings); + + if (ws2811_pin_settings != HWSETTINGS_WS2811LED_OUT_DISABLED && ws2811_pin_settings < NELEMENTS(pios_ws2811_pin_cfg)) { + PIOS_WS2811_Init(&pios_ws2811_cfg, &pios_ws2811_pin_cfg[ws2811_pin_settings]); + } + #endif // PIOS_INCLUDE_WS2811 } diff --git a/shared/uavobjectdefinition/hwsettings.xml b/shared/uavobjectdefinition/hwsettings.xml index a1bc068e8..f005a31ab 100644 --- a/shared/uavobjectdefinition/hwsettings.xml +++ b/shared/uavobjectdefinition/hwsettings.xml @@ -25,6 +25,7 @@ +