Skip to content

Commit

Permalink
Fix int wrapping for timer_expired macros and use MAX defines for con…
Browse files Browse the repository at this point in the history
…sistency and clarity (qmk#10996)
  • Loading branch information
XScorpion2 authored Nov 30, 2020
1 parent 9d7ab73 commit a3411f6
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions tmk_core/common/timer.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ uint16_t timer_elapsed(uint16_t last);
uint32_t timer_elapsed32(uint32_t last);

// Utility functions to check if a future time has expired & autmatically handle time wrapping if checked / reset frequently (half of max value)
#define timer_expired(current, future) (((uint16_t)current - (uint16_t)future) < 0x8000)
#define timer_expired32(current, future) (((uint32_t)current - (uint32_t)future) < 0x80000000)
#define timer_expired(current, future) ((uint16_t)(current - future) < UINT16_MAX / 2)
#define timer_expired32(current, future) ((uint32_t)(current - future) < UINT32_MAX / 2)

#ifdef __cplusplus
}
Expand Down

0 comments on commit a3411f6

Please sign in to comment.