Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add isCountingDown/Up functions to STM32 Timers #1096

Merged
merged 1 commit into from
Nov 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions src/modm/platform/timer/stm32/advanced.hpp.in
Original file line number Diff line number Diff line change
Expand Up @@ -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()
{
Expand Down
12 changes: 12 additions & 0 deletions src/modm/platform/timer/stm32/basic.hpp.in
Original file line number Diff line number Diff line change
Expand Up @@ -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()
{
Expand Down
8 changes: 8 additions & 0 deletions src/modm/platform/timer/stm32/basic_base.hpp.in
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down
24 changes: 24 additions & 0 deletions src/modm/platform/timer/stm32/general_purpose.hpp.in
Original file line number Diff line number Diff line change
Expand Up @@ -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()
{
Expand Down Expand Up @@ -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


Expand Down
Loading