Skip to content

Commit 386e7e7

Browse files
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`.
1 parent c93bf11 commit 386e7e7

File tree

3 files changed

+12
-12
lines changed

3 files changed

+12
-12
lines changed

cores/esp32/esp32-hal-gpio.c

Lines changed: 7 additions & 7 deletions
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

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

Lines changed: 3 additions & 3 deletions
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

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

Lines changed: 2 additions & 2 deletions
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);

0 commit comments

Comments
 (0)