@@ -10,8 +10,9 @@ static TimerAlarmRepeatingDriverSTM32 *timerAlarmRepeating = nullptr;
10
10
typedef void (*repeating_timer_callback_t )(void *obj);
11
11
12
12
/* *
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.
15
16
* @ingroup platform
16
17
* @author Phil Schatzmann
17
18
* @copyright GPLv3
@@ -26,21 +27,28 @@ class TimerAlarmRepeatingDriverSTM32 : public TimerAlarmRepeatingDriverBase {
26
27
}
27
28
// / selects the timer: 0 = TIM1, 1 = TIM2,2 = TIM3, 3 = TIM4, 4 = TIM5
28
29
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 {
29
36
if (this ->timer != nullptr ) {
30
37
delete this ->timer ;
31
38
}
32
- this ->timer = new HardwareTimer (timers[timerIdx] );
33
- timer_index = timerIdx ;
39
+ this ->timer = new HardwareTimer (timerDef );
40
+ timer_index = - 1 ;
34
41
timer->pause ();
35
42
}
36
43
44
+
37
45
/* *
38
46
* Starts the alarm timer
39
47
*/
40
48
bool begin (repeating_timer_callback_t callback_f, uint32_t time,
41
49
TimeUnit unit = MS) override {
42
50
TRACEI ();
43
- LOGI (" Using timer TIM%d" , timer_index + 1 );
51
+ if (timer_index>= 0 ) LOGI (" Using timer TIM%d" , timer_index + 1 );
44
52
timer->attachInterrupt (std::bind (callback_f, object));
45
53
46
54
// we determine the time in microseconds
0 commit comments