#pragma once #include "config.h" #include #if defined(USE_TIME_LITERALS) #include "frequency.h" #include #endif namespace TeensyTimerTool { //-------------------------------------------------------------- // Transform arithmetic, period and frequency values to float // For constant inputs the transformations are calculated at compile time // Arithmetic types template ::value, int> * = nullptr> float constexpr period2us(period_t v) { return (float)v; } #if defined(USE_TIME_LITERALS) // Duration types (s, ms, ns...) template ::value, int> * = nullptr> float constexpr period2us(period_t v) { return (duration_cast>(v).count()); } // Frequency types (Hz, MHz...) template ::value, int> * = nullptr> float constexpr period2us(period_t v) { return 1'000'000 / duration_cast(v).count(); } #endif } // namespace TeensyTimerTool