uTimerLib
https://github.com/Naguissa/uTimerLib
uTimerLib.h
Go to the documentation of this file.
1 
32 #ifndef _uTimerLib_
33 
36  #define _uTimerLib_
37 
38  #include "Arduino.h"
39 
40  #if defined(ARDUINO_ARCH_ESP8266) || defined(ARDUINO_ARCH_ESP32)
41  #include <Ticker.h> //Ticker Library
42  #endif
43  // Operation modes
47  #define UTIMERLIB_TYPE_OFF 0
48 
51  #define UTIMERLIB_TYPE_TIMEOUT 1
52 
55  #define UTIMERLIB_TYPE_INTERVAL 2
56 
57  #ifdef _VARIANT_ARDUINO_STM32_
58  #include "HardwareTimer.h"
59  extern HardwareTimer Timer3;
60  #endif
61 
62  class uTimerLib {
63  public:
64  uTimerLib();
65  void setInterval_us(void (*) (), unsigned long int);
66  void setInterval_s(void (*) (), unsigned long int);
67  void setTimeout_us(void (*) (), unsigned long int);
68  void setTimeout_s(void (*) (), unsigned long int);
69  void clearTimer();
70  void _interrupt();
71 
72  #ifdef _VARIANT_ARDUINO_STM32_
73  static void interrupt();
74  #endif
75 
76  #if defined(ARDUINO_ARCH_ESP8266) || defined(ARDUINO_ARCH_ESP32)
77  #pragma message "ESP8266 / ESP32 can only reach a ms resolution so any ms interrupt will be rounded to that"
78  static void interrupt();
79  #endif
80 
81  #ifdef _SAMD21_
82  #pragma message "SAMD21 support is still experimental"
83  TcCount16* _TC = (TcCount16*) TC3;
84  #endif
85 
86  #ifdef __SAMD51__
87  #pragma message "SAMD51 support is still experimental"
88  #endif
89 
90  private:
91  static uTimerLib *_instance;
92 
93  unsigned long int _overflows = 0;
94  unsigned long int __overflows = 0;
95  #ifdef ARDUINO_ARCH_AVR
96  unsigned char _remaining = 0;
97  unsigned char __remaining = 0;
98  #else
99  unsigned long int _remaining = 0;
100  unsigned long int __remaining = 0;
101  #endif
102  void (*_cb)() = NULL;
103  unsigned char _type = UTIMERLIB_TYPE_OFF;
104 
105  void _loadRemaining();
106 
107  void _attachInterrupt_us(unsigned long int);
108  void _attachInterrupt_s(unsigned long int);
109 
110  #ifdef _VARIANT_ARDUINO_STM32_
111  bool _toInit = true;
112  #endif
113 
114  #if defined(ARDUINO_ARCH_ESP8266) || defined(ARDUINO_ARCH_ESP32)
115  Ticker _ticker;
116  #endif
117  };
118 
119  extern uTimerLib TimerLib;
120 
121 #endif
122 
void clearTimer()
Clear timer interrupts.
Definition: uTimerLib.cpp:765
void setInterval_us(void(*)(), unsigned long int)
Attaches a callback function to be executed each us microseconds.
Definition: uTimerLib.cpp:54
#define UTIMERLIB_TYPE_OFF
Internal status.
Definition: uTimerLib.h:47
void setInterval_s(void(*)(), unsigned long int)
Attaches a callback function to be executed each s seconds.
Definition: uTimerLib.cpp:82
void _interrupt()
Internal intermediate function to control timer interrupts.
Definition: uTimerLib.cpp:813
Arduino tiny and cross-device compatible timer library.
Definition: uTimerLib.h:62
uTimerLib()
Constructor.
Definition: uTimerLib.cpp:41
uTimerLib TimerLib
Preinstantiate Object.
Definition: uTimerLib.cpp:918
void setTimeout_s(void(*)(), unsigned long int)
Attaches a callback function to be executed once when s seconds have passed.
Definition: uTimerLib.cpp:96
void setTimeout_us(void(*)(), unsigned long int)
Attaches a callback function to be executed once when us microseconds have passed.
Definition: uTimerLib.cpp:68