Skip to content

Commit

Permalink
LEDs: Add support for the WRGB/RGBW color order (WS2814+ LED chip)
Browse files Browse the repository at this point in the history
Feature: Add new LED Color Order configs
 >
 Add LED Color Order options with support for the WRGB/RGBW order
 (WS2814 LED chip). Allows for simplified bit OR logic.
 >
 Also replaces LED_TYPE_RGB and LED_TYPE_RGBW with simplified
 LED_TYPE_INTERNAL option. Related logic has been updated to
 follow suit.
  • Loading branch information
Jared-Is-Coding committed Nov 1, 2024
1 parent 290dba3 commit 172c8f6
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 14 deletions.
9 changes: 5 additions & 4 deletions src/conf/datatypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,8 @@ typedef enum {

typedef enum {
LED_TYPE_NONE = 0,
LED_TYPE_RGB,
LED_TYPE_RGBW,
LED_TYPE_EXTERNAL,
LED_TYPE_INTERNAL,
LED_TYPE_EXTERNAL
} LedType;

typedef enum {
Expand All @@ -47,7 +46,9 @@ typedef enum {

typedef enum {
LED_COLOR_GRB = 0,
LED_COLOR_RGB
LED_COLOR_RGB,
LED_COLOR_WRGB,
LED_COLOR_RGBW
} LedColorOrder;

typedef enum {
Expand Down
5 changes: 3 additions & 2 deletions src/conf/settings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3117,8 +3117,7 @@ p, li { white-space: pre-wrap; }
<cDefine>CFG_DFLT_HARDWARE_LED_TYPE</cDefine>
<valInt>0</valInt>
<enumNames>None</enumNames>
<enumNames>RGB</enumNames>
<enumNames>RGBW</enumNames>
<enumNames>Internal Module</enumNames>
<enumNames>External Module</enumNames>
</hardware.leds.type>
<hardware.leds.pin>
Expand Down Expand Up @@ -3160,6 +3159,8 @@ p, li { white-space: pre-wrap; }
<valInt>0</valInt>
<enumNames>GRB</enumNames>
<enumNames>RGB</enumNames>
<enumNames>WRGB</enumNames>
<enumNames>RGBW</enumNames>
</hardware.leds.color_order>
<hardware.leds.status.count>
<longName>Status LED Strip Length</longName>
Expand Down
15 changes: 7 additions & 8 deletions src/led_driver.c
Original file line number Diff line number Diff line change
Expand Up @@ -130,13 +130,13 @@ static void deinit_dma(LedPin pin) {
bool led_driver_init(
LedDriver *driver, LedPin pin, LedType type, LedColorOrder color_order, uint8_t led_nr
) {
if (type != LED_TYPE_RGB && type != LED_TYPE_RGBW) {
if (type != LED_TYPE_INTERNAL) {
driver->bitbuffer = NULL;
driver->bitbuffer_length = 0;
return false;
}

driver->bit_nr = type == LED_TYPE_RGBW ? 32 : 24;
driver->bit_nr = (color_order == LED_COLOR_WRGB || color_order == LED_COLOR_RGBW) ? 32 : 24;
driver->bitbuffer_length = driver->bit_nr * led_nr + BITBUFFER_PAD;
driver->bitbuffer = VESC_IF->malloc(sizeof(uint16_t) * driver->bitbuffer_length);
driver->pin = pin;
Expand Down Expand Up @@ -174,13 +174,12 @@ void led_driver_paint(LedDriver *driver, uint32_t *data, uint32_t length) {

if (driver->color_order == LED_COLOR_GRB) {
color = (g << 16) | (r << 8) | b;
} else {
} else if (driver->color_order == LED_COLOR_RGB) {
color = (r << 16) | (g << 8) | b;
}

if (driver->bit_nr == 32) {
color <<= 8;
color |= w;
} else if (driver->color_order == LED_COLOR_RGBW) {
color = (r << 24) | (g << 16) | (b << 8) | w;
} else if (driver->color_order == LED_COLOR_WRGB) {
color = (w << 24) | (r << 16) | (g << 8) | b;
}

for (int8_t bit = driver->bit_nr - 1; bit >= 0; --bit) {
Expand Down

0 comments on commit 172c8f6

Please sign in to comment.