Skip to content

Commit 82e7328

Browse files
Add support for WT32-ETH01 ethernet board and make ethernet support configurable (wled#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]>
1 parent d6b366c commit 82e7328

File tree

10 files changed

+96
-7
lines changed

10 files changed

+96
-7
lines changed

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

platformio.ini

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,7 @@ board = esp32-poe
284284
285285
upload_speed = 921600
286286
build_unflags = ${common.build_unflags}
287-
build_flags = ${common.build_flags_esp32} -D RLYPIN=-1 -D WLED_USE_ETHERNET
287+
build_flags = ${common.build_flags_esp32} -D RLYPIN=-1 -D WLED_USE_ETHERNET -D BTNPIN=-1
288288
lib_ignore =
289289
ESPAsyncTCP
290290
ESPAsyncUDP

wled00/cfg.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,11 @@ void deserializeConfig() {
7171
if (apHide > 1) apHide = 1;
7272

7373
CJSON(apBehavior, ap[F("behav")]);
74+
75+
#ifdef WLED_USE_ETHERNET
76+
JsonObject ethernet = doc[F("eth")];
77+
CJSON(ethernetType, ethernet[F("type")]);
78+
#endif
7479

7580
/*
7681
JsonArray ap_ip = ap[F("ip")];
@@ -383,6 +388,11 @@ void serializeConfig() {
383388
wifi[F("sleep")] = !noWifiSleep;
384389
wifi[F("phy")] = 1;
385390

391+
#ifdef WLED_USE_ETHERNET
392+
JsonObject ethernet = doc.createNestedObject("eth");
393+
ethernet[F("type")] = ethernetType;
394+
#endif
395+
386396
JsonObject hw = doc.createNestedObject("hw");
387397

388398
JsonObject hw_led = hw.createNestedObject("led");

wled00/const.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,10 @@
122122
#define BTN_TYPE_SWITCH 4 //not implemented
123123
#define BTN_TYPE_SWITCH_ACT_HIGH 5 //not implemented
124124

125+
//Ethernet board types
126+
#define WLED_ETH_NONE 0
127+
#define WLED_ETH_WT32_ETH01 1
128+
#define WLED_ETH_ESP32_POE 2
125129

126130
//Hue error codes
127131
#define HUE_ERROR_INACTIVE 0

wled00/data/settings_wifi.htm

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,13 @@ <h3>Configure Access Point</h3>
6363
<h3>Experimental</h3>
6464
Disable WiFi sleep: <input type="checkbox" name="WS"><br>
6565
<i>Can help with connectivity issues.<br>
66-
Do not enable if WiFi is working correctly, increases power consumption.</i>
66+
Do not enable if WiFi is working correctly, increases power consumption.</i>
67+
<div id="ethd">
68+
<h3>Ethernet Type</h3>
69+
<select name="ETH">
70+
<option value="0">None</option>
71+
<option value="1">WT32-ETH01</option>
72+
<option value="2">ESP32-POE</option></select><br><br></div>
6773
<hr>
6874
<button type="button" onclick="B()">Back</button><button type="submit">Save & Connect</button>
6975
</form>

wled00/html_settings.h

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,11 @@ value="2">Always</option><option value="3">Never (not recommended)</option>
6161
</select><br>AP IP: <span class="sip">Not active</span><br><h3>Experimental</h3>
6262
Disable WiFi sleep: <input type="checkbox" name="WS"><br><i>
6363
Can help with connectivity issues.<br>
64-
Do not enable if WiFi is working correctly, increases power consumption.</i><hr>
65-
<button type="button" onclick="B()">Back</button><button type="submit">
66-
Save & Connect</button></form></body></html>)=====";
64+
Do not enable if WiFi is working correctly, increases power consumption.</i><div
65+
id="ethd"><h3>Ethernet Type</h3><select name="ETH"><option value="0">None
66+
</option><option value="1">WT32-ETH01</option><option value="2">ESP32-POE
67+
</option></select><br><br></div><hr><button type="button" onclick="B()">Back
68+
</button><button type="submit">Save & Connect</button></form></body></html>)=====";
6769
6870
6971
// Autogenerated from wled00/data/settings_leds.htm, do not edit!!

wled00/set.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,10 @@ void handleSettingsSet(AsyncWebServerRequest *request, byte subPage)
5252

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

55+
#ifdef WLED_USE_ETHERNET
56+
ethernetType = request->arg(F("ETH")).toInt();
57+
#endif
58+
5559
char k[3]; k[2] = 0;
5660
for (int i = 0; i<4; i++)
5761
{

wled00/wled.cpp

Lines changed: 55 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,49 @@ WLED::WLED()
1010
{
1111
}
1212

13+
#ifdef WLED_USE_ETHERNET
14+
// settings for various ethernet boards
15+
typedef struct EthernetSettings {
16+
uint8_t eth_address;
17+
int eth_power;
18+
int eth_mdc;
19+
int eth_mdio;
20+
eth_phy_type_t eth_type;
21+
eth_clock_mode_t eth_clk_mode;
22+
} ethernet_settings;
23+
24+
ethernet_settings ethernetBoards[] = {
25+
// None
26+
{
27+
},
28+
29+
// WT32-EHT01
30+
// Please note, from my testing only these pins work for LED outputs:
31+
// IO2, IO4, IO12, IO14, IO15
32+
// These pins do not appear to work from my testing:
33+
// IO35, IO36, IO39
34+
{
35+
1, // eth_address,
36+
16, // eth_power,
37+
23, // eth_mdc,
38+
18, // eth_mdio,
39+
ETH_PHY_LAN8720, // eth_type,
40+
ETH_CLOCK_GPIO0_IN // eth_clk_mode
41+
},
42+
43+
// ESP32-POE
44+
{
45+
0, // eth_address,
46+
12, // eth_power,
47+
23, // eth_mdc,
48+
18, // eth_mdio,
49+
ETH_PHY_LAN8720, // eth_type,
50+
ETH_CLOCK_GPIO17_OUT // eth_clk_mode
51+
}
52+
};
53+
54+
#endif
55+
1356
// turns all LEDs off and restarts ESP
1457
void WLED::reset()
1558
{
@@ -393,7 +436,18 @@ void WLED::initConnection()
393436
#endif
394437

395438
#if defined(ARDUINO_ARCH_ESP32) && defined(WLED_USE_ETHERNET)
396-
ETH.begin();
439+
// Only initialize ethernet board if not NONE
440+
if (ethernetType != WLED_ETH_NONE) {
441+
ethernet_settings es = ethernetBoards[ethernetType];
442+
ETH.begin(
443+
(uint8_t) es.eth_address,
444+
(int) es.eth_power,
445+
(int) es.eth_mdc,
446+
(int) es.eth_mdio,
447+
(eth_phy_type_t) es.eth_type,
448+
(eth_clock_mode_t) es.eth_clk_mode
449+
);
450+
}
397451
#endif
398452

399453
WiFi.disconnect(true); // close old connections

wled00/wled.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,9 @@ WLED_GLOBAL IPAddress staticIP _INIT_N((( 0, 0, 0, 0))); // static IP
204204
WLED_GLOBAL IPAddress staticGateway _INIT_N((( 0, 0, 0, 0))); // gateway (router) IP
205205
WLED_GLOBAL IPAddress staticSubnet _INIT_N(((255, 255, 255, 0))); // most common subnet in home networks
206206
WLED_GLOBAL bool noWifiSleep _INIT(false); // disabling modem sleep modes will increase heat output and power usage, but may help with connection issues
207+
#ifdef WLED_USE_ETHERNET
208+
WLED_GLOBAL int ethernetType _INIT(WLED_ETH_ESP32_POE); // ethernet board type
209+
#endif
207210

208211
// LED CONFIG
209212
WLED_GLOBAL uint16_t ledCount _INIT(30); // overcurrent prevented by ABL

wled00/xml.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,12 @@ void getSettingsJS(byte subPage, char* dest)
219219
sappend('v',SET_F("AC"),apChannel);
220220
sappend('c',SET_F("WS"),noWifiSleep);
221221

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

223229
if (Network.isConnected()) //is connected
224230
{

0 commit comments

Comments
 (0)