chore: common led driver (#6927)

This commit is contained in:
3djc
2026-01-05 11:17:46 +10:00
committed by GitHub
parent 55d0455277
commit a9f86dc001
14 changed files with 30 additions and 560 deletions
+1 -1
View File
@@ -144,7 +144,7 @@ set(CMSIS_SRC ${TARGET_SRC_DIR}/system_clock.c)
add_library(board OBJECT EXCLUDE_FROM_ALL
${BOARD_COMMON_SRC}
${TARGET_SRC_DIR}/led_driver.cpp
${TARGET_SRC_DIR}/battery_driver.cpp
${TARGET_SRC_DIR}/battery_driver.cpp
targets/common/arm/stm32/audio_dac_driver.cpp
targets/common/arm/stm32/heartbeat_driver.cpp
targets/common/arm/stm32/lsm6ds_driver.cpp
-60
View File
@@ -26,42 +26,11 @@
#include "boards/generic_stm32/rgb_leds.h"
#include "board.h"
#if defined(LED_STRIP_GPIO)
#include "boards/generic_stm32/rgb_leds.h"
#endif
#define GET_RED(color) (((color) & 0xF80000) >>16)
#define GET_GREEN(color) (((color) & 0x000F800) >> 8)
#define GET_BLUE(color) (((color) & 0xF8))
#if defined(FUNCTION_SWITCHES) && !defined(FUNCTION_SWITCHES_RGB_LEDS)
static const uint32_t fsLeds[] = {FSLED_GPIO_PIN_1, FSLED_GPIO_PIN_2,
FSLED_GPIO_PIN_3, FSLED_GPIO_PIN_4,
FSLED_GPIO_PIN_5, FSLED_GPIO_PIN_6};
#endif
void ledInit()
{
#if defined(LED_GREEN_GPIO)
gpio_init(LED_GREEN_GPIO, GPIO_OUT, GPIO_PIN_SPEED_LOW);
#endif
#if defined(LED_RED_GPIO)
gpio_init(LED_RED_GPIO, GPIO_OUT, GPIO_PIN_SPEED_LOW);
#endif
#if defined(LED_BLUE_GPIO)
gpio_init(LED_BLUE_GPIO, GPIO_OUT, GPIO_PIN_SPEED_LOW);
#endif
#if defined(FUNCTION_SWITCHES) && !defined(FUNCTION_SWITCHES_RGB_LEDS)
for (size_t i = 0; i < DIM(fsLeds); i++) {
gpio_init(fsLeds[i], GPIO_OUT, GPIO_PIN_SPEED_LOW);
}
#endif
}
#if defined(FUNCTION_SWITCHES_RGB_LEDS)
// used to map switch number to led number in the rgbled chain
uint8_t ledMapping[] = {4, 6, 0, 2};
@@ -73,35 +42,6 @@ void fsLedRGB(uint8_t index, uint32_t color)
GET_GREEN(color),GET_BLUE(color));
}
uint32_t fsGetLedRGB(uint8_t index)
{
return rgbGetLedColor(ledMapping[index]);
}
uint8_t getRGBColorIndex(uint32_t color)
{
for (uint8_t i = 0; i < (sizeof(colorTable) / sizeof(colorTable[0])); i++) {
if (color == colorTable[i])
return(i);
}
return 5; // Custom value set with Companion
}
#elif defined(FUNCTION_SWITCHES)
void fsLedOff(uint8_t index)
{
gpio_clear(fsLeds[index]);
}
void fsLedOn(uint8_t index)
{
gpio_set(fsLeds[index]);
}
bool fsLedState(uint8_t index)
{
return gpio_read(fsLeds[index]) ? true : false;
}
#endif
void ledOff()
{
ws2812_set_color(8, 0, 0, 0);