introduce hardwareTX / hardwareRX

RX/TX is not defined on all boards.
Fall-back to previous behavior on "classic" ESP32 and 8266.
This commit is contained in:
Frank 2022-09-11 00:16:48 +02:00
parent ac10b3a5c7
commit 6771bd84c6
3 changed files with 45 additions and 8 deletions

View File

@ -274,6 +274,25 @@ void WLED::setup()
#ifdef ARDUINO_ARCH_ESP32
DEBUG_PRINT(F("esp32 "));
DEBUG_PRINTLN(ESP.getSdkVersion());
DEBUG_PRINT(F("CPU: ")); DEBUG_PRINT(ESP.getChipModel());
DEBUG_PRINT(F(" rev. ")); DEBUG_PRINT(ESP.getChipRevision());
DEBUG_PRINT(F(", ")); DEBUG_PRINT(ESP.getChipCores()); DEBUG_PRINT(F(" core(s)"));
DEBUG_PRINT(F(", ")); DEBUG_PRINT(ESP.getCpuFreqMHz()); DEBUG_PRINTLN(F("MHz."));
DEBUG_PRINT(F("FLASH: ")); DEBUG_PRINT((ESP.getFlashChipSize()/1024)/1024);
DEBUG_PRINT(F("MB, Mode ")); DEBUG_PRINT(ESP.getFlashChipMode());
#ifdef WLED_DEBUG
switch (ESP.getFlashChipMode()) {
// missing: Octal modes
case FM_QIO: DEBUG_PRINT(F(" (QIO)")); break;
case FM_QOUT: DEBUG_PRINT(F(" (QOUT)"));break;
case FM_DIO: DEBUG_PRINT(F(" (DIO)")); break;
case FM_DOUT: DEBUG_PRINT(F(" (DOUT)"));break;
default: break;
}
#endif
DEBUG_PRINT(F(", speed ")); DEBUG_PRINT(ESP.getFlashChipSpeed()/1000000);DEBUG_PRINTLN(F("MHz."));
#else
DEBUG_PRINT(F("esp8266 "));
DEBUG_PRINTLN(ESP.getCoreVersion());
@ -283,17 +302,25 @@ 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
DEBUG_PRINT(F("Total PSRAM: ")); DEBUG_PRINT(ESP.getPsramSize()/1024); DEBUG_PRINTLN("kB");
DEBUG_PRINT(F("Free PSRAM : ")); DEBUG_PRINT(ESP.getFreePsram()/1024); DEBUG_PRINTLN("kB");
} else
DEBUG_PRINTLN(F("No PSRAM found."));
#endif
#if defined(ARDUINO_ARCH_ESP32) && defined(BOARD_HAS_PSRAM) && !defined(WLED_USE_PSRAM)
DEBUG_PRINTLN(F("PSRAM not used."));
#endif
//DEBUG_PRINT(F("LEDs inited. heap usage ~"));
//DEBUG_PRINTLN(heapPreAlloc - ESP.getFreeHeap());
#ifdef WLED_DEBUG
pinManager.allocatePin(TX, true, PinOwner::DebugOut); // GPIO1 reserved for debug output
pinManager.allocatePin(hardwareTX, 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 +375,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(RX) && !pinManager.isPinAllocated(TX)) {
if (!pinManager.isPinAllocated(hardwareRX) && !pinManager.isPinAllocated(hardwareTX)) {
Serial.println(F("Ada"));
}
#endif

View File

@ -251,6 +251,16 @@ WLED_GLOBAL int8_t irPin _INIT(-1);
WLED_GLOBAL int8_t irPin _INIT(IRPIN);
#endif
#if defined(CONFIG_IDF_TARGET_ESP32S3) || defined(CONFIG_IDF_TARGET_ESP32C3) || defined(CONFIG_IDF_TARGET_ESP32S2) || (defined(RX) && defined(TX))
// use RX/TX as set by the framework - these boards do _not_ have RX=3 and TX=1
constexpr uint8_t hardwareRX = RX;
constexpr uint8_t hardwareTX = TX;
#else
// use defaults for RX/TX
constexpr uint8_t hardwareRX = 3;
constexpr uint8_t hardwareTX = 1;
#endif
//WLED_GLOBAL byte presetToApply _INIT(0);
WLED_GLOBAL char ntpServerName[33] _INIT("0.wled.pool.ntp.org"); // NTP server to use

View File

@ -26,7 +26,7 @@ void updateBaudRate(uint32_t rate){
if (rate100 == currentBaud || rate100 < 96) return;
currentBaud = rate100;
if (!pinManager.isPinAllocated(TX) || pinManager.getPinOwner(1) == PinOwner::DebugOut){
if (!pinManager.isPinAllocated(hardwareTX) || pinManager.getPinOwner(hardwareTX) == 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(RX)) return;
if (pinManager.isPinAllocated(hardwareRX)) 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(TX) || pinManager.getPinOwner(TX) == PinOwner::DebugOut){
if (!pinManager.isPinAllocated(hardwareTX) || pinManager.getPinOwner(hardwareTX) == PinOwner::DebugOut){
uint16_t used = strip.getLengthTotal();
Serial.write('[');
for (uint16_t i=0; i<used; i+=1) {
@ -82,7 +82,7 @@ void handleSerial()
Serial.println("]");
}
} else if (next == 'L') { //RGB LED data returned as bytes in tpm2 format. Faster, and slightly less easy to use on the other end.
if (!pinManager.isPinAllocated(TX) || pinManager.getPinOwner(TX) == PinOwner::DebugOut) {
if (!pinManager.isPinAllocated(hardwareTX) || pinManager.getPinOwner(hardwareTX) == PinOwner::DebugOut) {
Serial.write(0xC9); Serial.write(0xDA);
uint16_t used = strip.getLengthTotal();
uint16_t len = used*3;
@ -107,7 +107,7 @@ void handleSerial()
}
verboseResponse = deserializeState(doc.as<JsonObject>());
//only send response if TX pin is unused for other purposes
if (verboseResponse && (!pinManager.isPinAllocated(TX) || pinManager.getPinOwner(TX) == PinOwner::DebugOut)) {
if (verboseResponse && (!pinManager.isPinAllocated(hardwareTX) || pinManager.getPinOwner(hardwareTX) == PinOwner::DebugOut)) {
doc.clear();
JsonObject state = doc.createNestedObject("state");
serializeState(state);