Skip to content

Commit 05ae83a

Browse files
santaimpersonatorSuGliderVojtechBartoska
authored
Improve RGB driver in pull espressif#6808; solves espressif#6968 (espressif#6979)
* Improve RGB LED Driver Replaces the use of the `LED_BUILTIN` variable by creating a new variable called `RGB_BUILTIN`. On boards with both a regular LED and RGB LED, this change provides functionality to control either LED. The `LED_BRIGHTNESS` variable is changed to `RGB_BRIGHTNESS`, which aligns more closely with the `RGB_BUILTIN` variable name. `BOARD_HAS_NEOPIXEL` is no longer necessary; it is replaced by `RGB_BUILTIN`. * Update BlinkRGB example Update example code for changes with the RGB driver: - Replace `LED_BUILTIN` and `BOARD_HAS_NEOPIXEL` with `RGB_BUILTIN` - Replace `LED_BRIGHTNESS` with `RGB_BRIGHTNESS` * Update board variants Update board variants for changes with the RGB driver: - Remove `BOARD_HAS_NEOPIXEL` - Define `RGB_BUILTIN` pin - Replace `LED_BRIGHTNESS` with `RGB_BRIGHTNESS` to align with `RGB_BUILTIN` name Co-authored-by: Rodrigo Garcia <rodrigo.garcia@espressif.com> Co-authored-by: Vojtěch Bartoška <76958047+VojtechBartoska@users.noreply.github.com>
1 parent 53a097b commit 05ae83a

File tree

7 files changed

+27
-27
lines changed

7 files changed

+27
-27
lines changed

Diff for: cores/esp32/esp32-hal-gpio.c

+7-7
Original file line numberDiff line numberDiff line change
@@ -91,9 +91,9 @@ static InterruptHandle_t __pinInterruptHandlers[SOC_GPIO_PIN_COUNT] = {0,};
9191

9292
extern void ARDUINO_ISR_ATTR __pinMode(uint8_t pin, uint8_t mode)
9393
{
94-
#ifdef BOARD_HAS_NEOPIXEL
95-
if (pin == LED_BUILTIN){
96-
__pinMode(LED_BUILTIN-SOC_GPIO_PIN_COUNT, mode);
94+
#ifdef RGB_BUILTIN
95+
if (pin == RGB_BUILTIN){
96+
__pinMode(RGB_BUILTIN-SOC_GPIO_PIN_COUNT, mode);
9797
return;
9898
}
9999
#endif
@@ -134,11 +134,11 @@ extern void ARDUINO_ISR_ATTR __pinMode(uint8_t pin, uint8_t mode)
134134

135135
extern void ARDUINO_ISR_ATTR __digitalWrite(uint8_t pin, uint8_t val)
136136
{
137-
#ifdef BOARD_HAS_NEOPIXEL
138-
if(pin == LED_BUILTIN){
137+
#ifdef RGB_BUILTIN
138+
if(pin == RGB_BUILTIN){
139139
//use RMT to set all channels on/off
140-
const uint8_t comm_val = val != 0 ? LED_BRIGHTNESS : 0;
141-
neopixelWrite(LED_BUILTIN, comm_val, comm_val, comm_val);
140+
const uint8_t comm_val = val != 0 ? RGB_BRIGHTNESS : 0;
141+
neopixelWrite(RGB_BUILTIN, comm_val, comm_val, comm_val);
142142
return;
143143
}
144144
#endif

Diff for: cores/esp32/esp32-hal-rgb-led.c

+3-3
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ void neopixelWrite(uint8_t pin, uint8_t red_val, uint8_t green_val, uint8_t blue
77
static bool initialized = false;
88

99
uint8_t _pin = pin;
10-
#ifdef BOARD_HAS_NEOPIXEL
11-
if(pin == LED_BUILTIN){
12-
_pin = LED_BUILTIN-SOC_GPIO_PIN_COUNT;
10+
#ifdef RGB_BUILTIN
11+
if(pin == RGB_BUILTIN){
12+
_pin = RGB_BUILTIN-SOC_GPIO_PIN_COUNT;
1313
}
1414
#endif
1515

Diff for: cores/esp32/esp32-hal-rgb-led.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ extern "C" {
77

88
#include "esp32-hal.h"
99

10-
#ifndef LED_BRIGHTNESS
11-
#define LED_BRIGHTNESS 64
10+
#ifndef RGB_BRIGHTNESS
11+
#define RGB_BRIGHTNESS 64
1212
#endif
1313

1414
void neopixelWrite(uint8_t pin, uint8_t red_val, uint8_t green_val, uint8_t blue_val);

Diff for: libraries/ESP32/examples/GPIO/BlinkRGB/BlinkRGB.ino

+9-9
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,15 @@
33
44
Demonstrates usage of onboard RGB LED on some ESP dev boards.
55
6-
Calling digitalWrite(LED_BUILTIN, HIGH) will use hidden RGB driver.
6+
Calling digitalWrite(RGB_BUILTIN, HIGH) will use hidden RGB driver.
77
88
RGBLedWrite demonstrates controll of each channel:
99
void neopixelWrite(uint8_t pin, uint8_t red_val, uint8_t green_val, uint8_t blue_val)
1010
1111
WARNING: After using digitalWrite to drive RGB LED it will be impossible to drive the same pin
1212
with normal HIGH/LOW level
1313
*/
14-
//#define LED_BRIGHTNESS 64 // Change white brightness (max 255)
14+
//#define RGB_BRIGHTNESS 64 // Change white brightness (max 255)
1515

1616
// the setup function runs once when you press reset or power the board
1717

@@ -21,19 +21,19 @@ void setup() {
2121

2222
// the loop function runs over and over again forever
2323
void loop() {
24-
#ifdef BOARD_HAS_NEOPIXEL
25-
digitalWrite(LED_BUILTIN, HIGH); // Turn the RGB LED white
24+
#ifdef RGB_BUILTIN
25+
digitalWrite(RGB_BUILTIN, HIGH); // Turn the RGB LED white
2626
delay(1000);
27-
digitalWrite(LED_BUILTIN, LOW); // Turn the RGB LED off
27+
digitalWrite(RGB_BUILTIN, LOW); // Turn the RGB LED off
2828
delay(1000);
2929

30-
neopixelWrite(LED_BUILTIN,LED_BRIGHTNESS,0,0); // Red
30+
neopixelWrite(RGB_BUILTIN,RGB_BRIGHTNESS,0,0); // Red
3131
delay(1000);
32-
neopixelWrite(LED_BUILTIN,0,LED_BRIGHTNESS,0); // Green
32+
neopixelWrite(RGB_BUILTIN,0,RGB_BRIGHTNESS,0); // Green
3333
delay(1000);
34-
neopixelWrite(LED_BUILTIN,0,0,LED_BRIGHTNESS); // Blue
34+
neopixelWrite(RGB_BUILTIN,0,0,RGB_BRIGHTNESS); // Blue
3535
delay(1000);
36-
neopixelWrite(LED_BUILTIN,0,0,0); // Off / black
36+
neopixelWrite(RGB_BUILTIN,0,0,0); // Off / black
3737
delay(1000);
3838
#endif
3939
}

Diff for: variants/esp32c3/pins_arduino.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@
1111
static const uint8_t LED_BUILTIN = SOC_GPIO_PIN_COUNT+8;
1212
#define BUILTIN_LED LED_BUILTIN // backward compatibility
1313
#define LED_BUILTIN LED_BUILTIN
14-
#define BOARD_HAS_NEOPIXEL
15-
#define LED_BRIGHTNESS 64
14+
#define RGB_BUILTIN LED_BUILTIN
15+
#define RGB_BRIGHTNESS 64
1616

1717
#define analogInputToDigitalPin(p) (((p)<NUM_ANALOG_INPUTS)?(analogChannelToDigitalPin(p)):-1)
1818
#define digitalPinToInterrupt(p) (((p)<NUM_DIGITAL_PINS)?(p):-1)

Diff for: variants/esp32s2/pins_arduino.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ static const uint8_t LED_BUILTIN = SOC_GPIO_PIN_COUNT+18; // GPIO pin for Saola-
1212
//static const uint8_t LED_BUILTIN = SOC_GPIO_PIN_COUNT+45; // GPIO pin for Kaluga = 45
1313
#define BUILTIN_LED LED_BUILTIN // backward compatibility
1414
#define LED_BUILTIN LED_BUILTIN
15-
#define BOARD_HAS_NEOPIXEL
16-
#define LED_BRIGHTNESS 64
15+
#define RGB_BUILTIN LED_BUILTIN
16+
#define RGB_BRIGHTNESS 64
1717

1818
#define analogInputToDigitalPin(p) (((p)<20)?(analogChannelToDigitalPin(p)):-1)
1919
#define digitalPinToInterrupt(p) (((p)<48)?(p):-1)

Diff for: variants/esp32s3/pins_arduino.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@
1717
static const uint8_t LED_BUILTIN = SOC_GPIO_PIN_COUNT+48;
1818
#define BUILTIN_LED LED_BUILTIN // backward compatibility
1919
#define LED_BUILTIN LED_BUILTIN
20-
#define BOARD_HAS_NEOPIXEL
21-
#define LED_BRIGHTNESS 64
20+
#define RGB_BUILTIN LED_BUILTIN
21+
#define RGB_BRIGHTNESS 64
2222

2323
#define analogInputToDigitalPin(p) (((p)<20)?(analogChannelToDigitalPin(p)):-1)
2424
#define digitalPinToInterrupt(p) (((p)<48)?(p):-1)

0 commit comments

Comments
 (0)