Changed switch to if / else if in IRRemote.cpp because of ESP32 compiler bug. Closes #599, #689

This commit is contained in:
Armin 2020-08-02 19:32:55 +02:00
parent 6faf6946dd
commit 2e79ccfe94
4 changed files with 28 additions and 41 deletions

View File

@ -1,8 +1,12 @@
## 2.5.0 2020/07
## 2.5.1 2020/08
- Added support for MagiQuest IR wands.
- Corrected Samsung timing.
- NEC repeat implemantation.
- Formatting and changing TIMER_CONFIG_KHZ and TIMER_CONFIG_NORMAL macros to static functions.
- Added IRAM_ATTR for ESP32 ISR.
- Removed #define HAS_AVR_INTERRUPT_H.
- Changed Receiver States. Now starting with 0.
- Changed switch to if / else if in IRRemote,.cpp because of ESP32 compiler bug.
## 2.5.0 2020/06
- corrected keywords.txt.

View File

@ -23,10 +23,6 @@
#include "IRremote.h"
#undef IR_GLOBAL
#ifdef HAS_AVR_INTERRUPT_H
#include <avr/interrupt.h>
#endif
//+=============================================================================
// The match functions were (apparently) originally MACROs to improve code speed
// (although this would have bloated the code) hence the names being CAPS
@ -101,8 +97,8 @@ int MATCH_SPACE(int measured_ticks, int desired_us) {
DBG_PRINT(TICKS_HIGH(desired_us - MARK_EXCESS_MICROS) * MICROS_PER_TICK, DEC);
// compensate for marks exceeded and spaces shortened by demodulator hardware
bool passed = ((measured_ticks >= TICKS_LOW (desired_us - MARK_EXCESS_MICROS))
&& (measured_ticks <= TICKS_HIGH(desired_us - MARK_EXCESS_MICROS)));
bool passed = ((measured_ticks >= TICKS_LOW(desired_us - MARK_EXCESS_MICROS))
&& (measured_ticks <= TICKS_HIGH(desired_us - MARK_EXCESS_MICROS)));
if (passed) {
DBG_PRINTLN(F("?; passed"));
} else {
@ -124,7 +120,7 @@ int MATCH_SPACE(int measured_ticks, int desired_us) {
// Gap width is recorded; Ready is cleared; New logging starts
//
ISR (TIMER_INTR_NAME) {
TIMER_RESET;
TIMER_RESET; // reset timer interrupt flag if required (currently only for Teensy and ATmega4809)
// Read if IR Receiver -> SPACE [xmt LED off] or a MARK [xmt LED on]
// digitalRead() is very slow. Optimisation is possible, but makes the code unportable
@ -135,9 +131,13 @@ ISR (TIMER_INTR_NAME) {
irparams.rcvstate = IR_REC_STATE_OVERFLOW; // Buffer overflow
}
switch (irparams.rcvstate) {
/*
* Due to a ESP32 compiler bug https://github.com/espressif/esp-idf/issues/1552 no switch statements are possible for ESP32
* So we change the code to if / else if
*/
// switch (irparams.rcvstate) {
//......................................................................
case IR_REC_STATE_IDLE: // In the middle of a gap
if (irparams.rcvstate == IR_REC_STATE_IDLE) { // In the middle of a gap
if (irdata == MARK) {
if (irparams.timer < GAP_TICKS) { // Not big enough to be a gap.
irparams.timer = 0;
@ -150,17 +150,13 @@ ISR (TIMER_INTR_NAME) {
irparams.rcvstate = IR_REC_STATE_MARK;
}
}
break;
//......................................................................
case IR_REC_STATE_MARK: // Timing Mark
} else if (irparams.rcvstate == IR_REC_STATE_MARK) { // Timing Mark
if (irdata == SPACE) { // Mark ended; Record time
irparams.rawbuf[irparams.rawlen++] = irparams.timer;
irparams.timer = 0;
irparams.rcvstate = IR_REC_STATE_SPACE;
}
break;
//......................................................................
case IR_REC_STATE_SPACE: // Timing Space
} else if (irparams.rcvstate == IR_REC_STATE_SPACE) { // Timing Space
if (irdata == MARK) { // Space just ended; Record time
irparams.rawbuf[irparams.rawlen++] = irparams.timer;
irparams.timer = 0;
@ -173,18 +169,13 @@ ISR (TIMER_INTR_NAME) {
// Don't reset timer; keep counting Space width
irparams.rcvstate = IR_REC_STATE_STOP;
}
break;
//......................................................................
case IR_REC_STATE_STOP: // Waiting; Measuring Gap
} else if (irparams.rcvstate == IR_REC_STATE_STOP) { // Waiting; Measuring Gap
if (irdata == MARK) {
irparams.timer = 0; // Reset gap timer
}
break;
//......................................................................
case IR_REC_STATE_OVERFLOW: // Flag up a read overflow; Stop the State Machine
} else if (irparams.rcvstate == IR_REC_STATE_OVERFLOW) { // Flag up a read overflow; Stop the State Machine
irparams.overflow = true;
irparams.rcvstate = IR_REC_STATE_STOP;
break;
}
#ifdef BLINKLED

View File

@ -26,11 +26,6 @@
// Define some defaults, that some boards may like to override
// (This is to avoid negative logic, ! DONT_... is just awkward.)
/**
* Define if the current board has/needs the header avr/interrupt.h.
*/
#define HAS_AVR_INTERRUPT_H
/**
* Defined if the standard enableIRIn function should be used.
* Undefine for boards supplying their own.
@ -39,6 +34,7 @@
/**
* Define if the current board supports sending.
* Currently not used.
*/
#define SENDING_SUPPORTED
@ -103,8 +99,6 @@
// Do not define anything.
#undef HAS_AVR_INTERRUPT_H
#elif defined(CORE_LED0_PIN)
#define BLINKLED CORE_LED0_PIN
#define BLINKLED_ON() (digitalWrite(CORE_LED0_PIN, HIGH))
@ -140,15 +134,13 @@
#define USE_SOFT_CARRIER
// Define to use spin wait instead of delayMicros()
//#define USE_SPIN_WAIT
// Supply own enableIRIn()
#undef USE_DEFAULT_ENABLE_IR_IN
#elif defined(ESP32)
// No system LED on ESP32, disable blinking by NOT defining BLINKLED
// avr/interrupt.h is not present
#undef HAS_AVR_INTERRUPT_H
// Supply own enbleIRIn
// Supply own enableIRIn() and enableIROut()
#undef USE_DEFAULT_ENABLE_IR_IN
#undef USE_DEFAULT_ENABLE_IR_OUT
@ -704,7 +696,7 @@ static void timerConfigNormal() {
#endif
//---------------------------------------------------------
// Special carrier modulator timer
// Special carrier modulator timer for Teensy 3.0 / Teensy 3.1
//
#elif defined(IR_USE_TIMER_CMT)
@ -888,7 +880,7 @@ static void timerConfigNormal() {
#ifdef ISR
#undef ISR
#endif
#define ISR(f) void IRTimer()
#define ISR(f) void IRAM_ATTR IRTimer()
#elif defined(ARDUINO_ARCH_SAMD)
// use timer 3 hardcoded at this time

View File

@ -49,11 +49,11 @@ typedef struct {
} irparams_t;
// ISR State-Machine : Receiver States
#define IR_REC_STATE_IDLE 2
#define IR_REC_STATE_MARK 3
#define IR_REC_STATE_SPACE 4
#define IR_REC_STATE_STOP 5
#define IR_REC_STATE_OVERFLOW 6
#define IR_REC_STATE_IDLE 0
#define IR_REC_STATE_MARK 1
#define IR_REC_STATE_SPACE 2
#define IR_REC_STATE_STOP 3
#define IR_REC_STATE_OVERFLOW 4
/**
* Allow all parts of the code access to the ISR data