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

Improve RGB driver in pull #6808; solves #6968 #6979

Merged
merged 5 commits into from
Jul 18, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
14 changes: 7 additions & 7 deletions cores/esp32/esp32-hal-gpio.c
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,9 @@ static InterruptHandle_t __pinInterruptHandlers[SOC_GPIO_PIN_COUNT] = {0,};

extern void ARDUINO_ISR_ATTR __pinMode(uint8_t pin, uint8_t mode)
{
#ifdef BOARD_HAS_NEOPIXEL
if (pin == LED_BUILTIN){
__pinMode(LED_BUILTIN-SOC_GPIO_PIN_COUNT, mode);
#ifdef RGB_BUILTIN
if (pin == RGB_BUILTIN){
__pinMode(RGB_BUILTIN-SOC_GPIO_PIN_COUNT, mode);
return;
}
#endif
Expand Down Expand Up @@ -134,11 +134,11 @@ extern void ARDUINO_ISR_ATTR __pinMode(uint8_t pin, uint8_t mode)

extern void ARDUINO_ISR_ATTR __digitalWrite(uint8_t pin, uint8_t val)
{
#ifdef BOARD_HAS_NEOPIXEL
if(pin == LED_BUILTIN){
#ifdef RGB_BUILTIN
if(pin == RGB_BUILTIN){
//use RMT to set all channels on/off
const uint8_t comm_val = val != 0 ? LED_BRIGHTNESS : 0;
neopixelWrite(LED_BUILTIN, comm_val, comm_val, comm_val);
const uint8_t comm_val = val != 0 ? RGB_BRIGHTNESS : 0;
neopixelWrite(RGB_BUILTIN, comm_val, comm_val, comm_val);
return;
}
#endif
Expand Down
6 changes: 3 additions & 3 deletions cores/esp32/esp32-hal-rgb-led.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ void neopixelWrite(uint8_t pin, uint8_t red_val, uint8_t green_val, uint8_t blue
static bool initialized = false;

uint8_t _pin = pin;
#ifdef BOARD_HAS_NEOPIXEL
if(pin == LED_BUILTIN){
_pin = LED_BUILTIN-SOC_GPIO_PIN_COUNT;
#ifdef RGB_BUILTIN
if(pin == RGB_BUILTIN){
_pin = RGB_BUILTIN-SOC_GPIO_PIN_COUNT;
}
#endif

Expand Down
4 changes: 2 additions & 2 deletions cores/esp32/esp32-hal-rgb-led.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ extern "C" {

#include "esp32-hal.h"

#ifndef LED_BRIGHTNESS
#define LED_BRIGHTNESS 64
#ifndef RGB_BRIGHTNESS
#define RGB_BRIGHTNESS 64
#endif

void neopixelWrite(uint8_t pin, uint8_t red_val, uint8_t green_val, uint8_t blue_val);
Expand Down
18 changes: 9 additions & 9 deletions libraries/ESP32/examples/GPIO/BlinkRGB/BlinkRGB.ino
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@

Demonstrates usage of onboard RGB LED on some ESP dev boards.

Calling digitalWrite(LED_BUILTIN, HIGH) will use hidden RGB driver.
Calling digitalWrite(RGB_BUILTIN, HIGH) will use hidden RGB driver.

RGBLedWrite demonstrates controll of each channel:
void neopixelWrite(uint8_t pin, uint8_t red_val, uint8_t green_val, uint8_t blue_val)

WARNING: After using digitalWrite to drive RGB LED it will be impossible to drive the same pin
with normal HIGH/LOW level
*/
//#define LED_BRIGHTNESS 64 // Change white brightness (max 255)
//#define RGB_BRIGHTNESS 64 // Change white brightness (max 255)

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

Expand All @@ -21,19 +21,19 @@ void setup() {

// the loop function runs over and over again forever
void loop() {
#ifdef BOARD_HAS_NEOPIXEL
digitalWrite(LED_BUILTIN, HIGH); // Turn the RGB LED white
#ifdef RGB_BUILTIN
digitalWrite(RGB_BUILTIN, HIGH); // Turn the RGB LED white
delay(1000);
digitalWrite(LED_BUILTIN, LOW); // Turn the RGB LED off
digitalWrite(RGB_BUILTIN, LOW); // Turn the RGB LED off
delay(1000);

neopixelWrite(LED_BUILTIN,LED_BRIGHTNESS,0,0); // Red
neopixelWrite(RGB_BUILTIN,RGB_BRIGHTNESS,0,0); // Red
delay(1000);
neopixelWrite(LED_BUILTIN,0,LED_BRIGHTNESS,0); // Green
neopixelWrite(RGB_BUILTIN,0,RGB_BRIGHTNESS,0); // Green
delay(1000);
neopixelWrite(LED_BUILTIN,0,0,LED_BRIGHTNESS); // Blue
neopixelWrite(RGB_BUILTIN,0,0,RGB_BRIGHTNESS); // Blue
delay(1000);
neopixelWrite(LED_BUILTIN,0,0,0); // Off / black
neopixelWrite(RGB_BUILTIN,0,0,0); // Off / black
delay(1000);
#endif
}
4 changes: 2 additions & 2 deletions variants/esp32c3/pins_arduino.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
static const uint8_t LED_BUILTIN = SOC_GPIO_PIN_COUNT+8;
#define BUILTIN_LED LED_BUILTIN // backward compatibility
#define LED_BUILTIN LED_BUILTIN
#define BOARD_HAS_NEOPIXEL
#define LED_BRIGHTNESS 64
#define RGB_BUILTIN LED_BUILTIN
#define RGB_BRIGHTNESS 64

#define analogInputToDigitalPin(p) (((p)<NUM_ANALOG_INPUTS)?(analogChannelToDigitalPin(p)):-1)
#define digitalPinToInterrupt(p) (((p)<NUM_DIGITAL_PINS)?(p):-1)
Expand Down
4 changes: 2 additions & 2 deletions variants/esp32s2/pins_arduino.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ static const uint8_t LED_BUILTIN = SOC_GPIO_PIN_COUNT+18; // GPIO pin for Saola-
//static const uint8_t LED_BUILTIN = SOC_GPIO_PIN_COUNT+45; // GPIO pin for Kaluga = 45
#define BUILTIN_LED LED_BUILTIN // backward compatibility
#define LED_BUILTIN LED_BUILTIN
#define BOARD_HAS_NEOPIXEL
#define LED_BRIGHTNESS 64
#define RGB_BUILTIN LED_BUILTIN
#define RGB_BRIGHTNESS 64

#define analogInputToDigitalPin(p) (((p)<20)?(analogChannelToDigitalPin(p)):-1)
#define digitalPinToInterrupt(p) (((p)<48)?(p):-1)
Expand Down
4 changes: 2 additions & 2 deletions variants/esp32s3/pins_arduino.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
static const uint8_t LED_BUILTIN = SOC_GPIO_PIN_COUNT+48;
#define BUILTIN_LED LED_BUILTIN // backward compatibility
#define LED_BUILTIN LED_BUILTIN
#define BOARD_HAS_NEOPIXEL
#define LED_BRIGHTNESS 64
#define RGB_BUILTIN LED_BUILTIN
#define RGB_BRIGHTNESS 64

#define analogInputToDigitalPin(p) (((p)<20)?(analogChannelToDigitalPin(p)):-1)
#define digitalPinToInterrupt(p) (((p)<48)?(p):-1)
Expand Down