chore(radio): save some ram in radios with RGB LEDs (#5973)

Co-authored-by: 3djc <3djc@gh.com>
Co-authored-by: Risto <rotorman@users.noreply.github.com>
This commit is contained in:
3djc
2025-03-11 12:04:12 +10:00
committed by GitHub
co-authored by 3djc Risto
parent 538c5fcf40
commit 5bb7612040
8 changed files with 50 additions and 60 deletions
+17 -2
View File
@@ -36,6 +36,8 @@
#include <FreeRTOS/include/timers.h> #include <FreeRTOS/include/timers.h>
#endif #endif
static uint8_t _led_colors[WS2812_BYTES_PER_LED * LED_STRIP_LENGTH];
extern const stm32_pulse_timer_t _led_timer; extern const stm32_pulse_timer_t _led_timer;
static TimerHandle_t rgbLedTimer = nullptr; static TimerHandle_t rgbLedTimer = nullptr;
@@ -55,7 +57,6 @@ uint32_t rgbGetLedColor(uint8_t led)
return ws2812_get_color(led); return ws2812_get_color(led);
} }
bool rgbGetState(uint8_t led) bool rgbGetState(uint8_t led)
{ {
return ws2812_get_state(led); return ws2812_get_state(led);
@@ -63,7 +64,15 @@ bool rgbGetState(uint8_t led)
void rgbLedColorApply() void rgbLedColorApply()
{ {
ws2812_update(&_led_timer);; ws2812_update(&_led_timer);
}
void rgbLedClearAll()
{
for (uint8_t i = 0; i < LED_STRIP_LENGTH; i++) {
ws2812_set_color(i, 0, 0, 0);
}
ws2812_update(&_led_timer);
} }
static void rgbLedTimerCb(TimerHandle_t xTimer) static void rgbLedTimerCb(TimerHandle_t xTimer)
@@ -111,6 +120,12 @@ const stm32_pulse_timer_t _led_timer = {
.DMA_TC_CallbackPtr = nullptr, .DMA_TC_CallbackPtr = nullptr,
}; };
void rgbLedInit()
{
ws2812_init(&_led_timer, _led_colors, LED_STRIP_LENGTH, WS2812_GRB);
rgbLedClearAll();
}
// Make sure the timer channel is supported // Make sure the timer channel is supported
static_assert(__STM32_PULSE_IS_TIMER_CHANNEL_SUPPORTED(LED_STRIP_TIMER_CHANNEL), static_assert(__STM32_PULSE_IS_TIMER_CHANNEL_SUPPORTED(LED_STRIP_TIMER_CHANNEL),
"Unsupported timer channel"); "Unsupported timer channel");
+9 -2
View File
@@ -21,9 +21,16 @@
#pragma once #pragma once
#include <stdint.h>
void rgbLedInit();
void rgbLedStart(); void rgbLedStart();
void rgbLedStop(); void rgbLedStop();
void rgbSetLedColor(unsigned char, unsigned char, unsigned char, unsigned char);
void rgbSetLedColor(uint8_t led, uint8_t r, uint8_t g, uint8_t b);
uint32_t rgbGetLedColor(uint8_t led); uint32_t rgbGetLedColor(uint8_t led);
bool rgbGetState(unsigned char);
void rgbLedClearAll();
bool rgbGetState(uint8_t led);
void rgbLedColorApply(); void rgbLedColorApply();
@@ -32,10 +32,7 @@
#include <string.h> #include <string.h>
// Pixel values // Pixel values
static uint8_t _led_colors[WS2812_BYTES_PER_LED * WS2812_MAX_LEDS]; static uint8_t* _led_colors = nullptr;
// Timer used
// static const stm32_pulse_timer_t* _led_timer;
// LED strip length // LED strip length
static uint8_t _led_strip_len; static uint8_t _led_strip_len;
@@ -200,20 +197,17 @@ static void _init_timer(const stm32_pulse_timer_t* tim)
NVIC_SetPriority(tim->DMA_IRQn, WS2812_DMA_IRQ_PRIO); NVIC_SetPriority(tim->DMA_IRQn, WS2812_DMA_IRQ_PRIO);
} }
void ws2812_init(const stm32_pulse_timer_t* timer, uint8_t strip_len, uint8_t type) void ws2812_init(const stm32_pulse_timer_t* timer, uint8_t* strip_colors,
uint8_t strip_len, uint8_t type)
{ {
WS2812_DBG_INIT; WS2812_DBG_INIT;
pulse_inc = IS_TIM_32B_COUNTER_INSTANCE(timer->TIMx) ? 2 : 1; pulse_inc = IS_TIM_32B_COUNTER_INSTANCE(timer->TIMx) ? 2 : 1;
memset(_led_colors, 0, sizeof(_led_colors)); _led_colors = strip_colors;
_led_strip_len = strip_len;
memset(_led_colors, 0, strip_len * WS2812_BYTES_PER_LED);
memset(_led_dma_buffer, 0, sizeof(_led_dma_buffer)); memset(_led_dma_buffer, 0, sizeof(_led_dma_buffer));
if (strip_len <= WS2812_MAX_LEDS) {
_led_strip_len = strip_len;
} else {
_led_strip_len = WS2812_MAX_LEDS;
}
_r_offset = (type >> 4) & 0b11; _r_offset = (type >> 4) & 0b11;
_g_offset = (type >> 2) & 0b11; _g_offset = (type >> 2) & 0b11;
_b_offset = type & 0b11; _b_offset = type & 0b11;
@@ -30,17 +30,13 @@
// RGB // RGB
#define WS2812_BYTES_PER_LED 3 #define WS2812_BYTES_PER_LED 3
// Maximum number of supported LEDs
#if !defined(WS2812_MAX_LEDS)
# define WS2812_MAX_LEDS 48
#endif
// Number of LED periods used for trailing reset // Number of LED periods used for trailing reset
#if !defined(WS2812_TRAILING_RESET) #if !defined(WS2812_TRAILING_RESET)
# define WS2812_TRAILING_RESET 10 # define WS2812_TRAILING_RESET 10
#endif #endif
void ws2812_init(const stm32_pulse_timer_t* timer, uint8_t strip_len, uint8_t type); void ws2812_init(const stm32_pulse_timer_t* timer, uint8_t* strip_colors,
uint8_t strip_len, uint8_t type);
void ws2812_update(const stm32_pulse_timer_t* timer); void ws2812_update(const stm32_pulse_timer_t* timer);
bool ws2812_get_state(uint8_t led); bool ws2812_get_state(uint8_t led);
void ws2812_dma_isr(const stm32_pulse_timer_t* timer); void ws2812_dma_isr(const stm32_pulse_timer_t* timer);
+5 -18
View File
@@ -57,19 +57,6 @@
#include "csd203_sensor.h" #include "csd203_sensor.h"
#endif #endif
#if defined(LED_STRIP_GPIO)
// Common LED driver
extern const stm32_pulse_timer_t _led_timer;
void ledStripOff()
{
for (uint8_t i = 0; i < LED_STRIP_LENGTH; i++) {
ws2812_set_color(i, 0, 0, 0);
}
ws2812_update(&_led_timer);
}
#endif
HardwareOptions hardwareOptions; HardwareOptions hardwareOptions;
bool boardBacklightOn = false; bool boardBacklightOn = false;
@@ -144,12 +131,13 @@ uint16_t getSixPosAnalogValue(uint16_t adcValue)
} }
if (dirty) { if (dirty) {
for (uint8_t i = 0; i < 6; i++) { for (uint8_t i = 0; i < 6; i++) {
if (i == sixPosState) if (i == sixPosState) {
ws2812_set_color(i, SIXPOS_LED_RED, SIXPOS_LED_GREEN, SIXPOS_LED_BLUE); ws2812_set_color(i, SIXPOS_LED_RED, SIXPOS_LED_GREEN, SIXPOS_LED_BLUE);
else } else {
ws2812_set_color(i, 0, 0, 0); ws2812_set_color(i, 0, 0, 0);
}
} }
ws2812_update(&_led_timer); rgbLedColorApply();
} }
return (4096/5)*(sixPosState); return (4096/5)*(sixPosState);
} }
@@ -232,8 +220,7 @@ void boardInit()
hapticInit(); hapticInit();
#if defined(LED_STRIP_GPIO) #if defined(LED_STRIP_GPIO)
ws2812_init(&_led_timer, LED_STRIP_LENGTH, WS2812_GRB); rgbLedInit();
ledStripOff();
#endif #endif
#if defined(BLUETOOTH) #if defined(BLUETOOTH)
+1 -2
View File
@@ -234,8 +234,7 @@ void boardInit()
usbInit(); usbInit();
#if defined(LED_STRIP_GPIO) #if defined(LED_STRIP_GPIO)
ws2812_init(&_led_timer, LED_STRIP_LENGTH, WS2812_GRB); rgbLedInit();
ledStripOff();
#endif #endif
uint32_t press_start = 0; uint32_t press_start = 0;
+2 -10
View File
@@ -62,10 +62,6 @@
HardwareOptions hardwareOptions; HardwareOptions hardwareOptions;
#if defined(LED_STRIP_GPIO)
extern const stm32_pulse_timer_t _led_timer;
#endif
#if !defined(BOOT) #if !defined(BOOT)
#if defined(FUNCTION_SWITCHES) #if defined(FUNCTION_SWITCHES)
@@ -104,7 +100,7 @@ uint16_t getSixPosAnalogValue(uint16_t adcValue)
else else
ws2812_set_color(i, 0, 0, 0); ws2812_set_color(i, 0, 0, 0);
} }
ws2812_update(&_led_timer); rgbLedColorApply();
} }
return (4096/5)*(sixPosState); return (4096/5)*(sixPosState);
} }
@@ -244,11 +240,7 @@ void boardInit()
usbInit(); usbInit();
#if defined(LED_STRIP_GPIO) #if defined(LED_STRIP_GPIO)
ws2812_init(&_led_timer, LED_STRIP_LENGTH, WS2812_GRB); rgbLedInit();
for (uint8_t i = 0; i < LED_STRIP_LENGTH; i++) {
ws2812_set_color(i, 0, 0, 50);
}
ws2812_update(&_led_timer);
#endif #endif
#if defined(HAPTIC) #if defined(HAPTIC)
+5 -5
View File
@@ -1963,11 +1963,11 @@
// LED Strip // LED Strip
#if defined(RGBLEDS) #if defined(RGBLEDS)
#if defined(RADIO_GX12) #if defined(RADIO_GX12)
#define LED_STRIP_LENGTH 8 #define LED_STRIP_LENGTH 8
#else #else
#define LED_STRIP_LENGTH 7 #define LED_STRIP_LENGTH 7
#endif #endif
#define LED_STRIP_GPIO GPIO_PIN(GPIOA, 8) // PA.08 / TIM1_CH1 #define LED_STRIP_GPIO GPIO_PIN(GPIOA, 8) // PA.08 / TIM1_CH1
#define LED_STRIP_GPIO_AF LL_GPIO_AF_1 // TIM1 / TIM2 #define LED_STRIP_GPIO_AF LL_GPIO_AF_1 // TIM1 / TIM2
#define LED_STRIP_TIMER TIM1 #define LED_STRIP_TIMER TIM1