From 159c370bf058ab0234da4d3444ce5e5b9cb922f3 Mon Sep 17 00:00:00 2001 From: Frank Date: Fri, 2 Sep 2022 23:54:58 +0200 Subject: [PATCH] ESP32-S3: different GPIO mapping - change pins 1/3 to RX and TX as defined by the framework - adjusted 'isPinOk" method --- wled00/json.cpp | 6 +++++- wled00/pin_manager.cpp | 33 +++++++++++++++++++++++++++++++++ wled00/wled.cpp | 6 ++++-- wled00/wled_serial.cpp | 10 +++++----- 4 files changed, 47 insertions(+), 8 deletions(-) diff --git a/wled00/json.cpp b/wled00/json.cpp index 52358a0c..dfe5ef78 100644 --- a/wled00/json.cpp +++ b/wled00/json.cpp @@ -696,7 +696,11 @@ void serializeInfo(JsonObject root) wifi_info[F("txPower")] = (int) WiFi.getTxPower(); wifi_info[F("sleep")] = (bool) WiFi.getSleep(); #endif - root[F("arch")] = "esp32"; + #if !defined(CONFIG_IDF_TARGET_ESP32C2) && !defined(CONFIG_IDF_TARGET_ESP32C3) && !defined(CONFIG_IDF_TARGET_ESP32S2) && !defined(CONFIG_IDF_TARGET_ESP32S3) + root[F("arch")] = "esp32"; + #else + root[F("arch")] = ESP.getChipModel(); + #endif root[F("core")] = ESP.getSdkVersion(); //root[F("maxalloc")] = ESP.getMaxAllocHeap(); #ifdef WLED_DEBUG diff --git a/wled00/pin_manager.cpp b/wled00/pin_manager.cpp index d1b6740e..7263f2ab 100644 --- a/wled00/pin_manager.cpp +++ b/wled00/pin_manager.cpp @@ -198,6 +198,38 @@ bool PinManagerClass::isPinAllocated(byte gpio, PinOwner tag) return bitRead(pinAlloc[by], bi); } +#ifdef CONFIG_IDF_TARGET_ESP32S3 +// ESP32-S3 GPIO layout + /* see https://docs.espressif.com/projects/esp-idf/en/latest/esp32s3/api-reference/peripherals/gpio.html + * The ESP32-S3 chip features 45 physical GPIO pins (GPIO0 ~ GPIO21 and GPIO26 ~ GPIO48). Each pin can be used as a general-purpose I/O + * Strapping pins: GPIO0, GPIO3, GPIO45 and GPIO46 are strapping pins. For more infomation, please refer to ESP32-S3 datasheet. + * USB-JTAG: GPIO 19 and 20 are used by USB-JTAG by default. In order to use them as GPIOs, USB-JTAG will be disabled by the drivers. + * Serial TX = GPIO43, RX = GPIO44; LED BUILTIN is usually GPIO39 + * SPI0/1: GPIO26-32 are usually used for SPI flash and PSRAM and not recommended for other uses. + * When using Octal Flash or Octal PSRAM or both, GPIO33~37 are connected to SPIIO4 ~ SPIIO7 and SPIDQS. Therefore, on boards embedded with ESP32-S3R8 / ESP32-S3R8V chip, GPIO33~37 are also not recommended for other uses. + * + * see https://docs.espressif.com/projects/esp-idf/en/v4.4.2/esp32s3/api-reference/peripherals/adc.html + * https://docs.espressif.com/projects/esp-idf/en/latest/esp32s3/api-reference/peripherals/adc_oneshot.html + * ADC1: GPIO1 - GPIO10 (channel 0..9) + * ADC2: GPIO11 - GPIO20 (channel 0..9) + * adc_power_acquire(): Please do not use the interrupt of GPIO36 and GPIO39 when using ADC or Wi-Fi and Bluetooth with sleep mode enabled. As a workaround, call adc_power_acquire() in the APP. + * Since the ADC2 module is also used by the Wi-Fi, reading operation of adc2_get_raw() may fail between esp_wifi_start() and esp_wifi_stop(). Use the return code to see whether the reading is successful. + */ +bool PinManagerClass::isPinOk(byte gpio, bool output) +{ + if (gpio < 19) return true; // 00 to 18 are for general use. Be careful about straping pins GPIO0 and GPIO3 - these may be pulled-up or pulled-down on your board. + if (gpio < 21) return false; // 19 + 20 = USB-JTAG. Not recommended for other uses. + if((gpio > 21) && (gpio < 26)) return false; // 22 to 25: not connected + + if (gpio < 33) return false; // 26 to 32: SPI flash and PSRAM. Not recommended for other uses. + //if (gpio <38) return false; // 33 to 37: not availeable if using _octal_ SPI Flash or _octal_ PSRAM + + if (gpio < 49) return true; // 38 to 48 are for general use. Be careful about straping pins GPIO45 and GPIO46 - these may be pull-up or pulled-down on your board. + + return false; +} + +#else // ESP32 and ESP8266 GPIO layout bool PinManagerClass::isPinOk(byte gpio, bool output) { if (gpio < 6) return true; @@ -212,6 +244,7 @@ bool PinManagerClass::isPinOk(byte gpio, bool output) return false; } +#endif PinOwner PinManagerClass::getPinOwner(byte gpio) { if (!isPinOk(gpio, false)) return PinOwner::None; diff --git a/wled00/wled.cpp b/wled00/wled.cpp index c9f590fb..c444cc7d 100644 --- a/wled00/wled.cpp +++ b/wled00/wled.cpp @@ -283,9 +283,11 @@ void WLED::setup() #if defined(ARDUINO_ARCH_ESP32) && defined(WLED_USE_PSRAM) if (psramFound()) { +#if !defined(CONFIG_IDF_TARGET_ESP32S3) // GPIO16/GPIO17 reserved for SPI RAM managed_pin_type pins[2] = { {16, true}, {17, true} }; pinManager.allocateMultiplePins(pins, 2, PinOwner::SPI_RAM); +#endif } #endif @@ -293,7 +295,7 @@ void WLED::setup() //DEBUG_PRINTLN(heapPreAlloc - ESP.getFreeHeap()); #ifdef WLED_DEBUG - pinManager.allocatePin(1, true, PinOwner::DebugOut); // GPIO1 reserved for debug output + pinManager.allocatePin(TX, true, PinOwner::DebugOut); // TX (GPIO1 on ESP32) reserved for debug output #endif #ifdef WLED_ENABLE_DMX //reserve GPIO2 as hardcoded DMX pin pinManager.allocatePin(2, true, PinOwner::DMX); @@ -348,7 +350,7 @@ void WLED::setup() #ifdef WLED_ENABLE_ADALIGHT //Serial RX (Adalight, Improv, Serial JSON) only possible if GPIO3 unused //Serial TX (Debug, Improv, Serial JSON) only possible if GPIO1 unused - if (!pinManager.isPinAllocated(3) && !pinManager.isPinAllocated(1)) { + if (!pinManager.isPinAllocated(RX) && !pinManager.isPinAllocated(TX)) { Serial.println(F("Ada")); } #endif diff --git a/wled00/wled_serial.cpp b/wled00/wled_serial.cpp index a73127e0..70dfacfc 100644 --- a/wled00/wled_serial.cpp +++ b/wled00/wled_serial.cpp @@ -26,7 +26,7 @@ void updateBaudRate(uint32_t rate){ if (rate100 == currentBaud || rate100 < 96) return; currentBaud = rate100; - if (!pinManager.isPinAllocated(1) || pinManager.getPinOwner(1) == PinOwner::DebugOut){ + if (!pinManager.isPinAllocated(TX) || pinManager.getPinOwner(TX) == PinOwner::DebugOut){ Serial.print(F("Baud is now ")); Serial.println(rate); } @@ -36,7 +36,7 @@ void updateBaudRate(uint32_t rate){ void handleSerial() { - if (pinManager.isPinAllocated(3)) return; + if (pinManager.isPinAllocated(RX)) return; #ifdef WLED_ENABLE_ADALIGHT static auto state = AdaState::Header_A; @@ -72,7 +72,7 @@ void handleSerial() } else if (next == 0xB7) {updateBaudRate(1500000); } else if (next == 'l') { //RGB(W) LED data return as JSON array. Slow, but easy to use on the other end. - if (!pinManager.isPinAllocated(1) || pinManager.getPinOwner(1) == PinOwner::DebugOut){ + if (!pinManager.isPinAllocated(TX) || pinManager.getPinOwner(TX) == PinOwner::DebugOut){ uint16_t used = strip.getLengthTotal(); Serial.write('['); for (uint16_t i=0; i()); //only send response if TX pin is unused for other purposes - if (verboseResponse && (!pinManager.isPinAllocated(1) || pinManager.getPinOwner(1) == PinOwner::DebugOut)) { + if (verboseResponse && (!pinManager.isPinAllocated(TX) || pinManager.getPinOwner(TX) == PinOwner::DebugOut)) { doc.clear(); JsonObject state = doc.createNestedObject("state"); serializeState(state);