Skip to content

Commit

Permalink
Add: make digitalRead() for RGB_BUILTIN work (#9419)
Browse files Browse the repository at this point in the history
* make digitalRead() for RGB_BUILTIN work

Standard Arduino-Way of blinking a LED can be the shortest with:

void loop() {
  static uint32_t ledticker = 0;
  if (millis() - ledticker > 1000) {
    ledticker = millis();
    digitalWrite(RGB_BUILTIN, !digitalRead(RGB_BUILTIN));
  }
}

Worked with the old LED_BUILTIN on Pin 2, now even works with Pin 48/neopixel.

* Add: make digitalRead() for RGB_BUILTIN work

Standard Arduino-Way of blinking a LED can be the shortest with:

void loop() {
  static uint32_t ledticker = 0;
  if (millis() - ledticker > 1000) {
    ledticker = millis();
    digitalWrite(RGB_BUILTIN, !digitalRead(RGB_BUILTIN));
  }
}

Worked with the old LED_BUILTIN on Pin 2, now even works with Pin 48/neopixel.

(Retry. Didn't sync my local sources. Sorry.)
  • Loading branch information
holgerlembke authored Mar 26, 2024
1 parent 6345350 commit e92b4ca
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions cores/esp32/esp32-hal-gpio.c
Original file line number Diff line number Diff line change
Expand Up @@ -151,11 +151,16 @@ extern void ARDUINO_ISR_ATTR __pinMode(uint8_t pin, uint8_t mode)
}
}

#ifdef RGB_BUILTIN
uint8_t RGB_BUILTIN_storage = 0;
#endif

extern void ARDUINO_ISR_ATTR __digitalWrite(uint8_t pin, uint8_t val)
{
#ifdef RGB_BUILTIN
if(pin == RGB_BUILTIN){
//use RMT to set all channels on/off
RGB_BUILTIN_storage=val;
const uint8_t comm_val = val != 0 ? RGB_BRIGHTNESS : 0;
neopixelWrite(RGB_BUILTIN, comm_val, comm_val, comm_val);
return;
Expand All @@ -170,6 +175,12 @@ extern void ARDUINO_ISR_ATTR __digitalWrite(uint8_t pin, uint8_t val)

extern int ARDUINO_ISR_ATTR __digitalRead(uint8_t pin)
{
#ifdef RGB_BUILTIN
if(pin == RGB_BUILTIN){
return RGB_BUILTIN_storage;
}
#endif

if(perimanGetPinBus(pin, ESP32_BUS_TYPE_GPIO) != NULL){
return gpio_get_level((gpio_num_t)pin);
}
Expand Down

0 comments on commit e92b4ca

Please sign in to comment.