Skip to content

Commit

Permalink
Merge pull request #1 from pillo79/main
Browse files Browse the repository at this point in the history
fix: more specific conditions for attachInterrupt() patches
  • Loading branch information
MaffooClock authored Oct 27, 2023
2 parents 0c41955 + 2a6c254 commit 8ecd5ba
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 22 deletions.
12 changes: 7 additions & 5 deletions src/ESP32RotaryEncoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,12 +84,14 @@ void RotaryEncoder::beginLoopTimer()

void RotaryEncoder::attachInterrupts()
{
#if defined( CORE_CORE_FUNCTIONALINTERRUPT_H_ ) && defined( __IO_PIN_REMAP_H__ ) && defined( attachInterrupt )
#if defined( BOARD_HAS_PIN_REMAP ) && ( ESP_ARDUINO_VERSION < ESP_ARDUINO_VERSION_VAL(3,0,0) )
/**
* The io_pin_remap.h defines a `attachInterrupt()` macro that stomps on the function defined
* in FunctionalInterrupt.h, which prevents attaching class methods to interrupts. The macro just
* folds-in a call to `digitalPinToGPIONumber()`, but FunctionalInterrupt.h does this too, so
* we actually don't need the macro at all.
* The io_pin_remap.h in Arduino-ESP32 cores of the 2.0.x family
* (since 2.0.10) define an `attachInterrupt()` macro that folds-in
* a call to `digitalPinToGPIONumber()`, but FunctionalInterrupt.cpp
* does this too, so we actually don't need the macro at all.
* Since 3.x the call inside the function was removed, so the wrapping
* macro is useful again.
*/
#undef attachInterrupt
#endif
Expand Down
30 changes: 13 additions & 17 deletions src/ESP32RotaryEncoder.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,23 +20,19 @@
#define ARDUINO_ISR_ATTR IRAM_ATTR
#endif

/**
* BUG ALERT!
*
* As of 28 September 2023
*
* This will fail to compile. You need to modify FunctionalInterrupt.h and change:
* void attachInterrupt(...)
* to:
* void (attachInterrupt)(...)
*
* See: https://forum.arduino.cc/t/easybutton-library-sample-code-does-not-work/1155696/3
*
* Also see `attachInterrupts()` in ESP32RotaryEncoder.cpp for
* the note about the `attachInterrupt()` macro
*/
#include <FunctionalInterrupt.h>

#if defined( ESP_ARDUINO_VERSION ) && ( ESP_ARDUINO_VERSION == ESP_ARDUINO_VERSION_VAL(2,0,10) )
/**
* BUG ALERT!
*
* With Arduino-ESP32 core 2.0.10, the #include statement below
* fails to compile due to a bug.
* Also see `attachInterrupts()` in ESP32RotaryEncoder.cpp for
* the note about the `attachInterrupt()` macro in 2.x cores.
*/
#error Please upgrade the Arduino-ESP32 core to use this library.
#else
#include <FunctionalInterrupt.h>
#endif
#endif

#define RE_DEFAULT_PIN -1
Expand Down

0 comments on commit 8ecd5ba

Please sign in to comment.