Don't assign built-in LED as ProgLED by default. Allow disabling ProgLED by setting _ledPin=-1

This commit is contained in:
Phil1pp 2025-05-07 14:09:57 +02:00
parent d5b9ffa0a9
commit 38ee9066c8

View File

@ -28,9 +28,6 @@
void buttonUp(); void buttonUp();
#endif #endif
#elif defined(ARDUINO_ARCH_ESP32) #elif defined(ARDUINO_ARCH_ESP32)
#if !defined(LED_BUILTIN)
#define LED_BUILTIN 13
#endif
#include "esp32_platform.h" #include "esp32_platform.h"
#ifndef KNX_NO_AUTOMATIC_GLOBAL_INSTANCE #ifndef KNX_NO_AUTOMATIC_GLOBAL_INSTANCE
void buttonUp(); void buttonUp();
@ -41,14 +38,8 @@
void buttonUp(); void buttonUp();
#endif #endif
#elif __linux__ #elif __linux__
#if !defined(LED_BUILTIN)
#define LED_BUILTIN 0
#endif
#include "linux_platform.h" #include "linux_platform.h"
#else #else
#if !defined(LED_BUILTIN)
#define LED_BUILTIN 5 // see GPIO_PinConfig gpioPinConfigs[]
#endif
#include "cc1310_platform.h" #include "cc1310_platform.h"
#ifndef KNX_NO_AUTOMATIC_GLOBAL_INSTANCE #ifndef KNX_NO_AUTOMATIC_GLOBAL_INSTANCE
extern void buttonUp(); extern void buttonUp();
@ -56,7 +47,7 @@
#endif #endif
#ifndef KNX_LED #ifndef KNX_LED
#define KNX_LED LED_BUILTIN #define KNX_LED -1
#endif #endif
#ifndef KNX_LED_ACTIVE_ON #ifndef KNX_LED_ACTIVE_ON
#define KNX_LED_ACTIVE_ON 0 #define KNX_LED_ACTIVE_ON 0
@ -170,12 +161,12 @@ template <class P, class B> class KnxFacade : private SaveRestore
_ledPinActiveOn = value; _ledPinActiveOn = value;
} }
uint32_t ledPin() int32_t ledPin()
{ {
return _ledPin; return _ledPin;
} }
void ledPin(uint32_t value) void ledPin(int32_t value)
{ {
_ledPin = value; _ledPin = value;
} }
@ -269,14 +260,17 @@ template <class P, class B> class KnxFacade : private SaveRestore
void start() void start()
{ {
if (_progLedOffCallback == 0 || _progLedOnCallback == 0) if (_ledPin >= 0)
pinMode(ledPin(), OUTPUT); pinMode(_ledPin, OUTPUT);
progLedOff(); progLedOff();
if (_progButtonISRFuncPtr && _buttonPin >= 0) if(_buttonPin >= 0)
{
pinMode(_buttonPin, INPUT_PULLUP);
if (_progButtonISRFuncPtr)
{ {
pinMode(buttonPin(), INPUT_PULLUP);
// Workaround for https://github.com/arduino/ArduinoCore-samd/issues/587 // Workaround for https://github.com/arduino/ArduinoCore-samd/issues/587
#if (ARDUINO_API_VERSION >= 10200) #if (ARDUINO_API_VERSION >= 10200)
attachInterrupt(_buttonPin, _progButtonISRFuncPtr, (PinStatus)CHANGE); attachInterrupt(_buttonPin, _progButtonISRFuncPtr, (PinStatus)CHANGE);
@ -284,6 +278,7 @@ template <class P, class B> class KnxFacade : private SaveRestore
attachInterrupt(_buttonPin, _progButtonISRFuncPtr, CHANGE); attachInterrupt(_buttonPin, _progButtonISRFuncPtr, CHANGE);
#endif #endif
} }
}
enabled(true); enabled(true);
} }
@ -423,7 +418,7 @@ template <class P, class B> class KnxFacade : private SaveRestore
ActivityCallback _activityCallback = 0; ActivityCallback _activityCallback = 0;
#endif #endif
uint32_t _ledPinActiveOn = KNX_LED_ACTIVE_ON; uint32_t _ledPinActiveOn = KNX_LED_ACTIVE_ON;
uint32_t _ledPin = KNX_LED; int32_t _ledPin = KNX_LED;
int32_t _buttonPin = KNX_BUTTON; int32_t _buttonPin = KNX_BUTTON;
SaveCallback _saveCallback = 0; SaveCallback _saveCallback = 0;
RestoreCallback _restoreCallback = 0; RestoreCallback _restoreCallback = 0;
@ -460,17 +455,19 @@ template <class P, class B> class KnxFacade : private SaveRestore
void progLedOn() void progLedOn()
{ {
if (_progLedOnCallback == 0) if (_ledPin >= 0)
digitalWrite(ledPin(), _ledPinActiveOn); digitalWrite(_ledPin, _ledPinActiveOn);
else
if (_progLedOffCallback != 0)
_progLedOnCallback(); _progLedOnCallback();
} }
void progLedOff() void progLedOff()
{ {
if (_progLedOffCallback == 0) if (_ledPin >= 0)
digitalWrite(ledPin(), HIGH - _ledPinActiveOn); digitalWrite(_ledPin, HIGH - _ledPinActiveOn);
else
if (_progLedOffCallback != 0)
_progLedOffCallback(); _progLedOffCallback();
} }
}; };