Skip to content

Commit 11489d8

Browse files
author
Richard Unger
committed
improvements to STM32 PWM input
1 parent eeb3b37 commit 11489d8

File tree

3 files changed

+8
-9
lines changed

3 files changed

+8
-9
lines changed

src/comms/stm32speeddir/STM32SpeedDirInput.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ STM32SpeedDirInput::~STM32SpeedDirInput(){};
1212

1313
int STM32SpeedDirInput::init(){
1414
pinMode(_pin_dir, INPUT);
15-
return STM32PWMInput::init();
15+
return STM32PWMInput::initialize();
1616
};
1717

1818

src/utilities/stm32pwm/STM32PWMInput.cpp

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77

88
STM32PWMInput::STM32PWMInput(int pin){
9-
_pin = pin;
9+
_pin = digitalPinToPinName(pin);
1010
};
1111

1212

@@ -16,11 +16,10 @@ STM32PWMInput::~STM32PWMInput(){};
1616

1717

1818

19-
int STM32PWMInput::init(){
20-
PinName pinN = digitalPinToPinName(_pin);
21-
pinmap_pinout(pinN, PinMap_TIM);
22-
uint32_t channel = STM_PIN_CHANNEL(pinmap_function(pinN, PinMap_TIM));
23-
timer.Instance = (TIM_TypeDef *)pinmap_peripheral(pinN, PinMap_TIM);
19+
int STM32PWMInput::initialize(){
20+
pinmap_pinout(_pin, PinMap_TIM);
21+
uint32_t channel = STM_PIN_CHANNEL(pinmap_function(_pin, PinMap_TIM));
22+
timer.Instance = (TIM_TypeDef *)pinmap_peripheral(_pin, PinMap_TIM);
2423
timer.Init.Prescaler = 0;
2524
timer.Init.CounterMode = TIM_COUNTERMODE_UP;
2625
timer.Init.Period = 4.294967295E9; // TODO max period, depends on which timer is used - 32 bits or 16 bits

src/utilities/stm32pwm/STM32PWMInput.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,13 @@ class STM32PWMInput {
1010
STM32PWMInput(int pin);
1111
~STM32PWMInput();
1212

13-
int init();
13+
int initialize();
1414

1515
float getDutyCyclePercent();
1616
uint32_t getDutyCycleTicks();
1717
uint32_t getPeriodTicks();
1818
protected:
19-
int _pin;
19+
PinName _pin;
2020
TIM_HandleTypeDef timer;
2121
};
2222

0 commit comments

Comments
 (0)