From 6088fb16fece19ecd09c6a15a132685838c8b6dd Mon Sep 17 00:00:00 2001 From: HomeSpan Date: Mon, 6 Sep 2021 12:35:26 -0500 Subject: [PATCH] Added logic to Timer code to allow for compiling under S2 and C3 With these changes the code compiles but nothing has been tested yet to see if it actually works under S2 and C3! --- src/Utils.cpp | 29 +++++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/src/Utils.cpp b/src/Utils.cpp index 0bf1578..59a1da2 100644 --- a/src/Utils.cpp +++ b/src/Utils.cpp @@ -229,8 +229,13 @@ void Blinker::init(int pin, int timerNum){ pinMode(pin,OUTPUT); digitalWrite(pin,0); +#if SOC_TIMER_GROUP_TIMERS_PER_GROUP>1 // ESP32 and ESP32-S2 contains two timers per timer group group=((timerNum/2)%2==0)?TIMER_GROUP_0:TIMER_GROUP_1; - idx=(timerNum%2==0)?TIMER_0:TIMER_1; + idx=(timerNum%2==0)?TIMER_0:TIMER_1; // ESP32-C3 only contains one timer per timer group +#else + group=(timerNum%2==0)?TIMER_GROUP_0:TIMER_GROUP_1; + idx=TIMER_0; +#endif timer_config_t conf; conf.alarm_en=TIMER_ALARM_EN; @@ -251,7 +256,8 @@ void Blinker::init(int pin, int timerNum){ void Blinker::isrTimer(void *arg){ Blinker *b=(Blinker *)arg; - + +#if CONFIG_IDF_TARGET_ESP32 if(b->group){ if(b->idx) TIMERG1.int_clr_timers.t1=1; @@ -263,6 +269,25 @@ 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);