diff --git a/wled00/cfg.cpp b/wled00/cfg.cpp index 51d0a1eb..c35589a3 100644 --- a/wled00/cfg.cpp +++ b/wled00/cfg.cpp @@ -203,14 +203,28 @@ bool deserializeConfig(JsonObject doc, bool fromFS) { int8_t pin = btn["pin"][0] | -1; if (pin > -1 && pinManager.allocatePin(pin, false, PinOwner::Button)) { btnPin[s] = pin; - if (disablePullUp) { - pinMode(btnPin[s], INPUT); - } else { - #ifdef ESP32 - pinMode(btnPin[s], buttonType[s]==BTN_TYPE_PUSH_ACT_HIGH ? INPUT_PULLDOWN : INPUT_PULLUP); - #else - pinMode(btnPin[s], INPUT_PULLUP); - #endif + #ifdef ARDUINO_ARCH_ESP32 + // ESP32 only: check that analog button pin is a valid ADC gpio + if (((buttonType[s] == BTN_TYPE_ANALOG) || (buttonType[s] == BTN_TYPE_ANALOG_INVERTED)) && (digitalPinToAnalogChannel(btnPin[s]) < 0)) + { + // not an ADC analog pin + DEBUG_PRINTF("PIN ALLOC error: GPIO%d for analog button #%d is not an analog pin!\n", btnPin[s], s); + btnPin[s] = -1; + pinManager.deallocatePin(pin,PinOwner::Button); + } + else + #endif + { + if (disablePullUp) { + pinMode(btnPin[s], INPUT); + } else { + #ifdef ESP32 + // first check that analog button is valid + pinMode(btnPin[s], buttonType[s]==BTN_TYPE_PUSH_ACT_HIGH ? INPUT_PULLDOWN : INPUT_PULLUP); + #else + pinMode(btnPin[s], INPUT_PULLUP); + #endif + } } } else { btnPin[s] = -1; diff --git a/wled00/set.cpp b/wled00/set.cpp index b6cf7759..30a77fd4 100644 --- a/wled00/set.cpp +++ b/wled00/set.cpp @@ -169,14 +169,27 @@ void handleSettingsSet(AsyncWebServerRequest *request, byte subPage) if (pinManager.allocatePin(hw_btn_pin,false,PinOwner::Button)) { btnPin[i] = hw_btn_pin; buttonType[i] = request->arg(be).toInt(); - if (disablePullUp) { - pinMode(btnPin[i], INPUT); - } else { - #ifdef ESP32 - pinMode(btnPin[i], buttonType[i]==BTN_TYPE_PUSH_ACT_HIGH ? INPUT_PULLDOWN : INPUT_PULLUP); - #else - pinMode(btnPin[i], INPUT_PULLUP); - #endif + #ifdef ARDUINO_ARCH_ESP32 + // ESP32 only: check that analog button pin is a valid ADC gpio + if (((buttonType[i] == BTN_TYPE_ANALOG) || (buttonType[i] == BTN_TYPE_ANALOG_INVERTED)) && (digitalPinToAnalogChannel(btnPin[i]) < 0)) + { + // not an ADC analog pin + DEBUG_PRINTF("PIN ALLOC error: GPIO%d for analog button #%d is not an analog pin!\n", btnPin[i], i); + btnPin[i] = -1; + pinManager.deallocatePin(hw_btn_pin,PinOwner::Button); + } + else + #endif + { + if (disablePullUp) { + pinMode(btnPin[i], INPUT); + } else { + #ifdef ESP32 + pinMode(btnPin[i], buttonType[i]==BTN_TYPE_PUSH_ACT_HIGH ? INPUT_PULLDOWN : INPUT_PULLUP); + #else + pinMode(btnPin[i], INPUT_PULLUP); + #endif + } } } else { btnPin[i] = -1; diff --git a/wled00/wled.cpp b/wled00/wled.cpp index 41ee7c4f..87df1be0 100644 --- a/wled00/wled.cpp +++ b/wled00/wled.cpp @@ -272,6 +272,9 @@ void WLED::setup() #if defined(WLED_DEBUG) && defined(ARDUINO_ARCH_ESP32) && (defined(CONFIG_IDF_TARGET_ESP32S2) || defined(CONFIG_IDF_TARGET_ESP32C3) || ARDUINO_USB_CDC_ON_BOOT) delay(2500); // allow CDC USB serial to initialise #endif + #if !defined(WLED_DEBUG) && defined(ARDUINO_ARCH_ESP32) && !defined(WLED_DEBUG_HOST) && ARDUINO_USB_CDC_ON_BOOT + Serial.setDebugOutput(false); // switch off kernel messages when using USBCDC + #endif DEBUG_PRINTLN(); DEBUG_PRINT(F("---WLED ")); DEBUG_PRINT(versionString);