1
+ // Copyright 2024 Espressif Systems (Shanghai) PTE LTD
2
+ //
3
+ // Licensed under the Apache License, Version 2.0 (the "License");
4
+ // you may not use this file except in compliance with the License.
5
+ // You may obtain a copy of the License at
6
+
7
+ // http://www.apache.org/licenses/LICENSE-2.0
8
+ //
9
+ // Unless required by applicable law or agreed to in writing, software
10
+ // distributed under the License is distributed on an "AS IS" BASIS,
11
+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ // See the License for the specific language governing permissions and
13
+ // limitations under the License.
14
+
1
15
#include "soc/soc_caps.h"
2
16
3
17
#include "esp32-hal-rgb-led.h"
4
18
5
- void neopixelWrite (uint8_t pin , uint8_t red_val , uint8_t green_val , uint8_t blue_val ) {
19
+ void rgbLedWrite (uint8_t pin , uint8_t red_val , uint8_t green_val , uint8_t blue_val ) {
20
+ rgbLedWriteOrdered (pin , RGB_BUILTIN_LED_COLOR_ORDER , red_val , green_val , blue_val );
21
+ }
22
+
23
+ void rgbLedWriteOrdered (uint8_t pin , rgb_led_color_order_t order , uint8_t red_val , uint8_t green_val , uint8_t blue_val ) {
6
24
#if SOC_RMT_SUPPORTED
7
25
rmt_data_t led_data [24 ];
8
26
@@ -15,7 +33,39 @@ void neopixelWrite(uint8_t pin, uint8_t red_val, uint8_t green_val, uint8_t blue
15
33
return ;
16
34
}
17
35
18
- int color [] = {green_val , red_val , blue_val }; // Color coding is in order GREEN, RED, BLUE
36
+ // default WS2812B color order is G, R, B
37
+ int color [3 ] = {green_val , red_val , blue_val };
38
+
39
+ switch (order ) {
40
+ case LED_COLOR_ORDER_RGB :
41
+ color [0 ] = red_val ;
42
+ color [1 ] = green_val ;
43
+ color [2 ] = blue_val ;
44
+ break ;
45
+ case LED_COLOR_ORDER_BGR :
46
+ color [0 ] = blue_val ;
47
+ color [1 ] = green_val ;
48
+ color [2 ] = red_val ;
49
+ break ;
50
+ case LED_COLOR_ORDER_BRG :
51
+ color [0 ] = blue_val ;
52
+ color [1 ] = red_val ;
53
+ color [2 ] = green_val ;
54
+ break ;
55
+ case LED_COLOR_ORDER_RBG :
56
+ color [0 ] = red_val ;
57
+ color [1 ] = blue_val ;
58
+ color [2 ] = green_val ;
59
+ break ;
60
+ case LED_COLOR_ORDER_GBR :
61
+ color [0 ] = green_val ;
62
+ color [1 ] = blue_val ;
63
+ color [2 ] = red_val ;
64
+ break ;
65
+ default : // GRB
66
+ break ;
67
+ }
68
+
19
69
int i = 0 ;
20
70
for (int col = 0 ; col < 3 ; col ++ ) {
21
71
for (int bit = 0 ; bit < 8 ; bit ++ ) {
0 commit comments