Skip to content

Commit b808639

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

File tree

5 files changed

+67
-3
lines changed

5 files changed

+67
-3
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,

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

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

8383
// ----------------------------------------------------------------------------
84+
void
85+
modm::platform::Timer{{ id }}::configureInputChannel(uint32_t channel, uint8_t filter) {
86+
channel -= 1; // 1..4 -> 0..3
87+
88+
// disable channel
89+
TIM{{ id }}->CCER &= ~(TIM_CCER_CC1E << (channel * 4));
90+
91+
uint32_t flags = static_cast<uint32_t>(filter&0xf) << 4;
92+
93+
if (channel <= 1)
94+
{
95+
const uint32_t offset = 8 * channel;
96+
97+
flags <<= offset;
98+
flags |= TIM{{ id }}->CCMR1 & ~(0xf0 << offset);
99+
100+
TIM{{ id }}->CCMR1 = flags;
101+
}
102+
else {
103+
const uint32_t offset = 8 * (channel - 2);
104+
105+
flags <<= offset;
106+
flags |= TIM{{ id }}->CCMR2 & ~(0xf0 << offset);
107+
108+
TIM{{ id }}->CCMR2 = flags;
109+
}
110+
TIM{{ id }}->CCER |= TIM_CCER_CC1E << (channel * 4);
111+
}
112+
84113
void
85114
modm::platform::Timer{{ id }}::configureInputChannel(uint32_t channel,
86115
InputCaptureMapping input, InputCapturePrescaler prescaler,

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -317,6 +317,9 @@ public:
317317

318318

319319
public:
320+
static void
321+
configureInputChannel(uint32_t channel, uint8_t filter);
322+
320323
static void
321324
configureInputChannel(uint32_t channel, InputCaptureMapping input,
322325
InputCapturePrescaler prescaler,

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ public:
234234
/**
235235
* TODO Description
236236
*/
237-
void
237+
static void
238238
configureInputChannel(uint32_t channel, InputCaptureMapping input,
239239
InputCapturePrescaler prescaler, InputCapturePolarity polarity, uint8_t filter);
240240

@@ -256,7 +256,7 @@ public:
256256
* @param channel [1..4]
257257
* @param value Compare value
258258
*/
259-
static inline void
259+
static void
260260
setCompareValue(uint32_t channel, uint16_t value);
261261

262262
/**
@@ -265,7 +265,7 @@ public:
265265
* @param channel [1..4]
266266
* @return Current compare value
267267
*/
268-
static inline uint16_t
268+
static uint16_t
269269
getCompareValue(uint32_t channel);
270270
};
271271

0 commit comments

Comments
 (0)