Skip to content

Commit 1f0fc69

Browse files
authored
feat(rgbled): add color order feature
1 parent 84b20f0 commit 1f0fc69

File tree

1 file changed

+33
-3
lines changed

1 file changed

+33
-3
lines changed

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

+33-3
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,40 @@ void neopixelWrite(uint8_t pin, uint8_t red_val, uint8_t green_val, uint8_t blue
2929
return;
3030
}
3131

32-
#if !defined RGB_BUILTIN_COLOR_ORDER_STRUCT
33-
#define RGB_BUILTIN_COLOR_ORDER_STRUCT {green_val, red_val, blue_val}
32+
#if defined RGB_BUILTIN_LED_COLOR_ORDER_CHANGE
33+
// the onboard RGB LED has a different color order
34+
const int color[3];
35+
switch (RGB_BUILTIN_LED_COLOR_ORDER_CHANGE) {
36+
case LED_COLOR_ORDER_RGB:
37+
color[0] = red_val;
38+
color[1] = green_val;
39+
color[2] = blue_val;
40+
break;
41+
case LED_COLOR_ORDER_BGR:
42+
color[0] = blue_val;
43+
color[1] = green_val;
44+
color[2] = red_val;
45+
break;
46+
case LED_COLOR_ORDER_BRG:
47+
color[0] = blue_val;
48+
color[1] = red_val;
49+
color[2] = green_val;
50+
break;
51+
case LED_COLOR_ORDER_RBG:
52+
color[0] = red_val;
53+
color[1] = blue_val;
54+
color[2] = green_val;
55+
break;
56+
case LED_COLOR_ORDER_GBR:
57+
color[0] = green_val;
58+
color[1] = blue_val;
59+
color[2] = red_val;
60+
}
61+
#else
62+
// default WS2812B color order is G, R, B
63+
const int color[3] = {green_val, red_val, blue_val};
3464
#endif
35-
int color[] = RGB_BUILTIN_COLOR_ORDER_STRUCT;
65+
3666
int i = 0;
3767
for (int col = 0; col < 3; col++) {
3868
for (int bit = 0; bit < 8; bit++) {

0 commit comments

Comments
 (0)