diff --git a/tasmota/include/tasmota_globals.h b/tasmota/include/tasmota_globals.h index 7a7492877..5640460c8 100644 --- a/tasmota/include/tasmota_globals.h +++ b/tasmota/include/tasmota_globals.h @@ -54,13 +54,13 @@ void InfluxDbProcess(bool use_copy = false); #endif #ifdef ESP32 -#if CONFIG_IDF_TARGET_ESP32 // ESP32/PICO-D4 +//#if CONFIG_IDF_TARGET_ESP32 // ESP32/PICO-D4 #ifdef USE_ETHERNET IPAddress EthernetLocalIP(void); char* EthernetHostname(void); String EthernetMacAddress(void); #endif // USE_ETHERNET -#endif // CONFIG_IDF_TARGET_ESP32 +//#endif // CONFIG_IDF_TARGET_ESP32 #endif // ESP32 /*********************************************************************************************\ @@ -129,9 +129,9 @@ String EthernetMacAddress(void); #else // Disable features not present in other ESP32 like ESP32C3, ESP32S2, ESP32S3 etc. -#ifdef USE_ETHERNET -#undef USE_ETHERNET // All non-ESP32 do not support ethernet -#endif +//#ifdef USE_ETHERNET +//#undef USE_ETHERNET // All non-ESP32 do not support ethernet +//#endif #endif // CONFIG_IDF_TARGET_ESP32 /*-------------------------------------------------------------------------------------------*\ diff --git a/tasmota/tasmota_support/support_command.ino b/tasmota/tasmota_support/support_command.ino index 3bd08cef3..21a7a21cf 100644 --- a/tasmota/tasmota_support/support_command.ino +++ b/tasmota/tasmota_support/support_command.ino @@ -952,7 +952,8 @@ void CmndStatus(void) #ifdef USE_TASMESH ResponseAppend_P(PSTR(",\"SoftAPMac\":\"%s\""), WiFi.softAPmacAddress().c_str()); #endif // USE_TASMESH -#if defined(ESP32) && CONFIG_IDF_TARGET_ESP32 && defined(USE_ETHERNET) +//#if defined(ESP32) && CONFIG_IDF_TARGET_ESP32 && defined(USE_ETHERNET) +#if defined(ESP32) && defined(USE_ETHERNET) #ifdef USE_IPV6 ResponseAppend_P(PSTR(",\"Ethernet\":{\"" D_CMND_HOSTNAME "\":\"%s\",\"" D_CMND_IPADDRESS "\":\"%_I\",\"" D_JSON_GATEWAY "\":\"%_I\",\"" D_JSON_SUBNETMASK "\":\"%_I\",\"" diff --git a/tasmota/tasmota_support/support_wifi.ino b/tasmota/tasmota_support/support_wifi.ino index 33c5622e3..a1e7f02d0 100644 --- a/tasmota/tasmota_support/support_wifi.ino +++ b/tasmota/tasmota_support/support_wifi.ino @@ -525,7 +525,8 @@ String WifiGetIPv4Str(void) bool EthernetGetIPv4(IPAddress *ip) { -#if defined(ESP32) && CONFIG_IDF_TARGET_ESP32 && defined(USE_ETHERNET) +//#if defined(ESP32) && CONFIG_IDF_TARGET_ESP32 && defined(USE_ETHERNET) +#if defined(ESP32) && defined(USE_ETHERNET) uint32_t wifi_uint = (uint32_t) EthernetLocalIP(); if (ip != nullptr) { *ip = wifi_uint; } return wifi_uint != 0; @@ -661,7 +662,8 @@ void WifiDumpAddressesIPv6(void) } AddLog(LOG_LEVEL_DEBUG, "IP : DNS: %s %s", IPAddress(dns_getserver(0)).toString().c_str(), IPAddress(dns_getserver(1)).toString(true).c_str()); AddLog(LOG_LEVEL_DEBUG, "WIF: v4IP: %_I v6IP: %s mainIP: %s", (uint32_t) WiFi.localIP(), WifiGetIPv6Str().c_str(), WifiGetIPStr().c_str()); -#if defined(ESP32) && CONFIG_IDF_TARGET_ESP32 && defined(USE_ETHERNET) +//#if defined(ESP32) && CONFIG_IDF_TARGET_ESP32 && defined(USE_ETHERNET) +#if defined(ESP32) && defined(USE_ETHERNET) AddLog(LOG_LEVEL_DEBUG, "ETH: v4IP %_I v6IP: %s mainIP: %s", (uint32_t) EthernetLocalIP(), EthernetGetIPv6Str().c_str(), EthernetGetIPStr().c_str()); #endif AddLog(LOG_LEVEL_DEBUG, "IP : ListeningIP %s", IPGetListeningAddressStr().c_str()); @@ -681,7 +683,8 @@ bool IPGetListeningAddress(IPAddress * ip) IPAddress ip_wifi; bool has_wifi = WifiGetIP(&ip_wifi); -#if defined(ESP32) && CONFIG_IDF_TARGET_ESP32 && defined(USE_ETHERNET) +//#if defined(ESP32) && CONFIG_IDF_TARGET_ESP32 && defined(USE_ETHERNET) +#if defined(ESP32) && defined(USE_ETHERNET) IPAddress ip_eth; bool has_eth = EthernetGetIP(&ip_eth); if (has_wifi && has_eth) { @@ -700,7 +703,8 @@ bool IPGetListeningAddress(IPAddress * ip) *ip = IPAddress(); return false; #else // USE_IPV6 -#if defined(ESP32) && CONFIG_IDF_TARGET_ESP32 && defined(USE_ETHERNET) +//#if defined(ESP32) && CONFIG_IDF_TARGET_ESP32 && defined(USE_ETHERNET) +#if defined(ESP32) && defined(USE_ETHERNET) if (EthernetGetIP(ip)) { return true; } #endif if (WifiGetIP(ip)) { return true; } @@ -804,7 +808,8 @@ String WifiGetIPStr(void) // Has a routable IP, whether IPv4 or IPv6, Wifi or Ethernet bool HasIP(void) { if (WifiHasIP()) return true; -#if defined(ESP32) && CONFIG_IDF_TARGET_ESP32 && defined(USE_ETHERNET) +//#if defined(ESP32) && CONFIG_IDF_TARGET_ESP32 && defined(USE_ETHERNET) +#if defined(ESP32) && defined(USE_ETHERNET) if (EthernetHasIP()) return true; #endif return false; diff --git a/tasmota/tasmota_xdrv_driver/xdrv_01_9_webserver.ino b/tasmota/tasmota_xdrv_driver/xdrv_01_9_webserver.ino index 4bb006d75..1124a60ea 100644 --- a/tasmota/tasmota_xdrv_driver/xdrv_01_9_webserver.ino +++ b/tasmota/tasmota_xdrv_driver/xdrv_01_9_webserver.ino @@ -718,7 +718,8 @@ bool HttpCheckPriviledgedAccess(bool autorequestauth = true) if ((referer.indexOf(hostname) == 7) || (referer.indexOf(WiFi.localIP().toString()) == 7)) { return true; } -#if defined(ESP32) && CONFIG_IDF_TARGET_ESP32 && defined(USE_ETHERNET) +//#if defined(ESP32) && CONFIG_IDF_TARGET_ESP32 && defined(USE_ETHERNET) +#if defined(ESP32) && defined(USE_ETHERNET) hostname = EthernetHostname(); hostname.toUpperCase(); // TODO rework if IPv6 @@ -934,7 +935,8 @@ void WSContentSendStyle_P(const char* formatP, ...) { (lip && sip) ? ", " : "", (sip) ? WiFi.softAPIP().toString().c_str() : ""); } -#if defined(ESP32) && CONFIG_IDF_TARGET_ESP32 && defined(USE_ETHERNET) +//#if defined(ESP32) && CONFIG_IDF_TARGET_ESP32 && defined(USE_ETHERNET) +#if defined(ESP32) && defined(USE_ETHERNET) eip = EthernetHasIP(); if (eip) { WSContentSend_P(PSTR("%s%s%s (%s)"), // tasmota-eth.local (192.168.2.13) @@ -2469,7 +2471,8 @@ void HandleInformation(void) { WSContentSend_P(PSTR("}1" D_DNS_SERVER "2}2%_I"), Settings->ipv4_address[4]); #endif // USE_IPV6 } -#if defined(ESP32) && CONFIG_IDF_TARGET_ESP32 && defined(USE_ETHERNET) +//#if defined(ESP32) && CONFIG_IDF_TARGET_ESP32 && defined(USE_ETHERNET) +#if defined(ESP32) && defined(USE_ETHERNET) if (EthernetHasIP()) { if (show_hr) { WSContentSeparatorIThin(); diff --git a/tasmota/tasmota_xdrv_driver/xdrv_02_9_mqtt.ino b/tasmota/tasmota_xdrv_driver/xdrv_02_9_mqtt.ino index 047a9eb5f..d0b2d2d4c 100644 --- a/tasmota/tasmota_xdrv_driver/xdrv_02_9_mqtt.ino +++ b/tasmota/tasmota_xdrv_driver/xdrv_02_9_mqtt.ino @@ -980,7 +980,8 @@ void MqttConnected(void) { ResponseAppend_P(PSTR(",\"" D_JSON_IP6_LOCAL "\":\"%s\""), WifiGetIPv6LinkLocalStr().c_str()); #endif // USE_IPV6 } -#if defined(ESP32) && CONFIG_IDF_TARGET_ESP32 && defined(USE_ETHERNET) +//#if defined(ESP32) && CONFIG_IDF_TARGET_ESP32 && defined(USE_ETHERNET) +#if defined(ESP32) && defined(USE_ETHERNET) if (static_cast(EthernetLocalIP()) != 0) { ResponseAppend_P(PSTR(",\"Ethernet\":{\"" D_CMND_HOSTNAME "\":\"%s\",\"" D_CMND_IPADDRESS "\":\"%_I\"}"), EthernetHostname(), (uint32_t)EthernetLocalIP()); diff --git a/tasmota/tasmota_xdrv_driver/xdrv_10_rules.ino b/tasmota/tasmota_xdrv_driver/xdrv_10_rules.ino index f65484f86..903262d5a 100644 --- a/tasmota/tasmota_xdrv_driver/xdrv_10_rules.ino +++ b/tasmota/tasmota_xdrv_driver/xdrv_10_rules.ino @@ -1055,7 +1055,8 @@ void RulesEvery50ms(void) TasmotaGlobal.rules_flag.wifi_disconnected = 0; strncpy_P(json_event, PSTR("{\"WIFI\":{\"Disconnected\":1}}"), sizeof(json_event)); } -#if defined(ESP32) && CONFIG_IDF_TARGET_ESP32 && defined(USE_ETHERNET) +//#if defined(ESP32) && CONFIG_IDF_TARGET_ESP32 && defined(USE_ETHERNET) +#if defined(ESP32) && defined(USE_ETHERNET) else if (TasmotaGlobal.rules_flag.eth_connected) { TasmotaGlobal.rules_flag.eth_connected = 0; strncpy_P(json_event, PSTR("{\"ETH\":{\"Connected\":1}}"), sizeof(json_event)); diff --git a/tasmota/tasmota_xdrv_driver/xdrv_12_discovery.ino b/tasmota/tasmota_xdrv_driver/xdrv_12_discovery.ino index 07e963088..07da9257c 100644 --- a/tasmota/tasmota_xdrv_driver/xdrv_12_discovery.ino +++ b/tasmota/tasmota_xdrv_driver/xdrv_12_discovery.ino @@ -35,7 +35,8 @@ void TasDiscoverMessage(void) { uint32_t ip_address = (uint32_t)WiFi.localIP(); char* hostname = TasmotaGlobal.hostname; -#if defined(ESP32) && CONFIG_IDF_TARGET_ESP32 && defined(USE_ETHERNET) +//#if defined(ESP32) && CONFIG_IDF_TARGET_ESP32 && defined(USE_ETHERNET) +#if defined(ESP32) && defined(USE_ETHERNET) if (static_cast(EthernetLocalIP()) != 0) { ip_address = (uint32_t)EthernetLocalIP(); hostname = EthernetHostname(); diff --git a/tasmota/tasmota_xdrv_driver/xdrv_12_home_assistant.ino b/tasmota/tasmota_xdrv_driver/xdrv_12_home_assistant.ino index a58983ec2..7dcc10657 100644 --- a/tasmota/tasmota_xdrv_driver/xdrv_12_home_assistant.ino +++ b/tasmota/tasmota_xdrv_driver/xdrv_12_home_assistant.ino @@ -229,7 +229,8 @@ int hass_tele_period = 0; void HassDiscoverMessage(void) { uint32_t ip_address = (uint32_t)WiFi.localIP(); char* hostname = TasmotaGlobal.hostname; -#if defined(ESP32) && CONFIG_IDF_TARGET_ESP32 && defined(USE_ETHERNET) +//#if defined(ESP32) && CONFIG_IDF_TARGET_ESP32 && defined(USE_ETHERNET) +#if defined(ESP32) && defined(USE_ETHERNET) if (static_cast(EthernetLocalIP()) != 0) { ip_address = (uint32_t)EthernetLocalIP(); hostname = EthernetHostname(); diff --git a/tasmota/tasmota_xdrv_driver/xdrv_82_esp32_ethernet.ino b/tasmota/tasmota_xdrv_driver/xdrv_82_esp32_ethernet.ino index 9ea0e8f89..efac2c528 100644 --- a/tasmota/tasmota_xdrv_driver/xdrv_82_esp32_ethernet.ino +++ b/tasmota/tasmota_xdrv_driver/xdrv_82_esp32_ethernet.ino @@ -18,12 +18,12 @@ */ #ifdef ESP32 -#if CONFIG_IDF_TARGET_ESP32 +//#if CONFIG_IDF_TARGET_ESP32 #ifdef USE_ETHERNET /*********************************************************************************************\ * Ethernet support for ESP32 * - * Dedicated fixed Phy pins + * Dedicated fixed Phy pins (EMAC) * GPIO17 - EMAC_CLK_OUT_180 * GPIO19 - EMAC_TXD0(RMII) * GPIO21 - EMAC_TX_EN(RMII) @@ -55,6 +55,13 @@ * #define ETH_CLKMODE ETH_CLOCK_GPIO0_IN * #define ETH_ADDRESS 1 * + * Used SPI + * SPI_MOSI + * SPI_MISO + * SPI_CLK + * SPI_RST = Tasmota ETH_POWER + * SPI_IRQ = Tasmota ETH_MDIO + * SPI_CS = Tasmota ETH_MDC \*********************************************************************************************/ #define XDRV_82 82 @@ -187,18 +194,26 @@ void EthernetSetIp(void) { void EthernetInit(void) { if (!Settings->flag4.network_ethernet) { return; } + int eth_type = Settings->eth_type; +#if CONFIG_ETH_USE_ESP32_EMAC if (WT32_ETH01 == TasmotaGlobal.module_type) { Settings->eth_address = 1; // EthAddress Settings->eth_type = ETH_PHY_LAN8720; // EthType Settings->eth_clk_mode = ETH_CLOCK_GPIO0_IN; // EthClockMode } +#else // No CONFIG_ETH_USE_ESP32_EMAC + if (Settings->eth_type < 7) { + Settings->eth_type = 8; // Select W5500 (SPI) for non-EMAC hardware + } + eth_type = Settings->eth_type -7; // As No EMAC support substract EMAC enums (According ETH.cpp debug info) +#endif // CONFIG_ETH_USE_ESP32_EMAC if (!PinUsed(GPIO_ETH_PHY_MDC) && !PinUsed(GPIO_ETH_PHY_MDIO)) { if (Settings->eth_type < 7) { // CONFIG_ETH_USE_ESP32_EMAC AddLog(LOG_LEVEL_DEBUG, PSTR(D_LOG_ETH "No ETH MDC and ETH MDIO GPIO defined")); } else { - // CONFIG_ETH_SPI_ETHERNET + // ETH_SPI_SUPPORTS_CUSTOM if (!PinUsed(GPIO_ETH_PHY_POWER)) { AddLog(LOG_LEVEL_DEBUG, PSTR(D_LOG_ETH "No ETH MDC (SPI CS), ETH MDIO (SPI IRQ) and ETH POWER (SPI RST) GPIO defined")); } @@ -220,15 +235,18 @@ void EthernetInit(void) { bool init_ok = false; #if ESP_IDF_VERSION_MAJOR >= 5 if (Settings->eth_type < 7) { - // CONFIG_ETH_USE_ESP32_EMAC - init_ok = (ETH.begin((eth_phy_type_t)Settings->eth_type, Settings->eth_address, eth_mdc, eth_mdio, eth_power, (eth_clock_mode_t)Settings->eth_clk_mode)); +#if CONFIG_ETH_USE_ESP32_EMAC + init_ok = (ETH.begin((eth_phy_type_t)eth_type, Settings->eth_address, eth_mdc, eth_mdio, eth_power, (eth_clock_mode_t)Settings->eth_clk_mode)); +#endif // CONFIG_ETH_USE_ESP32_EMAC } else { - // CONFIG_ETH_SPI_ETHERNET - init_ok = (ETH.begin((eth_phy_type_t)Settings->eth_type, Settings->eth_address, eth_mdc, eth_mdio, eth_power, SPI, ETH_PHY_SPI_FREQ_MHZ)); + // ETH_SPI_SUPPORTS_CUSTOM +// SPISettings(ETH_PHY_SPI_FREQ_MHZ * 1000 * 1000, MSBFIRST, SPI_MODE0); // 20MHz + SPI.begin(Pin(GPIO_SPI_CLK), Pin(GPIO_SPI_MISO), Pin(GPIO_SPI_MOSI), -1); + init_ok = (ETH.begin((eth_phy_type_t)eth_type, Settings->eth_address, eth_mdc, eth_mdio, eth_power, SPI, ETH_PHY_SPI_FREQ_MHZ)); } #else init_ok = (ETH.begin(Settings->eth_address, eth_power, eth_mdc, eth_mdio, (eth_phy_type_t)Settings->eth_type, (eth_clock_mode_t)Settings->eth_clk_mode)); -#endif +#endif // ESP_IDF_VERSION_MAJOR >= 5 if (!init_ok) { AddLog(LOG_LEVEL_DEBUG, PSTR(D_LOG_ETH "Bad PHY type or init error")); return; @@ -402,5 +420,5 @@ bool Xdrv82(uint32_t function) { } #endif // USE_ETHERNET -#endif // CONFIG_IDF_TARGET_ESP32 +//#endif // CONFIG_IDF_TARGET_ESP32 #endif // ESP32