From 08e62bd0be8e7aaa6db8fa2d2294630c3f727bbb Mon Sep 17 00:00:00 2001 From: midilab Date: Thu, 29 Dec 2022 14:18:14 -0500 Subject: [PATCH] experimental support for esp32 --- src/uClock.cpp | 24 +++++++++++++++++++++++- src/uClock.h | 2 -- 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/src/uClock.cpp b/src/uClock.cpp index 9e6e12f..74d1cc8 100755 --- a/src/uClock.cpp +++ b/src/uClock.cpp @@ -50,9 +50,22 @@ // #if defined(ARDUINO_ARCH_ESP32) || defined(ESP32) hw_timer_t * _uclockTimer = NULL; + portMUX_TYPE _uclockTimerMux = portMUX_INITIALIZER_UNLOCKED; #define TIMER_ID 0 #endif +// +// multicore archs +// +#if defined(ARDUINO_ARCH_ESP32) || defined(ESP32) + #define ATOMIC(X) portENTER_CRITICAL_ISR(&_uclockTimerMux); X; portEXIT_CRITICAL_ISR(&_uclockTimerMux); +// +// singlecore archs +// +#else + #define ATOMIC(X) noInterrupts(); X; interrupts(); +#endif + #if defined(ARDUINO_ARCH_AVR) void uclockInitTimer() { @@ -73,7 +86,14 @@ void uclockInitTimer() ) } #else -void uclockISR(); + + // forward declaration of ISR + #if defined(ARDUINO_ARCH_ESP32) || defined(ESP32) + void ARDUINO_ISR_ATTR uclockISR(); + #else + void uclockISR(); + #endif + void uclockInitTimer() { // begin at 120bpm (20833us) @@ -501,6 +521,8 @@ volatile uint32_t _timer = 0; // #if defined(ARDUINO_ARCH_AVR) ISR(TIMER1_COMPA_vect) +#elif defined(ARDUINO_ARCH_ESP32) || defined(ESP32) +void ARDUINO_ISR_ATTR uclockISR() #else void uclockISR() #endif diff --git a/src/uClock.h b/src/uClock.h index cee7bd6..09b7a74 100755 --- a/src/uClock.h +++ b/src/uClock.h @@ -54,8 +54,6 @@ namespace umodular { namespace clock { #define SECS_PER_HOUR (3600UL) #define SECS_PER_DAY (SECS_PER_HOUR * 24L) -#define ATOMIC(X) noInterrupts(); X; interrupts(); - class uClockClass { private: