diff --git a/src/modm/platform/timer/stm32/advanced.hpp.in b/src/modm/platform/timer/stm32/advanced.hpp.in index e9d26dc31f..3d2ca0d6d3 100644 --- a/src/modm/platform/timer/stm32/advanced.hpp.in +++ b/src/modm/platform/timer/stm32/advanced.hpp.in @@ -231,6 +231,18 @@ public: return true; } + static inline bool + isCountingUp() + { + return (TIM{{ id }}->CR1 & TIM_CR1_DIR) == 0; + } + + static inline bool + isCountingDown() + { + return !isCountingUp(); + } + static inline void enableOutput() { diff --git a/src/modm/platform/timer/stm32/basic.hpp.in b/src/modm/platform/timer/stm32/basic.hpp.in index e7c246fb42..b8902e0a50 100644 --- a/src/modm/platform/timer/stm32/basic.hpp.in +++ b/src/modm/platform/timer/stm32/basic.hpp.in @@ -166,6 +166,18 @@ public: TIM{{ id }}->CNT = value; } + static inline bool + isCountingUp() + { + return true; + } + + static inline bool + isCountingDown() + { + return false; + } + static constexpr bool hasAdvancedPwmControl() { diff --git a/src/modm/platform/timer/stm32/basic_base.hpp.in b/src/modm/platform/timer/stm32/basic_base.hpp.in index 864e53e4c2..40ab3a3754 100644 --- a/src/modm/platform/timer/stm32/basic_base.hpp.in +++ b/src/modm/platform/timer/stm32/basic_base.hpp.in @@ -216,6 +216,14 @@ public: static constexpr bool hasAdvancedPwmControl(); + /** + * Check current count direction + */ + static inline bool + isCountingUp(); + static inline bool + isCountingDown(); + /** * Enables or disables the Interrupt Vector. * diff --git a/src/modm/platform/timer/stm32/general_purpose.hpp.in b/src/modm/platform/timer/stm32/general_purpose.hpp.in index cf79e2142d..d4826f44f2 100644 --- a/src/modm/platform/timer/stm32/general_purpose.hpp.in +++ b/src/modm/platform/timer/stm32/general_purpose.hpp.in @@ -259,6 +259,18 @@ public: %% if target.family not in ["l0", "l1"] and id in [15, 16, 17] + static inline bool + isCountingUp() + { + return true; + } + + static inline bool + isCountingDown() + { + return false; + } + static constexpr bool hasAdvancedPwmControl() { @@ -356,6 +368,18 @@ public: { return false; } + + static inline bool + isCountingUp() + { + return (TIM{{ id }}->CR1 & TIM_CR1_DIR) == 0; + } + + static inline bool + isCountingDown() + { + return !isCountingUp(); + } %% endif