Skip to content

Commit

Permalink
Fix prog button handling (#207)
Browse files Browse the repository at this point in the history
* Update stm32_platform.cpp

Addresses a side effect of #177, which causes the eeprom buffer to be overwritten every time getEepromBuffer is called. This prevented programming of STM32 boards as their initial bus address was lost before programming.

* progbutton fix

* Update stm32_platform.cpp

Addresses a side effect of #177, which causes the eeprom buffer to be overwritten every time getEepromBuffer is called. This prevented programming of STM32 boards as their initial bus address was lost before programming.

* Update knx_facade.h

Remove superfluous attribute _buttonPinInterruptOn

* Update knx_facade.h

attachInterrup on CHANGE for progbutton detection
  • Loading branch information
rueckix committed May 31, 2022
1 parent 3948045 commit bd907c2
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 38 deletions.
45 changes: 28 additions & 17 deletions src/knx_facade.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,66 +15,77 @@
#define ICACHE_RAM_ATTR
#endif

ICACHE_RAM_ATTR void buttonUp()
#ifndef PROG_BTN_PRESS_MIN_MILLIS
#define PROG_BTN_PRESS_MIN_MILLIS 50
#endif

#ifndef PROG_BTN_PRESS_MAX_MILLIS
#define PROG_BTN_PRESS_MAX_MILLIS 500
#endif


ICACHE_RAM_ATTR void buttonEvent()
{
static uint32_t lastpressed=0;
if (millis() - lastpressed > 200){
static uint32_t lastEvent=0;
uint32_t diff = millis() - lastEvent;
if (diff >= PROG_BTN_PRESS_MIN_MILLIS && diff <= PROG_BTN_PRESS_MAX_MILLIS){
knx.toggleProgMode();
lastpressed = millis();
}

lastEvent = millis();
}
#endif

#ifdef ARDUINO_ARCH_SAMD
// predefined global instance for TP or RF or TP/RF coupler
#if MASK_VERSION == 0x07B0
KnxFacade<SamdPlatform, Bau07B0> knx(buttonUp);
KnxFacade<SamdPlatform, Bau07B0> knx(buttonEvent);
#elif MASK_VERSION == 0x27B0
KnxFacade<SamdPlatform, Bau27B0> knx(buttonUp);
KnxFacade<SamdPlatform, Bau27B0> knx(buttonEvent);
#elif MASK_VERSION == 0x2920
KnxFacade<SamdPlatform, Bau2920> knx(buttonUp);
KnxFacade<SamdPlatform, Bau2920> knx(buttonEvent);
#else
#error "Mask version not supported on ARDUINO_ARCH_SAMD"
#endif
#elif defined(ARDUINO_ARCH_RP2040)
// predefined global instance for TP or RF or TP/RF coupler
#if MASK_VERSION == 0x07B0
KnxFacade<RP2040ArduinoPlatform, Bau07B0> knx(buttonUp);
KnxFacade<RP2040ArduinoPlatform, Bau07B0> knx(buttonEvent);
#elif MASK_VERSION == 0x27B0
KnxFacade<RP2040ArduinoPlatform, Bau27B0> knx(buttonUp);
KnxFacade<RP2040ArduinoPlatform, Bau27B0> knx(buttonEvent);
#elif MASK_VERSION == 0x2920
KnxFacade<RP2040ArduinoPlatform, Bau2920> knx(buttonUp);
KnxFacade<RP2040ArduinoPlatform, Bau2920> knx(buttonEvent);
#else
#error "Mask version not supported on ARDUINO_ARCH_RP2040"
#endif

#elif defined(ARDUINO_ARCH_ESP8266)
// predefined global instance for TP or IP or TP/IP coupler
#if MASK_VERSION == 0x07B0
KnxFacade<EspPlatform, Bau07B0> knx(buttonUp);
KnxFacade<EspPlatform, Bau07B0> knx(buttonEvent);
#elif MASK_VERSION == 0x57B0
KnxFacade<EspPlatform, Bau57B0> knx(buttonUp);
KnxFacade<EspPlatform, Bau57B0> knx(buttonEvent);
#elif MASK_VERSION == 0x091A
KnxFacade<EspPlatform, Bau091A> knx(buttonUp);
KnxFacade<EspPlatform, Bau091A> knx(buttonEvent);
#else
#error "Mask version not supported on ARDUINO_ARCH_ESP8266"
#endif

#elif defined(ARDUINO_ARCH_ESP32)
// predefined global instance for TP or IP or TP/IP coupler
#if MASK_VERSION == 0x07B0
KnxFacade<Esp32Platform, Bau07B0> knx(buttonUp);
KnxFacade<Esp32Platform, Bau07B0> knx(buttonEvent);
#elif MASK_VERSION == 0x57B0
KnxFacade<Esp32Platform, Bau57B0> knx(buttonUp);
KnxFacade<Esp32Platform, Bau57B0> knx(buttonEvent);
#elif MASK_VERSION == 0x091A
KnxFacade<Esp32Platform, Bau091A> knx(buttonUp);
KnxFacade<Esp32Platform, Bau091A> knx(buttonEvent);
#else
#error "Mask version not supported on ARDUINO_ARCH_ESP32"
#endif

#elif defined(ARDUINO_ARCH_STM32)
#if MASK_VERSION == 0x07B0
KnxFacade<Stm32Platform, Bau07B0> knx(buttonUp);
KnxFacade<Stm32Platform, Bau07B0> knx(buttonEvent);
#else
#error "Mask version not supported on ARDUINO_ARCH_STM32"
#endif
Expand Down
24 changes: 3 additions & 21 deletions src/knx_facade.h
Original file line number Diff line number Diff line change
Expand Up @@ -177,24 +177,7 @@ template <class P, class B> class KnxFacade : private SaveRestore
_progLedOnCallback = progLedOnCallback;
}

/**
* returns RISING if interrupt is created in a rising signal, FALLING otherwise
*/
uint32_t buttonPinInterruptOn()
{
return _buttonPinInterruptOn;
}

/**
* Sets if the programming button creates a RISING or a FALLING signal.
*
* Set to RISING for GPIO--BUTTON--VDD or to FALLING for GPIO--BUTTON--GND
*/
void buttonPinInterruptOn(uint32_t value)
{
_buttonPinInterruptOn = value;
}


uint32_t buttonPin()
{
return _buttonPin;
Expand Down Expand Up @@ -281,9 +264,9 @@ template <class P, class B> class KnxFacade : private SaveRestore
{
// Workaround for https://github.com/arduino/ArduinoCore-samd/issues/587
#if (ARDUINO_API_VERSION >= 10200)
attachInterrupt(_buttonPin, _progButtonISRFuncPtr, (PinStatus)_buttonPinInterruptOn);
attachInterrupt(_buttonPin, _progButtonISRFuncPtr, (PinStatus)CHANGE);
#else
attachInterrupt(_buttonPin, _progButtonISRFuncPtr, _buttonPinInterruptOn);
attachInterrupt(_buttonPin, _progButtonISRFuncPtr, CHANGE);
#endif
}

Expand Down Expand Up @@ -423,7 +406,6 @@ template <class P, class B> class KnxFacade : private SaveRestore
ProgLedOffCallback _progLedOffCallback = 0;
uint32_t _ledPinActiveOn = LOW;
uint32_t _ledPin = LED_BUILTIN;
uint32_t _buttonPinInterruptOn = RISING;
uint32_t _buttonPin = 0;
SaveCallback _saveCallback = 0;
RestoreCallback _restoreCallback = 0;
Expand Down

0 comments on commit bd907c2

Please sign in to comment.