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+
115#include "soc/soc_caps.h"
216
317#include "esp32-hal-rgb-led.h"
418
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 ) {
624#if SOC_RMT_SUPPORTED
725 rmt_data_t led_data [24 ];
826
@@ -15,7 +33,39 @@ void neopixelWrite(uint8_t pin, uint8_t red_val, uint8_t green_val, uint8_t blue
1533 return ;
1634 }
1735
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+
1969 int i = 0 ;
2070 for (int col = 0 ; col < 3 ; col ++ ) {
2171 for (int bit = 0 ; bit < 8 ; bit ++ ) {
0 commit comments