@@ -249,8 +249,8 @@ static void USE_IRAM_ATTR gpio_intr() {
249
249
timer->dev ->config .alarm_en = 1 ;
250
250
#else // _ESP32_IRRECV_TIMER_HACK
251
251
#if ( defined(ESP_ARDUINO_VERSION_MAJOR) && (ESP_ARDUINO_VERSION_MAJOR >= 3) )
252
- timerAlarm (timer, MS_TO_USEC (params. timeout ), ONCE , 0 );
253
- timerAttachInterrupt (timer, &read_timeout );
252
+ timerWrite (timer, 0 );
253
+ timerStart (timer);
254
254
#else // ESP_ARDUINO_VERSION_MAJOR >= 3
255
255
timerWrite (timer, 0 );
256
256
timerAlarmEnable (timer);
@@ -344,9 +344,6 @@ IRrecv::IRrecv(const uint16_t recvpin, const uint16_t bufsize,
344
344
// / timers or interrupts used.
345
345
IRrecv::~IRrecv (void ) {
346
346
disableIRIn ();
347
- #if defined(ESP32)
348
- if (timer != NULL ) timerEnd (timer); // Cleanup the ESP32 timeout timer.
349
- #endif // ESP32
350
347
delete[] params.rawbuf ;
351
348
if (params_save != NULL ) {
352
349
delete[] params_save->rawbuf ;
@@ -371,9 +368,9 @@ void IRrecv::enableIRIn(const bool pullup) {
371
368
// Initialise the ESP32 timer.
372
369
// 80MHz / 80 = 1 uSec granularity.
373
370
#if ( defined(ESP_ARDUINO_VERSION_MAJOR) && (ESP_ARDUINO_VERSION_MAJOR >= 3) )
374
- timer = timerBegin (80 );
371
+ timer = timerBegin (1000000 ); // 1 MHz
375
372
#else // ESP_ARDUINO_VERSION_MAJOR >= 3
376
- timer = timerBegin (_timer_num, 80 , true );
373
+ timer = timerBegin (_timer_num, 80 , true ); // 1 MHz : 80 MHz with divider 80
377
374
#endif // ESP_ARDUINO_VERSION_MAJOR >= 3
378
375
#ifdef DEBUG
379
376
if (timer == NULL ) {
@@ -383,8 +380,8 @@ void IRrecv::enableIRIn(const bool pullup) {
383
380
#endif // DEBUG
384
381
assert (timer != NULL ); // Check we actually got the timer.
385
382
#if ( defined(ESP_ARDUINO_VERSION_MAJOR) && (ESP_ARDUINO_VERSION_MAJOR >= 3) )
386
- timerAlarm (timer, MS_TO_USEC (params.timeout ), ONCE, 0 );
387
383
timerAttachInterrupt (timer, &read_timeout);
384
+ timerAlarm (timer, MS_TO_USEC (params.timeout ), ONCE, 0 );
388
385
#else // ESP_ARDUINO_VERSION_MAJOR >= 3
389
386
// Set the timer so it only fires once, and set it's trigger in uSeconds.
390
387
timerAlarmWrite (timer, MS_TO_USEC (params.timeout ), ONCE);
@@ -418,13 +415,16 @@ void IRrecv::disableIRIn(void) {
418
415
os_timer_disarm (&timer);
419
416
#endif // ESP8266
420
417
#if defined(ESP32)
418
+ if (timer == NULL ) { return ; } // Call only once (defensive)
421
419
#if ( defined(ESP_ARDUINO_VERSION_MAJOR) && (ESP_ARDUINO_VERSION_MAJOR >= 3) )
420
+ timerDetachInterrupt (timer);
422
421
timerEnd (timer);
423
422
#else // ESP_ARDUINO_VERSION_MAJOR >= 3
424
423
timerAlarmDisable (timer);
425
424
timerDetachInterrupt (timer);
426
425
timerEnd (timer);
427
426
#endif // ESP_ARDUINO_VERSION_MAJOR >= 3
427
+ timer = NULL ; // Cleanup the ESP32 timeout timer.
428
428
#endif // ESP32
429
429
detachInterrupt (params.recvpin );
430
430
#endif // UNIT_TEST
@@ -451,7 +451,7 @@ void IRrecv::resume(void) {
451
451
params.overflow = false ;
452
452
#if defined(ESP32)
453
453
#if ( defined(ESP_ARDUINO_VERSION_MAJOR) && (ESP_ARDUINO_VERSION_MAJOR >= 3) )
454
- timerEnd (timer);
454
+ timerStop (timer);
455
455
#else // ESP_ARDUINO_VERSION_MAJOR >= 3
456
456
timerAlarmDisable (timer);
457
457
#endif // ESP_ARDUINO_VERSION_MAJOR >= 3
0 commit comments