#pragma once #include #include // Starts a non-blocking timer for the specified number of milliseconds. // When the time has elapsed, the specified callback function is called. // It uses a timer from TIM2 to TIM7 if any available. // Returning the timer number or 0 if unavailable. uint8_t TIM_startTimer(int32_t ms, void (*callback)()); // Same as TIM_startTimer, but the timer will repeatedly call callback with // the intervall ms until the timer is cancelled with TIM_cancelTimer. uint8_t TIM_startRepeatingTimer(int32_t ms, void (*callback)()); // Get a timers current value in cycles, can be converted to milliseconds // with TIM_cyclesToMs. uint32_t TIM_getTimerValue(uint8_t timer); // Convert cycles to milliseconds. uint32_t TIM_cyclesToMs(uint32_t cycles); // Pause and unpause a specified timer, // true for enabled, false for disabled. void TIM_setTimerState(uint8_t timer, bool state); // Cancel a specified timer. // It stops the timer and make it available for reuse. void TIM_cancelTimer(uint8_t timer); // Starts a repeating timer configured for ADC triggers for DMA use. // The repeat intervall ms is in the range [1,32768]. // Returning the timer number or 0 if unavailable. uint8_t TIM_startAdcTimer(int32_t ms);