Skip to content

Commit db98aa0

Browse files
committed
[Lib] Add latest ESP32 fixes by @s-hadinger, add extra NULL safeguard, update Platform build
1 parent c359dc3 commit db98aa0

File tree

2 files changed

+11
-11
lines changed

2 files changed

+11
-11
lines changed

platformio.ini

+2-2
Original file line numberDiff line numberDiff line change
@@ -23,5 +23,5 @@ board = esp32dev
2323

2424
# Experimental IDF 5.x support
2525
[env:esp32devIDF5x]
26-
platform = https://github.com/tasmota/platform-espressif32/releases/download/2023.10.10/platform-espressif32.zip
27-
board = esp32dev
26+
platform = https://github.com/tasmota/platform-espressif32/releases/download/2023.10.12/platform-espressif32.zip
27+
board = esp32dev

src/IRrecv.cpp

+9-9
Original file line numberDiff line numberDiff line change
@@ -249,8 +249,8 @@ static void USE_IRAM_ATTR gpio_intr() {
249249
timer->dev->config.alarm_en = 1;
250250
#else // _ESP32_IRRECV_TIMER_HACK
251251
#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);
254254
#else // ESP_ARDUINO_VERSION_MAJOR >= 3
255255
timerWrite(timer, 0);
256256
timerAlarmEnable(timer);
@@ -344,9 +344,6 @@ IRrecv::IRrecv(const uint16_t recvpin, const uint16_t bufsize,
344344
/// timers or interrupts used.
345345
IRrecv::~IRrecv(void) {
346346
disableIRIn();
347-
#if defined(ESP32)
348-
if (timer != NULL) timerEnd(timer); // Cleanup the ESP32 timeout timer.
349-
#endif // ESP32
350347
delete[] params.rawbuf;
351348
if (params_save != NULL) {
352349
delete[] params_save->rawbuf;
@@ -371,9 +368,9 @@ void IRrecv::enableIRIn(const bool pullup) {
371368
// Initialise the ESP32 timer.
372369
// 80MHz / 80 = 1 uSec granularity.
373370
#if ( defined(ESP_ARDUINO_VERSION_MAJOR) && (ESP_ARDUINO_VERSION_MAJOR >= 3) )
374-
timer = timerBegin(80);
371+
timer = timerBegin(1000000); // 1 MHz
375372
#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
377374
#endif // ESP_ARDUINO_VERSION_MAJOR >= 3
378375
#ifdef DEBUG
379376
if (timer == NULL) {
@@ -383,8 +380,8 @@ void IRrecv::enableIRIn(const bool pullup) {
383380
#endif // DEBUG
384381
assert(timer != NULL); // Check we actually got the timer.
385382
#if ( defined(ESP_ARDUINO_VERSION_MAJOR) && (ESP_ARDUINO_VERSION_MAJOR >= 3) )
386-
timerAlarm(timer, MS_TO_USEC(params.timeout), ONCE, 0);
387383
timerAttachInterrupt(timer, &read_timeout);
384+
timerAlarm(timer, MS_TO_USEC(params.timeout), ONCE, 0);
388385
#else // ESP_ARDUINO_VERSION_MAJOR >= 3
389386
// Set the timer so it only fires once, and set it's trigger in uSeconds.
390387
timerAlarmWrite(timer, MS_TO_USEC(params.timeout), ONCE);
@@ -418,13 +415,16 @@ void IRrecv::disableIRIn(void) {
418415
os_timer_disarm(&timer);
419416
#endif // ESP8266
420417
#if defined(ESP32)
418+
if (timer == NULL) { return; } // Call only once (defensive)
421419
#if ( defined(ESP_ARDUINO_VERSION_MAJOR) && (ESP_ARDUINO_VERSION_MAJOR >= 3) )
420+
timerDetachInterrupt(timer);
422421
timerEnd(timer);
423422
#else // ESP_ARDUINO_VERSION_MAJOR >= 3
424423
timerAlarmDisable(timer);
425424
timerDetachInterrupt(timer);
426425
timerEnd(timer);
427426
#endif // ESP_ARDUINO_VERSION_MAJOR >= 3
427+
timer = NULL; // Cleanup the ESP32 timeout timer.
428428
#endif // ESP32
429429
detachInterrupt(params.recvpin);
430430
#endif // UNIT_TEST
@@ -451,7 +451,7 @@ void IRrecv::resume(void) {
451451
params.overflow = false;
452452
#if defined(ESP32)
453453
#if ( defined(ESP_ARDUINO_VERSION_MAJOR) && (ESP_ARDUINO_VERSION_MAJOR >= 3) )
454-
timerEnd(timer);
454+
timerStop(timer);
455455
#else // ESP_ARDUINO_VERSION_MAJOR >= 3
456456
timerAlarmDisable(timer);
457457
#endif // ESP_ARDUINO_VERSION_MAJOR >= 3

0 commit comments

Comments
 (0)