Skip to content
Merged
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions Doxyfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ INPUT = src
INPUT += docs/doxygen_index.md
RECURSIVE = YES
EXCLUDE = examples
EXCLUDE += src/hal
MULTILINE_CPP_IS_BRIEF = YES
TAB_SIZE = 2
EXTRACT_ALL = YES
Expand Down
64 changes: 47 additions & 17 deletions src/IRrecv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,20 +56,24 @@ static ETSTimer timer;
} // namespace _IRrecv
#endif // ESP8266
#if defined(ESP32)
#if ( defined(ESP_ARDUINO_VERSION) && \
(ESP_ARDUINO_VERSION >= ESP_ARDUINO_VERSION_VAL(3, 0, 0)) )
#define _ESP32_ARDUINO_CORE_V3PLUS
#endif // ESP_ARDUINO_VERSION >= 3
// We need a horrible timer hack for ESP32 Arduino framework < v2.0.0
#if !defined(_ESP32_IRRECV_TIMER_HACK)
#if !defined(_ESP32_ARDUINO_CORE_V2PLUS)
// 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
#define _ESP32_ARDUINO_CORE_V2PLUS 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
#define _ESP32_ARDUINO_CORE_V2PLUS true
#endif // Version check
#endif // !defined(_ESP32_IRRECV_TIMER_HACK)
#endif // !defined(_ESP32_ARDUINO_CORE_V2PLUS)

#if _ESP32_IRRECV_TIMER_HACK
#if _ESP32_ARDUINO_CORE_V2PLUS
// 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 @@ -131,10 +135,10 @@ typedef struct hw_timer_s {
uint8_t timer;
portMUX_TYPE lock;
} hw_timer_t;
#endif // _ESP32_IRRECV_TIMER_HACK / End of Horrible Hack.
#endif // _ESP32_ARDUINO_CORE_V2PLUS / End of Horrible Hack.

namespace _IRrecv {
static hw_timer_t * timer = NULL;
static hw_timer_t *timer = NULL;
} // namespace _IRrecv
#endif // ESP32
using _IRrecv::timer;
Expand Down Expand Up @@ -215,7 +219,7 @@ static void USE_IRAM_ATTR gpio_intr() {
else
params.rawbuf[rawlen] = (now - start) / kRawTick;
}
params.rawlen++;
params.rawlen = params.rawlen + 1; // C++20 fix

start = now;

Expand All @@ -225,8 +229,8 @@ 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:
#if _ESP32_ARDUINO_CORE_V2PLUS
// The following three lines of code are the equivalent of:
// `timerWrite(timer, 0);`
// We can't call that routine safely from inside an ISR as that procedure
// is not stored in IRAM. Hence, we do it manually so that it's covered by
Expand All @@ -241,10 +245,15 @@ 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
#elif defined(_ESP32_ARDUINO_CORE_V3PLUS)
// For ESP32 core version 3.x, replace `timerAlarmEnable`
timerWrite(timer, 0);
uint64_t alarm_value = 50000; // Example value (50ms)
timerAlarm(timer, alarm_value, false, 0);
#else // !_ESP32_ARDUINO_CORE_V3PLUS
timerWrite(timer, 0);
timerAlarmEnable(timer);
#endif // _ESP32_IRRECV_TIMER_HACK
#endif // _ESP32_ARDUINO_CORE_V2PLUS
#endif // ESP32
}
#endif // UNIT_TEST
Expand Down Expand Up @@ -366,21 +375,33 @@ void IRrecv::enableIRIn(const bool pullup) {
}
#if defined(ESP32)
// Initialise the ESP32 timer.
#if defined(_ESP32_ARDUINO_CORE_V3PLUS)
// Use newer timerBegin signature for ESP32 core version 3.x
timer = timerBegin(1000000); // Initialize with 1MHz (1us per tick)
#else // _ESP32_ARDUINO_CORE_V3PLUS
// 80MHz / 80 = 1 uSec granularity.
timer = timerBegin(_timer_num, 80, true);
#endif // _ESP32_ARDUINO_CORE_V3PLUS

// Ensure the timer is successfully initialized
#ifdef IR_DEBUG
if (timer == NULL) {
DPRINT("FATAL: Unable enable system timer: ");
DPRINTLN((uint16_t)_timer_num);
}
#endif // IR_DEBUG
assert(timer != NULL); // Check we actually got the timer.
// Set the timer so it only fires once, and set it's trigger in uSeconds.
// Set the timer so it only fires once, and set its trigger in microseconds.
#if defined(_ESP32_ARDUINO_CORE_V3PLUS)
timerWrite(timer, 0); // Reset the timer for ESP32 core version 3.x
timerAttachInterrupt(timer, &read_timeout);
#else // _ESP32_ARDUINO_CORE_V3PLUS
timerAlarmWrite(timer, MS_TO_USEC(params.timeout), ONCE);
// Note: Interrupt needs to be attached before it can be enabled or disabled.
// 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_ARDUINO_CORE_V3PLUS
#endif // ESP32

// Initialise state machine variables
Expand All @@ -404,8 +425,11 @@ void IRrecv::disableIRIn(void) {
#ifndef UNIT_TEST
#if defined(ESP8266)
os_timer_disarm(&timer);
#endif // ESP8266
#if defined(ESP32)
#elif defined(_ESP32_ARDUINO_CORE_V3PLUS)
timerWrite(timer, 0); // Reset the timer
timerDetachInterrupt(timer);
timerEnd(timer);
#elif defined(ESP32)
timerAlarmDisable(timer);
timerDetachInterrupt(timer);
timerEnd(timer);
Expand Down Expand Up @@ -434,7 +458,13 @@ void IRrecv::resume(void) {
params.rawlen = 0;
params.overflow = false;
#if defined(ESP32)
// Check for ESP32 core version and handle timer functions differently
#if defined(_ESP32_ARDUINO_CORE_V3PLUS)
timerWrite(timer, 0); // Reset the timer (no need for timerAlarmDisable)
#else // _ESP32_ARDUINO_CORE_V3PLUS
timerAlarmDisable(timer);
#endif // _ESP32_ARDUINO_CORE_V3PLUS
// Re-enable GPIO interrupt in both versions
gpio_intr_enable((gpio_num_t)params.recvpin);
#endif // ESP32
}
Expand Down Expand Up @@ -510,8 +540,8 @@ void IRrecv::crudeNoiseFilter(decode_results *results, const uint16_t floor) {
for (uint16_t i = offset + 2; i <= results->rawlen && i < kBufSize; i++)
results->rawbuf[i - 2] = results->rawbuf[i];
if (offset > 1) { // There is a previous pair we can add to.
// Merge this pair into into the previous space.
results->rawbuf[offset - 1] += addition;
// Merge this pair into into the previous space. // C++20 fix applied
results->rawbuf[offset - 1] = results->rawbuf[offset - 1] + addition;
}
results->rawlen -= 2; // Adjust the length.
} else {
Expand Down
13 changes: 5 additions & 8 deletions src/IRutils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -822,16 +822,13 @@ String addDayToString(const uint8_t day_of_week, const int8_t offset,
/// @return The resulting String.
String dayToString(const uint8_t day_of_week, const int8_t offset) {
if ((uint8_t)(day_of_week + offset) < 7)
#if UNIT_TEST
return String(kThreeLetterDayOfWeekStr).substr(
(day_of_week + offset) * 3, 3);
#elif defined(ARDUINO)
return String(kThreeLetterDayOfWeekStr).substring(
(day_of_week + offset) * 3, (day_of_week + offset) * 3 + 3);
#else // UNIT_TEST
#if defined(ARDUINO)
return String(kThreeLetterDayOfWeekStr).substring(
(day_of_week + offset) * 3, (day_of_week + offset) * 3 + 3);
#endif // UNIT_TEST
#else // ARDUINO
return String(kThreeLetterDayOfWeekStr).substr(
(day_of_week + offset) * 3, 3);
#endif // ARDUINO
else
return kUnknownStr;
}
Expand Down
Loading