From d28158bc748df307c91d9db3317bb1eb3a00381a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bla=C5=BE=20Kristan?= Date: Wed, 7 Jul 2021 08:12:03 +0200 Subject: [PATCH] ESP32 S2 fix for RMT channels. Ethernet pins stored in cfg.json for usermod checks. --- wled00/bus_wrapper.h | 7 ++++--- wled00/cfg.cpp | 37 +++++++++++++++++++++++++++++++++++++ wled00/wled.h | 2 +- wled00/xml.cpp | 9 ++++----- 4 files changed, 46 insertions(+), 9 deletions(-) diff --git a/wled00/bus_wrapper.h b/wled00/bus_wrapper.h index 9494d030b..224de1806 100644 --- a/wled00/bus_wrapper.h +++ b/wled00/bus_wrapper.h @@ -665,10 +665,11 @@ class PolyBus { uint8_t offset = 0; //0 = RMT (num 0-7) 8 = I2S0 9 = I2S1 #ifndef CONFIG_IDF_TARGET_ESP32S2 if (num > 9) return I_NONE; - #else - if (num > 8) return I_NONE; - #endif if (num > 7) offset = num -7; + #else + if (num > 5) return I_NONE; + if (num > 4) offset = num -4; + #endif switch (busType) { case TYPE_WS2812_RGB: case TYPE_WS2812_WWA: diff --git a/wled00/cfg.cpp b/wled00/cfg.cpp index 6ffaceefc..36f7169cc 100644 --- a/wled00/cfg.cpp +++ b/wled00/cfg.cpp @@ -1,4 +1,5 @@ #include "wled.h" +#include "wled_ethernet.h" /* * Serializes and parses the cfg.json and wsec.json settings files, stored in internal FS. @@ -56,6 +57,24 @@ bool deserializeConfig(JsonObject doc, bool fromFS) { #ifdef WLED_USE_ETHERNET JsonObject ethernet = doc[F("eth")]; CJSON(ethernetType, ethernet["type"]); + // allocate ethernet pins + if (ethernetType != WLED_ETH_NONE && ethernetType < WLED_NUM_ETH_TYPES) { + if (ethernetBoards[ethernetType].eth_power>=0) pinManager.allocatePin(ethernetBoards[ethernetType].eth_power); + if (ethernetBoards[ethernetType].eth_mdc>=0) pinManager.allocatePin(ethernetBoards[ethernetType].eth_mdc); + if (ethernetBoards[ethernetType].eth_mdio>=0) pinManager.allocatePin(ethernetBoards[ethernetType].eth_mdio); + switch (ethernetBoards[ethernetType].eth_clk_mode) { + case ETH_CLOCK_GPIO0_IN: + case ETH_CLOCK_GPIO0_OUT: + pinManager.allocatePin(0); + break; + case ETH_CLOCK_GPIO16_OUT: + pinManager.allocatePin(16); + break; + case ETH_CLOCK_GPIO17_OUT: + pinManager.allocatePin(17); + break; + } + } #endif /* @@ -484,6 +503,24 @@ void serializeConfig() { #ifdef WLED_USE_ETHERNET JsonObject ethernet = doc.createNestedObject("eth"); ethernet["type"] = ethernetType; + if (ethernetType != WLED_ETH_NONE && ethernetType < WLED_NUM_ETH_TYPES) { + JsonArray pins = ethernet.createNestedArray("pin"); + if (ethernetBoards[ethernetType].eth_power>=0) pins.add(ethernetBoards[ethernetType].eth_power); + if (ethernetBoards[ethernetType].eth_mdc>=0) pins.add(ethernetBoards[ethernetType].eth_mdc); + if (ethernetBoards[ethernetType].eth_mdio>=0) pins.add(ethernetBoards[ethernetType].eth_mdio); + switch (ethernetBoards[ethernetType].eth_clk_mode) { + case ETH_CLOCK_GPIO0_IN: + case ETH_CLOCK_GPIO0_OUT: + pins.add(0); + break; + case ETH_CLOCK_GPIO16_OUT: + pins.add(16); + break; + case ETH_CLOCK_GPIO17_OUT: + pins.add(17); + break; + } + } #endif JsonObject hw = doc.createNestedObject("hw"); diff --git a/wled00/wled.h b/wled00/wled.h index 25f17a6d2..669123411 100644 --- a/wled00/wled.h +++ b/wled00/wled.h @@ -8,7 +8,7 @@ */ // version code in format yymmddb (b = daily build) -#define VERSION 2107061 +#define VERSION 2107071 //uncomment this if you have a "my_config.h" file you'd like to use //#define WLED_USE_MY_CONFIG diff --git a/wled00/xml.cpp b/wled00/xml.cpp index 21bf7fcd8..133109491 100644 --- a/wled00/xml.cpp +++ b/wled00/xml.cpp @@ -324,11 +324,10 @@ void getSettingsJS(byte subPage, char* dest) #endif #ifdef WLED_USE_ETHERNET if (ethernetType != WLED_ETH_NONE && ethernetType < WLED_NUM_ETH_TYPES) { - ethernet_settings es = ethernetBoards[ethernetType]; - if (es.eth_power>0) { oappend(","); oappend(itoa(es.eth_power,nS,10)); } - if (es.eth_mdc>0) { oappend(","); oappend(itoa(es.eth_mdc,nS,10)); } - if (es.eth_mdio>0) { oappend(","); oappend(itoa(es.eth_mdio,nS,10)); } - switch (es.eth_clk_mode) { + if (ethernetBoards[ethernetType].eth_power>=0) { oappend(","); oappend(itoa(ethernetBoards[ethernetType].eth_power,nS,10)); } + if (ethernetBoards[ethernetType].eth_mdc>=0) { oappend(","); oappend(itoa(ethernetBoards[ethernetType].eth_mdc,nS,10)); } + if (ethernetBoards[ethernetType].eth_mdio>=0) { oappend(","); oappend(itoa(ethernetBoards[ethernetType].eth_mdio,nS,10)); } + switch (ethernetBoards[ethernetType].eth_clk_mode) { case ETH_CLOCK_GPIO0_IN: case ETH_CLOCK_GPIO0_OUT: oappend(SET_F(",0"));