Skip to content

Commit 77f8cae

Browse files
committed
change(esp32): Added the possibility to specify LED color order
1 parent ff20b12 commit 77f8cae

File tree

3 files changed

+7
-48
lines changed

3 files changed

+7
-48
lines changed

cores/esp32/esp32-hal-rgb-led.c

+6-37
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,6 @@
33
#include "esp32-hal-rgb-led.h"
44

55
void neopixelWrite(uint8_t pin, uint8_t red_val, uint8_t green_val, uint8_t blue_val) {
6-
neopixelWriteOrdered(pin, LED_COLOR_ORDER_GRB, red_val, green_val, blue_val);
7-
}
8-
9-
void neopixelWriteOrdered(uint8_t pin, rgb_led_color_order_t rgb_led_color_order, uint8_t red_val, uint8_t green_val, uint8_t blue_val) {
106
#if SOC_RMT_SUPPORTED
117
rmt_data_t led_data[24];
128

@@ -19,39 +15,12 @@ void neopixelWriteOrdered(uint8_t pin, rgb_led_color_order_t rgb_led_color_order
1915
return;
2016
}
2117

22-
int color[3];
23-
switch (rgb_led_color_order) {
24-
case LED_COLOR_ORDER_RGB:
25-
color[0] = red_val;
26-
color[1] = green_val;
27-
color[2] = blue_val;
28-
break;
29-
case LED_COLOR_ORDER_BGR:
30-
color[0] = blue_val;
31-
color[1] = green_val;
32-
color[2] = red_val;
33-
break;
34-
case LED_COLOR_ORDER_BRG:
35-
color[0] = blue_val;
36-
color[1] = red_val;
37-
color[2] = green_val;
38-
break;
39-
case LED_COLOR_ORDER_RBG:
40-
color[0] = red_val;
41-
color[1] = blue_val;
42-
color[2] = green_val;
43-
break;
44-
case LED_COLOR_ORDER_GBR:
45-
color[0] = green_val;
46-
color[1] = blue_val;
47-
color[2] = red_val;
48-
break;
49-
default:
50-
color[0] = green_val;
51-
color[1] = red_val;
52-
color[2] = blue_val;
53-
break;
54-
}
18+
#ifdef RGB_BUILTIN_COLOR_ORDER_STRUCT
19+
int color[] = RGB_BUILTIN_COLOR_ORDER_STRUCT;
20+
#else
21+
// WS2812B color bit order is G, R, B
22+
int color[] = {green_val, red_val, blue_val};
23+
#endif
5524
int i = 0;
5625
for (int col = 0; col < 3; col++) {
5726
for (int bit = 0; bit < 8; bit++) {

cores/esp32/esp32-hal-rgb-led.h

-11
Original file line numberDiff line numberDiff line change
@@ -11,19 +11,8 @@ extern "C" {
1111
#define RGB_BRIGHTNESS 64
1212
#endif
1313

14-
typedef enum {
15-
LED_COLOR_ORDER_RGB,
16-
LED_COLOR_ORDER_BGR,
17-
LED_COLOR_ORDER_BRG,
18-
LED_COLOR_ORDER_RBG,
19-
LED_COLOR_ORDER_GBR,
20-
LED_COLOR_ORDER_GRB
21-
} rgb_led_color_order_t;
22-
2314
void neopixelWrite(uint8_t pin, uint8_t red_val, uint8_t green_val, uint8_t blue_val);
2415

25-
void neopixelWriteOrdered(uint8_t pin, rgb_led_color_order_t rgb_led_color_order, uint8_t red_val, uint8_t green_val, uint8_t blue_val);
26-
2716
#ifdef __cplusplus
2817
}
2918
#endif

variants/lolin_s3_mini/pins_arduino.h

+1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ static const uint8_t LED_BUILTIN = 47 + SOC_GPIO_PIN_COUNT;
1212
#define LED_BUILTIN LED_BUILTIN // allow testing #ifdef LED_BUILTIN
1313
#define RGB_BUILTIN LED_BUILTIN
1414
#define RGB_BRIGHTNESS 64
15+
#define RGB_BUILTIN_COLOR_ORDER_STRUCT {red_val, green_val, blue_val}
1516

1617
static const uint8_t TX = 43;
1718
static const uint8_t RX = 44;

0 commit comments

Comments
 (0)