diff --git a/platformio_esp32c3_envs.ini b/platformio_esp32c3_envs.ini index 64978d9d3..36983a99c 100644 --- a/platformio_esp32c3_envs.ini +++ b/platformio_esp32c3_envs.ini @@ -55,6 +55,15 @@ build_flags = ${esp32c3_common_LittleFS.build_flags} extra_scripts = ${esp32c3_common_LittleFS.extra_scripts} pre:tools/pio/pre_custom_esp32.py +[env:custom_ESP32c3_4M316k_LittleFS_CDC_ETH] +extends = esp32c3_common_LittleFS +board = esp32c3cdc +build_flags = ${esp32c3_common_LittleFS.build_flags} + -DPLUGIN_BUILD_CUSTOM + -DFEATURE_ETHERNET=1 +extra_scripts = ${esp32c3_common_LittleFS.extra_scripts} + pre:tools/pio/pre_custom_esp32.py + [env:normal_ESP32c3_4M316k_CDC] diff --git a/src/src/Commands/Networks.cpp b/src/src/Commands/Networks.cpp index 46c7a8d7e..0db3581d0 100644 --- a/src/src/Commands/Networks.cpp +++ b/src/src/Commands/Networks.cpp @@ -76,17 +76,17 @@ String Command_ETH_Phy_Addr (struct EventStruct *event, const char* Line) String Command_ETH_Pin_mdc (struct EventStruct *event, const char* Line) { - return Command_GetORSetInt8_t(event, F("ETH_Pin_mdc:"), Line, reinterpret_cast(&Settings.ETH_Pin_mdc),1); + return Command_GetORSetInt8_t(event, F("ETH_Pin_mdc_cs:"), Line, reinterpret_cast(&Settings.ETH_Pin_mdc_cs),1); } String Command_ETH_Pin_mdio (struct EventStruct *event, const char* Line) { - return Command_GetORSetInt8_t(event, F("ETH_Pin_mdio:"), Line, reinterpret_cast(&Settings.ETH_Pin_mdio),1); + return Command_GetORSetInt8_t(event, F("ETH_Pin_mdio_irq:"), Line, reinterpret_cast(&Settings.ETH_Pin_mdio_irq),1); } String Command_ETH_Pin_power (struct EventStruct *event, const char* Line) { - return Command_GetORSetInt8_t(event, F("ETH_Pin_power:"), Line, reinterpret_cast(&Settings.ETH_Pin_power),1); + return Command_GetORSetInt8_t(event, F("ETH_Pin_power_rst:"), Line, reinterpret_cast(&Settings.ETH_Pin_power_rst),1); } String Command_ETH_Phy_Type (struct EventStruct *event, const char* Line) diff --git a/src/src/CustomBuild/ESPEasyDefaults.h b/src/src/CustomBuild/ESPEasyDefaults.h index 399265aab..b9057e18b 100644 --- a/src/src/CustomBuild/ESPEasyDefaults.h +++ b/src/src/CustomBuild/ESPEasyDefaults.h @@ -252,13 +252,21 @@ #define DEFAULT_ETH_PHY_ADDR 0 #endif #ifndef DEFAULT_ETH_PHY_TYPE -#define DEFAULT_ETH_PHY_TYPE EthPhyType_t::LAN8710 +#define DEFAULT_ETH_PHY_TYPE EthPhyType_t::notSet #endif #ifndef DEFAULT_ETH_PIN_MDC +#ifdef ESP32_CLASSIC #define DEFAULT_ETH_PIN_MDC 23 +#else +#define DEFAULT_ETH_PIN_MDC -1 +#endif #endif #ifndef DEFAULT_ETH_PIN_MDIO +#ifdef ESP32_CLASSIC #define DEFAULT_ETH_PIN_MDIO 18 +#else +#define DEFAULT_ETH_PIN_MDIO -1 +#endif #endif #ifndef DEFAULT_ETH_PIN_POWER #define DEFAULT_ETH_PIN_POWER -1 diff --git a/src/src/DataStructs/FactoryDefault_Network_NVS.cpp b/src/src/DataStructs/FactoryDefault_Network_NVS.cpp index 97a65c443..97a725e8c 100644 --- a/src/src/DataStructs/FactoryDefault_Network_NVS.cpp +++ b/src/src/DataStructs/FactoryDefault_Network_NVS.cpp @@ -35,9 +35,9 @@ bool FactoryDefault_Network_NVS::applyToSettings_from_NVS(ESPEasy_NVS_Helper& pr if (preferences.getPreference(F(FACTORY_DEFAULT_NVS_ETH_HW_CONF_KEY), ETH_HW_conf)) { Settings.ETH_Phy_Addr = bits.ETH_Phy_Addr; - Settings.ETH_Pin_mdc = bits.ETH_Pin_mdc; - Settings.ETH_Pin_mdio = bits.ETH_Pin_mdio; - Settings.ETH_Pin_power = bits.ETH_Pin_power; + Settings.ETH_Pin_mdc_cs = bits.ETH_Pin_mdc_cs; + Settings.ETH_Pin_mdio_irq = bits.ETH_Pin_mdio_irq; + Settings.ETH_Pin_power_rst = bits.ETH_Pin_power_rst; Settings.ETH_Phy_Type = static_cast(bits.ETH_Phy_Type); Settings.ETH_Clock_Mode = static_cast(bits.ETH_Clock_Mode); Settings.NetworkMedium = static_cast(bits.NetworkMedium); @@ -64,9 +64,9 @@ void FactoryDefault_Network_NVS::fromSettings_to_NVS(ESPEasy_NVS_Helper& prefere } { bits.ETH_Phy_Addr = Settings.ETH_Phy_Addr; - bits.ETH_Pin_mdc = Settings.ETH_Pin_mdc; - bits.ETH_Pin_mdio = Settings.ETH_Pin_mdio; - bits.ETH_Pin_power = Settings.ETH_Pin_power; + bits.ETH_Pin_mdc_cs = Settings.ETH_Pin_mdc_cs; + bits.ETH_Pin_mdio_irq = Settings.ETH_Pin_mdio_irq; + bits.ETH_Pin_power_rst = Settings.ETH_Pin_power_rst; bits.ETH_Phy_Type = static_cast(Settings.ETH_Phy_Type); bits.ETH_Clock_Mode = static_cast(Settings.ETH_Clock_Mode); bits.NetworkMedium = static_cast(Settings.NetworkMedium); diff --git a/src/src/DataStructs/FactoryDefault_Network_NVS.h b/src/src/DataStructs/FactoryDefault_Network_NVS.h index 7ed42dc24..1aa0b3bd6 100644 --- a/src/src/DataStructs/FactoryDefault_Network_NVS.h +++ b/src/src/DataStructs/FactoryDefault_Network_NVS.h @@ -29,9 +29,9 @@ private: union { struct { int8_t ETH_Phy_Addr; - int8_t ETH_Pin_mdc; - int8_t ETH_Pin_mdio; - int8_t ETH_Pin_power; + int8_t ETH_Pin_mdc_cs; + int8_t ETH_Pin_mdio_irq; + int8_t ETH_Pin_power_rst; uint8_t ETH_Phy_Type; uint8_t ETH_Clock_Mode; uint8_t NetworkMedium; diff --git a/src/src/DataStructs/GpioFactorySettingsStruct.cpp b/src/src/DataStructs/GpioFactorySettingsStruct.cpp index fd0415f17..14a283fb7 100644 --- a/src/src/DataStructs/GpioFactorySettingsStruct.cpp +++ b/src/src/DataStructs/GpioFactorySettingsStruct.cpp @@ -107,7 +107,7 @@ GpioFactorySettingsStruct::GpioFactorySettingsStruct(DeviceModel model) #endif -#ifdef ESP32 +# if CONFIG_ETH_USE_ESP32_EMAC case DeviceModel::DeviceModel_Olimex_ESP32_PoE: button[0] = 34; // BUT1 Button relais[0] = -1; // No LED's or relays on board @@ -199,12 +199,6 @@ GpioFactorySettingsStruct::GpioFactorySettingsStruct(DeviceModel model) network_medium = NetworkMedium_t::Ethernet; break; - #else - case DeviceModel::DeviceModel_Olimex_ESP32_PoE: - case DeviceModel::DeviceModel_Olimex_ESP32_EVB: - case DeviceModel::DeviceModel_Olimex_ESP32_GATEWAY: - case DeviceModel::DeviceModel_wESP32: - case DeviceModel::DeviceModel_WT32_ETH01: #endif case DeviceModel::DeviceModel_default: diff --git a/src/src/DataStructs/SettingsStruct.h b/src/src/DataStructs/SettingsStruct.h index c01ba255d..46ddf9a38 100644 --- a/src/src/DataStructs/SettingsStruct.h +++ b/src/src/DataStructs/SettingsStruct.h @@ -450,10 +450,10 @@ public: uint16_t SyslogPort = DEFAULT_SYSLOG_PORT; int8_t ETH_Phy_Addr = -1; - int8_t ETH_Pin_mdc = -1; - int8_t ETH_Pin_mdio = -1; - int8_t ETH_Pin_power = -1; - EthPhyType_t ETH_Phy_Type = EthPhyType_t::LAN8710; + int8_t ETH_Pin_mdc_cs = -1; + int8_t ETH_Pin_mdio_irq = -1; + int8_t ETH_Pin_power_rst = -1; + EthPhyType_t ETH_Phy_Type = EthPhyType_t::notSet; EthClockMode_t ETH_Clock_Mode = EthClockMode_t::Ext_crystal_osc; uint8_t ETH_IP[4] = {0}; uint8_t ETH_Gateway[4] = {0}; diff --git a/src/src/DataStructs/WiFiEventData.cpp b/src/src/DataStructs/WiFiEventData.cpp index f84f6abab..96214d1b4 100644 --- a/src/src/DataStructs/WiFiEventData.cpp +++ b/src/src/DataStructs/WiFiEventData.cpp @@ -185,7 +185,7 @@ void WiFiEventData_t::markGotIP() { void WiFiEventData_t::markGotIPv6(const IPAddress& ip6) { processedGotIP6 = false; unprocessed_IP6 = ip6; - addLog(LOG_LEVEL_INFO, String(F("WIFI : STA got IP6 ")) + ip.toString(true)); + addLog(LOG_LEVEL_INFO, String(F("WIFI : STA got IP6 ")) + ip6.toString(true)); } #endif diff --git a/src/src/DataStructs_templ/SettingsStruct.cpp b/src/src/DataStructs_templ/SettingsStruct.cpp index 5abc49eaa..6824ed0a0 100644 --- a/src/src/DataStructs_templ/SettingsStruct.cpp +++ b/src/src/DataStructs_templ/SettingsStruct.cpp @@ -565,9 +565,9 @@ void SettingsStruct_tmpl::clearMisc() { #ifdef ESP32 // Ethernet related settings are never used on ESP8266 ETH_Phy_Addr = DEFAULT_ETH_PHY_ADDR; - ETH_Pin_mdc = DEFAULT_ETH_PIN_MDC; - ETH_Pin_mdio = DEFAULT_ETH_PIN_MDIO; - ETH_Pin_power = DEFAULT_ETH_PIN_POWER; + ETH_Pin_mdc_cs = DEFAULT_ETH_PIN_MDC; + ETH_Pin_mdio_irq = DEFAULT_ETH_PIN_MDIO; + ETH_Pin_power_rst = DEFAULT_ETH_PIN_POWER; ETH_Phy_Type = DEFAULT_ETH_PHY_TYPE; ETH_Clock_Mode = DEFAULT_ETH_CLOCK_MODE; #endif @@ -938,9 +938,9 @@ bool SettingsStruct_tmpl::isEthernetPinOptional(int8_t pin) const { if (pin < 0) return false; if (NetworkMedium == NetworkMedium_t::Ethernet) { if (isGpioUsedInETHClockMode(ETH_Clock_Mode, pin)) return true; - if (ETH_Pin_mdc == pin) return true; - if (ETH_Pin_mdio == pin) return true; - if (ETH_Pin_power == pin) return true; + if (ETH_Pin_mdc_cs == pin) return true; + if (ETH_Pin_mdio_irq == pin) return true; + if (ETH_Pin_power_rst == pin) return true; } #endif // if FEATURE_ETHERNET return false; diff --git a/src/src/DataTypes/DeviceModel.h b/src/src/DataTypes/DeviceModel.h index 18c994d55..3af8f1f45 100644 --- a/src/src/DataTypes/DeviceModel.h +++ b/src/src/DataTypes/DeviceModel.h @@ -21,11 +21,13 @@ enum class DeviceModel : uint8_t { DeviceModel_Sonoff_POWr2, DeviceModel_Shelly1, DeviceModel_ShellyPLUG_S, +# if CONFIG_ETH_USE_ESP32_EMAC DeviceModel_Olimex_ESP32_PoE, DeviceModel_Olimex_ESP32_EVB, DeviceModel_Olimex_ESP32_GATEWAY, DeviceModel_wESP32, DeviceModel_WT32_ETH01, +#endif DeviceModel_MAX diff --git a/src/src/DataTypes/EthernetParameters.cpp b/src/src/DataTypes/EthernetParameters.cpp index f6f5313ff..5a6b90ef9 100644 --- a/src/src/DataTypes/EthernetParameters.cpp +++ b/src/src/DataTypes/EthernetParameters.cpp @@ -14,7 +14,7 @@ bool isValid(EthClockMode_t clockMode) { } bool isGpioUsedInETHClockMode(EthClockMode_t clockMode, - int8_t gpio) { + int8_t gpio) { if (((clockMode == EthClockMode_t::Int_50MHz_GPIO_0) && (gpio == 0)) || ((clockMode == EthClockMode_t::Int_50MHz_GPIO_16) && (gpio == 16)) || ((clockMode == EthClockMode_t::Int_50MHz_GPIO_17_inv) && (gpio == 17))) { @@ -23,7 +23,7 @@ bool isGpioUsedInETHClockMode(EthClockMode_t clockMode, return false; } -const __FlashStringHelper * toString(EthClockMode_t clockMode) { +const __FlashStringHelper* toString(EthClockMode_t clockMode) { switch (clockMode) { case EthClockMode_t::Ext_crystal_osc: return F("External crystal oscillator"); case EthClockMode_t::Int_50MHz_GPIO_0: return F("50MHz APLL Output on GPIO0"); @@ -37,32 +37,120 @@ const __FlashStringHelper * toString(EthClockMode_t clockMode) { bool isValid(EthPhyType_t phyType) { switch (phyType) { +# if CONFIG_ETH_USE_ESP32_EMAC case EthPhyType_t::LAN8710: - case EthPhyType_t::TLK110: - return true; + case EthPhyType_t::TLK110: +#if ESP_IDF_VERSION_MAJOR > 3 case EthPhyType_t::RTL8201: + case EthPhyType_t::JL1101: case EthPhyType_t::DP83848: - case EthPhyType_t::DM9051: - #if ESP_IDF_VERSION_MAJOR > 3 - return true; // FIXME TD-er: Must check if supported per IDF version - #else - return false; - #endif + case EthPhyType_t::KSZ8041: + case EthPhyType_t::KSZ8081: +#endif + return true; +# endif // if CONFIG_ETH_USE_ESP32_EMAC + +#if ESP_IDF_VERSION_MAJOR > 3 +# if CONFIG_ETH_SPI_ETHERNET_DM9051 + case EthPhyType_t::DM9051: return true; +# endif // if CONFIG_ETH_SPI_ETHERNET_DM9051 +# if CONFIG_ETH_SPI_ETHERNET_W5500 + case EthPhyType_t::W5500: return true; +# endif // if CONFIG_ETH_SPI_ETHERNET_W5500 +# if CONFIG_ETH_SPI_ETHERNET_KSZ8851SNL + case EthPhyType_t::KSZ8851: return true; +# endif // if CONFIG_ETH_SPI_ETHERNET_KSZ8851SNL +#endif + case EthPhyType_t::notSet: + break; - // Do not use default: as this allows the compiler to detect any missing cases. } return false; } -const __FlashStringHelper * toString(EthPhyType_t phyType) { +#if FEATURE_ETHERNET +bool isSPI_EthernetType(EthPhyType_t phyType) { +#if ESP_IDF_VERSION_MAJOR > 3 + return +# if CONFIG_ETH_SPI_ETHERNET_DM9051 + phyType == EthPhyType_t::DM9051 || +# endif // if CONFIG_ETH_SPI_ETHERNET_DM9051 +# if CONFIG_ETH_SPI_ETHERNET_W5500 + phyType == EthPhyType_t::W5500 || +# endif // if CONFIG_ETH_SPI_ETHERNET_W5500 +# if CONFIG_ETH_SPI_ETHERNET_KSZ8851SNL + phyType == EthPhyType_t::KSZ8851 || +# endif // if CONFIG_ETH_SPI_ETHERNET_KSZ8851SNL + false; +#else + return false; +#endif +} + +eth_phy_type_t to_ESP_phy_type(EthPhyType_t phyType) +{ switch (phyType) { - case EthPhyType_t::LAN8710: return F("LAN8710/LAN8720"); - case EthPhyType_t::TLK110: return F("TLK110"); - case EthPhyType_t::RTL8201: return F("RTL8201"); - case EthPhyType_t::DP83848: return F("DP83848"); - case EthPhyType_t::DM9051: return F("DM9051"); +# if CONFIG_ETH_USE_ESP32_EMAC + case EthPhyType_t::LAN8710: return ETH_PHY_LAN8710; + case EthPhyType_t::TLK110: return ETH_PHY_TLK110; +#if ESP_IDF_VERSION_MAJOR > 3 + case EthPhyType_t::RTL8201: return ETH_PHY_RTL8201; + case EthPhyType_t::JL1101: return ETH_PHY_JL1101; + case EthPhyType_t::DP83848: return ETH_PHY_DP83848; + case EthPhyType_t::KSZ8041: return ETH_PHY_KSZ8041; + case EthPhyType_t::KSZ8081: return ETH_PHY_KSZ8081; +#endif +# endif // if CONFIG_ETH_USE_ESP32_EMAC + +#if ESP_IDF_VERSION_MAJOR > 3 +# if CONFIG_ETH_SPI_ETHERNET_DM9051 + case EthPhyType_t::DM9051: return ETH_PHY_DM9051; +# endif // if CONFIG_ETH_SPI_ETHERNET_DM9051 +# if CONFIG_ETH_SPI_ETHERNET_W5500 + case EthPhyType_t::W5500: return ETH_PHY_W5500; +# endif // if CONFIG_ETH_SPI_ETHERNET_W5500 +# if CONFIG_ETH_SPI_ETHERNET_KSZ8851SNL + case EthPhyType_t::KSZ8851: return ETH_PHY_KSZ8851; +# endif // if CONFIG_ETH_SPI_ETHERNET_KSZ8851SNL +#endif + case EthPhyType_t::notSet: + break; + } + return ETH_PHY_MAX; +} + +#endif // if FEATURE_ETHERNET + + +const __FlashStringHelper* toString(EthPhyType_t phyType) { + switch (phyType) { +# if CONFIG_ETH_USE_ESP32_EMAC + case EthPhyType_t::LAN8710: return F("LAN8710/LAN8720"); + case EthPhyType_t::TLK110: return F("TLK110"); +#if ESP_IDF_VERSION_MAJOR > 3 + case EthPhyType_t::RTL8201: return F("RTL8201"); + case EthPhyType_t::JL1101: return F("JL1101"); + case EthPhyType_t::DP83848: return F("DP83848"); + case EthPhyType_t::KSZ8041: return F("KSZ8041"); + case EthPhyType_t::KSZ8081: return F("KSZ8081"); +#endif +# endif // if CONFIG_ETH_USE_ESP32_EMAC + +#if ESP_IDF_VERSION_MAJOR > 3 +# if CONFIG_ETH_SPI_ETHERNET_DM9051 + case EthPhyType_t::DM9051: return F("DM9051"); +# endif // if CONFIG_ETH_SPI_ETHERNET_DM9051 +# if CONFIG_ETH_SPI_ETHERNET_W5500 + case EthPhyType_t::W5500: return F("W5500"); +# endif // if CONFIG_ETH_SPI_ETHERNET_W5500 +# if CONFIG_ETH_SPI_ETHERNET_KSZ8851SNL + case EthPhyType_t::KSZ8851: return F("KSZ8851"); +# endif // if CONFIG_ETH_SPI_ETHERNET_KSZ8851SNL +#endif + case EthPhyType_t::notSet: + break; // Do not use default: as this allows the compiler to detect any missing cases. } - return F("Unknown"); + return F(""); } diff --git a/src/src/DataTypes/EthernetParameters.h b/src/src/DataTypes/EthernetParameters.h index 08441fb87..01b210446 100644 --- a/src/src/DataTypes/EthernetParameters.h +++ b/src/src/DataTypes/EthernetParameters.h @@ -3,6 +3,7 @@ #include "../../ESPEasy_common.h" + // Is stored in settings enum class EthClockMode_t : uint8_t { Ext_crystal_osc = 0, @@ -20,16 +21,43 @@ bool isGpioUsedInETHClockMode(EthClockMode_t clockMode, // Is stored in settings enum class EthPhyType_t : uint8_t { +#if CONFIG_ETH_USE_ESP32_EMAC LAN8710 = 0, TLK110 = 1, +#if ESP_IDF_VERSION_MAJOR > 3 + RTL8201 = 2, - DP83848 = 3, - DM9051 = 4 - //,KSZ8081 = 5 + JL1101 = 3, + DP83848 = 4, + KSZ8041 = 5, + KSZ8081 = 6, +#endif +#endif +#if ESP_IDF_VERSION_MAJOR > 3 +#if CONFIG_ETH_SPI_ETHERNET_DM9051 + DM9051 = 10, +#endif +#if CONFIG_ETH_SPI_ETHERNET_W5500 + W5500 = 11, +#endif +#if CONFIG_ETH_SPI_ETHERNET_KSZ8851SNL + KSZ8851 = 12, +#endif +#endif + notSet = 255 }; bool isValid(EthPhyType_t phyType); +#if FEATURE_ETHERNET +#include + +bool isSPI_EthernetType(EthPhyType_t phyType); + +// Convert to internal enum type as those enum values may not always be the same int value +eth_phy_type_t to_ESP_phy_type(EthPhyType_t phyType); +#endif + const __FlashStringHelper * toString(EthPhyType_t phyType); diff --git a/src/src/ESPEasyCore/ESPEasyEth.cpp b/src/src/ESPEasyCore/ESPEasyEth.cpp index acf99a66d..8e48d730e 100644 --- a/src/src/ESPEasyCore/ESPEasyEth.cpp +++ b/src/src/ESPEasyCore/ESPEasyEth.cpp @@ -66,9 +66,9 @@ bool ethCheckSettings() { return isValid(Settings.ETH_Phy_Type) && isValid(Settings.ETH_Clock_Mode) && isValid(Settings.NetworkMedium) - && validGpio(Settings.ETH_Pin_mdc) - && validGpio(Settings.ETH_Pin_mdio) - && (validGpio(Settings.ETH_Pin_power) || (Settings.ETH_Pin_power == -1)); // Some boards have fixed power + && validGpio(Settings.ETH_Pin_mdc_cs) + && validGpio(Settings.ETH_Pin_mdio_irq) + && (validGpio(Settings.ETH_Pin_power_rst) || (Settings.ETH_Pin_power_rst == -1)); // Some boards have fixed power } bool ethPrepare() { @@ -89,14 +89,16 @@ void ethPrintSettings() { log += toString(Settings.ETH_Phy_Type); log += F(" PHY Addr: "); log += Settings.ETH_Phy_Addr; - log += F(" Eth Clock mode: "); - log += toString(Settings.ETH_Clock_Mode); - log += F(" MDC Pin: "); - log += String(Settings.ETH_Pin_mdc); - log += F(" MIO Pin: "); - log += String(Settings.ETH_Pin_mdio); - log += F(" Power Pin: "); - log += String(Settings.ETH_Pin_power); + + if (!isSPI_EthernetType(Settings.ETH_Phy_Type)) { + log += F(" Eth Clock mode: "); + log += toString(Settings.ETH_Clock_Mode); + } + log += strformat(isSPI_EthernetType(Settings.ETH_Phy_Type) + ? F(" CS: %d IRQ: %d RST: %d") : F(" MDC: %d MIO: %d PWR: %d"), + Settings.ETH_Pin_mdc_cs, + Settings.ETH_Pin_mdio_irq, + Settings.ETH_Pin_power_rst); addLogMove(LOG_LEVEL_INFO, log); } } @@ -156,9 +158,9 @@ bool ETHConnectRelaxed() { #if ESP_IDF_VERSION_MAJOR < 5 EthEventData.ethInitSuccess = ETH.begin( Settings.ETH_Phy_Addr, - Settings.ETH_Pin_power, - Settings.ETH_Pin_mdc, - Settings.ETH_Pin_mdio, + Settings.ETH_Pin_power_rst, + Settings.ETH_Pin_mdc_cs, + Settings.ETH_Pin_mdio_irq, (eth_phy_type_t)Settings.ETH_Phy_Type, (eth_clock_mode_t)Settings.ETH_Clock_Mode); #else @@ -166,13 +168,40 @@ bool ETHConnectRelaxed() { ETH.enableIPv6(true); #endif + if (isSPI_EthernetType(Settings.ETH_Phy_Type)) { + int sck=-1; + int miso=-1; + int mosi=-1; + #ifdef ESP32C3 + // FIXME TD-er: Must make this configurable + sck = 7; + miso = 3; + mosi = 10; + #endif + + + EthEventData.ethInitSuccess = ETH.begin( + to_ESP_phy_type(Settings.ETH_Phy_Type), + Settings.ETH_Phy_Addr, + Settings.ETH_Pin_mdc_cs, + Settings.ETH_Pin_mdio_irq, + Settings.ETH_Pin_power_rst, + SPI2_HOST, + sck, + miso, + mosi); + + } else { +# if CONFIG_ETH_USE_ESP32_EMAC EthEventData.ethInitSuccess = ETH.begin( - (eth_phy_type_t)Settings.ETH_Phy_Type, + to_ESP_phy_type(Settings.ETH_Phy_Type), Settings.ETH_Phy_Addr, - Settings.ETH_Pin_mdc, - Settings.ETH_Pin_mdio, - Settings.ETH_Pin_power, + Settings.ETH_Pin_mdc_cs, + Settings.ETH_Pin_mdio_irq, + Settings.ETH_Pin_power_rst, (eth_clock_mode_t)Settings.ETH_Clock_Mode); +#endif + } #endif } @@ -189,8 +218,10 @@ bool ETHConnectRelaxed() { } void ethPower(bool enable) { - if (Settings.ETH_Pin_power != -1) { - if (GPIO_Internal_Read(Settings.ETH_Pin_power) == enable) { + if (isSPI_EthernetType(Settings.ETH_Phy_Type)) + return; + if (Settings.ETH_Pin_power_rst != -1) { + if (GPIO_Internal_Read(Settings.ETH_Pin_power_rst) == enable) { // Already the desired state return; } @@ -211,9 +242,9 @@ void ethPower(bool enable) { if (enable) { // ethResetGPIOpins(); } -// gpio_reset_pin((gpio_num_t)Settings.ETH_Pin_power); +// gpio_reset_pin((gpio_num_t)Settings.ETH_Pin_power_rst); - GPIO_Write(PLUGIN_GPIO, Settings.ETH_Pin_power, enable ? 1 : 0); + GPIO_Write(PLUGIN_GPIO, Settings.ETH_Pin_power_rst, enable ? 1 : 0); if (!enable) { if (Settings.ETH_Clock_Mode == EthClockMode_t::Ext_crystal_osc) { delay(600); // Give some time to discharge any capacitors @@ -226,18 +257,23 @@ void ethPower(bool enable) { } void ethResetGPIOpins() { + if (isSPI_EthernetType(Settings.ETH_Phy_Type)) + return; + // fix an disconnection issue after rebooting Olimex POE - this forces a clean state for all GPIO involved in RMII // Thanks to @s-hadinger and @Jason2866 // Resetting state of power pin is done in ethPower() addLog(LOG_LEVEL_INFO, F("ethResetGPIOpins()")); - gpio_reset_pin((gpio_num_t)Settings.ETH_Pin_mdc); - gpio_reset_pin((gpio_num_t)Settings.ETH_Pin_mdio); + gpio_reset_pin((gpio_num_t)Settings.ETH_Pin_mdc_cs); + gpio_reset_pin((gpio_num_t)Settings.ETH_Pin_mdio_irq); +# if CONFIG_ETH_USE_ESP32_EMAC gpio_reset_pin(GPIO_NUM_19); // EMAC_TXD0 - hardcoded gpio_reset_pin(GPIO_NUM_21); // EMAC_TX_EN - hardcoded gpio_reset_pin(GPIO_NUM_22); // EMAC_TXD1 - hardcoded gpio_reset_pin(GPIO_NUM_25); // EMAC_RXD0 - hardcoded gpio_reset_pin(GPIO_NUM_26); // EMAC_RXD1 - hardcoded gpio_reset_pin(GPIO_NUM_27); // EMAC_RX_CRS_DV - hardcoded +#endif /* switch (Settings.ETH_Clock_Mode) { case EthClockMode_t::Ext_crystal_osc: // ETH_CLOCK_GPIO0_IN diff --git a/src/src/ESPEasyCore/ESPEasy_setup.cpp b/src/src/ESPEasyCore/ESPEasy_setup.cpp index c3f3c41e6..a47dbfd21 100644 --- a/src/src/ESPEasyCore/ESPEasy_setup.cpp +++ b/src/src/ESPEasyCore/ESPEasy_setup.cpp @@ -581,8 +581,8 @@ void ESPEasy_setup() #endif #if FEATURE_ETHERNET - if (Settings.ETH_Pin_power != -1) { - GPIO_Write(PLUGIN_GPIO, Settings.ETH_Pin_power, 1); + if (Settings.ETH_Pin_power_rst != -1) { + GPIO_Write(PLUGIN_GPIO, Settings.ETH_Pin_power_rst, 1); } #endif diff --git a/src/src/Helpers/ESPEasy_FactoryDefault.cpp b/src/src/Helpers/ESPEasy_FactoryDefault.cpp index 3577ca3d6..3bbcade1b 100644 --- a/src/src/Helpers/ESPEasy_FactoryDefault.cpp +++ b/src/src/Helpers/ESPEasy_FactoryDefault.cpp @@ -306,9 +306,9 @@ void ResetFactory(bool formatFS) // Ethernet related settings are never used on ESP8266 Settings.ETH_Phy_Addr = gpio_settings.eth_phyaddr; - Settings.ETH_Pin_mdc = gpio_settings.eth_mdc; - Settings.ETH_Pin_mdio = gpio_settings.eth_mdio; - Settings.ETH_Pin_power = gpio_settings.eth_power; + Settings.ETH_Pin_mdc_cs = gpio_settings.eth_mdc; + Settings.ETH_Pin_mdio_irq = gpio_settings.eth_mdio; + Settings.ETH_Pin_power_rst = gpio_settings.eth_power; Settings.ETH_Phy_Type = gpio_settings.eth_phytype; Settings.ETH_Clock_Mode = gpio_settings.eth_clock_mode; #endif // ifdef ESP32 diff --git a/src/src/Helpers/ESPEasy_Storage.cpp b/src/src/Helpers/ESPEasy_Storage.cpp index 78fef1e53..e92675af4 100644 --- a/src/src/Helpers/ESPEasy_Storage.cpp +++ b/src/src/Helpers/ESPEasy_Storage.cpp @@ -338,9 +338,9 @@ bool BuildFixes() #ifdef ESP32 // Ethernet related settings are never used on ESP8266 Settings.ETH_Phy_Addr = DEFAULT_ETH_PHY_ADDR; - Settings.ETH_Pin_mdc = DEFAULT_ETH_PIN_MDC; - Settings.ETH_Pin_mdio = DEFAULT_ETH_PIN_MDIO; - Settings.ETH_Pin_power = DEFAULT_ETH_PIN_POWER; + Settings.ETH_Pin_mdc_cs = DEFAULT_ETH_PIN_MDC; + Settings.ETH_Pin_mdio_irq = DEFAULT_ETH_PIN_MDIO; + Settings.ETH_Pin_power_rst = DEFAULT_ETH_PIN_POWER; Settings.ETH_Phy_Type = DEFAULT_ETH_PHY_TYPE; Settings.ETH_Clock_Mode = DEFAULT_ETH_CLOCK_MODE; #endif diff --git a/src/src/Helpers/Hardware.cpp b/src/src/Helpers/Hardware.cpp index 45c2b9b39..d9444a153 100644 --- a/src/src/Helpers/Hardware.cpp +++ b/src/src/Helpers/Hardware.cpp @@ -148,11 +148,11 @@ void hardwareInit() PinBootState bootState = Settings.getPinBootState(gpio); #if FEATURE_ETHERNET /* - if (Settings.ETH_Pin_power == gpio) + if (Settings.ETH_Pin_power_rst == gpio) { if (loglevelActiveFor(LOG_LEVEL_INFO)) { String log = F("ETH : Reset ETH module on pin "); - log += Settings.ETH_Pin_power; + log += Settings.ETH_Pin_power_rst; addLog(LOG_LEVEL_INFO, log); } bootState = PinBootState::Output_low; @@ -759,6 +759,7 @@ const __FlashStringHelper* getDeviceModelBrandString(DeviceModel model) { case DeviceModel::DeviceModel_Sonoff_POWr2: return F("Sonoff"); case DeviceModel::DeviceModel_Shelly1: case DeviceModel::DeviceModel_ShellyPLUG_S: return F("Shelly"); +# if CONFIG_ETH_USE_ESP32_EMAC case DeviceModel::DeviceModel_Olimex_ESP32_PoE: case DeviceModel::DeviceModel_Olimex_ESP32_EVB: case DeviceModel::DeviceModel_Olimex_ESP32_GATEWAY: @@ -773,6 +774,7 @@ const __FlashStringHelper* getDeviceModelBrandString(DeviceModel model) { #ifdef ESP32_CLASSIC return F("WT32-ETH01"); #endif // ifdef ESP32_CLASSIC +#endif case DeviceModel::DeviceModel_default: case DeviceModel::DeviceModel_MAX: break; @@ -810,19 +812,13 @@ const __FlashStringHelper* getDeviceModelTypeString(DeviceModel model) case DeviceModel::DeviceModel_ShellyPLUG_S: return F("default"); #endif // if defined(ESP8266) && !defined(LIMIT_BUILD_SIZE) -#ifdef ESP32_CLASSIC +# if CONFIG_ETH_USE_ESP32_EMAC case DeviceModel::DeviceModel_Olimex_ESP32_PoE: return F(" ESP32-PoE"); case DeviceModel::DeviceModel_Olimex_ESP32_EVB: return F(" ESP32-EVB"); case DeviceModel::DeviceModel_Olimex_ESP32_GATEWAY: return F(" ESP32-GATEWAY"); case DeviceModel::DeviceModel_wESP32: break; case DeviceModel::DeviceModel_WT32_ETH01: return F(" add-on"); -#else // ifdef ESP32_CLASSIC - case DeviceModel::DeviceModel_Olimex_ESP32_PoE: - case DeviceModel::DeviceModel_Olimex_ESP32_EVB: - case DeviceModel::DeviceModel_Olimex_ESP32_GATEWAY: - case DeviceModel::DeviceModel_wESP32: - case DeviceModel::DeviceModel_WT32_ETH01: -#endif // ifdef ESP32_CLASSIC +#endif case DeviceModel::DeviceModel_default: case DeviceModel::DeviceModel_MAX: return F("default"); @@ -875,6 +871,7 @@ bool modelMatchingFlashSize(DeviceModel model) { #endif // ifdef ESP8266 // These Olimex boards all have Ethernet +# if CONFIG_ETH_USE_ESP32_EMAC case DeviceModel::DeviceModel_Olimex_ESP32_PoE: case DeviceModel::DeviceModel_Olimex_ESP32_EVB: case DeviceModel::DeviceModel_Olimex_ESP32_GATEWAY: @@ -885,7 +882,7 @@ bool modelMatchingFlashSize(DeviceModel model) { #else // if defined(ESP32_CLASSIC) && FEATURE_ETHERNET return false; #endif // if defined(ESP32_CLASSIC) && FEATURE_ETHERNET - +#endif case DeviceModel::DeviceModel_default: case DeviceModel::DeviceModel_MAX: return true; diff --git a/src/src/Helpers/StringGenerator_GPIO.cpp b/src/src/Helpers/StringGenerator_GPIO.cpp index 6c9763de4..6ae416bf8 100644 --- a/src/src/Helpers/StringGenerator_GPIO.cpp +++ b/src/src/Helpers/StringGenerator_GPIO.cpp @@ -295,11 +295,11 @@ const __FlashStringHelper* getConflictingUse(int gpio, PinSelectPurpose purpose) if (includeEthernet && Settings.isEthernetPinOptional(gpio)) { if (isGpioUsedInETHClockMode(Settings.ETH_Clock_Mode, gpio)) { return F("Eth Clock"); } - if (Settings.ETH_Pin_mdc == gpio) { return F("Eth MDC"); } + if (Settings.ETH_Pin_mdc_cs == gpio) { return F("Eth MDC"); } - if (Settings.ETH_Pin_mdio == gpio) { return F("Eth MDIO"); } + if (Settings.ETH_Pin_mdio_irq == gpio) { return F("Eth MDIO"); } - if (Settings.ETH_Pin_power == gpio) { return F("Eth Pwr"); } + if (Settings.ETH_Pin_power_rst == gpio) { return F("Eth Pwr"); } return F("Eth"); } diff --git a/src/src/WebServer/HardwarePage.cpp b/src/src/WebServer/HardwarePage.cpp index 0029b93da..637740061 100644 --- a/src/src/WebServer/HardwarePage.cpp +++ b/src/src/WebServer/HardwarePage.cpp @@ -72,11 +72,13 @@ void handle_hardware() { Settings.Pin_sd_cs = getFormItemInt(F("sd")); #if FEATURE_ETHERNET Settings.ETH_Phy_Addr = getFormItemInt(F("ethphy")); - Settings.ETH_Pin_mdc = getFormItemInt(F("ethmdc")); - Settings.ETH_Pin_mdio = getFormItemInt(F("ethmdio")); - Settings.ETH_Pin_power = getFormItemInt(F("ethpower")); + Settings.ETH_Pin_mdc_cs = getFormItemInt(F("ethmdc")); + Settings.ETH_Pin_mdio_irq = getFormItemInt(F("ethmdio")); + Settings.ETH_Pin_power_rst = getFormItemInt(F("ethpower")); Settings.ETH_Phy_Type = static_cast(getFormItemInt(F("ethtype"))); +#if CONFIG_ETH_USE_ESP32_EMAC Settings.ETH_Clock_Mode = static_cast(getFormItemInt(F("ethclock"))); +#endif Settings.NetworkMedium = static_cast(getFormItemInt(F("ethwifi"))); #endif // if FEATURE_ETHERNET int gpio = 0; @@ -250,33 +252,94 @@ void handle_hardware() { const uint32_t nrItems = 2; #endif const __FlashStringHelper * ethPhyTypes[nrItems] = { - toString(EthPhyType_t::LAN8710), - toString(EthPhyType_t::TLK110) - #if ESP_IDF_VERSION_MAJOR > 3 - , - toString(EthPhyType_t::RTL8201), - toString(EthPhyType_t::DP83848), - toString(EthPhyType_t::DM9051) - #endif + toString(EthPhyType_t::notSet), +# if CONFIG_ETH_USE_ESP32_EMAC + toString(EthPhyType_t::LAN8710), + toString(EthPhyType_t::TLK110), +#if ESP_IDF_VERSION_MAJOR > 3 + toString(EthPhyType_t::RTL8201), + toString(EthPhyType_t::JL1101), + toString(EthPhyType_t::DP83848), + toString(EthPhyType_t::KSZ8041), + toString(EthPhyType_t::KSZ8081), +#endif +# endif // if CONFIG_ETH_USE_ESP32_EMAC + +#if ESP_IDF_VERSION_MAJOR > 3 +# if CONFIG_ETH_SPI_ETHERNET_DM9051 + toString(EthPhyType_t::DM9051), +# endif // if CONFIG_ETH_SPI_ETHERNET_DM9051 +# if CONFIG_ETH_SPI_ETHERNET_W5500 + toString(EthPhyType_t::W5500), +# endif // if CONFIG_ETH_SPI_ETHERNET_W5500 +# if CONFIG_ETH_SPI_ETHERNET_KSZ8851SNL + toString(EthPhyType_t::KSZ8851), +# endif // if CONFIG_ETH_SPI_ETHERNET_KSZ8851SNL +#endif }; const int ethPhyTypes_index[] = { - static_cast(EthPhyType_t::LAN8710), - static_cast(EthPhyType_t::TLK110) - #if ESP_IDF_VERSION_MAJOR > 3 - , - static_cast(EthPhyType_t::RTL8201), - static_cast(EthPhyType_t::DP83848), - static_cast(EthPhyType_t::DM9051) - #endif + static_cast(EthPhyType_t::notSet), +# if CONFIG_ETH_USE_ESP32_EMAC + static_cast(EthPhyType_t::LAN8710), + static_cast(EthPhyType_t::TLK110), +#if ESP_IDF_VERSION_MAJOR > 3 + static_cast(EthPhyType_t::RTL8201), + static_cast(EthPhyType_t::JL1101), + static_cast(EthPhyType_t::DP83848), + static_cast(EthPhyType_t::KSZ8041), + static_cast(EthPhyType_t::KSZ8081), +#endif +# endif // if CONFIG_ETH_USE_ESP32_EMAC + +#if ESP_IDF_VERSION_MAJOR > 3 +# if CONFIG_ETH_SPI_ETHERNET_DM9051 + static_cast(EthPhyType_t::DM9051), +# endif // if CONFIG_ETH_SPI_ETHERNET_DM9051 +# if CONFIG_ETH_SPI_ETHERNET_W5500 + static_cast(EthPhyType_t::W5500), +# endif // if CONFIG_ETH_SPI_ETHERNET_W5500 +# if CONFIG_ETH_SPI_ETHERNET_KSZ8851SNL + static_cast(EthPhyType_t::KSZ8851), +# endif // if CONFIG_ETH_SPI_ETHERNET_KSZ8851SNL +#endif }; - addSelector(F("ethtype"), nrItems, ethPhyTypes, ethPhyTypes_index, nullptr, static_cast(Settings.ETH_Phy_Type), false, true); + const int choice = isValid(Settings.ETH_Phy_Type) + ? static_cast(Settings.ETH_Phy_Type) + : static_cast(EthPhyType_t::notSet); + addSelector(F("ethtype"), nrItems, ethPhyTypes, ethPhyTypes_index, nullptr, choice, false, true); } + +#if CONFIG_ETH_USE_SPI_ETHERNET && CONFIG_ETH_USE_ESP32_EMAC +#define MDC_CS_PIN_DESCR "Ethernet MDC/CS pin" +#define MIO_IRQ_PIN_DESCR "Ethernet MIO/IRQ pin" +#define PWR_RST_PIN_DESCR "Ethernet Power/RST pin" +#elif CONFIG_ETH_USE_SPI_ETHERNET +#define MDC_CS_PIN_DESCR "Ethernet CS pin" +#define MIO_IRQ_PIN_DESCR "Ethernet IRQ pin" +#define PWR_RST_PIN_DESCR "Ethernet RST pin" +#else // #elif CONFIG_ETH_USE_ESP32_EMAC +#define MDC_CS_PIN_DESCR "Ethernet MDC pin" +#define MIO_IRQ_PIN_DESCR "Ethernet MIO pin" +#define PWR_RST_PIN_DESCR "Ethernet Power pin" +#endif + addFormNumericBox(F("Ethernet PHY Address"), F("ethphy"), Settings.ETH_Phy_Addr, -1, 127); - addFormNote(F("I²C-address of Ethernet PHY (0 or 1 for LAN8720, 31 for TLK110, -1 autodetect)")); - addFormPinSelect(PinSelectPurpose::Ethernet, formatGpioName_output(F("Ethernet MDC pin")), F("ethmdc"), Settings.ETH_Pin_mdc); - addFormPinSelect(PinSelectPurpose::Ethernet, formatGpioName_input(F("Ethernet MIO pin")), F("ethmdio"), Settings.ETH_Pin_mdio); - addFormPinSelect(PinSelectPurpose::Ethernet, formatGpioName_output(F("Ethernet Power pin")), F("ethpower"), Settings.ETH_Pin_power); + addFormNote(F("I²C-address of Ethernet PHY" +#if CONFIG_ETH_USE_ESP32_EMAC + " (0 or 1 for LAN8720, 31 for TLK110, -1 autodetect)" +#endif + )); + addFormPinSelect(PinSelectPurpose::Ethernet, formatGpioName_output( + F(MDC_CS_PIN_DESCR)), + F("ethmdc"), Settings.ETH_Pin_mdc_cs); + addFormPinSelect(PinSelectPurpose::Ethernet, formatGpioName_input( + F(MIO_IRQ_PIN_DESCR)), + F("ethmdio"), Settings.ETH_Pin_mdio_irq); + addFormPinSelect(PinSelectPurpose::Ethernet, formatGpioName_output( + F(PWR_RST_PIN_DESCR)), + F("ethpower"), Settings.ETH_Pin_power_rst); +#if CONFIG_ETH_USE_ESP32_EMAC addRowLabel_tr_id(F("Ethernet Clock"), F("ethclock")); { const __FlashStringHelper * ethClockOptions[4] = { @@ -287,6 +350,7 @@ void handle_hardware() { }; addSelector(F("ethclock"), 4, ethClockOptions, nullptr, nullptr, static_cast(Settings.ETH_Clock_Mode), false, true); } +#endif #endif // if FEATURE_ETHERNET addFormSubHeader(F("GPIO boot states"));