Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 31899b0

Browse filesBrowse files
Merge branch 'master' into middleware
2 parents 6607a91 + 66c9c0b commit 31899b0
Copy full SHA for 31899b0

File tree

3 files changed

+75
-3
lines changed
Filter options

3 files changed

+75
-3
lines changed

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

Copy file name to clipboardExpand all lines: cores/esp32/esp32-hal-rgb-led.c
+52-2Lines changed: 52 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,26 @@
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++) {

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

Copy file name to clipboardExpand all lines: cores/esp32/esp32-hal-rgb-led.h
+20-1Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,26 @@ extern "C" {
1111
#define RGB_BRIGHTNESS 64
1212
#endif
1313

14-
void neopixelWrite(uint8_t pin, uint8_t red_val, uint8_t green_val, uint8_t blue_val);
14+
#ifndef RGB_BUILTIN_LED_COLOR_ORDER
15+
#define RGB_BUILTIN_LED_COLOR_ORDER LED_COLOR_ORDER_GRB // default WS2812B color order
16+
#endif
17+
18+
typedef enum {
19+
LED_COLOR_ORDER_RGB,
20+
LED_COLOR_ORDER_BGR,
21+
LED_COLOR_ORDER_BRG,
22+
LED_COLOR_ORDER_RBG,
23+
LED_COLOR_ORDER_GBR,
24+
LED_COLOR_ORDER_GRB
25+
} rgb_led_color_order_t;
26+
27+
void rgbLedWriteOrdered(uint8_t pin, rgb_led_color_order_t order, uint8_t red_val, uint8_t green_val, uint8_t blue_val);
28+
29+
// Will use RGB_BUILTIN_LED_COLOR_ORDER
30+
void rgbLedWrite(uint8_t pin, uint8_t red_val, uint8_t green_val, uint8_t blue_val);
31+
32+
// Backward compatibility
33+
#define neopixelWrite(p, r, g, b) rgbLedWrite(p, r, g, b)
1534

1635
#ifdef __cplusplus
1736
}

‎variants/lolin_s3_mini/pins_arduino.h

Copy file name to clipboardExpand all lines: variants/lolin_s3_mini/pins_arduino.h
+3Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ 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+
// This board has a builtin RGB LED that works with a different signal color order
16+
// Other order options can be found in https://github.com/espressif/arduino-esp32/blob/master/cores/esp32/esp32-hal-rgb-led.h
17+
#define RGB_BUILTIN_LED_COLOR_ORDER LED_COLOR_ORDER_RGB
1518

1619
static const uint8_t TX = 43;
1720
static const uint8_t RX = 44;

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.