Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ability for boards to provide a custom pixel order in neopixelWrite() #10128

Merged
merged 21 commits into from
Aug 19, 2024
Merged
Show file tree
Hide file tree
Changes from 17 commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
a64ffd0
fix(esp32): Fixed the hint for the builtin neopixleWrite() function
sblantipodi Aug 7, 2024
96180dc
change(esp32): Added neopixelWriteOrdered() function
sblantipodi Aug 7, 2024
fc43ac4
change(esp32): Added neopixelWriteOrdered() function
sblantipodi Aug 7, 2024
ff20b12
change(esp32): Added neopixelWriteOrdered() function
sblantipodi Aug 7, 2024
77f8cae
change(esp32): Added the possibility to specify LED color order
sblantipodi Aug 13, 2024
35b0bc6
change(esp32): Added the possibility to specify LED color order
sblantipodi Aug 13, 2024
2b8ea08
Merge branch 'master' into master
SuGlider Aug 13, 2024
92f3d3b
feat(rgbled): add license information
SuGlider Aug 13, 2024
84b20f0
feat(rgbled): add color order enum
SuGlider Aug 14, 2024
1f0fc69
feat(rgbled): add color order feature
SuGlider Aug 14, 2024
0ca996a
feat(rgbled): change color order for lolin_s3_mini
SuGlider Aug 14, 2024
a0886af
fix(rgbled): suffix
SuGlider Aug 14, 2024
2bf9d99
fix(rgbled): suffix
SuGlider Aug 14, 2024
3dd5f70
ci(pre-commit): Apply automatic fixes
pre-commit-ci-lite[bot] Aug 14, 2024
f489e16
Merge branch 'master' into master
SuGlider Aug 16, 2024
2814861
fix(rgbled): it lacks GRB case
SuGlider Aug 16, 2024
347b7c7
fix(rgbled): add guard for rgb_led_color_order_t
SuGlider Aug 16, 2024
1705caf
fix(rgb-led): Implement rgbLedWriteOrdered()
me-no-dev Aug 19, 2024
e94fe39
ci(pre-commit): Apply automatic fixes
pre-commit-ci-lite[bot] Aug 19, 2024
530b263
Remove const to allow changing the order
me-no-dev Aug 19, 2024
ec3d597
Merge branch 'master' into master
SuGlider Aug 19, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 47 additions & 1 deletion cores/esp32/esp32-hal-rgb-led.c
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
// Copyright 2024 Espressif Systems (Shanghai) PTE LTD
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at

// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

#include "soc/soc_caps.h"

#include "esp32-hal-rgb-led.h"
Expand All @@ -15,7 +29,39 @@ void neopixelWrite(uint8_t pin, uint8_t red_val, uint8_t green_val, uint8_t blue
return;
}

int color[] = {green_val, red_val, blue_val}; // Color coding is in order GREEN, RED, BLUE
// default WS2812B color order is G, R, B
const int color[3] = {green_val, red_val, blue_val};

#if defined RGB_BUILTIN_LED_COLOR_ORDER
me-no-dev marked this conversation as resolved.
Show resolved Hide resolved
// the onboard RGB LED has a different color order
switch (RGB_BUILTIN_LED_COLOR_ORDER) {
case LED_COLOR_ORDER_RGB:
color[0] = red_val;
color[1] = green_val;
color[2] = blue_val;
break;
case LED_COLOR_ORDER_BGR:
color[0] = blue_val;
color[1] = green_val;
color[2] = red_val;
break;
case LED_COLOR_ORDER_BRG:
color[0] = blue_val;
color[1] = red_val;
color[2] = green_val;
break;
case LED_COLOR_ORDER_RBG:
color[0] = red_val;
color[1] = blue_val;
color[2] = green_val;
break;
case LED_COLOR_ORDER_GBR:
color[0] = green_val;
color[1] = blue_val;
color[2] = red_val;
}
#endif

int i = 0;
for (int col = 0; col < 3; col++) {
for (int bit = 0; bit < 8; bit++) {
Expand Down
11 changes: 11 additions & 0 deletions cores/esp32/esp32-hal-rgb-led.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,17 @@ extern "C" {
#define RGB_BRIGHTNESS 64
#endif

#if defined RGB_BUILTIN_LED_COLOR_ORDER
me-no-dev marked this conversation as resolved.
Show resolved Hide resolved
typedef enum {
LED_COLOR_ORDER_RGB,
LED_COLOR_ORDER_BGR,
LED_COLOR_ORDER_BRG,
LED_COLOR_ORDER_RBG,
LED_COLOR_ORDER_GBR,
LED_COLOR_ORDER_GRB
} rgb_led_color_order_t;
#endif

SuGlider marked this conversation as resolved.
Show resolved Hide resolved
void neopixelWrite(uint8_t pin, uint8_t red_val, uint8_t green_val, uint8_t blue_val);

#ifdef __cplusplus
Expand Down
3 changes: 3 additions & 0 deletions variants/lolin_s3_mini/pins_arduino.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ static const uint8_t LED_BUILTIN = 47 + SOC_GPIO_PIN_COUNT;
#define LED_BUILTIN LED_BUILTIN // allow testing #ifdef LED_BUILTIN
#define RGB_BUILTIN LED_BUILTIN
#define RGB_BRIGHTNESS 64
// This board has a builtin RGB LED that works with a different signal color order
// Other order options can be found in https://github.com/espressif/arduino-esp32/blob/master/cores/esp32/esp32-hal-rgb-led.h
#define RGB_BUILTIN_LED_COLOR_ORDER LED_COLOR_ORDER_RGB

static const uint8_t TX = 43;
static const uint8_t RX = 44;
Expand Down
Loading