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
// 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], defPin, j)) {
while (pinManager.isPinAllocated(defPin[j]) || !pinManager.isPinOk(defPin[j],true)) {
if (validPin) {
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
validPin = false;
}
if (defPin[j] < WLED_NUM_PINS) {
} else if (defPin[j] < WLED_NUM_PINS) {
defPin[j]++;
} else {
DEBUG_PRINTLN(F("No available pins left! Can't configure output."));
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;

View File

@ -567,19 +567,6 @@
#define WLED_MAX_NODES 150
#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
#if (LEDPIN == 2)
#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
let v = parseInt(i.value);
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;
let foundPin = d.um_p.indexOf(j);
let txt = (j === -1) ? "unused" : `${j}`;

View File

@ -32,8 +32,8 @@
GetV();
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
d.Sf.SDA.max = d.Sf.SCL.max = d.Sf.MOSI.max = d.Sf.SCLK.max = d.Sf.MISO.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;
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-1;
pinDD(); // convert INPUT to SELECT for pins
});
// error event
@ -80,7 +80,7 @@
for (var i=0; i<pins.length; i++) {
if (k==pinO[i]) continue;
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 {
switch (o.name) {
@ -94,7 +94,7 @@
for (var i=0; i<pins.length; i++) {
//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] || 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":
c = `value="${o}"`;
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";
} else {
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
let v = parseInt(i.value);
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;
let foundPin = pins.indexOf(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)
{
#ifdef READ_ONLY_PINS
const unsigned pins[] = {READ_ONLY_PINS};
const unsigned numPins = ((sizeof pins) / (sizeof pins[0]));
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;
}
#ifdef ARDUINO_ARCH_ESP32
if (gpio < WLED_NUM_PINS) return digitalPinCanOutput(gpio);
#endif
return false;
}

View File

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

View File

@ -204,17 +204,7 @@ void appendGPIOinfo() {
// add info about max. # of pins
oappend(SET_F("d.max_gpio="));
#if defined(CONFIG_IDF_TARGET_ESP32S2)
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
oappendi(WLED_NUM_PINS);
oappend(SET_F(";"));
}