aboutsummaryrefslogtreecommitdiff
path: root/tmk_core/common
diff options
context:
space:
mode:
Diffstat (limited to 'tmk_core/common')
-rw-r--r--tmk_core/common/timer.h11
1 files changed, 11 insertions, 0 deletions
diff --git a/tmk_core/common/timer.h b/tmk_core/common/timer.h
index fe23f87ae..a8dd85663 100644
--- a/tmk_core/common/timer.h
+++ b/tmk_core/common/timer.h
@@ -19,6 +19,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
19#define TIMER_H 1 19#define TIMER_H 1
20 20
21#include <stdint.h> 21#include <stdint.h>
22#include <stdbool.h>
22 23
23#if defined(__AVR__) 24#if defined(__AVR__)
24#include "avr/timer_avr.h" 25#include "avr/timer_avr.h"
@@ -46,6 +47,16 @@ uint32_t timer_read32(void);
46uint16_t timer_elapsed(uint16_t last); 47uint16_t timer_elapsed(uint16_t last);
47uint32_t timer_elapsed32(uint32_t last); 48uint32_t timer_elapsed32(uint32_t last);
48 49
50// Utility functions to check if a future time has expired & autmatically handle time wrapping if checked / reset frequently (half of max value)
51inline bool timer_expired(uint16_t current, uint16_t last)
52{
53 return current - last < 0x8000;
54}
55
56inline bool timer_expired32(uint32_t current, uint32_t future) {
57 return current - future < 0x80000000;
58}
59
49#ifdef __cplusplus 60#ifdef __cplusplus
50} 61}
51#endif 62#endif