Skip to content

Commit e6c605e

Browse files
committed
TimerAlarmRepeatingDriverSTM32 setTimer
1 parent d4c94ea commit e6c605e

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

src/AudioTimer/AudioTimerSTM32.h

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,9 @@ static TimerAlarmRepeatingDriverSTM32 *timerAlarmRepeating = nullptr;
1010
typedef void (*repeating_timer_callback_t)(void *obj);
1111

1212
/**
13-
* @brief STM32 Repeating Timer functions for repeated execution: Plaease use
14-
* the typedef TimerAlarmRepeating
13+
* @brief STM32 Repeating Timer functions for repeated execution: Please use
14+
* the typedef TimerAlarmRepeating.
15+
* By default the TIM1 is used.
1516
* @ingroup platform
1617
* @author Phil Schatzmann
1718
* @copyright GPLv3
@@ -26,21 +27,28 @@ class TimerAlarmRepeatingDriverSTM32 : public TimerAlarmRepeatingDriverBase {
2627
}
2728
/// selects the timer: 0 = TIM1, 1 = TIM2,2 = TIM3, 3 = TIM4, 4 = TIM5
2829
void setTimer(int timerIdx) override {
30+
setTimer(timers[timerIdx])
31+
timer_index = timerIdx;
32+
}
33+
34+
/// select the timer
35+
void setTimer(TIM_TypeDef timerDef) override {
2936
if (this->timer != nullptr) {
3037
delete this->timer;
3138
}
32-
this->timer = new HardwareTimer(timers[timerIdx]);
33-
timer_index = timerIdx;
39+
this->timer = new HardwareTimer(timerDef);
40+
timer_index = -1;
3441
timer->pause();
3542
}
3643

44+
3745
/**
3846
* Starts the alarm timer
3947
*/
4048
bool begin(repeating_timer_callback_t callback_f, uint32_t time,
4149
TimeUnit unit = MS) override {
4250
TRACEI();
43-
LOGI("Using timer TIM%d", timer_index + 1);
51+
if (timer_index>=0) LOGI("Using timer TIM%d", timer_index + 1);
4452
timer->attachInterrupt(std::bind(callback_f, object));
4553

4654
// we determine the time in microseconds

0 commit comments

Comments
 (0)