Reduce display startup time
This commit is contained in:
29
Core/Src/shorttimer.c
Normal file
29
Core/Src/shorttimer.c
Normal file
@ -0,0 +1,29 @@
|
||||
#include "shorttimer.h"
|
||||
|
||||
#include "stm32h7xx_hal.h"
|
||||
#include "stm32h7xx_hal_tim.h"
|
||||
#include <stdint.h>
|
||||
|
||||
static TIM_HandleTypeDef *htim;
|
||||
static uint32_t ticks;
|
||||
|
||||
void shorttimer_init(TIM_HandleTypeDef *handle) {
|
||||
htim = handle;
|
||||
ticks = 0;
|
||||
HAL_TIM_Base_Start_IT(htim);
|
||||
}
|
||||
|
||||
uint32_t shorttimer_gettick(void) { return ticks; }
|
||||
|
||||
void shorttimer_sleep(uint32_t microseconds) {
|
||||
volatile uint32_t start = shorttimer_gettick();
|
||||
// Add another tick to guarantee a minimum wait
|
||||
if (microseconds < UINT32_MAX) {
|
||||
microseconds++;
|
||||
}
|
||||
|
||||
while (shorttimer_gettick() - start < microseconds) {
|
||||
}
|
||||
}
|
||||
|
||||
void shorttimer_callback() { ticks++; }
|
||||
Reference in New Issue
Block a user