Skip to content

Commit

Permalink
Add isCountingDown/Up functions to STM32 Timers
Browse files Browse the repository at this point in the history
  • Loading branch information
Sergey Pluzhnikov committed Nov 3, 2023
1 parent a771042 commit 354da57
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 0 deletions.
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

0 comments on commit 354da57

Please sign in to comment.