@@ -134,7 +134,8 @@ typedef struct hw_timer_s {
134
134
#endif // _ESP32_IRRECV_TIMER_HACK / End of Horrible Hack.
135
135
136
136
namespace _IRrecv {
137
- static hw_timer_t * timer = NULL ;
137
+ static hw_timer_t *timer = NULL ; // Declare ESP32 timer variable
138
+
138
139
} // namespace _IRrecv
139
140
#endif // ESP32
140
141
using _IRrecv::timer;
@@ -247,7 +248,9 @@ static void USE_IRAM_ATTR gpio_intr() {
247
248
(ESP_ARDUINO_VERSION >= ESP_ARDUINO_VERSION_VAL (3 , 0 , 0 ))
248
249
// For ESP32 core version 3.x, replace `timerAlarmEnable`
249
250
timerWrite (timer, 0 );
250
- timerAlarm (timer, 0 , true , 0 ); // Use the updated function
251
+ uint64_t alarm_value = 50000 ; // Example value (50ms)
252
+ timerAlarm (timer, alarm_value, false , 0 ); // Disable auto-reload
253
+
251
254
#else
252
255
// For ESP32 core version 2.x, keep using `timerAlarmEnable`
253
256
timerWrite (timer, 0 );
@@ -369,17 +372,22 @@ void IRrecv::enableIRIn(const bool pullup) {
369
372
370
373
#if defined(ESP32)
371
374
// Initialise the ESP32 timer.
372
- // 80MHz / 80 = 1 uSec granularity.
373
- // Check for ESP32 core version and handle timerBegin differently
374
375
#if defined(ESP_ARDUINO_VERSION) && \
375
376
(ESP_ARDUINO_VERSION >= ESP_ARDUINO_VERSION_VAL (3 , 0 , 0 ))
376
- // For ESP32 core version 3.x (three arguments)
377
- timer = timerBegin (_timer_num);
378
- #else
379
- // For ESP32 core version 2.0.x (one argument)
380
- timer = timerBegin (_timer_num, 80 , true );
381
- #endif
377
+ // Use newer timerBegin signature for ESP32 core version 3.x
378
+ timer = timerBegin (1000000 ); // Initialize with 1MHz (1us per tick)
379
+ Serial.println (" Starting timer initialization..." );
380
+ Serial.print (" Timer number: " );
381
+ Serial.println (_timer_num);
382
+ Serial.println ((uint16_t )_timer_num);
383
+ #else
384
+ // Initialise the ESP32 timer.
385
+ // 80MHz / 80 = 1 uSec granularity.
386
+ // Check for ESP32 core version and handle timerBegin differently
387
+ timer = timerBegin (_timer_num, 80 , true );
388
+ #endif
382
389
390
+ // Ensure the timer is successfully initialized
383
391
#ifdef DEBUG
384
392
if (timer == NULL ) {
385
393
DPRINT (" FATAL: Unable enable system timer: " );
@@ -390,15 +398,13 @@ void IRrecv::enableIRIn(const bool pullup) {
390
398
// Set the timer so it only fires once, and set its trigger in microseconds.
391
399
#if defined(ESP_ARDUINO_VERSION) && \
392
400
(ESP_ARDUINO_VERSION >= ESP_ARDUINO_VERSION_VAL (3 , 0 , 0 ))
393
- // For ESP32 core version 3.x (use timerWrite)
394
- timerWrite (timer, 0 ); // Reset the timer
401
+ timerWrite (timer, 0 ); // Reset the timer for ESP32 core version 3.x
395
402
timerAttachInterrupt (timer, &read_timeout);
396
- #else
397
- timerAlarmWrite (timer, MS_TO_USEC (params.timeout ), ONCE);
403
+ #else
404
+ // Attach timer interrupt for core version 2.x
405
+ timerAlarmWrite (timer, MS_TO_USEC (params.timeout ), true );
398
406
timerAttachInterrupt (timer, &read_timeout, false );
399
- #endif
400
- // Note: Interrupt needs to be attached before it can be enabled or disabled.
401
- // Note: EDGE (true) is not supported, use LEVEL (false). Ref: #1713
407
+ #endif
402
408
403
409
#endif // ESP32
404
410
0 commit comments