Skip to content

Commit 0255fcc

Browse files
author
Richard Unger
committed
add a check to ensure encoder mode is supported
1 parent b1ae311 commit 0255fcc

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

src/encoders/stm32hwencoder/STM32HWEncoder.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,10 @@ int STM32HWEncoder::hasIndex() { return 0; }
2929
void STM32HWEncoder::init() {
3030
// GPIO configuration
3131
TIM_TypeDef *InstanceA = (TIM_TypeDef *)pinmap_peripheral(_pinA, PinMap_TIM);
32+
if (!IS_TIM_ENCODER_INTERFACE_INSTANCE(InstanceA)) {
33+
initialized = false;
34+
return;
35+
}
3236
TIM_TypeDef *InstanceB = (TIM_TypeDef *)pinmap_peripheral(_pinB, PinMap_TIM);
3337
if (InstanceA != InstanceB) {
3438
initialized = false;
@@ -37,6 +41,9 @@ void STM32HWEncoder::init() {
3741
pinmap_pinout(_pinA, PinMap_TIM);
3842
pinmap_pinout(_pinB, PinMap_TIM);
3943

44+
// TODO check width:
45+
//IS_TIM_32B_COUNTER_INSTANCE(InstanceA);
46+
4047
// set up timer for encoder
4148
encoder_handle.Init.Period = cpr - 1;
4249
encoder_handle.Init.Prescaler = 0;

0 commit comments

Comments
 (0)