qmk-dactyl-manuform-a/tmk_core/common/mbed/timer.c

24 lines
631 B
C
Raw Normal View History

#include "cmsis.h"
#include "timer.h"
/* Mill second tick count */
volatile uint32_t timer_count = 0;
/* Timer interrupt handler */
2019-08-30 20:19:03 +02:00
void SysTick_Handler(void) { timer_count++; }
2019-08-30 20:19:03 +02:00
void timer_init(void) {
timer_count = 0;
SysTick_Config(SystemCoreClock / 1000); /* 1ms tick */
}
2019-08-30 20:19:03 +02:00
void timer_clear(void) { timer_count = 0; }
2019-08-30 20:19:03 +02:00
uint16_t timer_read(void) { return (uint16_t)(timer_count & 0xFFFF); }
2019-08-30 20:19:03 +02:00
uint32_t timer_read32(void) { return timer_count; }
2019-08-30 20:19:03 +02:00
uint16_t timer_elapsed(uint16_t last) { return TIMER_DIFF_16(timer_read(), last); }
2019-08-30 20:19:03 +02:00
uint32_t timer_elapsed32(uint32_t last) { return TIMER_DIFF_32(timer_read32(), last); }