diff --git a/src/shared/drivers/HardwareTimer.h b/src/shared/drivers/HardwareTimer.h index cb82f77b63815471b8cd60cb673be7ec53b65afa..4da7f7b2e9244c5dbe55f8df44d8758513626910 100644 --- a/src/shared/drivers/HardwareTimer.h +++ b/src/shared/drivers/HardwareTimer.h @@ -137,6 +137,8 @@ public: */ float toMicroSeconds(Type ticks); + uint64_t toIntMicroSeconds(Type ticks); + /** * @brief Converts from ticks to milliseconds, using the current prescaler * setting @@ -185,9 +187,9 @@ public: private: TIM_TypeDef* tim; - unsigned prescaler_freq; + unsigned int prescaler_freq; - bool ticking = false; + bool ticking = false; uint16_t prescaler = 0; Type auto_reload = static_cast<Type>(-1); // Max value of Type (Type is unsigned) @@ -253,6 +255,13 @@ float HardwareTimer<Type>::toMicroSeconds(Type ticks) return (1.0f * ticks * 1000000 * (1 + prescaler)) / prescaler_freq; } +template <typename Type> +uint64_t HardwareTimer<Type>::toIntMicroSeconds(Type ticks) +{ + return ((uint64_t)ticks * 1000000 * (uint64_t)(1 + prescaler)) / + (uint64_t)prescaler_freq; +} + template <typename Type> float HardwareTimer<Type>::toMilliSeconds(Type ticks) {