From e92b4ca62b7f1375b762ee18ceb9f59dbd4a04dc Mon Sep 17 00:00:00 2001 From: Holger Lembke Date: Tue, 26 Mar 2024 16:46:59 +0100 Subject: [PATCH] Add: make digitalRead() for RGB_BUILTIN work (#9419) * 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.) --- cores/esp32/esp32-hal-gpio.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/cores/esp32/esp32-hal-gpio.c b/cores/esp32/esp32-hal-gpio.c index df0e6a299..2301302d6 100644 --- a/cores/esp32/esp32-hal-gpio.c +++ b/cores/esp32/esp32-hal-gpio.c @@ -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; @@ -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); }