From 8c9ed2d43786943e3bff4063906aba41e934bdaa Mon Sep 17 00:00:00 2001 From: blckmn Date: Wed, 9 Nov 2016 09:58:21 +1100 Subject: [PATCH 1/4] Small tidy of LED code --- src/main/drivers/light_ws2811strip.c | 5 +++ src/main/drivers/light_ws2811strip.h | 33 ++++++++++++------- src/main/drivers/light_ws2811strip_hal.c | 6 ++-- .../drivers/light_ws2811strip_stm32f10x.c | 6 ---- .../drivers/light_ws2811strip_stm32f30x.c | 6 ---- .../drivers/light_ws2811strip_stm32f4xx.c | 6 ---- 6 files changed, 29 insertions(+), 33 deletions(-) diff --git a/src/main/drivers/light_ws2811strip.c b/src/main/drivers/light_ws2811strip.c index 149c9b6129..15607cd346 100644 --- a/src/main/drivers/light_ws2811strip.c +++ b/src/main/drivers/light_ws2811strip.c @@ -89,6 +89,11 @@ void ws2811LedStripInit(ioTag_t ioTag) { memset(&ledStripDMABuffer, 0, WS2811_DMA_BUFFER_SIZE); ws2811LedStripHardwareInit(ioTag); + + const hsvColor_t hsv_white = { 0, 255, 255}; + setStripColor(&hsv_white); + ws2811UpdateStrip(); + ws2811UpdateStrip(); } diff --git a/src/main/drivers/light_ws2811strip.h b/src/main/drivers/light_ws2811strip.h index 894ef4b1d6..2a1f708e7f 100644 --- a/src/main/drivers/light_ws2811strip.h +++ b/src/main/drivers/light_ws2811strip.h @@ -19,23 +19,34 @@ #include "io_types.h" -#define WS2811_LED_STRIP_LENGTH 32 -#define WS2811_BITS_PER_LED 24 -#define WS2811_DELAY_BUFFER_LENGTH 42 // for 50us delay +#define WS2811_LED_STRIP_LENGTH 32 +#define WS2811_BITS_PER_LED 24 +// for 50us delay +#define WS2811_DELAY_BUFFER_LENGTH 42 #define WS2811_DATA_BUFFER_SIZE (WS2811_BITS_PER_LED * WS2811_LED_STRIP_LENGTH) - -#define WS2811_DMA_BUFFER_SIZE (WS2811_DATA_BUFFER_SIZE + WS2811_DELAY_BUFFER_LENGTH) // number of bytes needed is #LEDs * 24 bytes + 42 trailing bytes) +// number of bytes needed is #LEDs * 24 bytes + 42 trailing bytes) +#define WS2811_DMA_BUFFER_SIZE (WS2811_DATA_BUFFER_SIZE + WS2811_DELAY_BUFFER_LENGTH) #if defined(STM32F40_41xxx) -#define BIT_COMPARE_1 67 // timer compare value for logical 1 -#define BIT_COMPARE_0 33 // timer compare value for logical 0 +#define WS2811_TIMER_HZ 84000000 +#define WS2811_TIMER_PERIOD 104 +// timer compare value for logical 1 +#define BIT_COMPARE_1 67 +// timer compare value for logical 0 +#define BIT_COMPARE_0 33 #elif defined(STM32F7) -#define BIT_COMPARE_1 76 // timer compare value for logical 1 -#define BIT_COMPARE_0 38 // timer compare value for logical 0 +// timer compare value for logical 1 +#define BIT_COMPARE_1 76 +// timer compare value for logical 0 +#define BIT_COMPARE_0 38 #else -#define BIT_COMPARE_1 17 // timer compare value for logical 1 -#define BIT_COMPARE_0 9 // timer compare value for logical 0 +#define WS2811_TIMER_HZ 24000000 +#define WS2811_TIMER_PERIOD 29 +// timer compare value for logical 1 +#define BIT_COMPARE_1 17 +// timer compare value for logical 0 +#define BIT_COMPARE_0 9 #endif void ws2811LedStripInit(ioTag_t ioTag); diff --git a/src/main/drivers/light_ws2811strip_hal.c b/src/main/drivers/light_ws2811strip_hal.c index 5d8e4cd0c2..260b9b374d 100644 --- a/src/main/drivers/light_ws2811strip_hal.c +++ b/src/main/drivers/light_ws2811strip_hal.c @@ -131,9 +131,7 @@ void ws2811LedStripHardwareInit(ioTag_t ioTag) return; } - const hsvColor_t hsv_white = { 0, 255, 255}; ws2811Initialised = true; - setStripColor(&hsv_white); } @@ -145,9 +143,9 @@ void ws2811LedStripDMAEnable(void) return; } - if( HAL_TIM_PWM_Start_DMA(&TimHandle, timerChannel, ledStripDMABuffer, WS2811_DMA_BUFFER_SIZE) != HAL_OK) + if (HAL_TIM_PWM_Start_DMA(&TimHandle, timerChannel, ledStripDMABuffer, WS2811_DMA_BUFFER_SIZE) != HAL_OK) { - /* Starting PWM generation Error */ + /* Starting PWM generation Error */ ws2811LedDataTransferInProgress = 0; return; } diff --git a/src/main/drivers/light_ws2811strip_stm32f10x.c b/src/main/drivers/light_ws2811strip_stm32f10x.c index 1933e0a1c8..e0bb9656fc 100644 --- a/src/main/drivers/light_ws2811strip_stm32f10x.c +++ b/src/main/drivers/light_ws2811strip_stm32f10x.c @@ -30,9 +30,6 @@ #include "rcc.h" #include "timer.h" -#define WS2811_TIMER_HZ 24000000 -#define WS2811_TIMER_PERIOD 29 - static IO_t ws2811IO = IO_NONE; bool ws2811Initialised = false; static DMA_Channel_TypeDef *dmaChannel = NULL; @@ -116,10 +113,7 @@ void ws2811LedStripHardwareInit(ioTag_t ioTag) DMA_ITConfig(dmaChannel, DMA_IT_TC, ENABLE); dmaSetHandler(timerHardware->dmaIrqHandler, WS2811_DMA_IRQHandler, NVIC_PRIO_WS2811_DMA, 0); - const hsvColor_t hsv_white = { 0, 255, 255}; ws2811Initialised = true; - setStripColor(&hsv_white); - ws2811UpdateStrip(); } void ws2811LedStripDMAEnable(void) diff --git a/src/main/drivers/light_ws2811strip_stm32f30x.c b/src/main/drivers/light_ws2811strip_stm32f30x.c index ffb6269d85..0165241f53 100644 --- a/src/main/drivers/light_ws2811strip_stm32f30x.c +++ b/src/main/drivers/light_ws2811strip_stm32f30x.c @@ -31,9 +31,6 @@ #include "rcc.h" #include "timer.h" -#define WS2811_TIMER_HZ 24000000 -#define WS2811_TIMER_PERIOD 29 - static IO_t ws2811IO = IO_NONE; bool ws2811Initialised = false; static DMA_Channel_TypeDef *dmaChannel = NULL; @@ -126,10 +123,7 @@ void ws2811LedStripHardwareInit(ioTag_t ioTag) DMA_ITConfig(dmaChannel, DMA_IT_TC, ENABLE); dmaSetHandler(timerHardware->dmaIrqHandler, WS2811_DMA_IRQHandler, NVIC_PRIO_WS2811_DMA, 0); - const hsvColor_t hsv_white = { 0, 255, 255}; ws2811Initialised = true; - setStripColor(&hsv_white); - ws2811UpdateStrip(); } void ws2811LedStripDMAEnable(void) diff --git a/src/main/drivers/light_ws2811strip_stm32f4xx.c b/src/main/drivers/light_ws2811strip_stm32f4xx.c index 4fd38325ee..e2b7d1dbfa 100644 --- a/src/main/drivers/light_ws2811strip_stm32f4xx.c +++ b/src/main/drivers/light_ws2811strip_stm32f4xx.c @@ -33,9 +33,6 @@ #include "timer_stm32f4xx.h" #include "io.h" -#define WS2811_TIMER_HZ 84000000 -#define WS2811_TIMER_PERIOD 104 - static IO_t ws2811IO = IO_NONE; bool ws2811Initialised = false; static DMA_Stream_TypeDef *stream = NULL; @@ -140,10 +137,7 @@ void ws2811LedStripHardwareInit(ioTag_t ioTag) dmaSetHandler(timerHardware->dmaIrqHandler, WS2811_DMA_IRQHandler, NVIC_PRIO_WS2811_DMA, 0); - const hsvColor_t hsv_white = { 0, 255, 255 }; ws2811Initialised = true; - setStripColor(&hsv_white); - ws2811UpdateStrip(); } void ws2811LedStripDMAEnable(void) From 3fbe5cf8a643e59440fa661003d2a31993b91ffa Mon Sep 17 00:00:00 2001 From: blckmn Date: Wed, 9 Nov 2016 17:47:10 +1100 Subject: [PATCH 2/4] Fix NAZE LED hard fault --- src/main/drivers/light_ws2811strip_stm32f10x.c | 1 + src/main/drivers/light_ws2811strip_stm32f30x.c | 3 +-- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/drivers/light_ws2811strip_stm32f10x.c b/src/main/drivers/light_ws2811strip_stm32f10x.c index e0bb9656fc..bb191b226f 100644 --- a/src/main/drivers/light_ws2811strip_stm32f10x.c +++ b/src/main/drivers/light_ws2811strip_stm32f10x.c @@ -90,6 +90,7 @@ void ws2811LedStripHardwareInit(ioTag_t ioTag) /* configure DMA */ /* DMA1 Channel6 Config */ + dmaChannel = timerHardware->dmaChannel; DMA_DeInit(dmaChannel); DMA_StructInit(&DMA_InitStructure); diff --git a/src/main/drivers/light_ws2811strip_stm32f30x.c b/src/main/drivers/light_ws2811strip_stm32f30x.c index 0165241f53..5de0390dbf 100644 --- a/src/main/drivers/light_ws2811strip_stm32f30x.c +++ b/src/main/drivers/light_ws2811strip_stm32f30x.c @@ -97,10 +97,9 @@ void ws2811LedStripHardwareInit(ioTag_t ioTag) TIM_CtrlPWMOutputs(timer, ENABLE); - dmaChannel = timerHardware->dmaChannel; - /* configure DMA */ /* DMA1 Channel Config */ + dmaChannel = timerHardware->dmaChannel; DMA_DeInit(dmaChannel); DMA_StructInit(&DMA_InitStructure); From b1844eb5f90bd2d8ea5eff8c50499acf5f99843e Mon Sep 17 00:00:00 2001 From: blckmn Date: Wed, 9 Nov 2016 18:46:01 +1100 Subject: [PATCH 3/4] Removed double up, and remove 4way interface so BEEBRAIN fits. --- src/main/drivers/light_ws2811strip.c | 2 -- src/main/target/NAZE/target.h | 2 ++ 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/drivers/light_ws2811strip.c b/src/main/drivers/light_ws2811strip.c index 15607cd346..ad10af7173 100644 --- a/src/main/drivers/light_ws2811strip.c +++ b/src/main/drivers/light_ws2811strip.c @@ -93,8 +93,6 @@ void ws2811LedStripInit(ioTag_t ioTag) const hsvColor_t hsv_white = { 0, 255, 255}; setStripColor(&hsv_white); ws2811UpdateStrip(); - - ws2811UpdateStrip(); } bool isWS2811LedStripReady(void) diff --git a/src/main/target/NAZE/target.h b/src/main/target/NAZE/target.h index d1d09f6043..8a37117e10 100644 --- a/src/main/target/NAZE/target.h +++ b/src/main/target/NAZE/target.h @@ -157,7 +157,9 @@ // USART2, PA3 #define BIND_PIN PA3 +#if !defined(BEEBRAIN) #define USE_SERIAL_4WAY_BLHELI_INTERFACE +#endif #define DEFAULT_RX_FEATURE FEATURE_RX_PPM From 0a1f940bcb926d998afd444c58c98d15efcf7d40 Mon Sep 17 00:00:00 2001 From: blckmn Date: Wed, 9 Nov 2016 20:07:13 +1100 Subject: [PATCH 4/4] Adjusted as per suggestion - could be other future brushed motor FCs based on NAZE --- src/main/target/NAZE/target.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/target/NAZE/target.h b/src/main/target/NAZE/target.h index 8a37117e10..f048215e40 100644 --- a/src/main/target/NAZE/target.h +++ b/src/main/target/NAZE/target.h @@ -157,7 +157,7 @@ // USART2, PA3 #define BIND_PIN PA3 -#if !defined(BEEBRAIN) +#if !defined(BRUSHED_MOTORS) #define USE_SERIAL_4WAY_BLHELI_INTERFACE #endif