diff --git a/platformio.ini b/platformio.ini index 93a904a..35aab29 100644 --- a/platformio.ini +++ b/platformio.ini @@ -55,3 +55,11 @@ platform = https://github.com/maxgerhardt/platform-raspberrypi.git board = pico framework = arduino board_build.core = earlephilhower + +[env:esp32dev] +board = esp32dev +framework = arduino +platform = espressif32@6.7.0 +platform_packages= + platformio/framework-arduinoespressif32 @ https://github.com/espressif/arduino-esp32.git#3.0.1 + platformio/framework-arduinoespressif32-libs @ https://github.com/espressif/arduino-esp32/releases/download/3.0.1/esp32-arduino-libs-3.0.1.zip diff --git a/src/hw_timer_esp32.cpp b/src/hw_timer_esp32.cpp index f16e24e..15cb835 100644 --- a/src/hw_timer_esp32.cpp +++ b/src/hw_timer_esp32.cpp @@ -26,6 +26,11 @@ const static int TIMER_ID = 0; static hw_timer_t* timer = nullptr; void timerInit(void (*callback)()) { +#if ESP_IDF_VERSION_MAJOR >= 5 + timer = timerBegin(1000000); + timerWrite(timer, 0); + timerAttachInterrupt(timer, callback); +#else // Use 1st timer of 4 (counted from zero). // Set 80 divider for prescaler (see ESP32 Technical Reference Manual for more // info), count up. The counter starts to increase its value. @@ -34,21 +39,31 @@ void timerInit(void (*callback)()) { timerWrite(timer, 0); timerAttachInterrupt(timer, callback, false); +#endif } void ARDUINO_ISR_ATTR startTimerAndTrigger(uint32_t delay) { +#if ESP_IDF_VERSION_MAJOR >= 5 + timerRestart(timer); + timerAlarm(timer, delay, false, 0); +#else timerWrite(timer, 0); timerAlarmWrite(timer, delay, false); timerAlarmEnable(timer); timerStart(timer); +#endif } void ARDUINO_ISR_ATTR setAlarm(uint32_t delay) { +#if ESP_IDF_VERSION_MAJOR >= 5 + timerAlarm(timer, delay, false, 0); +#else timerAlarmWrite(timer, delay, false); // On core v2.0.0-2.0.1, the timer alarm is automatically disabled after triggering, // so re-enable the alarm timerAlarmEnable(timer); +#endif } void ARDUINO_ISR_ATTR stopTimer() {