From 95ea61a12dc9f256212104e649b39de1ab6631e7 Mon Sep 17 00:00:00 2001 From: Naguissa Date: Fri, 28 Dec 2018 15:34:00 +0100 Subject: [PATCH] Added ESP32 support (same as ESP8266) --- README.md | 6 +++++- library.properties | 4 ++-- src/uTimerLib.cpp | 10 ++++++---- src/uTimerLib.h | 9 +++++---- 4 files changed, 18 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index aae2b97..b9d362c 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,7 @@ Tiny and cross-device compatible timer-driven timed function calls library. -Supports Arduino AVR, SAM, STM32, ESP8266 and SAMD21 microcontrollers. +Supports Arduino AVR, SAM, STM32, ESP8266, ESP32 and SAMD21 microcontrollers. ## Current status ## @@ -14,6 +14,7 @@ Currently suported architectures: - STM32 - SAM (Arduino Due) - ESP8266 + - ESP32 - SAMD21 (Arduino Zero and Zero MKR; experimental support) - SAMD51 (Adafruit Feather M4, Adafruit Metro M4; work in progress, not functional -need for a SAMD51 board...) @@ -26,9 +27,12 @@ Depending on wich architecture this library uses one or another device timer. Ta - STM32: Timer3 (3rd timer) - SAM: TC3 (Timer1, channel 0) - ESP8266: Ticker library (inside ESP8266 core, no extras needed) + - ESP32: OS Timer, one slof of software timer. - SAMD21: Timer3 (4th timer), CC0; 16 bit mode - SAMD51: Timer1 (2nd timer); 16 bit mode +*Note*: On ESP8266 and ESP32 this library uses "ticker" to manage timer, so it's maximum resolution is miliseconds. On "_us" functions times will be rounded to miliseconds. + ## Usage ## This library defines a global variable when included called "TimerLib". diff --git a/library.properties b/library.properties index 43fb8e4..06c8adc 100644 --- a/library.properties +++ b/library.properties @@ -1,9 +1,9 @@ name=uTimerLib -version=1.0.0 +version=1.1.0 author=Naguissa maintainer=Naguissa sentence=Tiny and cross-device compatible timer library -paragraph=Supports Arduino AVR, SAM, STM32, ESP8266 and SAMD21 microcontrollers +paragraph=Supports Arduino AVR, SAM, STM32, ESP8266, ESP32 and SAMD21 microcontrollers category=Timing url=https://github.com/Naguissa/uTimerLib architectures=* diff --git a/src/uTimerLib.cpp b/src/uTimerLib.cpp index a273907..a26893f 100644 --- a/src/uTimerLib.cpp +++ b/src/uTimerLib.cpp @@ -6,6 +6,7 @@ * STM32: Timer3 (3rd timer) * SAM (Due): TC3 (Timer1, channel 0) * ESP8266: OS Timer, one slof of seven available (Software timer provided by Arduino because ESP8266 has only two hardware timers and one is needed by it normal operation) + * ESP32: OS Timer, one slof of software timer. * SAMD21: Timer 4, CC0 (TC3). See http://ww1.microchip.com/downloads/en/DeviceDoc/40001882A.pdf * SAMD51: Timer 2 (TC1), 16 bits mode (See http://ww1.microchip.com/downloads/en/DeviceDoc/60001507C.pdf * @@ -256,7 +257,7 @@ void uTimerLib::_attachInterrupt_us(unsigned long int us) { - #ifdef ARDUINO_ARCH_ESP8266 + #if defined(ARDUINO_ARCH_ESP8266) || defined(ARDUINO_ARCH_ESP32) unsigned long int ms = (us / 1000) + 0.5; if (ms == 0) { ms = 1; @@ -523,7 +524,7 @@ void uTimerLib::_attachInterrupt_s(unsigned long int s) { TC_Start(TC1, 0); #endif - #ifdef ARDUINO_ARCH_ESP8266 + #if defined(ARDUINO_ARCH_ESP8266) || defined(ARDUINO_ARCH_ESP32) __overflows = _overflows = __remaining = _remaining = 0; _ticker.attach(s, uTimerLib::interrupt); #endif @@ -632,6 +633,7 @@ void uTimerLib::_loadRemaining() { #endif // ESP8266 + // ESP32 // SAMD21, Arduino Zero #ifdef _SAMD21_ @@ -670,7 +672,7 @@ void uTimerLib::clearTimer() { NVIC_DisableIRQ(TC3_IRQn); #endif - #ifdef ARDUINO_ARCH_ESP8266 + #if defined(ARDUINO_ARCH_ESP8266) || defined(ARDUINO_ARCH_ESP32) _ticker.detach(); #endif @@ -812,7 +814,7 @@ uTimerLib TimerLib = uTimerLib(); #endif -#ifdef ARDUINO_ARCH_ESP8266 +#if defined(ARDUINO_ARCH_ESP8266) || defined(ARDUINO_ARCH_ESP32) void uTimerLib::interrupt() { TimerLib._interrupt(); } diff --git a/src/uTimerLib.h b/src/uTimerLib.h index 1d3b481..4e76356 100644 --- a/src/uTimerLib.h +++ b/src/uTimerLib.h @@ -6,6 +6,7 @@ * STM32: Timer3 (3rd timer) * SAM (Due): TC3 (Timer1, channel 0) * ESP8266: OS Timer, one slof of seven available (Software timer provided by Arduino because ESP8266 has only two hardware timers and one is needed by it normal operation) + * ESP32: OS Timer, one slof of software timer. * SAMD21: Timer 4, CC0 (TC3). See http://ww1.microchip.com/downloads/en/DeviceDoc/40001882A.pdf * SAMD51: Timer 2 (TC1), 16 bits mode (See http://ww1.microchip.com/downloads/en/DeviceDoc/60001507C.pdf * @@ -20,7 +21,7 @@ #include "Arduino.h" - #ifdef ARDUINO_ARCH_ESP8266 + #if defined(ARDUINO_ARCH_ESP8266) || defined(ARDUINO_ARCH_ESP32) #include //Ticker Library #endif // Operation modes @@ -47,8 +48,8 @@ static void interrupt(); #endif - #ifdef ARDUINO_ARCH_ESP8266 - #pragma message "ESP8266 can only reach a ms resolution so any ms interrupt will be rounded to that" + #if defined(ARDUINO_ARCH_ESP8266) || defined(ARDUINO_ARCH_ESP32) + #pragma message "ESP8266 / ESP32 can only reach a ms resolution so any ms interrupt will be rounded to that" static void interrupt(); #endif @@ -85,7 +86,7 @@ bool _toInit = true; #endif - #ifdef ARDUINO_ARCH_ESP8266 + #if defined(ARDUINO_ARCH_ESP8266) || defined(ARDUINO_ARCH_ESP32) Ticker _ticker; #endif };