Skip to content

Commit

Permalink
Add support for WT32-ETH01 ethernet board and make ethernet support c…
Browse files Browse the repository at this point in the history
…onfigurable (Aircoookie#1583)

* Initial support for WT32-ETH01 board

* Initial ethernet config option, doesn't save yet

* Fixed saving/restoring ethernet option, works now!

* Fixed ESP32-POE pin config (thanks to tbnobody)

* Remove esp32_eth target (use poe), minor cleanup

* Fix BTNPIN for WT32-ETH01, as found by @k7bbr

* Various fixes to ethernet option

Co-authored-by: cschwinne <[email protected]>
  • Loading branch information
lonestriker and Aircoookie authored Jan 15, 2021
1 parent d6b366c commit 82e7328
Show file tree
Hide file tree
Showing 10 changed files with 96 additions and 7 deletions.
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ board = esp32-poe
platform = [email protected]
upload_speed = 921600
build_unflags = ${common.build_unflags}
build_flags = ${common.build_flags_esp32} -D RLYPIN=-1 -D WLED_USE_ETHERNET
build_flags = ${common.build_flags_esp32} -D RLYPIN=-1 -D WLED_USE_ETHERNET -D BTNPIN=-1
lib_ignore =
ESPAsyncTCP
ESPAsyncUDP
Expand Down
10 changes: 10 additions & 0 deletions wled00/cfg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,11 @@ void deserializeConfig() {
if (apHide > 1) apHide = 1;

CJSON(apBehavior, ap[F("behav")]);

#ifdef WLED_USE_ETHERNET
JsonObject ethernet = doc[F("eth")];
CJSON(ethernetType, ethernet[F("type")]);
#endif

/*
JsonArray ap_ip = ap[F("ip")];
Expand Down Expand Up @@ -383,6 +388,11 @@ void serializeConfig() {
wifi[F("sleep")] = !noWifiSleep;
wifi[F("phy")] = 1;

#ifdef WLED_USE_ETHERNET
JsonObject ethernet = doc.createNestedObject("eth");
ethernet[F("type")] = ethernetType;
#endif

JsonObject hw = doc.createNestedObject("hw");

JsonObject hw_led = hw.createNestedObject("led");
Expand Down
4 changes: 4 additions & 0 deletions wled00/const.h
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,10 @@
#define BTN_TYPE_SWITCH 4 //not implemented
#define BTN_TYPE_SWITCH_ACT_HIGH 5 //not implemented

//Ethernet board types
#define WLED_ETH_NONE 0
#define WLED_ETH_WT32_ETH01 1
#define WLED_ETH_ESP32_POE 2

//Hue error codes
#define HUE_ERROR_INACTIVE 0
Expand Down
8 changes: 7 additions & 1 deletion wled00/data/settings_wifi.htm
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,13 @@ <h3>Configure Access Point</h3>
<h3>Experimental</h3>
Disable WiFi sleep: <input type="checkbox" name="WS"><br>
<i>Can help with connectivity issues.<br>
Do not enable if WiFi is working correctly, increases power consumption.</i>
Do not enable if WiFi is working correctly, increases power consumption.</i>
<div id="ethd">
<h3>Ethernet Type</h3>
<select name="ETH">
<option value="0">None</option>
<option value="1">WT32-ETH01</option>
<option value="2">ESP32-POE</option></select><br><br></div>
<hr>
<button type="button" onclick="B()">Back</button><button type="submit">Save & Connect</button>
</form>
Expand Down
8 changes: 5 additions & 3 deletions wled00/html_settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,11 @@ value="2">Always</option><option value="3">Never (not recommended)</option>
</select><br>AP IP: <span class="sip">Not active</span><br><h3>Experimental</h3>
Disable WiFi sleep: <input type="checkbox" name="WS"><br><i>
Can help with connectivity issues.<br>
Do not enable if WiFi is working correctly, increases power consumption.</i><hr>
<button type="button" onclick="B()">Back</button><button type="submit">
Save & Connect</button></form></body></html>)=====";
Do not enable if WiFi is working correctly, increases power consumption.</i><div
id="ethd"><h3>Ethernet Type</h3><select name="ETH"><option value="0">None
</option><option value="1">WT32-ETH01</option><option value="2">ESP32-POE
</option></select><br><br></div><hr><button type="button" onclick="B()">Back
</button><button type="submit">Save & Connect</button></form></body></html>)=====";
// Autogenerated from wled00/data/settings_leds.htm, do not edit!!
Expand Down
4 changes: 4 additions & 0 deletions wled00/set.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@ void handleSettingsSet(AsyncWebServerRequest *request, byte subPage)

noWifiSleep = request->hasArg(F("WS"));

#ifdef WLED_USE_ETHERNET
ethernetType = request->arg(F("ETH")).toInt();
#endif

char k[3]; k[2] = 0;
for (int i = 0; i<4; i++)
{
Expand Down
56 changes: 55 additions & 1 deletion wled00/wled.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,49 @@ WLED::WLED()
{
}

#ifdef WLED_USE_ETHERNET
// settings for various ethernet boards
typedef struct EthernetSettings {
uint8_t eth_address;
int eth_power;
int eth_mdc;
int eth_mdio;
eth_phy_type_t eth_type;
eth_clock_mode_t eth_clk_mode;
} ethernet_settings;

ethernet_settings ethernetBoards[] = {
// None
{
},

// WT32-EHT01
// Please note, from my testing only these pins work for LED outputs:
// IO2, IO4, IO12, IO14, IO15
// These pins do not appear to work from my testing:
// IO35, IO36, IO39
{
1, // eth_address,
16, // eth_power,
23, // eth_mdc,
18, // eth_mdio,
ETH_PHY_LAN8720, // eth_type,
ETH_CLOCK_GPIO0_IN // eth_clk_mode
},

// ESP32-POE
{
0, // eth_address,
12, // eth_power,
23, // eth_mdc,
18, // eth_mdio,
ETH_PHY_LAN8720, // eth_type,
ETH_CLOCK_GPIO17_OUT // eth_clk_mode
}
};

#endif

// turns all LEDs off and restarts ESP
void WLED::reset()
{
Expand Down Expand Up @@ -393,7 +436,18 @@ void WLED::initConnection()
#endif

#if defined(ARDUINO_ARCH_ESP32) && defined(WLED_USE_ETHERNET)
ETH.begin();
// Only initialize ethernet board if not NONE
if (ethernetType != WLED_ETH_NONE) {
ethernet_settings es = ethernetBoards[ethernetType];
ETH.begin(
(uint8_t) es.eth_address,
(int) es.eth_power,
(int) es.eth_mdc,
(int) es.eth_mdio,
(eth_phy_type_t) es.eth_type,
(eth_clock_mode_t) es.eth_clk_mode
);
}
#endif

WiFi.disconnect(true); // close old connections
Expand Down
3 changes: 3 additions & 0 deletions wled00/wled.h
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,9 @@ WLED_GLOBAL IPAddress staticIP _INIT_N((( 0, 0, 0, 0))); // static IP
WLED_GLOBAL IPAddress staticGateway _INIT_N((( 0, 0, 0, 0))); // gateway (router) IP
WLED_GLOBAL IPAddress staticSubnet _INIT_N(((255, 255, 255, 0))); // most common subnet in home networks
WLED_GLOBAL bool noWifiSleep _INIT(false); // disabling modem sleep modes will increase heat output and power usage, but may help with connection issues
#ifdef WLED_USE_ETHERNET
WLED_GLOBAL int ethernetType _INIT(WLED_ETH_ESP32_POE); // ethernet board type
#endif

// LED CONFIG
WLED_GLOBAL uint16_t ledCount _INIT(30); // overcurrent prevented by ABL
Expand Down
6 changes: 6 additions & 0 deletions wled00/xml.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,12 @@ void getSettingsJS(byte subPage, char* dest)
sappend('v',SET_F("AC"),apChannel);
sappend('c',SET_F("WS"),noWifiSleep);

#ifdef WLED_USE_ETHERNET
sappend('i',SET_F("ETH"),ethernetType);
#else
//hide ethernet setting if not compiled in
oappend(SET_F("document.getElementById('ethd').style.display='none';"));
#endif

if (Network.isConnected()) //is connected
{
Expand Down

0 comments on commit 82e7328

Please sign in to comment.