From 83170306f5e77b4585e04ea41397ee42ea0068ab Mon Sep 17 00:00:00 2001 From: Gregg Date: Thu, 25 Nov 2021 10:03:57 -0600 Subject: [PATCH] Updated Blinker class for compatibility with Arduino-ESP32 v2.0.1 The update from Arduino-ESP32 2.0.0 to 2.0.1 contained significant changes to the structures used by the IDF for generic timers. This broke the Blinker code (would not compile for ESP32-S2 and C3 chips). The solution: Modified Blinker::isrTimer() to use a *generic* interrupt-clearing function when available (IDF version >= 4.0.0). Below 4.0.0 the code continues to manually clear the interrupt flag by resetting specific structure variables, though the logic is simpler since this is only needed for the ESP32 chip (the S2 and C3 are not supported in earlier versions of Arduino-ESP32). This provides for full compatibility with Arduino-ESP32 versions 2.0.1, 2.0.0, and 1.0.6. The use of a generic interrupt clearing function when IDF>=4.0.0 will hopefully make this future-proof to any further changes by Espressif to the underlying timer structures. --- src/Utils.cpp | 24 ++++-------------------- src/src.ino | 2 +- 2 files changed, 5 insertions(+), 21 deletions(-) diff --git a/src/Utils.cpp b/src/Utils.cpp index 15de921..e6f5294 100644 --- a/src/Utils.cpp +++ b/src/Utils.cpp @@ -279,7 +279,9 @@ void Blinker::isrTimer(void *arg){ Blinker *b=(Blinker *)arg; -#if CONFIG_IDF_TARGET_ESP32 +#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(4, 0, 0) // use new method that is generic to ESP32, S2, and C3 + timer_group_clr_intr_status_in_isr(b->group,b->idx); +#else // use older method that is only for ESP32 if(b->group){ if(b->idx) TIMERG1.int_clr_timers.t1=1; @@ -291,26 +293,8 @@ void Blinker::isrTimer(void *arg){ else TIMERG0.int_clr_timers.t0=1; } -#elif CONFIG_IDF_TARGET_ESP32S2 // for some reason, the ESP32-S2 and ESP32-C3 use "int_clr" instead of "int_clr_timers" in their timer structure - if(b->group){ - if(b->idx) - TIMERG1.int_clr.t1=1; - else - TIMERG1.int_clr.t0=1; - } else { - if(b->idx) - TIMERG0.int_clr.t1=1; - else - TIMERG0.int_clr.t0=1; - } -#elif CONFIG_IDF_TARGET_ESP32C3 // ESP32-C3 only has one timer per timer group - if(b->group){ - TIMERG1.int_clr.t0=1; - } else { - TIMERG0.int_clr.t0=1; - } #endif - + if(!digitalRead(b->pin)){ digitalWrite(b->pin,1); timer_set_alarm_value(b->group,b->idx,b->onTime); diff --git a/src/src.ino b/src/src.ino index df75ea3..e90df18 100644 --- a/src/src.ino +++ b/src/src.ino @@ -11,7 +11,7 @@ void setup() { Serial.begin(115200); homeSpan.setLogLevel(2); - homeSpan.setStatusPin(5); + homeSpan.setStatusPin(13); homeSpan.setControlPin(33); homeSpan.setHostNameSuffix("-lamp1");