diff options
Diffstat (limited to 'tmk_core')
-rw-r--r-- | tmk_core/common/timer.h | 5 |
1 files changed, 4 insertions, 1 deletions
diff --git a/tmk_core/common/timer.h b/tmk_core/common/timer.h index bbaae109d..117b41d1b 100644 --- a/tmk_core/common/timer.h +++ b/tmk_core/common/timer.h @@ -25,7 +25,10 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. # include "avr/timer_avr.h" #endif -#define TIMER_DIFF(a, b, max) ((a) >= (b) ? (a) - (b) : (max) - (b) + (a)) +#define TIMER_DIFF(a, b, max) ((max == UINT8_MAX) ? ((uint8_t)((a)-(b))) : ( \ + (max == UINT16_MAX) ? ((uint16_t)((a)-(b))) : ( \ + (max == UINT32_MAX) ? ((uint32_t)((a)-(b))) : ( \ + (a) >= (b) ? (a) - (b) : (max) + 1 - (b) + (a) )))) #define TIMER_DIFF_8(a, b) TIMER_DIFF(a, b, UINT8_MAX) #define TIMER_DIFF_16(a, b) TIMER_DIFF(a, b, UINT16_MAX) #define TIMER_DIFF_32(a, b) TIMER_DIFF(a, b, UINT32_MAX) |