Skip to content

Commit 95ea61a

Browse files
committed
Added ESP32 support (same as ESP8266)
1 parent cff7e9d commit 95ea61a

File tree

4 files changed

+18
-11
lines changed

4 files changed

+18
-11
lines changed

README.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
Tiny and cross-device compatible timer-driven timed function calls library.
66

7-
Supports Arduino AVR, SAM, STM32, ESP8266 and SAMD21 microcontrollers.
7+
Supports Arduino AVR, SAM, STM32, ESP8266, ESP32 and SAMD21 microcontrollers.
88

99

1010
## Current status ##
@@ -14,6 +14,7 @@ Currently suported architectures:
1414
- STM32
1515
- SAM (Arduino Due)
1616
- ESP8266
17+
- ESP32
1718
- SAMD21 (Arduino Zero and Zero MKR; experimental support)
1819

1920
- 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
2627
- STM32: Timer3 (3rd timer)
2728
- SAM: TC3 (Timer1, channel 0)
2829
- ESP8266: Ticker library (inside ESP8266 core, no extras needed)
30+
- ESP32: OS Timer, one slof of software timer.
2931
- SAMD21: Timer3 (4th timer), CC0; 16 bit mode
3032
- SAMD51: Timer1 (2nd timer); 16 bit mode
3133

34+
*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.
35+
3236
## Usage ##
3337

3438
This library defines a global variable when included called "TimerLib".

library.properties

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
name=uTimerLib
2-
version=1.0.0
2+
version=1.1.0
33
author=Naguissa <naguissa@foroelectro.net>
44
maintainer=Naguissa <naguissa@foroelectro.net>
55
sentence=Tiny and cross-device compatible timer library
6-
paragraph=Supports Arduino AVR, SAM, STM32, ESP8266 and SAMD21 microcontrollers
6+
paragraph=Supports Arduino AVR, SAM, STM32, ESP8266, ESP32 and SAMD21 microcontrollers
77
category=Timing
88
url=https://github.com/Naguissa/uTimerLib
99
architectures=*

src/uTimerLib.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
* STM32: Timer3 (3rd timer)
77
* SAM (Due): TC3 (Timer1, channel 0)
88
* 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)
9+
* ESP32: OS Timer, one slof of software timer.
910
* SAMD21: Timer 4, CC0 (TC3). See http://ww1.microchip.com/downloads/en/DeviceDoc/40001882A.pdf
1011
* SAMD51: Timer 2 (TC1), 16 bits mode (See http://ww1.microchip.com/downloads/en/DeviceDoc/60001507C.pdf
1112
*
@@ -256,7 +257,7 @@ void uTimerLib::_attachInterrupt_us(unsigned long int us) {
256257

257258

258259

259-
#ifdef ARDUINO_ARCH_ESP8266
260+
#if defined(ARDUINO_ARCH_ESP8266) || defined(ARDUINO_ARCH_ESP32)
260261
unsigned long int ms = (us / 1000) + 0.5;
261262
if (ms == 0) {
262263
ms = 1;
@@ -523,7 +524,7 @@ void uTimerLib::_attachInterrupt_s(unsigned long int s) {
523524
TC_Start(TC1, 0);
524525
#endif
525526

526-
#ifdef ARDUINO_ARCH_ESP8266
527+
#if defined(ARDUINO_ARCH_ESP8266) || defined(ARDUINO_ARCH_ESP32)
527528
__overflows = _overflows = __remaining = _remaining = 0;
528529
_ticker.attach(s, uTimerLib::interrupt);
529530
#endif
@@ -632,6 +633,7 @@ void uTimerLib::_loadRemaining() {
632633
#endif
633634

634635
// ESP8266
636+
// ESP32
635637

636638
// SAMD21, Arduino Zero
637639
#ifdef _SAMD21_
@@ -670,7 +672,7 @@ void uTimerLib::clearTimer() {
670672
NVIC_DisableIRQ(TC3_IRQn);
671673
#endif
672674

673-
#ifdef ARDUINO_ARCH_ESP8266
675+
#if defined(ARDUINO_ARCH_ESP8266) || defined(ARDUINO_ARCH_ESP32)
674676
_ticker.detach();
675677
#endif
676678

@@ -812,7 +814,7 @@ uTimerLib TimerLib = uTimerLib();
812814
#endif
813815

814816

815-
#ifdef ARDUINO_ARCH_ESP8266
817+
#if defined(ARDUINO_ARCH_ESP8266) || defined(ARDUINO_ARCH_ESP32)
816818
void uTimerLib::interrupt() {
817819
TimerLib._interrupt();
818820
}

src/uTimerLib.h

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
* STM32: Timer3 (3rd timer)
77
* SAM (Due): TC3 (Timer1, channel 0)
88
* 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)
9+
* ESP32: OS Timer, one slof of software timer.
910
* SAMD21: Timer 4, CC0 (TC3). See http://ww1.microchip.com/downloads/en/DeviceDoc/40001882A.pdf
1011
* SAMD51: Timer 2 (TC1), 16 bits mode (See http://ww1.microchip.com/downloads/en/DeviceDoc/60001507C.pdf
1112
*
@@ -20,7 +21,7 @@
2021

2122
#include "Arduino.h"
2223

23-
#ifdef ARDUINO_ARCH_ESP8266
24+
#if defined(ARDUINO_ARCH_ESP8266) || defined(ARDUINO_ARCH_ESP32)
2425
#include <Ticker.h> //Ticker Library
2526
#endif
2627
// Operation modes
@@ -47,8 +48,8 @@
4748
static void interrupt();
4849
#endif
4950

50-
#ifdef ARDUINO_ARCH_ESP8266
51-
#pragma message "ESP8266 can only reach a ms resolution so any ms interrupt will be rounded to that"
51+
#if defined(ARDUINO_ARCH_ESP8266) || defined(ARDUINO_ARCH_ESP32)
52+
#pragma message "ESP8266 / ESP32 can only reach a ms resolution so any ms interrupt will be rounded to that"
5253
static void interrupt();
5354
#endif
5455

@@ -85,7 +86,7 @@
8586
bool _toInit = true;
8687
#endif
8788

88-
#ifdef ARDUINO_ARCH_ESP8266
89+
#if defined(ARDUINO_ARCH_ESP8266) || defined(ARDUINO_ARCH_ESP32)
8990
Ticker _ticker;
9091
#endif
9192
};

0 commit comments

Comments
 (0)