Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 24 additions & 3 deletions src/IRrecv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ extern "C" {
}
#endif // ESP8266
#include <Arduino.h>
#endif
#endif // UNIT_TEST
#include <algorithm>
#ifdef UNIT_TEST
#include <cassert>
Expand Down Expand Up @@ -56,6 +56,20 @@ static ETSTimer timer;
} // namespace _IRrecv
#endif // ESP8266
#if defined(ESP32)
// We need a horrible timer hack for ESP32 Arduino framework < v2.0.0
#if !defined(_ESP32_IRRECV_TIMER_HACK)
// Version check
#if ( defined(ESP_ARDUINO_VERSION_MAJOR) && (ESP_ARDUINO_VERSION_MAJOR >= 2) )
// No need for the hack if we are running version >= 2.0.0
#define _ESP32_IRRECV_TIMER_HACK false
#else // Version check
// If no ESP_ARDUINO_VERSION_MAJOR is defined, or less than 2, then we are
// using an old ESP32 core, so we need the hack.
#define _ESP32_IRRECV_TIMER_HACK true
#endif // Version check
#endif // !defined(_ESP32_IRRECV_TIMER_HACK)

#if _ESP32_IRRECV_TIMER_HACK
// Required structs/types from:
// https://github.com/espressif/arduino-esp32/blob/6b0114366baf986c155e8173ab7c22bc0c5fcedc/cores/esp32/esp32-hal-timer.c#L28-L58
// These are needed to be able to directly manipulate the timer registers from
Expand Down Expand Up @@ -117,7 +131,7 @@ typedef struct hw_timer_s {
uint8_t timer;
portMUX_TYPE lock;
} hw_timer_t;
// End of Horrible Hack.
#endif // _ESP32_IRRECV_TIMER_HACK / End of Horrible Hack.

namespace _IRrecv {
static hw_timer_t * timer = NULL;
Expand Down Expand Up @@ -211,6 +225,7 @@ static void USE_IRAM_ATTR gpio_intr() {
#if defined(ESP32)
// Reset the timeout.
//
#if _ESP32_IRRECV_TIMER_HACK
// The following three lines of code are the equiv of:
// `timerWrite(timer, 0);`
// We can't call that routine safely from inside an ISR as that procedure
Expand All @@ -226,6 +241,10 @@ static void USE_IRAM_ATTR gpio_intr() {
// @see https://github.com/crankyoldgit/IRremoteESP8266/issues/1350
// @see https://github.com/espressif/arduino-esp32/blob/6b0114366baf986c155e8173ab7c22bc0c5fcedc/cores/esp32/esp32-hal-timer.c#L176-L178
timer->dev->config.alarm_en = 1;
#else // _ESP32_IRRECV_TIMER_HACK
timerWrite(timer, 0);
timerAlarmEnable(timer);
#endif // _ESP32_IRRECV_TIMER_HACK
#endif // ESP32
}
#endif // UNIT_TEST
Expand Down Expand Up @@ -337,7 +356,9 @@ void IRrecv::enableIRIn(const bool pullup) {
// Set the timer so it only fires once, and set it's trigger in uSeconds.
timerAlarmWrite(timer, MS_TO_USEC(params.timeout), ONCE);
// Note: Interrupt needs to be attached before it can be enabled or disabled.
timerAttachInterrupt(timer, &read_timeout, true);
// Note: EDGE (true) is not supported, use LEVEL (false). Ref: #1713
// See: https://github.com/espressif/arduino-esp32/blob/caef4006af491130136b219c1205bdcf8f08bf2b/cores/esp32/esp32-hal-timer.c#L224-L227
timerAttachInterrupt(timer, &read_timeout, false);
#endif // ESP32

// Initialise state machine variables
Expand Down