@@ -69,6 +69,14 @@ static ETSTimer timer;
69
69
#endif // Version check
70
70
#endif // !defined(_ESP32_IRRECV_TIMER_HACK)
71
71
72
+ // Define ARDUINO_COREV3 macro
73
+ #if defined(ESP_ARDUINO_VERSION) && \
74
+ (ESP_ARDUINO_VERSION >= ESP_ARDUINO_VERSION_VAL(3 , 0 , 0 ))
75
+ #define ARDUINO_COREV3 1
76
+ #else
77
+ #define ARDUINO_COREV3 0
78
+ #endif
79
+
72
80
#if _ESP32_IRRECV_TIMER_HACK
73
81
// Required structs/types from:
74
82
// https://github.com/espressif/arduino-esp32/blob/6b0114366baf986c155e8173ab7c22bc0c5fcedc/cores/esp32/esp32-hal-timer.c#L28-L58
@@ -242,21 +250,15 @@ static void USE_IRAM_ATTR gpio_intr() {
242
250
// @see https://github.com/crankyoldgit/IRremoteESP8266/issues/1350
243
251
// @see https://github.com/espressif/arduino-esp32/blob/6b0114366baf986c155e8173ab7c22bc0c5fcedc/cores/esp32/esp32-hal-timer.c#L176-L178
244
252
timer->dev ->config .alarm_en = 1 ;
245
- #else // _ESP32_IRRECV_TIMER_HACK
246
- // Check the ESP32 core version
247
- #if defined(ESP_ARDUINO_VERSION) && \
248
- (ESP_ARDUINO_VERSION >= ESP_ARDUINO_VERSION_VAL (3 , 0 , 0 ))
249
- // For ESP32 core version 3.x, replace `timerAlarmEnable`
250
- timerWrite (timer, 0 );
251
- uint64_t alarm_value = 50000 ; // Example value (50ms)
252
- timerAlarm (timer, alarm_value, false , 0 ); // Disable auto-reload
253
-
254
- #else
253
+ #elif ARDUINO_COREV3
254
+ // For ESP32 core version 3.x, replace `timerAlarmEnable`
255
+ timerWrite (timer, 0 );
256
+ uint64_t alarm_value = 50000 ; // Example value (50ms)
257
+ timerAlarm (timer, alarm_value, false , 0 ); // Disable auto-reloadmer, alarm_value, false, 0); // Disable auto-reload
258
+ #else
255
259
// For ESP32 core version 2.x, keep using `timerAlarmEnable`
256
260
timerWrite (timer, 0 );
257
261
timerAlarmEnable (timer);
258
- #endif
259
-
260
262
#endif // _ESP32_IRRECV_TIMER_HACK
261
263
#endif // ESP32
262
264
}
@@ -372,15 +374,12 @@ void IRrecv::enableIRIn(const bool pullup) {
372
374
373
375
#if defined(ESP32)
374
376
// Initialise the ESP32 timer.
375
- #if defined(ESP_ARDUINO_VERSION) && \
376
- (ESP_ARDUINO_VERSION >= ESP_ARDUINO_VERSION_VAL (3 , 0 , 0 ))
377
- // Use newer timerBegin signature for ESP32 core version 3.x
378
- timer = timerBegin (1000000 ); // Initialize with 1MHz (1us per tick)
377
+ #if ARDUINO_COREV3
378
+ // Use newer timerBegin signature for ESP32 core version 3.x
379
+ timer = timerBegin (1000000 ); // Initialize with 1MHz (1us per tick)
379
380
#else
380
- // Initialise the ESP32 timer.
381
- // 80MHz / 80 = 1 uSec granularity.
382
- // Check for ESP32 core version and handle timerBegin differently
383
- timer = timerBegin (_timer_num, 80 , true );
381
+ // Fallback for ESP32 core version 2.x or earlier
382
+ timer = timerBegin (0 , 1000000 , true ); // Old signature with divider
384
383
#endif
385
384
386
385
// Ensure the timer is successfully initialized
@@ -392,8 +391,7 @@ void IRrecv::enableIRIn(const bool pullup) {
392
391
#endif // DEBUG
393
392
assert (timer != NULL ); // Check we actually got the timer.
394
393
// Set the timer so it only fires once, and set its trigger in microseconds.
395
- #if defined(ESP_ARDUINO_VERSION) && \
396
- (ESP_ARDUINO_VERSION >= ESP_ARDUINO_VERSION_VAL (3 , 0 , 0 ))
394
+ #if ARDUINO_COREV3
397
395
timerWrite (timer, 0 ); // Reset the timer for ESP32 core version 3.x
398
396
timerAttachInterrupt (timer, &read_timeout);
399
397
#else
@@ -428,8 +426,7 @@ void IRrecv::disableIRIn(void) {
428
426
#endif // ESP8266
429
427
#if defined(ESP32)
430
428
// Check for ESP32 core version and handle timer functions differently
431
- #if defined(ESP_ARDUINO_VERSION) && \
432
- (ESP_ARDUINO_VERSION >= ESP_ARDUINO_VERSION_VAL (3 , 0 , 0 ))
429
+ #if ARDUINO_COREV3
433
430
// For ESP32 core version 3.x
434
431
timerWrite (timer, 0 ); // Reset the timer
435
432
timerDetachInterrupt (timer); // Detach the interrupt
0 commit comments