diff options
Diffstat (limited to 'tmk_core/common/timer.h')
-rw-r--r-- | tmk_core/common/timer.h | 28 |
1 files changed, 10 insertions, 18 deletions
diff --git a/tmk_core/common/timer.h b/tmk_core/common/timer.h index a8dd85663..853cb9839 100644 --- a/tmk_core/common/timer.h +++ b/tmk_core/common/timer.h | |||
@@ -22,16 +22,14 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. | |||
22 | #include <stdbool.h> | 22 | #include <stdbool.h> |
23 | 23 | ||
24 | #if defined(__AVR__) | 24 | #if defined(__AVR__) |
25 | #include "avr/timer_avr.h" | 25 | # include "avr/timer_avr.h" |
26 | #endif | 26 | #endif |
27 | 27 | ||
28 | 28 | #define TIMER_DIFF(a, b, max) ((a) >= (b) ? (a) - (b) : (max) - (b) + (a)) | |
29 | #define TIMER_DIFF(a, b, max) ((a) >= (b) ? (a) - (b) : (max) - (b) + (a)) | 29 | #define TIMER_DIFF_8(a, b) TIMER_DIFF(a, b, UINT8_MAX) |
30 | #define TIMER_DIFF_8(a, b) TIMER_DIFF(a, b, UINT8_MAX) | 30 | #define TIMER_DIFF_16(a, b) TIMER_DIFF(a, b, UINT16_MAX) |
31 | #define TIMER_DIFF_16(a, b) TIMER_DIFF(a, b, UINT16_MAX) | 31 | #define TIMER_DIFF_32(a, b) TIMER_DIFF(a, b, UINT32_MAX) |
32 | #define TIMER_DIFF_32(a, b) TIMER_DIFF(a, b, UINT32_MAX) | 32 | #define TIMER_DIFF_RAW(a, b) TIMER_DIFF_8(a, b) |
33 | #define TIMER_DIFF_RAW(a, b) TIMER_DIFF_8(a, b) | ||
34 | |||
35 | 33 | ||
36 | #ifdef __cplusplus | 34 | #ifdef __cplusplus |
37 | extern "C" { | 35 | extern "C" { |
@@ -39,23 +37,17 @@ extern "C" { | |||
39 | 37 | ||
40 | extern volatile uint32_t timer_count; | 38 | extern volatile uint32_t timer_count; |
41 | 39 | ||
42 | 40 | void timer_init(void); | |
43 | void timer_init(void); | 41 | void timer_clear(void); |
44 | void timer_clear(void); | ||
45 | uint16_t timer_read(void); | 42 | uint16_t timer_read(void); |
46 | uint32_t timer_read32(void); | 43 | uint32_t timer_read32(void); |
47 | uint16_t timer_elapsed(uint16_t last); | 44 | uint16_t timer_elapsed(uint16_t last); |
48 | uint32_t timer_elapsed32(uint32_t last); | 45 | uint32_t timer_elapsed32(uint32_t last); |
49 | 46 | ||
50 | // Utility functions to check if a future time has expired & autmatically handle time wrapping if checked / reset frequently (half of max value) | 47 | // Utility functions to check if a future time has expired & autmatically handle time wrapping if checked / reset frequently (half of max value) |
51 | inline bool timer_expired(uint16_t current, uint16_t last) | 48 | inline bool timer_expired(uint16_t current, uint16_t last) { return current - last < 0x8000; } |
52 | { | ||
53 | return current - last < 0x8000; | ||
54 | } | ||
55 | 49 | ||
56 | inline bool timer_expired32(uint32_t current, uint32_t future) { | 50 | inline bool timer_expired32(uint32_t current, uint32_t future) { return current - future < 0x80000000; } |
57 | return current - future < 0x80000000; | ||
58 | } | ||
59 | 51 | ||
60 | #ifdef __cplusplus | 52 | #ifdef __cplusplus |
61 | } | 53 | } |