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.
This commit is contained in:
Gregg 2021-11-25 10:03:57 -06:00
parent d8bb51902f
commit 83170306f5
2 changed files with 5 additions and 21 deletions

View File

@ -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,24 +293,6 @@ 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)){

View File

@ -11,7 +11,7 @@ void setup() {
Serial.begin(115200);
homeSpan.setLogLevel(2);
homeSpan.setStatusPin(5);
homeSpan.setStatusPin(13);
homeSpan.setControlPin(33);
homeSpan.setHostNameSuffix("-lamp1");