Skip to content

Commit

Permalink
Added ESP32 support (same as ESP8266)
Browse files Browse the repository at this point in the history
  • Loading branch information
Naguissa committed Dec 28, 2018
1 parent cff7e9d commit 95ea61a
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 11 deletions.
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 ##
Expand All @@ -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...)
Expand All @@ -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".
Expand Down
4 changes: 2 additions & 2 deletions library.properties
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
name=uTimerLib
version=1.0.0
version=1.1.0
author=Naguissa <naguissa@foroelectro.net>
maintainer=Naguissa <naguissa@foroelectro.net>
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=*
Expand Down
10 changes: 6 additions & 4 deletions src/uTimerLib.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -632,6 +633,7 @@ void uTimerLib::_loadRemaining() {
#endif

// ESP8266
// ESP32

// SAMD21, Arduino Zero
#ifdef _SAMD21_
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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();
}
Expand Down
9 changes: 5 additions & 4 deletions src/uTimerLib.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand All @@ -20,7 +21,7 @@

#include "Arduino.h"

#ifdef ARDUINO_ARCH_ESP8266
#if defined(ARDUINO_ARCH_ESP8266) || defined(ARDUINO_ARCH_ESP32)
#include <Ticker.h> //Ticker Library
#endif
// Operation modes
Expand All @@ -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

Expand Down Expand Up @@ -85,7 +86,7 @@
bool _toInit = true;
#endif

#ifdef ARDUINO_ARCH_ESP8266
#if defined(ARDUINO_ARCH_ESP8266) || defined(ARDUINO_ARCH_ESP32)
Ticker _ticker;
#endif
};
Expand Down

0 comments on commit 95ea61a

Please sign in to comment.