diff --git a/wled00/pin_manager.cpp b/wled00/pin_manager.cpp index 0db06ba5..fa065635 100644 --- a/wled00/pin_manager.cpp +++ b/wled00/pin_manager.cpp @@ -68,6 +68,7 @@ String PinManagerClass::getOwnerText(PinOwner tag) { String PinManagerClass::getPinSpecialText(int gpio) { // special purpose PIN info if ((gpio == 0xFF) || (gpio < 0)) return(F("")); // explicitly allow -1 as a no-op +#ifdef USERMOD_AUDIOREACTIVE // audioreactive settings - unfortunately, these are hiddden inside usermod now :-( // if((gpio == audioPin) && (dmType == 0)) return(F("analog audio in")); // if((gpio == i2ssdPin) && (dmType > 0)) return(F("I2S SD")); @@ -86,16 +87,19 @@ String PinManagerClass::getPinSpecialText(int gpio) { // special purpose PIN in #ifdef MCLK_PIN if (gpio == MCLK_PIN) return(F("(default) I2S MCLK")); #endif +#endif // hardware special purpose PINS if (gpio == hardwareTX) return(F("Serial TX")); // Serial (debug monitor) TX pin (usually GPIO1) if (gpio == hardwareRX) return(F("Serial RX")); // Serial (debug monitor) RX pin (usually GPIO3) if ((gpio == i2c_sda) || ((gpio == HW_PIN_SDA) && (i2c_sda < 0))) return(F("(default) I2C SDA")); if ((gpio == i2c_scl) || ((gpio == HW_PIN_SCL) && (i2c_scl < 0))) return(F("(default) I2C SCL")); - if ((gpio == spi_sclk) || ((gpio == HW_PIN_CLOCKSPI) && (spi_sclk < 0))) return(F("(default) SPI CLK")); - if ((gpio == spi_mosi) || ((gpio == HW_PIN_DATASPI) && (spi_mosi < 0))) return(F("(default) SPI MOSI")); - if ((gpio == spi_miso) || ((gpio == HW_PIN_MISOSPI) && (spi_miso < 0))) return(F("(default) SPI MISO")); - if ((gpio == HW_PIN_CSSPI)) return(F("(default) SPI SS")); // no part of usermod default settings + if ((gpio == spi_sclk) || ((gpio == HW_PIN_CLOCKSPI) && (spi_sclk < 0))) return(F("(default) SPI SLK , aka SCK")); + if ((gpio == spi_mosi) || ((gpio == HW_PIN_DATASPI) && (spi_mosi < 0))) return(F("(default) SPI PICO, aka MOSI")); + if ((gpio == spi_miso) || ((gpio == HW_PIN_MISOSPI) && (spi_miso < 0))) return(F("(default) SPI POCI, aka MISO")); +#if defined(WLED_USE_SD_MMC) || defined(WLED_USE_SD_SPI) || defined(SD_ADAPTER) + if ((gpio == HW_PIN_CSSPI)) return(F("(default) SPI SS")); // no part of usermod default settings, currently only needed by SD_CARD usermod +#endif // MCU special PINS #ifdef ARDUINO_ARCH_ESP32 @@ -118,7 +122,6 @@ String PinManagerClass::getPinSpecialText(int gpio) { // special purpose PIN in #elif defined(CONFIG_IDF_TARGET_ESP32C3) // ESP32-C3 if (gpio > 17 && gpio < 20) return (F("USB (CDC) / JTAG")); - if (gpio == 46) return (F("pulled-down, input only")); //if (gpio == 2 || gpio == 8 || gpio == 9) return (F("(strapping pin)")); #else @@ -298,7 +301,7 @@ bool PinManagerClass::allocateMultiplePins(const managed_pin_type * mptArray, by DEBUG_PRINT(" as "); DEBUG_PRINT(mptArray[i].isOutput ? "output": "input"); // WLEDMM DEBUG_PRINTLN(F("")); #endif - if ((gpio < 50) && (gpio >= 0) && (tag != PinOwner::None)) { + if ((gpio < WLED_NUM_PINS) && (gpio >= 0) && (tag != PinOwner::None)) { ownerConflict[gpio] = tag; // WLEDMM record conflict } shouldFail = true; @@ -333,6 +336,9 @@ bool PinManagerClass::allocateMultiplePins(const managed_pin_type * mptArray, by // as this can greatly simplify configuration arrays continue; } + if (gpio >= WLED_NUM_PINS) + continue; // WLEDMM - invalid GPIO => avoid array bounds violation + byte by = gpio >> 3; byte bi = gpio - 8*by; bitWrite(pinAlloc[by], bi, true); @@ -352,11 +358,11 @@ bool PinManagerClass::allocateMultiplePins(const managed_pin_type * mptArray, by bool PinManagerClass::allocatePin(byte gpio, bool output, PinOwner tag) { // HW I2C & SPI pins have to be allocated using allocateMultiplePins variant since there is always SCL/SDA pair - if (!isPinOk(gpio, output) || tag==PinOwner::HW_I2C || tag==PinOwner::HW_SPI) { + if (!isPinOk(gpio, output) || (gpio >= WLED_NUM_PINS) || tag==PinOwner::HW_I2C || tag==PinOwner::HW_SPI) { // WLEDMM bugfix - avoid array bounds violation #ifdef WLED_DEBUG if (gpio < 255) { // 255 (-1) is the "not defined GPIO" if (!isPinOk(gpio, output)) { - if ((gpio < 50) && (gpio >= 0) && (tag != PinOwner::None)) { + if ((gpio < WLED_NUM_PINS) && (gpio >= 0) && (tag != PinOwner::None)) { ownerConflict[gpio] = tag; // WLEDMM record conflict } DEBUG_PRINT(F("PIN ALLOC: FAIL for owner ")); diff --git a/wled00/pin_manager.h b/wled00/pin_manager.h index 3184b42f..879ae47b 100644 --- a/wled00/pin_manager.h +++ b/wled00/pin_manager.h @@ -65,14 +65,16 @@ static_assert(0u == static_cast(PinOwner::None), "PinOwner::None must b class PinManagerClass { private: #ifdef ESP8266 + #define WLED_NUM_PINS 17 uint8_t pinAlloc[3] = {0x00, 0x00, 0x00}; //24bit, 1 bit per pin, we use first 17bits - PinOwner ownerTag[17] = { PinOwner::None }; - PinOwner ownerConflict[17] = { PinOwner::None }; // WLEDMM: record pin alloc conflicts + PinOwner ownerTag[WLED_NUM_PINS] = { PinOwner::None }; + PinOwner ownerConflict[WLED_NUM_PINS] = { PinOwner::None }; // WLEDMM: record pin alloc conflicts #else + #define WLED_NUM_PINS 50 uint8_t pinAlloc[7] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; //WLEDMM bugfix - 56bit, 1 bit per pin, we use 50 bits on -S3 uint8_t ledcAlloc[2] = {0x00, 0x00}; //16 LEDC channels - PinOwner ownerTag[50] = { PinOwner::None }; // WLEDMM bugfix - new MCU's have up to 50 GPIO - PinOwner ownerConflict[50] = { PinOwner::None }; // WLEDMM: record pin alloc conflicts + PinOwner ownerTag[WLED_NUM_PINS] = { PinOwner::None }; // WLEDMM bugfix - new MCU's have up to 50 GPIO + PinOwner ownerConflict[WLED_NUM_PINS] = { PinOwner::None }; // WLEDMM: record pin alloc conflicts #endif struct { uint8_t i2cAllocCount : 4; // allow multiple allocation of I2C bus pins but keep track of allocations diff --git a/wled00/wled.cpp b/wled00/wled.cpp index e756da57..9ebc4fd3 100644 --- a/wled00/wled.cpp +++ b/wled00/wled.cpp @@ -476,7 +476,7 @@ void WLED::setup() Serial.println(F("WLED initialization completed.")); Serial.println(F("\nGPIO\t| Assigned to\t\t| Info")); Serial.println(F("--------|-----------------------|------------")); - for(int pinNr = 0; pinNr < 50; pinNr++) { // 49 = highest PIN on ESP32-S3 + for(int pinNr = 0; pinNr < WLED_NUM_PINS; pinNr++) { // 49 = highest PIN on ESP32-S3 if(pinManager.isPinOk(pinNr, false)) { if ((!pinManager.isPinAllocated(pinNr)) && (pinManager.getPinSpecialText(pinNr).length() == 0)) continue; // comment out to include no-name,unused GPIO pins bool is_inOut = pinManager.isPinOk(pinNr, true);