mirror of
https://github.com/wled/WLED.git
synced 2025-04-24 06:47:18 +00:00
bug fix on pin already defined check
This commit is contained in:
parent
c5435ec1fa
commit
daf0bcfac3
@ -1248,15 +1248,16 @@ void WS2812FX::finalizeInit(void) {
|
||||
// if we need more pins than available all outputs have been configured
|
||||
if (pinsIndex + busPins > defNumPins) break;
|
||||
|
||||
for (unsigned j = 0; j < busPins && j < OUTPUT_MAX_PINS; j++) {
|
||||
defPin[j] = defDataPins[pinsIndex + j];
|
||||
// Assign all pins first so we can check for conflicts on this bus
|
||||
for (unsigned j = 0; j < busPins && j < OUTPUT_MAX_PINS; j++) defPin[j] = defDataPins[pinsIndex + j];
|
||||
|
||||
for (unsigned j = 0; j < busPins && j < OUTPUT_MAX_PINS; j++) {
|
||||
bool validPin = true;
|
||||
// When booting without config (1st boot) we need to make sure GPIOs defined for LED output don't clash with hardware
|
||||
// i.e. DEBUG (GPIO1), DMX (2), SPI RAM/FLASH (16&17 on ESP32-WROVER/PICO), read/only pins, etc.
|
||||
// Pin should not be already allocated, read/only or defined for current bus
|
||||
while (pinManager.isPinAllocated(defPin[j]) || pinManager.isReadOnlyPin(defPin[j]) ||
|
||||
pinManager.isPinDefined(defPin[j], defDataPins, pinsIndex + j + 1, pinsIndex + busPins)) {
|
||||
while (pinManager.isPinAllocated(defPin[j]) || pinManager.isReadOnlyPin(defPin[j]) || pinManager.isPinDefined(defPin[j], defPin, j)) {
|
||||
DEBUG_PRINTLN(F("Some of the provided pins cannot be used to configure this LED output."));
|
||||
if (validPin) {
|
||||
defPin[j] = 1; // start with GPIO1 and work upwards
|
||||
validPin = false;
|
||||
|
@ -281,9 +281,11 @@ bool PinManagerClass::isReadOnlyPin(byte gpio)
|
||||
return false;
|
||||
}
|
||||
|
||||
bool PinManagerClass::isPinDefined(byte gpio, const unsigned *pins, unsigned start, unsigned end) {
|
||||
for (unsigned i = start; i < end; i++) {
|
||||
if (pins[i] == gpio) return true;
|
||||
// Given an array of pins, check if a given pin is defined except at given index
|
||||
bool PinManagerClass::isPinDefined(const byte gpio, const uint8_t *pins, const unsigned index) {
|
||||
unsigned numPins = ((sizeof pins) / (sizeof pins[0]));
|
||||
for (unsigned i = 0; i < numPins; i++) {
|
||||
if ((pins[i] == gpio) && (i != index)) return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
@ -113,7 +113,7 @@ class PinManagerClass {
|
||||
bool isPinOk(byte gpio, bool output = true) const;
|
||||
|
||||
static bool isReadOnlyPin(byte gpio);
|
||||
static bool isPinDefined(byte gpio, const unsigned* pins, unsigned start = 0, unsigned end = WLED_NUM_PINS);
|
||||
static bool isPinDefined(const byte gpio, const uint8_t* pins, const unsigned index = 255);
|
||||
|
||||
PinOwner getPinOwner(byte gpio) const;
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user