#pragma once #include "ErrorHandling/error_codes.h" #include "baseTimer.h" #include "type_traits" namespace TeensyTimerTool { class OneShotTimer : public BaseTimer { public: inline OneShotTimer(TimerGenerator* generator = nullptr); inline errorCode begin(callback_t cb); template errorCode trigger(T delay); template errorCode triggerDirect(T reload); template errorCode getTriggerReload(float delay, T* reload); #if defined(USE_TIME_LITERALS) template errorCode trigger(duration _delay) { T delay = duration_cast(_delay).count(); return trigger(delay); } #endif }; // Implementation ================================================ OneShotTimer::OneShotTimer(TimerGenerator* generator) : BaseTimer(generator, false) {} errorCode OneShotTimer::begin(callback_t callback) { return BaseTimer::begin(callback, 0, false); } template errorCode OneShotTimer::trigger(T delay) { static_assert(std::is_integral() || std::is_floating_point(), "Only floating point or integral types allowed"); errorCode result; if (std::is_floating_point()) result = timerChannel->trigger((float)delay); else result = timerChannel->trigger((uint32_t)delay); return result; } template errorCode OneShotTimer::triggerDirect(T reload) { return timerChannel->triggerDirect(reload); } template errorCode OneShotTimer::getTriggerReload(float delay, T* reload) { return timerChannel->getTriggerReload(delay, reload); } }