ICACHE_RAM_ATTR problem + Documentation

This commit is contained in:
Armin 2021-09-16 22:28:02 +02:00
parent ef868f6474
commit e238368164
6 changed files with 34 additions and 18 deletions

View File

@ -171,7 +171,7 @@ jobs:
sketches-exclude: IRDispatcherDemo,MicroGirs,MinimalReceiver # no tone()
# Do not cancel all jobs / architectures if one job fails
fail-fast: false
# fail-fast: false
steps:
- name: Checkout

View File

@ -56,7 +56,7 @@ If you use an (old) Arduino core that does not use the `-flto` flag for compile,
- Overflow, Repeat and other flags are now in [`IrReceiver.receivedIRData.flags`](https://github.com/Arduino-IRremote/Arduino-IRremote/blob/master/src/IRremote.h#L126).
- Seldom used: `results.rawbuf` and `results.rawlen` must be replaced by `IrReceiver.decodedIRData.rawDataPtr->rawbuf` and `IrReceiver.decodedIRData.rawDataPtr->rawlen`.
# Do not convert your 2.x program and use the 3.x library version
# Do not want to convert your 2.x program and use the 3.x library version?
The 3.x versions try to be backwards compatible, so you can easily run your old examples. But some functions like e.g. `sendNEC()` -see below- could not made backwards compatible, so in this cases you must revisit your code and adapt it to the 3.x library.<br/>
If you program look like:
```
@ -94,6 +94,12 @@ Example:
0x40802CD3 is binary 01000000100000000010110011010011.<br/>
If you read the first binary sequence backwards (right to left), you get the second sequence.
# Sending IR codes
Please do not use the old send*Raw() functions for sending like e.g. `IrSender.sendNECRaw(0xE61957A8,2)`,
even if this functions are used in a lot of **(old)** tutorials. They are only kept for backward compatibility and unsupported and error prone.<br/>
**Much better** is to use the **new structured functions** with address and command parameters like e.g. `IrSender.sendNEC(0xA8, 0x19, 2)`.
Especially if you are able to receive these remote codes and get the address and command values. You will discover that **the address is a constant** and the commands sometimes are sensibly grouped.
# FAQ
- IR does not work right when I use **Neopixels** (aka WS2811/WS2812/WS2812B) or other libraries blocking interrupts for a longer time (> 50 us).<br/>
Whether you use the Adafruit Neopixel lib, or FastLED, interrupts get disabled on many lower end CPUs like the basic Arduinos for longer than 50 µs.

View File

@ -52,11 +52,13 @@ void IRCommandDispatcher::init() {
* This is the function is called if a complete command was received
*/
#if defined(ESP8266)
ICACHE_RAM_ATTR
void ICACHE_RAM_ATTR handleReceivedTinyIRData(uint16_t aAddress, uint8_t aCommand, bool isRepeat)
#elif defined(ESP32)
IRAM_ATTR
void IRAM_ATTR handleReceivedTinyIRData(uint16_t aAddress, uint8_t aCommand, bool isRepeat)
#else
void handleReceivedTinyIRData(uint16_t aAddress, uint8_t aCommand, bool isRepeat)
#endif
void handleReceivedTinyIRData(uint16_t aAddress, uint8_t aCommand, bool isRepeat) {
{
IRDispatcher.IRReceivedData.address = aAddress;
IRDispatcher.IRReceivedData.command = aCommand;
IRDispatcher.IRReceivedData.isRepeat = isRepeat;
@ -91,11 +93,13 @@ void IRCommandDispatcher::init() {
* This is the function is called if a complete command was received
*/
#if defined(ESP8266)
ICACHE_RAM_ATTR
void ICACHE_RAM_ATTR handleReceivedIRData()
#elif defined(ESP32)
IRAM_ATTR
void IRAM_ATTR handleReceivedIRData()
#else
void handleReceivedIRData()
#endif
void handleReceivedIRData() {
{
IRMP_DATA tTeporaryData;
irmp_get_data(&tTeporaryData);
IRDispatcher.IRReceivedData.address = tTeporaryData.address;

View File

@ -89,11 +89,13 @@ void loop() {
* This is the function is called if a complete command was received
*/
#if defined(ESP8266)
ICACHE_RAM_ATTR
void ICACHE_RAM_ATTR handleReceivedTinyIRData(uint16_t aAddress, uint8_t aCommand, bool isRepeat)
#elif defined(ESP32)
IRAM_ATTR
void IRAM_ATTR handleReceivedTinyIRData(uint16_t aAddress, uint8_t aCommand, bool isRepeat)
#else
void handleReceivedTinyIRData(uint16_t aAddress, uint8_t aCommand, bool isRepeat)
#endif
void handleReceivedTinyIRData(uint16_t aAddress, uint8_t aCommand, bool isRepeat) {
{
/*
* Print only very short output, since we are in an interrupt context and do not want to miss the next interrupts of the repeats coming soon
*/

View File

@ -57,11 +57,12 @@ TinyIRReceiverStruct TinyIRReceiverControl;
* It is called every time a complete IR command or repeat was received.
*/
#if defined(ESP8266)
ICACHE_RAM_ATTR
void ICACHE_RAM_ATTR handleReceivedIRData(uint16_t aAddress, uint8_t aCommand, bool isRepetition);
#elif defined(ESP32)
IRAM_ATTR
#endif
void IRAM_ATTR handleReceivedIRData(uint16_t aAddress, uint8_t aCommand, bool isRepetition);
#else
void handleReceivedIRData(uint16_t aAddress, uint8_t aCommand, bool isRepetition);
#endif
/**
* The ISR of TinyIRRreceiver.
@ -69,11 +70,13 @@ void handleReceivedIRData(uint16_t aAddress, uint8_t aCommand, bool isRepetition
* 5 us + 3 us for push + pop for a 16MHz ATmega
*/
#if defined(ESP8266)
ICACHE_RAM_ATTR
void ICACHE_RAM_ATTR IRPinChangeInterruptHandler(void)
#elif defined(ESP32)
IRAM_ATTR
void IRAM_ATTR IRPinChangeInterruptHandler(void)
#else
void IRPinChangeInterruptHandler(void)
#endif
void IRPinChangeInterruptHandler(void) {
{
#if defined(IR_MEASURE_TIMING) && defined(IR_TIMING_TEST_PIN)
digitalWriteFast(IR_TIMING_TEST_PIN, HIGH); // 2 clock cycles
#endif

View File

@ -27,7 +27,8 @@
// Sparkfun Pro Micro is __AVR_ATmega32U4__ but has different external circuit
#elif defined(ARDUINO_AVR_PROMICRO)
// We have no built in LED -> reuse RX LED
// We have no built in LED at pin 13 -> reuse RX LED
#undef LED_BUILTIN
#define LED_BUILTIN LED_BUILTIN_RX
#define FEEDBACK_LED_ON() RXLED1
#define FEEDBACK_LED_OFF() RXLED0