@@ -28,6 +28,7 @@ typedef struct {
28
28
struct timer_struct_t {
29
29
gptimer_handle_t timer_handle ;
30
30
interrupt_config_t interrupt_handle ;
31
+ bool timer_started ;
31
32
};
32
33
33
34
inline uint64_t timerRead (hw_timer_t * timer ){
@@ -62,10 +63,12 @@ uint32_t timerGetFrequency(hw_timer_t * timer){
62
63
63
64
void timerStart (hw_timer_t * timer ){
64
65
gptimer_start (timer -> timer_handle );
66
+ timer -> timer_started = true;
65
67
}
66
68
67
69
void timerStop (hw_timer_t * timer ){
68
70
gptimer_stop (timer -> timer_handle );
71
+ timer -> timer_started = false;
69
72
}
70
73
71
74
void timerRestart (hw_timer_t * timer ){
@@ -111,11 +114,15 @@ hw_timer_t * timerBegin(uint32_t frequency){
111
114
}
112
115
gptimer_enable (timer -> timer_handle );
113
116
gptimer_start (timer -> timer_handle );
117
+ timer -> timer_started = true;
114
118
return timer ;
115
119
}
116
120
117
121
void timerEnd (hw_timer_t * timer ){
118
122
esp_err_t err = ESP_OK ;
123
+ if (timer -> timer_started == true){
124
+ gptimer_stop (timer -> timer_handle );
125
+ }
119
126
gptimer_disable (timer -> timer_handle );
120
127
err = gptimer_del_timer (timer -> timer_handle );
121
128
if (err != ESP_OK ){
@@ -147,14 +154,20 @@ void timerAttachInterruptFunctionalArg(hw_timer_t * timer, void (*userFunc)(void
147
154
timer -> interrupt_handle .fn = (voidFuncPtr )userFunc ;
148
155
timer -> interrupt_handle .arg = arg ;
149
156
157
+ if (timer -> timer_started == true){
158
+ gptimer_stop (timer -> timer_handle );
159
+ }
150
160
gptimer_disable (timer -> timer_handle );
151
161
err = gptimer_register_event_callbacks (timer -> timer_handle , & cbs , & timer -> interrupt_handle );
152
162
if (err != ESP_OK ){
153
163
log_e ("Timer Attach Interrupt failed, error num=%d" , err );
154
164
}
155
165
gptimer_enable (timer -> timer_handle );
156
- }
166
+ if (timer -> timer_started == true){
167
+ gptimer_start (timer -> timer_handle );
168
+ }
157
169
170
+ }
158
171
159
172
void timerAttachInterruptArg (hw_timer_t * timer , void (* userFunc )(void * ), void * arg ){
160
173
timerAttachInterruptFunctionalArg (timer , userFunc , arg );
0 commit comments