@@ -21,6 +21,12 @@ extern "C" {
2121#include " IRremoteESP8266.h"
2222#include " IRutils.h"
2323
24+ #if defined(ESP32)
25+ #if ( defined(ESP_ARDUINO_VERSION_MAJOR) && (ESP_ARDUINO_VERSION_MAJOR >= 3) )
26+ #include < driver/gpio.h>
27+ #endif // ESP_ARDUINO_VERSION_MAJOR >= 3
28+ #endif
29+
2430#ifdef UNIT_TEST
2531#undef ICACHE_RAM_ATTR
2632#define ICACHE_RAM_ATTR
@@ -148,7 +154,7 @@ namespace _IRrecv { // Namespace extension
148154#if defined(ESP32)
149155portMUX_TYPE mux = portMUX_INITIALIZER_UNLOCKED;
150156#endif // ESP32
151- volatile irparams_t params;
157+ atomic_irparams_t params;
152158irparams_t *params_save; // A copy of the interrupt state while decoding.
153159} // namespace _IRrecv
154160
@@ -219,7 +225,7 @@ static void USE_IRAM_ATTR gpio_intr() {
219225 else
220226 params.rawbuf [rawlen] = (now - start) / kRawTick ;
221227 }
222- params.rawlen ++;
228+ params.rawlen = params. rawlen + 1 ; // C++20 fix
223229
224230 start = now;
225231
@@ -342,9 +348,6 @@ IRrecv::IRrecv(const uint16_t recvpin, const uint16_t bufsize,
342348// / timers or interrupts used.
343349IRrecv::~IRrecv (void ) {
344350 disableIRIn ();
345- #if defined(ESP32)
346- if (timer != NULL ) timerEnd (timer); // Cleanup the ESP32 timeout timer.
347- #endif // ESP32
348351 delete[] params.rawbuf ;
349352 if (params_save != NULL ) {
350353 delete[] params_save->rawbuf ;
@@ -425,6 +428,7 @@ void IRrecv::disableIRIn(void) {
425428 timerAlarmDisable (timer);
426429 timerDetachInterrupt (timer);
427430 timerEnd (timer);
431+ timer = NULL ; // Cleanup the ESP32 timeout timer.
428432#endif // ESP32
429433 detachInterrupt (params.recvpin );
430434#endif // UNIT_TEST
@@ -467,7 +471,7 @@ void IRrecv::resume(void) {
467471// / i.e. In kStopState.
468472// / @param[in] src Pointer to an irparams_t structure to copy from.
469473// / @param[out] dst Pointer to an irparams_t structure to copy to.
470- void IRrecv::copyIrParams (volatile irparams_t *src, irparams_t *dst) {
474+ void IRrecv::copyIrParams (atomic_irparams_t *src, irparams_t *dst) {
471475 // Typecast src and dst addresses to (char *)
472476 char *csrc = (char *)src; // NOLINT(readability/casting)
473477 char *cdst = (char *)dst; // NOLINT(readability/casting)
@@ -532,8 +536,8 @@ void IRrecv::crudeNoiseFilter(decode_results *results, const uint16_t floor) {
532536 for (uint16_t i = offset + 2 ; i <= results->rawlen && i < kBufSize ; i++)
533537 results->rawbuf [i - 2 ] = results->rawbuf [i];
534538 if (offset > 1 ) { // There is a previous pair we can add to.
535- // Merge this pair into into the previous space.
536- results->rawbuf [offset - 1 ] += addition;
539+ // Merge this pair into into the previous space. // C++20 fix applied
540+ results->rawbuf [offset - 1 ] = results-> rawbuf [offset - 1 ] + addition;
537541 }
538542 results->rawlen -= 2 ; // Adjust the length.
539543 } else {
@@ -1489,7 +1493,7 @@ bool IRrecv::decodeHash(decode_results *results) {
14891493// / @return A match_result_t structure containing the success (or not), the
14901494// / data value, and how many buffer entries were used.
14911495match_result_t IRrecv::matchData (
1492- volatile uint16_t *data_ptr, const uint16_t nbits, const uint16_t onemark,
1496+ atomic_uint16_t *data_ptr, const uint16_t nbits, const uint16_t onemark,
14931497 const uint32_t onespace, const uint16_t zeromark, const uint32_t zerospace,
14941498 const uint8_t tolerance, const int16_t excess, const bool MSBfirst,
14951499 const bool expectlastspace) {
@@ -1549,7 +1553,7 @@ match_result_t IRrecv::matchData(
15491553// / true is Most Significant Bit First Order, false is Least Significant First
15501554// / @param[in] expectlastspace Do we expect a space at the end of the message?
15511555// / @return If successful, how many buffer entries were used. Otherwise 0.
1552- uint16_t IRrecv::matchBytes (volatile uint16_t *data_ptr, uint8_t *result_ptr,
1556+ uint16_t IRrecv::matchBytes (atomic_uint16_t *data_ptr, uint8_t *result_ptr,
15531557 const uint16_t remaining, const uint16_t nbytes,
15541558 const uint16_t onemark, const uint32_t onespace,
15551559 const uint16_t zeromark, const uint32_t zerospace,
@@ -1601,7 +1605,7 @@ uint16_t IRrecv::matchBytes(volatile uint16_t *data_ptr, uint8_t *result_ptr,
16011605// / @param[in] MSBfirst Bit order to save the data in. (Def: true)
16021606// / true is Most Significant Bit First Order, false is Least Significant First
16031607// / @return If successful, how many buffer entries were used. Otherwise 0.
1604- uint16_t IRrecv::_matchGeneric (volatile uint16_t *data_ptr,
1608+ uint16_t IRrecv::_matchGeneric (atomic_uint16_t *data_ptr,
16051609 uint64_t *result_bits_ptr,
16061610 uint8_t *result_bytes_ptr,
16071611 const bool use_bits,
@@ -1703,7 +1707,7 @@ uint16_t IRrecv::_matchGeneric(volatile uint16_t *data_ptr,
17031707// / @param[in] MSBfirst Bit order to save the data in. (Def: true)
17041708// / true is Most Significant Bit First Order, false is Least Significant First
17051709// / @return If successful, how many buffer entries were used. Otherwise 0.
1706- uint16_t IRrecv::matchGeneric (volatile uint16_t *data_ptr,
1710+ uint16_t IRrecv::matchGeneric (atomic_uint16_t *data_ptr,
17071711 uint64_t *result_ptr,
17081712 const uint16_t remaining,
17091713 const uint16_t nbits,
@@ -1750,7 +1754,7 @@ uint16_t IRrecv::matchGeneric(volatile uint16_t *data_ptr,
17501754// / @param[in] MSBfirst Bit order to save the data in. (Def: true)
17511755// / true is Most Significant Bit First Order, false is Least Significant First
17521756// / @return If successful, how many buffer entries were used. Otherwise 0.
1753- uint16_t IRrecv::matchGeneric (volatile uint16_t *data_ptr,
1757+ uint16_t IRrecv::matchGeneric (atomic_uint16_t *data_ptr,
17541758 uint8_t *result_ptr,
17551759 const uint16_t remaining,
17561760 const uint16_t nbits,
@@ -1797,7 +1801,7 @@ uint16_t IRrecv::matchGeneric(volatile uint16_t *data_ptr,
17971801// / @return If successful, how many buffer entries were used. Otherwise 0.
17981802// / @note Parameters one + zero add up to the total time for a bit.
17991803// / e.g. mark(one) + space(zero) is a `1`, mark(zero) + space(one) is a `0`.
1800- uint16_t IRrecv::matchGenericConstBitTime (volatile uint16_t *data_ptr,
1804+ uint16_t IRrecv::matchGenericConstBitTime (atomic_uint16_t *data_ptr,
18011805 uint64_t *result_ptr,
18021806 const uint16_t remaining,
18031807 const uint16_t nbits,
@@ -1884,7 +1888,7 @@ uint16_t IRrecv::matchGenericConstBitTime(volatile uint16_t *data_ptr,
18841888// / @return If successful, how many buffer entries were used. Otherwise 0.
18851889// / @see https://en.wikipedia.org/wiki/Manchester_code
18861890// / @see http://ww1.microchip.com/downloads/en/AppNotes/Atmel-9164-Manchester-Coding-Basics_Application-Note.pdf
1887- uint16_t IRrecv::matchManchester (volatile const uint16_t *data_ptr,
1891+ uint16_t IRrecv::matchManchester (atomic_const_uint16_t *data_ptr,
18881892 uint64_t *result_ptr,
18891893 const uint16_t remaining,
18901894 const uint16_t nbits,
@@ -1991,7 +1995,7 @@ uint16_t IRrecv::matchManchester(volatile const uint16_t *data_ptr,
19911995// / @see https://en.wikipedia.org/wiki/Manchester_code
19921996// / @see http://ww1.microchip.com/downloads/en/AppNotes/Atmel-9164-Manchester-Coding-Basics_Application-Note.pdf
19931997// / @todo Clean up and optimise this. It is just "get it working code" atm.
1994- uint16_t IRrecv::matchManchesterData (volatile const uint16_t *data_ptr,
1998+ uint16_t IRrecv::matchManchesterData (atomic_const_uint16_t *data_ptr,
19951999 uint64_t *result_ptr,
19962000 const uint16_t remaining,
19972001 const uint16_t nbits,
@@ -2112,7 +2116,7 @@ uint16_t IRrecv::matchManchesterData(volatile const uint16_t *data_ptr,
21122116
21132117#if UNIT_TEST
21142118// / Unit test helper to get access to the params structure.
2115- volatile irparams_t *IRrecv::_getParamsPtr (void ) {
2119+ atomic_irparams_t *IRrecv::_getParamsPtr (void ) {
21162120 return ¶ms;
21172121}
21182122#endif // UNIT_TEST
0 commit comments