Minor fixes

- rely on HAL for RO pins and max pins
- remove isPinDefined() and do clash check inline
- JS fix to use HAL max pins
This commit is contained in:
Blaz Kristan 2024-09-14 11:39:56 +02:00
parent 6a188033c6
commit e3d9417b84
7 changed files with 24 additions and 53 deletions

View File

@ -1256,18 +1256,28 @@ void WS2812FX::finalizeInit() {
// When booting without config (1st boot) we need to make sure GPIOs defined for LED output don't clash with hardware // 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. // 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 // 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], defPin, j)) { while (pinManager.isPinAllocated(defPin[j]) || !pinManager.isPinOk(defPin[j],true)) {
if (validPin) { if (validPin) {
DEBUG_PRINTLN(F("Some of the provided pins cannot be used to configure this LED output.")); DEBUG_PRINTLN(F("Some of the provided pins cannot be used to configure this LED output."));
defPin[j] = 1; // start with GPIO1 and work upwards defPin[j] = 1; // start with GPIO1 and work upwards
validPin = false; validPin = false;
} } else if (defPin[j] < WLED_NUM_PINS) {
if (defPin[j] < WLED_NUM_PINS) {
defPin[j]++; defPin[j]++;
} else { } else {
DEBUG_PRINTLN(F("No available pins left! Can't configure output.")); DEBUG_PRINTLN(F("No available pins left! Can't configure output."));
return; return;
} }
// is the newly assigned pin already defined? try next in line until there are no clashes
bool clash;
do {
clash = false;
for (const auto pin : defDataPins) {
if (pin == defPin[j]) {
defPin[j]++;
if (defPin[j] < WLED_NUM_PINS) clash = true;
}
}
} while (clash);
} }
} }
pinsIndex += busPins; pinsIndex += busPins;

View File

@ -567,19 +567,6 @@
#define WLED_MAX_NODES 150 #define WLED_MAX_NODES 150
#endif #endif
// List of read only pins. Cannot be used for LED outputs.
#if defined(CONFIG_IDF_TARGET_ESP32S2)
#define READ_ONLY_PINS 46
#elif defined(CONFIG_IDF_TARGET_ESP32S3)
// none for S3
#elif defined(CONFIG_IDF_TARGET_ESP32C3)
// none for C3
#elif defined(ESP32)
#define READ_ONLY_PINS 34,35,36,37,38,39
#else
// none for ESP8266
#endif
#ifdef WLED_ENABLE_DMX #ifdef WLED_ENABLE_DMX
#if (LEDPIN == 2) #if (LEDPIN == 2)
#undef LEDPIN #undef LEDPIN

View File

@ -671,7 +671,7 @@ Swap: <select id="xw${s}" name="XW${s}">
if (i.type === "number" && fields.includes(i.name)) { //select all pin select elements if (i.type === "number" && fields.includes(i.name)) { //select all pin select elements
let v = parseInt(i.value); let v = parseInt(i.value);
let sel = addDropdown(i.name,0); let sel = addDropdown(i.name,0);
for (var j = -1; j <= d.max_gpio; j++) { for (var j = -1; j < d.max_gpio; j++) {
if (d.rsvd.includes(j)) continue; if (d.rsvd.includes(j)) continue;
let foundPin = d.um_p.indexOf(j); let foundPin = d.um_p.indexOf(j);
let txt = (j === -1) ? "unused" : `${j}`; let txt = (j === -1) ? "unused" : `${j}`;

View File

@ -32,8 +32,8 @@
GetV(); GetV();
for (let r of d.rsvd) { pins.push(r); pinO.push("rsvd"); } // reserved pins for (let r of d.rsvd) { pins.push(r); pinO.push("rsvd"); } // reserved pins
if (d.um_p[0]==-1) d.um_p.shift(); // remove filler if (d.um_p[0]==-1) d.um_p.shift(); // remove filler
d.Sf.SDA.max = d.Sf.SCL.max = d.Sf.MOSI.max = d.Sf.SCLK.max = d.Sf.MISO.max = d.max_gpio; d.Sf.SDA.max = d.Sf.SCL.max = d.Sf.MOSI.max = d.Sf.SCLK.max = d.Sf.MISO.max = d.max_gpio-1;
//for (let i of d.getElementsByTagName("input")) if (i.type === "number" && i.name.replace("[]","").substr(-3) === "pin") i.max = d.max_gpio; //for (let i of d.getElementsByTagName("input")) if (i.type === "number" && i.name.replace("[]","").substr(-3) === "pin") i.max = d.max_gpio-1;
pinDD(); // convert INPUT to SELECT for pins pinDD(); // convert INPUT to SELECT for pins
}); });
// error event // error event
@ -80,7 +80,7 @@
for (var i=0; i<pins.length; i++) { for (var i=0; i<pins.length; i++) {
if (k==pinO[i]) continue; if (k==pinO[i]) continue;
if (o.value==pins[i] && pinO[i]==="if") { o.style.color="lime"; break; } if (o.value==pins[i] && pinO[i]==="if") { o.style.color="lime"; break; }
if (o.value==pins[i] || o.value<-1 || o.value>d.max_gpio) { o.style.color="red"; break; } else o.style.color=d.ro_gpio.some((e)=>e==parseInt(o.value,10))?"orange":"#fff"; if (o.value==pins[i] || o.value<-1 || o.value>d.max_gpio-1) { o.style.color="red"; break; } else o.style.color=d.ro_gpio.some((e)=>e==parseInt(o.value,10))?"orange":"#fff";
} }
} else { } else {
switch (o.name) { switch (o.name) {
@ -94,7 +94,7 @@
for (var i=0; i<pins.length; i++) { for (var i=0; i<pins.length; i++) {
//if (k==pinO[i]) continue; // same owner //if (k==pinO[i]) continue; // same owner
if (o.value==pins[i] && pinO[i]==="if") { o.style.color="tomato"; break; } if (o.value==pins[i] && pinO[i]==="if") { o.style.color="tomato"; break; }
if (o.value==pins[i] || o.value<-1 || o.value>d.max_gpio) { o.style.color="red"; break; } else o.style.color=d.ro_gpio.some((e)=>e==parseInt(o.value,10))?"orange":"#fff"; if (o.value==pins[i] || o.value<-1 || o.value>d.max_gpio-1) { o.style.color="red"; break; } else o.style.color=d.ro_gpio.some((e)=>e==parseInt(o.value,10))?"orange":"#fff";
} }
} }
*/ */
@ -148,7 +148,7 @@
case "number": case "number":
c = `value="${o}"`; c = `value="${o}"`;
if (f.substr(-3)==="pin") { if (f.substr(-3)==="pin") {
c += ` max="${d.max_gpio}" min="-1" class="s"`; c += ` max="${d.max_gpio-1}" min="-1" class="s"`;
t = "int"; t = "int";
} else { } else {
c += ' step="any" class="xxl"'; c += ' step="any" class="xxl"';
@ -170,7 +170,7 @@
if (i.type === "number" && (i.name.includes("pin") || ["SDA","SCL","MOSI","MISO","SCLK"].includes(i.name))) { //select all pin select elements if (i.type === "number" && (i.name.includes("pin") || ["SDA","SCL","MOSI","MISO","SCLK"].includes(i.name))) { //select all pin select elements
let v = parseInt(i.value); let v = parseInt(i.value);
let sel = addDD(i.name,0); let sel = addDD(i.name,0);
for (var j = -1; j <= d.max_gpio; j++) { for (var j = -1; j < d.max_gpio; j++) {
if (d.rsvd.includes(j)) continue; if (d.rsvd.includes(j)) continue;
let foundPin = pins.indexOf(j); let foundPin = pins.indexOf(j);
let txt = (j === -1) ? "unused" : `${j}`; let txt = (j === -1) ? "unused" : `${j}`;

View File

@ -269,24 +269,9 @@ bool PinManagerClass::isPinOk(byte gpio, bool output) const
bool PinManagerClass::isReadOnlyPin(byte gpio) bool PinManagerClass::isReadOnlyPin(byte gpio)
{ {
#ifdef READ_ONLY_PINS #ifdef ARDUINO_ARCH_ESP32
const unsigned pins[] = {READ_ONLY_PINS}; if (gpio < WLED_NUM_PINS) return digitalPinCanOutput(gpio);
const unsigned numPins = ((sizeof pins) / (sizeof pins[0])); #endif
if (gpio <= WLED_NUM_PINS) {
for (unsigned i = 0; i < numPins; i++) if (gpio == pins[i]) return true;
}
#endif
return false;
}
// 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; return false;
} }

View File

@ -113,7 +113,6 @@ class PinManagerClass {
bool isPinOk(byte gpio, bool output = true) const; bool isPinOk(byte gpio, bool output = true) const;
static bool isReadOnlyPin(byte gpio); static bool isReadOnlyPin(byte gpio);
static bool isPinDefined(const byte gpio, const uint8_t* pins, const unsigned index = 255);
PinOwner getPinOwner(byte gpio) const; PinOwner getPinOwner(byte gpio) const;

View File

@ -204,17 +204,7 @@ void appendGPIOinfo() {
// add info about max. # of pins // add info about max. # of pins
oappend(SET_F("d.max_gpio=")); oappend(SET_F("d.max_gpio="));
#if defined(CONFIG_IDF_TARGET_ESP32S2) oappendi(WLED_NUM_PINS);
oappendi(46);
#elif defined(CONFIG_IDF_TARGET_ESP32S3)
oappendi(48);
#elif defined(CONFIG_IDF_TARGET_ESP32C3)
oappendi(21);
#elif defined(ESP32)
oappendi(39);
#else
oappendi(16);
#endif
oappend(SET_F(";")); oappend(SET_F(";"));
} }