diff --git a/library.json b/library.json index c66d060..c0c98c2 100644 --- a/library.json +++ b/library.json @@ -1,6 +1,6 @@ { "name": "uClock", - "version": "2.2.0", + "version": "2.2.1", "description": "A Library to implement BPM clock tick calls using hardware interruption. Supported and tested on AVR boards(ATmega168/328, ATmega16u4/32u4 and ATmega2560) and ARM boards(Teensy, STM32XX, ESP32, Raspberry Pico, Seedstudio XIAO M0 and RP2040)", "keywords": "bpm, clock, timing, tick, music, generator", "repository": diff --git a/library.properties b/library.properties index 0f4cce0..300684b 100755 --- a/library.properties +++ b/library.properties @@ -1,5 +1,5 @@ name=uClock -version=2.2.0 +version=2.2.1 author=Romulo Silva maintainer=Romulo Silva sentence=BPM clock generator for Arduino platform. diff --git a/src/platforms/avr.h b/src/platforms/avr.h index 9904c92..9931dac 100644 --- a/src/platforms/avr.h +++ b/src/platforms/avr.h @@ -6,6 +6,15 @@ // TODO: we should do this using macro guards for avrs different clocks freqeuncy setup at compile time #define AVR_CLOCK_FREQ 16000000 +// forward declaration of uClockHandler +void uClockHandler(); + +// AVR ISR Entrypoint +ISR(TIMER1_COMPA_vect) +{ + uClockHandler(); +} + void initTimer(uint32_t init_clock) { ATOMIC( diff --git a/src/platforms/esp32-nofrertos.h b/src/platforms/esp32-nofrertos.h new file mode 100644 index 0000000..70d2720 --- /dev/null +++ b/src/platforms/esp32-nofrertos.h @@ -0,0 +1,32 @@ +#include + +#define TIMER_ID 0 + +hw_timer_t * _uclockTimer = NULL; +portMUX_TYPE _uclockTimerMux = portMUX_INITIALIZER_UNLOCKED; +#define ATOMIC(X) portENTER_CRITICAL_ISR(&_uclockTimerMux); X; portEXIT_CRITICAL_ISR(&_uclockTimerMux); + +// forward declaration of uClockHandler +void uClockHandler(); + +// ISR handler +void ARDUINO_ISR_ATTR handlerISR(void) +{ + uClockHandler(); +} + +void initTimer(uint32_t init_clock) +{ + _uclockTimer = timerBegin(init_clock); + + // attach to generic uclock ISR + timerAttachInterrupt(_uclockTimer, &handlerISR); + + // init clock tick time + timerAlarm(_uclockTimer, init_clock, true, 0); +} + +void setTimer(uint32_t us_interval) +{ + timerAlarmWrite(_uclockTimer, us_interval, true); +} \ No newline at end of file diff --git a/src/platforms/esp32.h b/src/platforms/esp32.h index 372ca93..f0ef639 100644 --- a/src/platforms/esp32.h +++ b/src/platforms/esp32.h @@ -3,11 +3,7 @@ #include // esp32-specific timer -#define TIMER_ID 0 hw_timer_t * _uclockTimer = NULL; -// mutex control for ISR -//portMUX_TYPE _uclockTimerMux = portMUX_INITIALIZER_UNLOCKED; -//#define ATOMIC(X) portENTER_CRITICAL_ISR(&_uclockTimerMux); X; portEXIT_CRITICAL_ISR(&_uclockTimerMux); // FreeRTOS main clock task size in bytes #define CLOCK_STACK_SIZE 5*1024 // adjust for your needs, a sequencer with heavy serial handling should be large in size @@ -47,7 +43,7 @@ void initTimer(uint32_t init_clock) // create the clockTask xTaskCreate(clockTask, "clockTask", CLOCK_STACK_SIZE, NULL, 1, &taskHandle); - _uclockTimer = timerBegin(1000000); + _uclockTimer = timerBegin(init_clock); // attach to generic uclock ISR timerAttachInterrupt(_uclockTimer, &handlerISR); diff --git a/src/uClock.cpp b/src/uClock.cpp index 9f27935..c06a9fa 100755 --- a/src/uClock.cpp +++ b/src/uClock.cpp @@ -2,7 +2,7 @@ * @file uClock.cpp * Project BPM clock generator for Arduino * @brief A Library to implement BPM clock tick calls using hardware interruption. Supported and tested on AVR boards(ATmega168/328, ATmega16u4/32u4 and ATmega2560) and ARM boards(RPI2040, Teensy, Seedstudio XIAO M0 and ESP32) - * @version 2.2.0 + * @version 2.2.1 * @author Romulo Silva * @date 10/06/2017 * @license MIT - (c) 2024 - Romulo Silva - contact@midilab.co @@ -532,11 +532,7 @@ volatile uint32_t _millis = 0; // // TIMER HANDLER // -#if defined(ARDUINO_ARCH_AVR) -ISR(TIMER1_COMPA_vect) -#else void uClockHandler() -#endif { // global timer counter _millis = millis(); diff --git a/src/uClock.h b/src/uClock.h index df1a08d..45f0899 100755 --- a/src/uClock.h +++ b/src/uClock.h @@ -2,7 +2,7 @@ * @file uClock.h * Project BPM clock generator for Arduino * @brief A Library to implement BPM clock tick calls using hardware interruption. Supported and tested on AVR boards(ATmega168/328, ATmega16u4/32u4 and ATmega2560) and ARM boards(RPI2040, Teensy, Seedstudio XIAO M0 and ESP32) - * @version 2.2.0 + * @version 2.2.1 * @author Romulo Silva * @date 10/06/2017 * @license MIT - (c) 2024 - Romulo Silva - contact@midilab.co