From d27b3e8c0f386a11596df3e3fe4ee2a1dd304a1f Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Sun, 15 Mar 2026 17:01:17 -1000 Subject: [PATCH] [ethernet] Add explicit PHY/MAC includes and exclude JL1101 driver when unused - Add explicit includes for per-chip PHY/MAC headers (required on IDF 6.0 where they are no longer pulled in via esp_eth.h, also works on IDF 5.x) - Exclude esp_eth_phy_jl1101.c from compilation on IDF >= 6.0 (uses generic PHY) and IDF >= 5.4.2 with PlatformIO (uses builtin driver) --- esphome/components/ethernet/__init__.py | 24 ++++++++++++++++++- .../ethernet/ethernet_component_esp32.cpp | 23 ++++++++++++++++++ 2 files changed, 46 insertions(+), 1 deletion(-) diff --git a/esphome/components/ethernet/__init__.py b/esphome/components/ethernet/__init__.py index ba8830948ac..20e79279ff7 100644 --- a/esphome/components/ethernet/__init__.py +++ b/esphome/components/ethernet/__init__.py @@ -600,11 +600,33 @@ async def final_step(): cg.add_define("ESPHOME_ETHERNET_IP_STATE_LISTENERS", ip_state_count) -FILTER_SOURCE_FILES = filter_source_files_from_platform( +_platform_filter = filter_source_files_from_platform( { "ethernet_component_esp32.cpp": { PlatformFramework.ESP32_IDF, PlatformFramework.ESP32_ARDUINO, }, + "esp_eth_phy_jl1101.c": { + PlatformFramework.ESP32_IDF, + PlatformFramework.ESP32_ARDUINO, + }, } ) + + +def _filter_source_files() -> list[str]: + excluded = _platform_filter() + if not CORE.is_esp32: + return excluded + from esphome.components.esp32 import idf_version + + # Custom JL1101 driver not needed on IDF >= 6.0 (uses generic PHY) + # or IDF >= 5.4.2 with PlatformIO (uses builtin driver) + if idf_version() >= cv.Version(6, 0, 0) or ( + idf_version() >= cv.Version(5, 4, 2) and CORE.using_platformio + ): + excluded.append("esp_eth_phy_jl1101.c") + return excluded + + +FILTER_SOURCE_FILES = _filter_source_files diff --git a/esphome/components/ethernet/ethernet_component_esp32.cpp b/esphome/components/ethernet/ethernet_component_esp32.cpp index 82ac69f4b9b..212a60356eb 100644 --- a/esphome/components/ethernet/ethernet_component_esp32.cpp +++ b/esphome/components/ethernet/ethernet_component_esp32.cpp @@ -10,9 +10,32 @@ #include #include "esp_event.h" +#ifdef USE_ETHERNET_LAN8720 +#include "esp_eth_phy_lan87xx.h" +#endif +#ifdef USE_ETHERNET_RTL8201 +#include "esp_eth_phy_rtl8201.h" +#endif +#ifdef USE_ETHERNET_DP83848 +#include "esp_eth_phy_dp83848.h" +#endif +#ifdef USE_ETHERNET_IP101 +#include "esp_eth_phy_ip101.h" +#endif +#ifdef USE_ETHERNET_KSZ8081 +#include "esp_eth_phy_ksz80xx.h" +#endif #ifdef USE_ETHERNET_LAN8670 #include "esp_eth_phy_lan867x.h" #endif +#ifdef USE_ETHERNET_W5500 +#include "esp_eth_mac_w5500.h" +#include "esp_eth_phy_w5500.h" +#endif +#ifdef USE_ETHERNET_DM9051 +#include "esp_eth_mac_dm9051.h" +#include "esp_eth_phy_dm9051.h" +#endif #ifdef USE_ETHERNET_SPI #include