Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions radio/src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ AddHWGenTarget(${HW_DESC_JSON} yaml_inputs yaml_inputs.inc)
AddHWGenTarget(${HW_DESC_JSON} lua_inputs lua_inputs.inc)
AddHWGenTarget(${HW_DESC_JSON} lua_mixsrc lua_mixsrc.inc)
AddHWGenTarget(${HW_DESC_JSON} lua_keys lua_keys.inc)
AddHWGenTarget(${HW_DESC_JSON} lua_leds lua_leds.inc)

AddHWGenTarget(${HW_DESC_JSON} stm32_keys stm32_keys.inc)
AddHWGenTarget(${HW_DESC_JSON} stm32_switches stm32_switches.inc)
Expand All @@ -156,7 +157,7 @@ AddHWGenTarget(${HW_DESC_JSON} simu_switches simu_switches.inc)
AddHWGenTarget(${HW_DESC_JSON} hal_keys_lock hal_keys_lock.h)
AddHWGenTarget(${HW_DESC_JSON} hal_usb_descriptor usb_descriptor.h)

add_dependencies(board hal_settings hal_pwm_sticks hal_keys hal_keys_lock hal_adc_inputs stm32_keys stm32_switches stm32_adc_inputs stm32_pwm_inputs yaml_inputs lua_inputs lua_mixsrc lua_keys)
add_dependencies(board hal_settings hal_pwm_sticks hal_keys hal_keys_lock hal_adc_inputs stm32_keys stm32_switches stm32_adc_inputs stm32_pwm_inputs yaml_inputs lua_inputs lua_mixsrc lua_keys lua_leds)
add_dependencies(board_bl hal_settings hal_pwm_sticks hal_keys stm32_keys)


Expand Down Expand Up @@ -612,7 +613,7 @@ if(NATIVE_BUILD)
)
add_dependencies(radiolib_native ${RADIO_DEPENDENCIES}
hal_settings hal_pwm_sticks hal_keys hal_keys_lock hal_adc_inputs
yaml_inputs lua_inputs lua_mixsrc lua_keys)
yaml_inputs lua_inputs lua_mixsrc lua_keys lua_leds)
set_property(TARGET radiolib_native PROPERTY POSITION_INDEPENDENT_CODE ON)

add_subdirectory(targets/simu)
Expand Down
21 changes: 19 additions & 2 deletions radio/src/boards/generic_stm32/led_driver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,26 @@ __weak void ledInit()
}

#if defined(FUNCTION_SWITCHES_RGB_LEDS)
#if !defined(CFS_LED_STRIP_START)
#define CFS_LED_STRIP_START 0
#endif
#if !defined(CFS_LEDS_PER_SWITCH)
#define CFS_LEDS_PER_SWITCH 1
#endif

// First strip LED of a custom switch, boards with a non-linear layout
// override this
__weak uint8_t fsLedFirstIndex(uint8_t index)
{
return CFS_LED_STRIP_START + index * CFS_LEDS_PER_SWITCH;
}

__weak void fsLedRGB(uint8_t index, uint32_t color)
{
rgbSetLedColor(index, GET_RED(color), GET_GREEN(color), GET_BLUE(color));
uint8_t led = fsLedFirstIndex(index);
for (uint8_t i = 0; i < CFS_LEDS_PER_SWITCH; i++) {
rgbSetLedColor(led + i, GET_RED(color), GET_GREEN(color), GET_BLUE(color));
}
rgbLedColorApply();
}

Expand Down Expand Up @@ -145,6 +162,6 @@ __weak void ledBlue()
#if defined(FUNCTION_SWITCHES_RGB_LEDS)
__weak uint32_t fsGetLedRGB(uint8_t index)
{
return rgbGetLedColor(index + CFS_LED_STRIP_START);
return rgbGetLedColor(fsLedFirstIndex(index));
}
#endif
4 changes: 4 additions & 0 deletions radio/src/boards/hw_defs/gx15.json
Original file line number Diff line number Diff line change
Expand Up @@ -453,6 +453,10 @@
"led_strip_length": 26,
"bling_led_strip_start": 6,
"bling_led_strip_length": 20,
"bling_groups": [
{ "name": "gimbal_right", "first": 0, "count": 10, "start_angle": 190, "direction": -1 },
{ "name": "gimbal_left", "first": 10, "count": 10, "start_angle": 350, "direction": 1 }
],
"cfs_led_strip_start": 0,
"cfs_led_strip_length": 6,
"cfs_leds_per_switch": 1,
Expand Down
4 changes: 4 additions & 0 deletions radio/src/boards/hw_defs/st16.json
Original file line number Diff line number Diff line change
Expand Up @@ -408,6 +408,10 @@
"led_strip_length": 24,
"bling_led_strip_start": 0,
"bling_led_strip_length": 12,
"bling_groups": [
{ "name": "gimbal_right", "first": 6, "count": 6, "start_angle": 30, "direction": -1 },
{ "name": "gimbal_left", "first": 0, "count": 6, "start_angle": 330, "direction": -1 }
],
"cfs_led_strip_start": 12,
"cfs_led_strip_length": 12,
"cfs_leds_per_switch": 2,
Expand Down
4 changes: 4 additions & 0 deletions radio/src/boards/hw_defs/tx15.json
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,10 @@
"led_strip_length": 26,
"bling_led_strip_start": 6,
"bling_led_strip_length": 20,
"bling_groups": [
{ "name": "gimbal_right", "first": 0, "count": 10, "start_angle": 190, "direction": -1 },
{ "name": "gimbal_left", "first": 10, "count": 10, "start_angle": 10, "direction": -1 }
],
"cfs_led_strip_start": 0,
"cfs_led_strip_length": 6,
"cfs_leds_per_switch": 1,
Expand Down
4 changes: 4 additions & 0 deletions radio/src/boards/hw_defs/tx16smk3.json
Original file line number Diff line number Diff line change
Expand Up @@ -463,6 +463,10 @@
"led_strip_length": 26,
"bling_led_strip_start": 6,
"bling_led_strip_length": 20,
"bling_groups": [
{ "name": "gimbal_right", "first": 0, "count": 10, "start_angle": 190, "direction": -1 },
{ "name": "gimbal_left", "first": 10, "count": 10, "start_angle": 350, "direction": 1 }
],
"cfs_led_strip_start": 0,
"cfs_led_strip_length": 6,
"cfs_leds_per_switch": 1,
Expand Down
2 changes: 1 addition & 1 deletion radio/src/hal/rgbleds.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ void setFSLedON(uint8_t index) {

bool getFSLedState(uint8_t index) {
uint8_t cfsIdx = switchGetCustomSwitchIdx(index);
return rgbGetLedColor(cfsIdx) == g_model.getSwitchOnColor(index).getColor();
return fsGetLedRGB(cfsIdx) == g_model.getSwitchOnColor(index).getColor();
}

uint32_t getFSLedRGBColor(uint8_t index)
Expand Down
99 changes: 90 additions & 9 deletions radio/src/lua/api_general.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3014,17 +3014,26 @@ static int luaGetTrainerStatus(lua_State * L)

#if (BLING_LED_STRIP_LENGTH > 0) || (CFS_LED_STRIP_LENGTH > 0)
/*luadoc
@function setRGBLedColor(id, rvalue, bvalue, cvalue)
@function setRGBLedColor(id, rvalue, gvalue, bvalue)

@param id: integer identifying a led in the led chain
Set the color of a LED, the change is visible after applyRGBLedColors()

@param rvalue: interger, value of red channel
@param id: integer LED index, 0 to LED_STRIP_LENGTH - 1.
Indexes 0 to BLING_LED_STRIP_LENGTH - 1 are the decorative ('bling') LEDs.
The remaining indexes are the custom switch LEDs, which can only be set
while that custom switch is set to NONE (use setCFSLedColor() for the
others). Scripts that only want the decorative LEDs, and still run on older
firmware, can loop to `(BLING_LED_STRIP_LENGTH or LED_STRIP_LENGTH) - 1`.
See getRGBLedInfo() for how the LEDs are grouped.

@param gvalue: interger, value of green channel
@param rvalue: integer, value of red channel

@param bvalue: interger, value of blue channel
@param gvalue: integer, value of green channel

@retval: true if LED index is valid, false otherwise
@param bvalue: integer, value of blue channel

@retval: true if the LED was set, false if the index is out of range or the
LED belongs to a custom switch that is in use

@status current Introduced in 2.10
*/
Expand All @@ -3051,12 +3060,14 @@ static int luaSetRgbLedColor(lua_State * L)
}
id -= BLING_LED_STRIP_LENGTH;
#endif
uint8_t swIdx = switchGetSwitchFromCustomIdx(id / CFS_LEDS_PER_SWITCH);
if (g_model.getSwitchType(swIdx) != SWITCH_NONE) {
uint8_t cfsIdx = id / CFS_LEDS_PER_SWITCH;
uint8_t swIdx = switchGetSwitchFromCustomIdx(cfsIdx);
if (swIdx >= switchGetMaxSwitches() ||
g_model.getSwitchType(swIdx) != SWITCH_NONE) {
lua_pushboolean(L, false);
return 1;
}
rgbSetLedColor(id + CFS_LED_STRIP_START, r, g, b);
rgbSetLedColor(fsLedFirstIndex(cfsIdx) + id % CFS_LEDS_PER_SWITCH, r, g, b);
#else
rgbSetLedColor(id + BLING_LED_STRIP_START, r, g, b);
#endif
Expand Down Expand Up @@ -3134,6 +3145,73 @@ static int luaApplyRGBLedColors(lua_State * L)
rgbLedColorApply();
return 1;
}

struct LuaLedGroup {
const char* name;
uint8_t first;
uint8_t count;
int16_t startAngle;
int8_t direction; // 0 when the group is not a ring
};

#include "lua_leds.inc"

/*luadoc
@function getRGBLedInfo()

Describe the LEDs that setRGBLedColor() can address

@retval table with the following fields:
* `length` (number) total number of LEDs, same as LED_STRIP_LENGTH
* `bling` (number) number of decorative LEDs, same as BLING_LED_STRIP_LENGTH.
They use indexes 0 to `bling` - 1
* `cfs` (table) custom switch LEDs, only present if the radio has them:
* `first` (number) index of the first custom switch LED
* `count` (number) number of custom switch LEDs
* `perSwitch` (number) number of LEDs for each custom switch
* `groups` (table) groups of decorative LEDs indexed by name
(e.g. `gimbal_left`, `gimbal_right`), empty if none are known. Each group has:
* `first` (number) index of the first LED of the group
* `count` (number) number of LEDs in the group
* `startAngle` (number) only for an evenly spaced ring, angle of the
first LED in degrees (0 = right, 90 = up)
* `direction` (number) only for an evenly spaced ring, 1 if the following
LEDs go counter clockwise, -1 if they go clockwise

@status current Introduced in 3.0.0
*/
static int luaGetRGBLedInfo(lua_State * L)
{
lua_newtable(L);
lua_pushtableinteger(L, "length", BLING_LED_STRIP_LENGTH + CFS_LED_STRIP_LENGTH);
lua_pushtableinteger(L, "bling", BLING_LED_STRIP_LENGTH);

#if CFS_LED_STRIP_LENGTH > 0
lua_pushstring(L, "cfs");
lua_newtable(L);
lua_pushtableinteger(L, "first", BLING_LED_STRIP_LENGTH);
lua_pushtableinteger(L, "count", CFS_LED_STRIP_LENGTH);
lua_pushtableinteger(L, "perSwitch", CFS_LEDS_PER_SWITCH);
lua_settable(L, -3);
#endif

lua_pushstring(L, "groups");
lua_newtable(L);
for (const LuaLedGroup* group = luaLedGroups; group->name; group++) {
lua_pushstring(L, group->name);
lua_newtable(L);
lua_pushtableinteger(L, "first", group->first);
lua_pushtableinteger(L, "count", group->count);
if (group->direction) {
lua_pushtableinteger(L, "startAngle", group->startAngle);
lua_pushtableinteger(L, "direction", group->direction);
}
lua_settable(L, -3);
}
lua_settable(L, -3);

return 1;
}
#endif


Expand Down Expand Up @@ -3307,6 +3385,7 @@ LROT_BEGIN(etxlib, NULL, 0)
#if (BLING_LED_STRIP_LENGTH > 0) || (CFS_LED_STRIP_LENGTH > 0)
LROT_FUNCENTRY( setRGBLedColor, luaSetRgbLedColor )
LROT_FUNCENTRY( applyRGBLedColors, luaApplyRGBLedColors )
LROT_FUNCENTRY( getRGBLedInfo, luaGetRGBLedInfo )
#endif
#if (CFS_LED_STRIP_LENGTH > 0)
LROT_FUNCENTRY( setCFSLedColor, luaSetCFSLedColor )
Expand Down Expand Up @@ -3404,6 +3483,7 @@ LROT_BEGIN(etxcst, NULL, 0)
LROT_NUMENTRY( FUNC_BACKLIGHT, FUNC_BACKLIGHT )
LROT_NUMENTRY( FUNC_SCREENSHOT, FUNC_SCREENSHOT )
LROT_NUMENTRY( FUNC_RACING_MODE, FUNC_RACING_MODE )
LROT_NUMENTRY( FUNC_RGB_LED, FUNC_RGB_LED )
#if defined(FUNCTION_SWITCHES)
LROT_NUMENTRY( FUNC_PUSH_CUST_SWITCH, FUNC_PUSH_CUST_SWITCH )
#endif
Expand Down Expand Up @@ -3464,6 +3544,7 @@ LROT_BEGIN(etxcst, NULL, 0)
LROT_NUMENTRY( TIMEHOUR, TIMEHOUR )
#if (BLING_LED_STRIP_LENGTH > 0) || (CFS_LED_STRIP_LENGTH > 0)
LROT_NUMENTRY( LED_STRIP_LENGTH, BLING_LED_STRIP_LENGTH + CFS_LED_STRIP_LENGTH )
LROT_NUMENTRY( BLING_LED_STRIP_LENGTH, BLING_LED_STRIP_LENGTH )
#endif
LROT_NUMENTRY( UNIT_RAW, UNIT_RAW )
LROT_NUMENTRY( UNIT_VOLTS, UNIT_VOLTS )
Expand Down
1 change: 1 addition & 0 deletions radio/src/switches.h
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ void fsLedOn(uint8_t index);
bool fsLedState(uint8_t index);
void fsLedRGB(uint8_t index, uint32_t color);
uint32_t fsGetLedRGB(uint8_t index);
uint8_t fsLedFirstIndex(uint8_t index);
uint8_t getRGBColorIndex(uint32_t color);
#endif

Expand Down
11 changes: 8 additions & 3 deletions radio/src/targets/pa01/led_driver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,18 @@
#define GET_BLUE(color) (((color) & 0xF8))

// used to map switch number to led number in the rgbled chain
uint8_t ledMapping[] = {4, 6, 0, 2};
static const uint8_t ledMapping[] = {4, 6, 0, 2};

uint8_t fsLedFirstIndex(uint8_t index)
{
return ledMapping[index];
}

void fsLedRGB(uint8_t index, uint32_t color)
{
rgbSetLedColor(ledMapping[index], GET_RED(color),
rgbSetLedColor(fsLedFirstIndex(index), GET_RED(color),
GET_GREEN(color),GET_BLUE(color));
rgbSetLedColor(ledMapping[index]+1, GET_RED(color),
rgbSetLedColor(fsLedFirstIndex(index)+1, GET_RED(color),
GET_GREEN(color),GET_BLUE(color));
rgbLedColorApply();
}
Expand Down
19 changes: 17 additions & 2 deletions radio/src/targets/simu/led_driver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,14 +77,29 @@ uint32_t rgbGetLedColor(uint8_t led)
return (pixel[1] << 16) + (pixel[0] << 8) + pixel[2];
}

#if !defined(CFS_LED_STRIP_START)
#define CFS_LED_STRIP_START 0
#endif
#if !defined(CFS_LEDS_PER_SWITCH)
#define CFS_LEDS_PER_SWITCH 1
#endif

uint8_t fsLedFirstIndex(uint8_t index)
{
return CFS_LED_STRIP_START + index * CFS_LEDS_PER_SWITCH;
}

void fsLedRGB(uint8_t idx, uint32_t color)
{
rgbSetLedColor(idx, (color >> 16) & 0xFF, (color >> 8) & 0xFF, color & 0xFF);
uint8_t led = fsLedFirstIndex(idx);
for (uint8_t i = 0; i < CFS_LEDS_PER_SWITCH; i++) {
rgbSetLedColor(led + i, (color >> 16) & 0xFF, (color >> 8) & 0xFF, color & 0xFF);
}
}

uint32_t fsGetLedRGB(uint8_t index)
{
return rgbGetLedColor(index);
return rgbGetLedColor(fsLedFirstIndex(index));
}

void fsLedOn(uint8_t idx)
Expand Down
1 change: 0 additions & 1 deletion radio/src/targets/st16/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,6 @@ set(CMSIS_SRC ${TARGET_SRC_DIR}/system_clock.c)
# Firmware board library
add_library(board OBJECT EXCLUDE_FROM_ALL
${BOARD_COMMON_SRC}
${TARGET_SRC_DIR}/led_driver.cpp
${TARGET_SRC_DIR}/touch_driver.cpp
${TARGET_SRC_DIR}/battery_driver.cpp
targets/common/arm/stm32/heartbeat_driver.cpp
Expand Down
45 changes: 0 additions & 45 deletions radio/src/targets/st16/led_driver.cpp

This file was deleted.

Loading
Loading