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
@@ -33,6 +33,7 @@ set(BOARD_LIB_SRC
boards/generic_stm32/bor_level.cpp
boards/generic_stm32/rgb_leds.cpp
boards/generic_stm32/battery_voltage.cpp
boards/generic_stm32/led_driver.cpp
)
add_library(minimal_board_lib OBJECT EXCLUDE_FROM_ALL ${MINIMAL_BOARD_LIB_SRC})
@@ -28,17 +28,24 @@
#include "stm32_ws2812.h"
#endif
#define __weak __attribute__((weak))
#define GET_RED(color) (((color) & 0xFF0000) >>16)
#define GET_GREEN(color) (((color) & 0x00FF00) >> 8)
#define GET_BLUE(color) ((color) & 0x0000FF)
#if !defined(GPIO_LED_GPIO_ON)
#define GPIO_LED_GPIO_ON gpio_set
#define GPIO_LED_GPIO_OFF gpio_clear
#endif
#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()
__weak void ledInit()
{
#if defined(LED_GREEN_GPIO)
gpio_init(LED_GREEN_GPIO, GPIO_OUT, GPIO_PIN_SPEED_LOW);
@@ -60,7 +67,7 @@ void ledInit()
}
#if defined(FUNCTION_SWITCHES_RGB_LEDS)
void fsLedRGB(uint8_t index, uint32_t color)
__weak void fsLedRGB(uint8_t index, uint32_t color)
{
ws2812_set_color(index, GET_RED(color), \
GET_GREEN(color),GET_BLUE(color));
@@ -75,23 +82,23 @@ uint8_t getRGBColorIndex(uint32_t color)
return 5; // Custom value set with Companion
}
#elif defined(FUNCTION_SWITCHES)
void fsLedOff(uint8_t index)
__weak void fsLedOff(uint8_t index)
{
gpio_clear(fsLeds[index]);
}
void fsLedOn(uint8_t index)
__weak void fsLedOn(uint8_t index)
{
gpio_set(fsLeds[index]);
}
bool fsLedState(uint8_t index)
__weak bool fsLedState(uint8_t index)
{
return gpio_read(fsLeds[index]) ? true : false;
}
#endif
void ledOff()
__weak void ledOff()
{
#if defined(LED_RED_GPIO)
GPIO_LED_GPIO_OFF(LED_RED_GPIO);
@@ -104,7 +111,7 @@ void ledOff()
#endif
}
void ledRed()
__weak void ledRed()
{
ledOff();
#if defined(LED_RED_GPIO)
@@ -112,7 +119,7 @@ void ledRed()
#endif
}
void ledGreen()
__weak void ledGreen()
{
ledOff();
#if defined(LED_GREEN_GPIO)
@@ -120,7 +127,7 @@ void ledGreen()
#endif
}
void ledBlue()
__weak void ledBlue()
{
ledOff();
#if defined(LED_BLUE_GPIO)
@@ -128,7 +135,9 @@ void ledBlue()
#endif
}
uint32_t fsGetLedRGB(uint8_t index)
#if defined(FUNCTION_SWITCHES_RGB_LEDS)
__weak uint32_t fsGetLedRGB(uint8_t index)
{
return rgbGetLedColor(index + CFS_LED_STRIP_START);
}
}
#endif
-132
View File
@@ -1,132 +0,0 @@
/*
* Copyright (C) EdgeTX
*
* Based on code named
* opentx - https://github.com/opentx/opentx
* th9x - http://code.google.com/p/th9x
* er9x - http://code.google.com/p/er9x
* gruvin9x - http://code.google.com/p/gruvin9x
*
* License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*/
#include "hal/gpio.h"
#include "hal/rgbleds.h"
#include "stm32_gpio.h"
#include "stm32_ws2812.h"
#include "boards/generic_stm32/rgb_leds.h"
#include "board.h"
#define GET_RED(color) (((color) & 0xFF0000) >>16)
#define GET_GREEN(color) (((color) & 0x00FF00) >> 8)
#define GET_BLUE(color) ((color) & 0x0000FF)
#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)
void fsLedRGB(uint8_t index, uint32_t color)
{
ws2812_set_color(index + CFS_LED_STRIP_START, GET_RED(color), GET_GREEN(color),
GET_BLUE(color));
}
uint32_t fsGetLedRGB(uint8_t index)
{
return rgbGetLedColor(index + CFS_LED_STRIP_START);
}
uint8_t getRGBColorIndex(uint32_t color)
{
for (uint8_t i = 0; i < DIM(colorTable); i++) {
if (color == colorTable[i])
return(i + 1);
}
return 0; // 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()
{
#if defined(LED_RED_GPIO)
GPIO_LED_GPIO_OFF(LED_RED_GPIO);
#endif
#if defined(LED_BLUE_GPIO)
GPIO_LED_GPIO_OFF(LED_BLUE_GPIO);
#endif
#if defined(LED_GREEN_GPIO)
GPIO_LED_GPIO_OFF(LED_GREEN_GPIO);
#endif
}
void ledRed()
{
#if defined(LED_RED_GPIO)
ledOff();
GPIO_LED_GPIO_ON(LED_RED_GPIO);
#endif
}
void ledGreen()
{
#if defined(LED_GREEN_GPIO)
ledOff();
GPIO_LED_GPIO_ON(LED_GREEN_GPIO);
#endif
}
void ledBlue()
{
#if defined(LED_BLUE_GPIO)
ledOff();
GPIO_LED_GPIO_ON(LED_BLUE_GPIO);
#endif
}