Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix IR receive on ESP32 with Arduino Core 3 #19904

Merged
merged 1 commit into from
Nov 1, 2023
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
18 changes: 11 additions & 7 deletions lib/lib_basic/IRremoteESP8266/IRremoteESP8266/src/IRrecv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -248,8 +248,8 @@ static void USE_IRAM_ATTR gpio_intr() {
timer->dev->config.alarm_en = 1;
#else // _ESP32_IRRECV_TIMER_HACK
#if ( defined(ESP_ARDUINO_VERSION_MAJOR) && (ESP_ARDUINO_VERSION_MAJOR >= 3) )
timerAlarm(timer, MS_TO_USEC(params.timeout), ONCE, 0);
timerAttachInterrupt(timer, &read_timeout);
timerWrite(timer, 0);
timerStart(timer);
#else // ESP_ARDUINO_VERSION_MAJOR >= 3
timerWrite(timer, 0);
timerAlarmEnable(timer);
Expand Down Expand Up @@ -344,7 +344,10 @@ IRrecv::IRrecv(const uint16_t recvpin, const uint16_t bufsize,
IRrecv::~IRrecv(void) {
disableIRIn();
#if defined(ESP32)
if (timer != NULL) timerEnd(timer); // Cleanup the ESP32 timeout timer.
if (timer != NULL) {
timerEnd(timer); // Cleanup the ESP32 timeout timer.
timer = NULL;
}
#endif // ESP32
delete[] params.rawbuf;
if (params_save != NULL) {
Expand All @@ -370,9 +373,9 @@ void IRrecv::enableIRIn(const bool pullup) {
// Initialise the ESP32 timer.
// 80MHz / 80 = 1 uSec granularity.
#if ( defined(ESP_ARDUINO_VERSION_MAJOR) && (ESP_ARDUINO_VERSION_MAJOR >= 3) )
timer = timerBegin(80);
timer = timerBegin(1000000); // 1 MHz
#else // ESP_ARDUINO_VERSION_MAJOR >= 3
timer = timerBegin(_timer_num, 80, true);
timer = timerBegin(_timer_num, 80, true); // 1 MHz : 80 MHz with divider 80
#endif // ESP_ARDUINO_VERSION_MAJOR >= 3
#ifdef DEBUG
if (timer == NULL) {
Expand All @@ -382,8 +385,8 @@ void IRrecv::enableIRIn(const bool pullup) {
#endif // DEBUG
assert(timer != NULL); // Check we actually got the timer.
#if ( defined(ESP_ARDUINO_VERSION_MAJOR) && (ESP_ARDUINO_VERSION_MAJOR >= 3) )
timerAlarm(timer, MS_TO_USEC(params.timeout), ONCE, 0);
timerAttachInterrupt(timer, &read_timeout);
timerAlarm(timer, MS_TO_USEC(params.timeout), ONCE, 0);
#else // ESP_ARDUINO_VERSION_MAJOR >= 3
// Set the timer so it only fires once, and set it's trigger in uSeconds.
timerAlarmWrite(timer, MS_TO_USEC(params.timeout), ONCE);
Expand Down Expand Up @@ -418,6 +421,7 @@ void IRrecv::disableIRIn(void) {
#endif // ESP8266
#if defined(ESP32)
#if ( defined(ESP_ARDUINO_VERSION_MAJOR) && (ESP_ARDUINO_VERSION_MAJOR >= 3) )
timerDetachInterrupt(timer);
timerEnd(timer);
#else // ESP_ARDUINO_VERSION_MAJOR >= 3
timerAlarmDisable(timer);
Expand Down Expand Up @@ -450,7 +454,7 @@ void IRrecv::resume(void) {
params.overflow = false;
#if defined(ESP32)
#if ( defined(ESP_ARDUINO_VERSION_MAJOR) && (ESP_ARDUINO_VERSION_MAJOR >= 3) )
timerEnd(timer);
timerStop(timer);
#else // ESP_ARDUINO_VERSION_MAJOR >= 3
timerAlarmDisable(timer);
#endif // ESP_ARDUINO_VERSION_MAJOR >= 3
Expand Down