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
@@ -32,10 +32,7 @@
#include <string.h>
// Pixel values
static uint8_t _led_colors[WS2812_BYTES_PER_LED * WS2812_MAX_LEDS];
// Timer used
// static const stm32_pulse_timer_t* _led_timer;
static uint8_t* _led_colors = nullptr;
// LED strip length
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);
}
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;
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));
if (strip_len <= WS2812_MAX_LEDS) {
_led_strip_len = strip_len;
} else {
_led_strip_len = WS2812_MAX_LEDS;
}
_r_offset = (type >> 4) & 0b11;
_g_offset = (type >> 2) & 0b11;
_b_offset = type & 0b11;
@@ -30,20 +30,16 @@
// RGB
#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
#if !defined(WS2812_TRAILING_RESET)
# define WS2812_TRAILING_RESET 10
#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);
bool ws2812_get_state(uint8_t led);
void ws2812_dma_isr(const stm32_pulse_timer_t* timer);
void ws2812_set_color(uint8_t led, uint8_t r, uint8_t g, uint8_t b);
uint32_t ws2812_get_color(uint8_t led);
uint32_t ws2812_get_color(uint8_t led);
+5 -18
View File
@@ -57,19 +57,6 @@
#include "csd203_sensor.h"
#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;
bool boardBacklightOn = false;
@@ -144,12 +131,13 @@ uint16_t getSixPosAnalogValue(uint16_t adcValue)
}
if (dirty) {
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);
else
} else {
ws2812_set_color(i, 0, 0, 0);
}
}
ws2812_update(&_led_timer);
rgbLedColorApply();
}
return (4096/5)*(sixPosState);
}
@@ -232,8 +220,7 @@ void boardInit()
hapticInit();
#if defined(LED_STRIP_GPIO)
ws2812_init(&_led_timer, LED_STRIP_LENGTH, WS2812_GRB);
ledStripOff();
rgbLedInit();
#endif
#if defined(BLUETOOTH)
+1 -2
View File
@@ -234,8 +234,7 @@ void boardInit()
usbInit();
#if defined(LED_STRIP_GPIO)
ws2812_init(&_led_timer, LED_STRIP_LENGTH, WS2812_GRB);
ledStripOff();
rgbLedInit();
#endif
uint32_t press_start = 0;
+2 -10
View File
@@ -62,10 +62,6 @@
HardwareOptions hardwareOptions;
#if defined(LED_STRIP_GPIO)
extern const stm32_pulse_timer_t _led_timer;
#endif
#if !defined(BOOT)
#if defined(FUNCTION_SWITCHES)
@@ -104,7 +100,7 @@ uint16_t getSixPosAnalogValue(uint16_t adcValue)
else
ws2812_set_color(i, 0, 0, 0);
}
ws2812_update(&_led_timer);
rgbLedColorApply();
}
return (4096/5)*(sixPosState);
}
@@ -244,11 +240,7 @@ void boardInit()
usbInit();
#if defined(LED_STRIP_GPIO)
ws2812_init(&_led_timer, LED_STRIP_LENGTH, WS2812_GRB);
for (uint8_t i = 0; i < LED_STRIP_LENGTH; i++) {
ws2812_set_color(i, 0, 0, 50);
}
ws2812_update(&_led_timer);
rgbLedInit();
#endif
#if defined(HAPTIC)
+5 -5
View File
@@ -1963,11 +1963,11 @@
// LED Strip
#if defined(RGBLEDS)
#if defined(RADIO_GX12)
#define LED_STRIP_LENGTH 8
#else
#define LED_STRIP_LENGTH 7
#endif
#if defined(RADIO_GX12)
#define LED_STRIP_LENGTH 8
#else
#define LED_STRIP_LENGTH 7
#endif
#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_TIMER TIM1