Sming Framework API
Sming - Open Source framework for high efficiency WiFi SoC ESP8266 native development with C++ language.
HardwareTimer.h
1 /*
2  * HWTimer.h
3  *
4  * Sming Framework Project - Open Source framework for high efficiency native ESP8266 development.
5  * Created 23.11.2015 by johndoe
6  * http://github.com/anakod/Sming
7  * All files of the Sming Core are provided under the LGPL v3 license.
8  ****/
9 
15 #ifndef _SMING_CORE_HWTIMER_H_
16 #define _SMING_CORE_HWTIMER_H_
17 
18 #include "../SmingCore/Interrupts.h"
19 #include "../SmingCore/Delegate.h"
20 
21 #define MAX_HW_TIMER_INTERVAL_US 0x7fffff
22 #define MIN_HW_TIMER_INTERVAL_US 0x32
23 
24 
27 
30 {
31 public:
35  virtual ~Hardware_Timer();
36 
42  Hardware_Timer& IRAM_ATTR initializeUs(uint32_t microseconds, InterruptCallback callback = NULL); // Init in Microseconds.
43 
49  Hardware_Timer& IRAM_ATTR initializeMs(uint32_t milliseconds, InterruptCallback callback = NULL); // Init in Milliseconds.
50 
55  bool IRAM_ATTR start(bool repeating = true);
56 
61  bool __forceinline IRAM_ATTR startOnce() { return start(false); }
62 
67  bool IRAM_ATTR stop();
68 
73  bool IRAM_ATTR restart();
74 
78  bool isStarted();
79 
83  uint32_t getIntervalUs();
84 
88  uint32_t getIntervalMs();
89 
93  bool IRAM_ATTR setIntervalUs(uint32_t microseconds = 1000000);
94 
98  bool IRAM_ATTR setIntervalMs(uint32_t milliseconds = 1000000);
99 
103  void IRAM_ATTR setCallback(InterruptCallback callback);
104 
108  void __forceinline IRAM_ATTR call() {
109  if (callback) {
110  callback();
111  }
112  }
113 
114 
115 private:
116  uint32_t interval = 0;
117  InterruptCallback callback = nullptr;
118  bool repeating = false;
119  bool started = false;
120 };
121 
123 #endif /* _SMING_CORE_HWTIMER_H_ */
Hardware timer class.
Definition: HardwareTimer.h:29
void IRAM_ATTR setCallback(InterruptCallback callback)
Set timer trigger callback.
Hardware_Timer &IRAM_ATTR initializeUs(uint32_t microseconds, InterruptCallback callback=NULL)
Initialise hardware timer.
void __forceinline IRAM_ATTR call()
Call timer callback.
Definition: HardwareTimer.h:108
bool isStarted()
Check if timer is started.
uint32_t getIntervalMs()
Get timer interval.
bool IRAM_ATTR setIntervalMs(uint32_t milliseconds=1000000)
Set timer interval.
uint32_t getIntervalUs()
Get timer interval.
Hardware_Timer()
Hardware timer.
bool IRAM_ATTR setIntervalUs(uint32_t microseconds=1000000)
Set timer interval.
Delegate< void()> TimerDelegate
Delegate callback type for timer trigger.
Definition: HardwareTimer.h:26
bool IRAM_ATTR stop()
Stops timer.
bool IRAM_ATTR restart()
Restart timer.
Hardware_Timer &IRAM_ATTR initializeMs(uint32_t milliseconds, InterruptCallback callback=NULL)
Initialise hardware timer.
bool IRAM_ATTR start(bool repeating=true)
Start timer running.
bool __forceinline IRAM_ATTR startOnce()
Start one-shot timer.
Definition: HardwareTimer.h:61