Skip to content

Commit 981a84e

Browse files
strongly-typedsalkinium
authored andcommitted
[stm32] [timer] Add getClockFrequency()
When using the timer as a template parameter, there is no other way to get the clock frequency at which a timer is running. This is required for some userspace calculations for prescaler and overflow.
1 parent 50b98e4 commit 981a84e

File tree

3 files changed

+21
-0
lines changed

3 files changed

+21
-0
lines changed

src/modm/platform/timer/stm32/advanced.hpp.in

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,13 @@ public:
170170
return TIM{{ id }}->ARR;
171171
}
172172

173+
template<class SystemClock>
174+
static constexpr uint32_t
175+
getClockFrequency()
176+
{
177+
return SystemClock::Timer{{ id }};
178+
}
179+
173180
template<class SystemClock, class Rep, class Period>
174181
static Value
175182
setPeriod(std::chrono::duration<Rep, Period> duration, bool autoApply = true)

src/modm/platform/timer/stm32/basic.hpp.in

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,13 @@ public:
111111
return TIM{{ id }}->ARR;
112112
}
113113

114+
template<class SystemClock>
115+
static constexpr uint32_t
116+
getClockFrequency()
117+
{
118+
return SystemClock::Timer{{ id }};
119+
}
120+
114121
template<class SystemClock, class Rep, class Period>
115122
static Value
116123
setPeriod(std::chrono::duration<Rep, Period> duration, bool autoApply = true)

src/modm/platform/timer/stm32/general_purpose.hpp.in

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,13 @@ public:
184184
return TIM{{ id }}->ARR;
185185
}
186186

187+
template<class SystemClock>
188+
static constexpr uint32_t
189+
getClockFrequency()
190+
{
191+
return SystemClock::Timer{{ id }};
192+
}
193+
187194
template<class SystemClock, class Rep, class Period>
188195
static Value
189196
setPeriod(std::chrono::duration<Rep, Period> duration, bool autoApply = true)

0 commit comments

Comments
 (0)