Skip to content

Commit 1290c4d

Browse files
committed
added STM32 Timer{{ id }}::configureInputChannel(channel, filter)
1 parent c3f17a2 commit 1290c4d

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed

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

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,35 @@ modm::platform::Timer{{ id }}::setMode(Mode mode, SlaveMode slaveMode,
6666
}
6767

6868
// ----------------------------------------------------------------------------
69+
void
70+
modm::platform::Timer{{ id }}::configureInputChannel(uint32_t channel, uint8_t filter) {
71+
channel -= 1; // 1..4 -> 0..3
72+
73+
// disable channel
74+
TIM{{ id }}->CCER &= ~(TIM_CCER_CC1E << (channel * 4));
75+
76+
uint32_t flags = static_cast<uint32_t>(filter&0xf) << 4;
77+
78+
if (channel <= 1)
79+
{
80+
const uint32_t offset = 8 * channel;
81+
82+
flags <<= offset;
83+
flags |= TIM{{ id }}->CCMR1 & ~(0xf0 << offset);
84+
85+
TIM{{ id }}->CCMR1 = flags;
86+
}
87+
else {
88+
const uint32_t offset = 8 * (channel - 2);
89+
90+
flags <<= offset;
91+
flags |= TIM{{ id }}->CCMR2 & ~(0xf0 << offset);
92+
93+
TIM{{ id }}->CCMR2 = flags;
94+
}
95+
TIM{{ id }}->CCER |= TIM_CCER_CC1E << (channel * 4);
96+
}
97+
6998
void
7099
modm::platform::Timer{{ id }}::configureInputChannel(uint32_t channel,
71100
InputCaptureMapping input, InputCapturePrescaler prescaler,

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,9 @@ public:
303303
}
304304

305305
public:
306+
static void
307+
configureInputChannel(uint32_t channel, uint8_t filter);
308+
306309
static void
307310
configureInputChannel(uint32_t channel, InputCaptureMapping input,
308311
InputCapturePrescaler prescaler,

0 commit comments

Comments
 (0)