diff --git a/examples/DumbIRRepeater/DumbIRRepeater.ino b/examples/DumbIRRepeater/DumbIRRepeater.ino index d3ddbdb6a..2d3f1a8b3 100644 --- a/examples/DumbIRRepeater/DumbIRRepeater.ino +++ b/examples/DumbIRRepeater/DumbIRRepeater.ino @@ -57,7 +57,12 @@ // The GPIO an IR detector/demodulator is connected to. Recommended: 14 (D5) // Note: GPIO 16 won't work on the ESP8266 as it does not have interrupts. +// Note: GPIO 14 won't work on the ESP32-C3 as it causes the board to reboot. +#ifdef ARDUINO_ESP32C3_DEV +const uint16_t kRecvPin = 10; // 14 on a ESP32-C3 causes a boot loop. +#else // ARDUINO_ESP32C3_DEV const uint16_t kRecvPin = 14; +#endif // ARDUINO_ESP32C3_DEV // GPIO to use to control the IR LED circuit. Recommended: 4 (D2). const uint16_t kIrLedPin = 4; diff --git a/examples/IRrecvDemo/IRrecvDemo.ino b/examples/IRrecvDemo/IRrecvDemo.ino index 2ae2e1410..743d32c4e 100644 --- a/examples/IRrecvDemo/IRrecvDemo.ino +++ b/examples/IRrecvDemo/IRrecvDemo.ino @@ -24,7 +24,12 @@ // An IR detector/demodulator is connected to GPIO pin 14(D5 on a NodeMCU // board). // Note: GPIO 16 won't work on the ESP8266 as it does not have interrupts. +// Note: GPIO 14 won't work on the ESP32-C3 as it causes the board to reboot. +#ifdef ARDUINO_ESP32C3_DEV +const uint16_t kRecvPin = 10; // 14 on a ESP32-C3 causes a boot loop. +#else // ARDUINO_ESP32C3_DEV const uint16_t kRecvPin = 14; +#endif // ARDUINO_ESP32C3_DEV IRrecv irrecv(kRecvPin); diff --git a/examples/IRrecvDumpV2/IRrecvDumpV2.ino b/examples/IRrecvDumpV2/IRrecvDumpV2.ino index 70dbdba42..f0bebff12 100644 --- a/examples/IRrecvDumpV2/IRrecvDumpV2.ino +++ b/examples/IRrecvDumpV2/IRrecvDumpV2.ino @@ -38,7 +38,12 @@ // An IR detector/demodulator is connected to GPIO pin 14 // e.g. D5 on a NodeMCU board. // Note: GPIO 16 won't work on the ESP8266 as it does not have interrupts. +// Note: GPIO 14 won't work on the ESP32-C3 as it causes the board to reboot. +#ifdef ARDUINO_ESP32C3_DEV +const uint16_t kRecvPin = 10; // 14 on a ESP32-C3 causes a boot loop. +#else // ARDUINO_ESP32C3_DEV const uint16_t kRecvPin = 14; +#endif // ARDUINO_ESP32C3_DEV // The Serial connection baud rate. // i.e. Status message will be sent to the PC at this baud rate. diff --git a/examples/IRrecvDumpV3/IRrecvDumpV3.ino b/examples/IRrecvDumpV3/IRrecvDumpV3.ino index 0948ae5e9..6bc054a3c 100644 --- a/examples/IRrecvDumpV3/IRrecvDumpV3.ino +++ b/examples/IRrecvDumpV3/IRrecvDumpV3.ino @@ -45,7 +45,12 @@ // An IR detector/demodulator is connected to GPIO pin 14 // e.g. D5 on a NodeMCU board. // Note: GPIO 16 won't work on the ESP8266 as it does not have interrupts. +// Note: GPIO 14 won't work on the ESP32-C3 as it causes the board to reboot. +#ifdef ARDUINO_ESP32C3_DEV +const uint16_t kRecvPin = 10; // 14 on a ESP32-C3 causes a boot loop. +#else // ARDUINO_ESP32C3_DEV const uint16_t kRecvPin = 14; +#endif // ARDUINO_ESP32C3_DEV // The Serial connection baud rate. // i.e. Status message will be sent to the PC at this baud rate. diff --git a/examples/SmartIRRepeater/SmartIRRepeater.ino b/examples/SmartIRRepeater/SmartIRRepeater.ino index d35c4cef6..10554735d 100644 --- a/examples/SmartIRRepeater/SmartIRRepeater.ino +++ b/examples/SmartIRRepeater/SmartIRRepeater.ino @@ -60,7 +60,12 @@ // The GPIO an IR detector/demodulator is connected to. Recommended: 14 (D5) // Note: GPIO 16 won't work on the ESP8266 as it does not have interrupts. +// Note: GPIO 14 won't work on the ESP32-C3 as it causes the board to reboot. +#ifdef ARDUINO_ESP32C3_DEV +const uint16_t kRecvPin = 10; // 14 on a ESP32-C3 causes a boot loop. +#else // ARDUINO_ESP32C3_DEV const uint16_t kRecvPin = 14; +#endif // ARDUINO_ESP32C3_DEV // GPIO to use to control the IR LED circuit. Recommended: 4 (D2). const uint16_t kIrLedPin = 4; diff --git a/src/IRrecv.cpp b/src/IRrecv.cpp index 5626db2c7..6debda635 100644 --- a/src/IRrecv.cpp +++ b/src/IRrecv.cpp @@ -261,13 +261,20 @@ static void USE_IRAM_ATTR gpio_intr() { /// capturing data. (Default: kTimeoutMs) /// @param[in] save_buffer Use a second (save) buffer to decode from. /// (Default: false) -/// @param[in] timer_num Nr. of the ESP32 timer to use (0 to 3) (ESP32 Only) +/// @param[in] timer_num Nr. of the ESP32 timer to use. (0 to 3) (ESP32 Only) +/// or (0 to 1) (ESP32-C3) #if defined(ESP32) IRrecv::IRrecv(const uint16_t recvpin, const uint16_t bufsize, const uint8_t timeout, const bool save_buffer, const uint8_t timer_num) { - // There are only 4 timers. 0 to 3. - _timer_num = std::min(timer_num, (uint8_t)3); + // Ensure we use a valid timer number. + _timer_num = std::min(timer_num, + (uint8_t)( +#ifdef SOC_TIMER_GROUP_TOTAL_TIMERS + SOC_TIMER_GROUP_TOTAL_TIMERS - 1)); +#else // SOC_TIMER_GROUP_TOTAL_TIMERS + 3)); +#endif // SOC_TIMER_GROUP_TOTAL_TIMERS #else // ESP32 /// @cond IGNORE /// Class constructor @@ -353,6 +360,13 @@ void IRrecv::enableIRIn(const bool pullup) { // Initialise the ESP32 timer. // 80MHz / 80 = 1 uSec granularity. timer = timerBegin(_timer_num, 80, true); +#ifdef DEBUG + if (timer == NULL) { + DPRINT("FATAL: Unable enable system timer: "); + DPRINTLN((uint16_t)_timer_num); + } +#endif // 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. timerAlarmWrite(timer, MS_TO_USEC(params.timeout), ONCE); // Note: Interrupt needs to be attached before it can be enabled or disabled. diff --git a/src/IRrecv.h b/src/IRrecv.h index f9ff4b0ef..425fc4b24 100644 --- a/src/IRrecv.h +++ b/src/IRrecv.h @@ -52,8 +52,15 @@ const uint16_t kMaxTimeoutMs = kRawTick * (UINT16_MAX / MS_TO_USEC(1)); const uint32_t kFnvPrime32 = 16777619UL; const uint32_t kFnvBasis32 = 2166136261UL; -// Which of the ESP32 timers to use by default. (0-3) +#ifdef ESP32 +// Which of the ESP32 timers to use by default. +// (3 for most ESP32s, 1 for ESP32-C3s) +#ifdef SOC_TIMER_GROUP_TOTAL_TIMERS +const uint8_t kDefaultESP32Timer = SOC_TIMER_GROUP_TOTAL_TIMERS - 1; +#else // SOC_TIMER_GROUP_TOTAL_TIMERS const uint8_t kDefaultESP32Timer = 3; +#endif // SOC_TIMER_GROUP_TOTAL_TIMERS +#endif // ESP32 #if DECODE_AC // Hitachi AC is the current largest state size.