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.)
This commit is contained in:
Holger Lembke 2024-03-26 16:46:59 +01:00 committed by GitHub
parent 6345350584
commit e92b4ca62b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -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);
}