From 849bdc52f64ef0bd2be4cbf222a429b694055a61 Mon Sep 17 00:00:00 2001 From: Blaz Kristan Date: Fri, 27 Aug 2021 19:48:55 +0200 Subject: [PATCH] Ethernet modifications. Added fixed Ethernet pins to cfg.json and settings page --- wled00/cfg.cpp | 9 +++++---- wled00/wled.cpp | 42 +++++++++++++++++++++++++++--------------- wled00/wled.h | 2 +- wled00/wled_ethernet.h | 18 +++++------------- wled00/xml.cpp | 22 +++++++--------------- 5 files changed, 45 insertions(+), 48 deletions(-) diff --git a/wled00/cfg.cpp b/wled00/cfg.cpp index d62b9e1f..a5fba1e5 100644 --- a/wled00/cfg.cpp +++ b/wled00/cfg.cpp @@ -86,7 +86,6 @@ bool deserializeConfig(JsonObject doc, bool fromFS) { CJSON(strip.ablMilliampsMax, hw_led[F("maxpwr")]); CJSON(strip.milliampsPerLed, hw_led[F("ledma")]); - //CJSON(strip.reverseMode, hw_led["rev"]); CJSON(strip.rgbwMode, hw_led[F("rgbwm")]); JsonArray ins = hw_led["ins"]; @@ -137,6 +136,7 @@ bool deserializeConfig(JsonObject doc, bool fromFS) { // finalization done in beginStrip() } if (lC > ledCount) ledCount = lC; // fix incorrect total length (honour analog setup) + if (hw_led["rev"]) busses.getBus(0)->reversed = true; //set 0.11 global reversed setting for first bus // read multiple button configuration JsonObject btn_obj = hw["btn"]; @@ -519,9 +519,10 @@ void serializeConfig() { 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); + for (uint8_t p=0; p=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: diff --git a/wled00/wled.cpp b/wled00/wled.cpp index f8fd6482..f24b7894 100644 --- a/wled00/wled.cpp +++ b/wled00/wled.cpp @@ -8,16 +8,20 @@ #include "soc/rtc_cntl_reg.h" #endif -/* - * Main WLED class implementation. Mostly initialization and connection logic - */ - -WLED::WLED() -{ -} - #ifdef WLED_USE_ETHERNET -ethernet_settings ethernetBoards[] = { +// The following six pins are neither configurable nor +// can they be re-assigned through IOMUX / GPIO matrix. +// See https://docs.espressif.com/projects/esp-idf/en/latest/esp32/hw-reference/esp32/get-started-ethernet-kit-v1.1.html#ip101gri-phy-interface +const managed_pin_type esp32_nonconfigurable_ethernet_pins[WLED_ETH_RSVD_PINS_COUNT] = { + { 21, true }, // RMII EMAC TX EN == When high, clocks the data on TXD0 and TXD1 to transmitter + { 19, true }, // RMII EMAC TXD0 == First bit of transmitted data + { 22, true }, // RMII EMAC TXD1 == Second bit of transmitted data + { 25, false }, // RMII EMAC RXD0 == First bit of received data + { 26, false }, // RMII EMAC RXD1 == Second bit of received data + { 27, true }, // RMII EMAC CRS_DV == Carrier Sense and RX Data Valid +}; + +const ethernet_settings ethernetBoards[] = { // None { }, @@ -78,16 +82,24 @@ ethernet_settings ethernetBoards[] = { // ESP3DEUXQuattro { - 1, // eth_address, - -1, // eth_power, - 23, // eth_mdc, - 18, // eth_mdio, - ETH_PHY_LAN8720, // eth_type, - ETH_CLOCK_GPIO17_OUT // eth_clk_mode + 1, // eth_address, + -1, // eth_power, + 23, // eth_mdc, + 18, // eth_mdio, + ETH_PHY_LAN8720, // eth_type, + ETH_CLOCK_GPIO17_OUT // eth_clk_mode } }; #endif +/* + * Main WLED class implementation. Mostly initialization and connection logic + */ + +WLED::WLED() +{ +} + // turns all LEDs off and restarts ESP void WLED::reset() { diff --git a/wled00/wled.h b/wled00/wled.h index 91705289..c127c4d5 100644 --- a/wled00/wled.h +++ b/wled00/wled.h @@ -8,7 +8,7 @@ */ // version code in format yymmddb (b = daily build) -#define VERSION 2108261 +#define VERSION 2108271 //uncomment this if you have a "my_config.h" file you'd like to use //#define WLED_USE_MY_CONFIG diff --git a/wled00/wled_ethernet.h b/wled00/wled_ethernet.h index 52bdb2a1..6b8f0ba5 100644 --- a/wled00/wled_ethernet.h +++ b/wled00/wled_ethernet.h @@ -1,20 +1,9 @@ #ifndef WLED_ETHERNET_H #define WLED_ETHERNET_H -#ifdef WLED_USE_ETHERNET #include "pin_manager.h" -// The following six pins are neither configurable nor -// can they be re-assigned through IOMUX / GPIO matrix. -// See https://docs.espressif.com/projects/esp-idf/en/latest/esp32/hw-reference/esp32/get-started-ethernet-kit-v1.1.html#ip101gri-phy-interface -const managed_pin_type esp32_nonconfigurable_ethernet_pins[6] = { - { 21, true }, // RMII EMAC TX EN == When high, clocks the data on TXD0 and TXD1 to transmitter - { 19, true }, // RMII EMAC TXD0 == First bit of transmitted data - { 22, true }, // RMII EMAC TXD1 == Second bit of transmitted data - { 25, false }, // RMII EMAC RXD0 == First bit of received data - { 26, false }, // RMII EMAC RXD1 == Second bit of received data - { 27, true }, // RMII EMAC CRS_DV == Carrier Sense and RX Data Valid -}; +#ifdef WLED_USE_ETHERNET // For ESP32, the remaining five pins are at least somewhat configurable. // eth_address is in range [0..31], indicates which PHY (MAC?) address should be allocated to the interface @@ -37,7 +26,10 @@ typedef struct EthernetSettings { eth_clock_mode_t eth_clk_mode; } ethernet_settings; -extern ethernet_settings ethernetBoards[]; +extern const ethernet_settings ethernetBoards[]; + +#define WLED_ETH_RSVD_PINS_COUNT 6 +extern const managed_pin_type esp32_nonconfigurable_ethernet_pins[WLED_ETH_RSVD_PINS_COUNT]; #endif #endif \ No newline at end of file diff --git a/wled00/xml.cpp b/wled00/xml.cpp index a0ab50fa..93dc025a 100644 --- a/wled00/xml.cpp +++ b/wled00/xml.cpp @@ -266,9 +266,8 @@ void getSettingsJS(byte subPage, char* dest) DynamicJsonDocument doc(JSON_BUFFER_SIZE/2); JsonObject mods = doc.createNestedObject(F("um")); usermods.addToConfig(mods); - oappend(SET_F("d.um_p=[")); + oappend(SET_F("d.um_p=[6,7,8,9,10,11")); if (!mods.isNull()) { - uint8_t i=0; for (JsonPair kv : mods) { if (!kv.value().isNull()) { // element is an JsonObject @@ -277,22 +276,14 @@ void getSettingsJS(byte subPage, char* dest) if (obj["pin"].is()) { JsonArray pins = obj["pin"].as(); for (JsonVariant pv : pins) { - if (pv.as() > -1) { - if (i++) oappend(SET_F(",")); - oappendi(pv.as()); - } + if (pv.as() > -1) { oappend(","); oappendi(pv.as()); } } } else { - if (obj["pin"].as() > -1) { - if (i++) oappend(SET_F(",")); - oappendi(obj["pin"].as()); - } + if (obj["pin"].as() > -1) { oappend(","); oappendi(obj["pin"].as()); } } } } } - if (i) oappend(SET_F(",")); - oappend(SET_F("6,7,8,9,10,11")); // flash memory pins #ifdef WLED_ENABLE_DMX oappend(SET_F(",2")); // DMX hardcoded pin #endif @@ -324,9 +315,10 @@ void getSettingsJS(byte subPage, char* dest) #endif #ifdef WLED_USE_ETHERNET if (ethernetType != WLED_ETH_NONE && ethernetType < WLED_NUM_ETH_TYPES) { - 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)); } + for (uint8_t p=0; p=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: