2021-10-11 14:13:34 +02:00
|
|
|
#include "wled.h"
|
|
|
|
#include "fcn_declare.h"
|
|
|
|
#include "wled_ethernet.h"
|
|
|
|
|
|
|
|
|
|
|
|
#ifdef WLED_USE_ETHERNET
|
|
|
|
// 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
|
|
|
|
{
|
|
|
|
},
|
2023-01-06 09:24:29 +01:00
|
|
|
|
2021-10-11 14:13:34 +02:00
|
|
|
// 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
|
|
|
|
{
|
2023-05-08 08:48:52 +02:00
|
|
|
1, // eth_address,
|
|
|
|
16, // eth_power,
|
|
|
|
23, // eth_mdc,
|
|
|
|
18, // eth_mdio,
|
|
|
|
ETH_PHY_LAN8720, // eth_type,
|
|
|
|
ETH_CLOCK_GPIO0_IN // eth_clk_mode
|
2021-10-11 14:13:34 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
// ESP32-POE
|
|
|
|
{
|
2023-05-08 08:48:52 +02:00
|
|
|
0, // eth_address,
|
|
|
|
12, // eth_power,
|
|
|
|
23, // eth_mdc,
|
|
|
|
18, // eth_mdio,
|
|
|
|
ETH_PHY_LAN8720, // eth_type,
|
|
|
|
ETH_CLOCK_GPIO17_OUT // eth_clk_mode
|
2021-10-11 14:13:34 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
// WESP32
|
|
|
|
{
|
|
|
|
0, // eth_address,
|
|
|
|
-1, // eth_power,
|
|
|
|
16, // eth_mdc,
|
|
|
|
17, // eth_mdio,
|
|
|
|
ETH_PHY_LAN8720, // eth_type,
|
|
|
|
ETH_CLOCK_GPIO0_IN // eth_clk_mode
|
|
|
|
},
|
|
|
|
|
|
|
|
// QuinLed-ESP32-Ethernet
|
|
|
|
{
|
|
|
|
0, // eth_address,
|
|
|
|
5, // eth_power,
|
|
|
|
23, // eth_mdc,
|
|
|
|
18, // eth_mdio,
|
|
|
|
ETH_PHY_LAN8720, // eth_type,
|
|
|
|
ETH_CLOCK_GPIO17_OUT // eth_clk_mode
|
|
|
|
},
|
|
|
|
|
|
|
|
// TwilightLord-ESP32 Ethernet Shield
|
|
|
|
{
|
|
|
|
0, // eth_address,
|
|
|
|
5, // eth_power,
|
|
|
|
23, // eth_mdc,
|
|
|
|
18, // eth_mdio,
|
|
|
|
ETH_PHY_LAN8720, // eth_type,
|
|
|
|
ETH_CLOCK_GPIO17_OUT // eth_clk_mode
|
|
|
|
},
|
|
|
|
|
|
|
|
// ESP3DEUXQuattro
|
|
|
|
{
|
2023-01-06 09:24:29 +01:00
|
|
|
1, // eth_address,
|
|
|
|
-1, // eth_power,
|
|
|
|
23, // eth_mdc,
|
|
|
|
18, // eth_mdio,
|
2021-10-11 14:13:34 +02:00
|
|
|
ETH_PHY_LAN8720, // eth_type,
|
|
|
|
ETH_CLOCK_GPIO17_OUT // eth_clk_mode
|
2022-04-04 20:52:42 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
// ESP32-ETHERNET-KIT-VE
|
|
|
|
{
|
2023-01-06 09:24:29 +01:00
|
|
|
0, // eth_address,
|
2023-05-08 08:48:52 +02:00
|
|
|
5, // eth_power,
|
2023-01-06 09:24:29 +01:00
|
|
|
23, // eth_mdc,
|
|
|
|
18, // eth_mdio,
|
2023-05-08 08:48:52 +02:00
|
|
|
ETH_PHY_IP101, // eth_type,
|
|
|
|
ETH_CLOCK_GPIO0_IN // eth_clk_mode
|
2022-10-21 03:56:00 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
// QuinLed-Dig-Octa Brainboard-32-8L and LilyGO-T-ETH-POE
|
|
|
|
{
|
|
|
|
0, // eth_address,
|
|
|
|
-1, // eth_power,
|
|
|
|
23, // eth_mdc,
|
|
|
|
18, // eth_mdio,
|
|
|
|
ETH_PHY_LAN8720, // eth_type,
|
|
|
|
ETH_CLOCK_GPIO17_OUT // eth_clk_mode
|
|
|
|
},
|
2023-04-28 17:15:31 +02:00
|
|
|
|
|
|
|
// ABC! WLED Controller V43 + Ethernet Shield & compatible
|
|
|
|
{
|
|
|
|
1, // eth_address,
|
|
|
|
5, // eth_power,
|
|
|
|
23, // eth_mdc,
|
|
|
|
33, // eth_mdio,
|
|
|
|
ETH_PHY_LAN8720, // eth_type,
|
|
|
|
ETH_CLOCK_GPIO17_OUT // eth_clk_mode
|
|
|
|
},
|
|
|
|
|
2023-05-08 08:48:52 +02:00
|
|
|
// Serg74-ESP32 Ethernet Shield
|
|
|
|
{
|
|
|
|
1, // eth_address,
|
|
|
|
5, // eth_power,
|
|
|
|
23, // eth_mdc,
|
|
|
|
18, // eth_mdio,
|
|
|
|
ETH_PHY_LAN8720, // eth_type,
|
|
|
|
ETH_CLOCK_GPIO17_OUT // eth_clk_mode
|
|
|
|
}
|
2021-10-11 14:13:34 +02:00
|
|
|
};
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
//by https://github.com/tzapu/WiFiManager/blob/master/WiFiManager.cpp
|
|
|
|
int getSignalQuality(int rssi)
|
|
|
|
{
|
|
|
|
int quality = 0;
|
|
|
|
|
|
|
|
if (rssi <= -100)
|
|
|
|
{
|
|
|
|
quality = 0;
|
|
|
|
}
|
|
|
|
else if (rssi >= -50)
|
|
|
|
{
|
|
|
|
quality = 100;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
quality = 2 * (rssi + 100);
|
|
|
|
}
|
|
|
|
return quality;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//handle Ethernet connection event
|
|
|
|
void WiFiEvent(WiFiEvent_t event)
|
|
|
|
{
|
|
|
|
switch (event) {
|
|
|
|
#if defined(ARDUINO_ARCH_ESP32) && defined(WLED_USE_ETHERNET)
|
|
|
|
case SYSTEM_EVENT_ETH_START:
|
2022-11-09 20:09:01 +01:00
|
|
|
DEBUG_PRINTLN(F("ETH Started"));
|
2021-10-11 14:13:34 +02:00
|
|
|
break;
|
|
|
|
case SYSTEM_EVENT_ETH_CONNECTED:
|
2023-05-28 22:50:19 +02:00
|
|
|
{
|
2022-11-09 20:09:01 +01:00
|
|
|
DEBUG_PRINTLN(F("ETH Connected"));
|
2021-10-11 14:13:34 +02:00
|
|
|
if (!apActive) {
|
|
|
|
WiFi.disconnect(true);
|
|
|
|
}
|
|
|
|
if (staticIP != (uint32_t)0x00000000 && staticGateway != (uint32_t)0x00000000) {
|
|
|
|
ETH.config(staticIP, staticGateway, staticSubnet, IPAddress(8, 8, 8, 8));
|
|
|
|
} else {
|
|
|
|
ETH.config(INADDR_NONE, INADDR_NONE, INADDR_NONE);
|
|
|
|
}
|
|
|
|
// convert the "serverDescription" into a valid DNS hostname (alphanumeric)
|
2023-05-28 22:50:19 +02:00
|
|
|
char hostname[64];
|
2021-10-11 14:13:34 +02:00
|
|
|
prepareHostname(hostname);
|
|
|
|
ETH.setHostname(hostname);
|
|
|
|
showWelcomePage = false;
|
|
|
|
break;
|
2023-05-28 22:50:19 +02:00
|
|
|
}
|
2021-10-11 14:13:34 +02:00
|
|
|
case SYSTEM_EVENT_ETH_DISCONNECTED:
|
2022-11-09 20:09:01 +01:00
|
|
|
DEBUG_PRINTLN(F("ETH Disconnected"));
|
2021-10-11 14:13:34 +02:00
|
|
|
// This doesn't really affect ethernet per se,
|
|
|
|
// as it's only configured once. Rather, it
|
|
|
|
// may be necessary to reconnect the WiFi when
|
|
|
|
// ethernet disconnects, as a way to provide
|
|
|
|
// alternative access to the device.
|
|
|
|
forceReconnect = true;
|
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|