mirror of
https://github.com/esphome/esphome.git
synced 2026-09-01 02:26:01 +00:00
[ethernet] Only compile JL1101 driver when needed
- Exclude esp_eth_phy_jl1101.c when JL1101 is not configured - Exclude on IDF 5.4.2-5.x where pioarduino has it builtin - Keep custom driver for IDF < 5.4.2 and IDF 6.0+ (pioarduino may not have patched JL1101 into their IDF 6.0 fork yet) - Always use esp_eth_phy_new_jl1101() in C++ (no generic fallback) - Namespace ethernet type in CORE.data[KEY_ETHERNET]
This commit is contained in:
@@ -54,6 +54,9 @@ LOGGER = logging.getLogger(__name__)
|
||||
|
||||
# Key for tracking IP state listener count in CORE.data
|
||||
ETHERNET_IP_STATE_LISTENERS_KEY = "ethernet_ip_state_listeners"
|
||||
# Key for tracking configured ethernet type
|
||||
ETHERNET_TYPE_KEY = "ethernet_type"
|
||||
KEY_ETHERNET = "ethernet"
|
||||
|
||||
|
||||
def request_ethernet_ip_state_listener() -> None:
|
||||
@@ -430,6 +433,7 @@ async def to_code(config):
|
||||
|
||||
cg.add(var.set_type(ETHERNET_TYPES[config[CONF_TYPE]]))
|
||||
cg.add(var.set_use_address(config[CONF_USE_ADDRESS]))
|
||||
CORE.data.setdefault(KEY_ETHERNET, {})[ETHERNET_TYPE_KEY] = config[CONF_TYPE]
|
||||
|
||||
if CONF_MANUAL_IP in config:
|
||||
cg.add_define("USE_ETHERNET_MANUAL_IP")
|
||||
@@ -616,15 +620,18 @@ _platform_filter = filter_source_files_from_platform(
|
||||
|
||||
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)
|
||||
# On IDF 5.4.2+ with PlatformIO, the .c file compiles to empty via
|
||||
# its own preprocessor guard (PLATFORMIO is a C-level define)
|
||||
if idf_version() >= cv.Version(6, 0, 0):
|
||||
eth_data = CORE.data.get(KEY_ETHERNET, {})
|
||||
eth_type = eth_data.get(ETHERNET_TYPE_KEY)
|
||||
# Only compile the custom JL1101 driver when JL1101 is configured
|
||||
# and pioarduino doesn't have it builtin (IDF 5.4.2 to 5.x)
|
||||
if eth_type != "JL1101":
|
||||
excluded.append("esp_eth_phy_jl1101.c")
|
||||
elif CORE.is_esp32:
|
||||
from esphome.components.esp32 import idf_version
|
||||
|
||||
ver = idf_version()
|
||||
if cv.Version(5, 4, 2) <= ver < cv.Version(6, 0, 0):
|
||||
excluded.append("esp_eth_phy_jl1101.c")
|
||||
return excluded
|
||||
|
||||
|
||||
|
||||
@@ -29,8 +29,7 @@
|
||||
#include "esp_rom_sys.h"
|
||||
#include "esp_idf_version.h"
|
||||
|
||||
#if defined(USE_ETHERNET_JL1101) && ESP_IDF_VERSION < ESP_IDF_VERSION_VAL(6, 0, 0) && \
|
||||
(ESP_IDF_VERSION < ESP_IDF_VERSION_VAL(5, 4, 2) || !defined(PLATFORMIO))
|
||||
#if defined(USE_ETHERNET_JL1101) && (ESP_IDF_VERSION < ESP_IDF_VERSION_VAL(5, 4, 2) || !defined(PLATFORMIO))
|
||||
|
||||
static const char *TAG = "jl1101";
|
||||
#define PHY_CHECK(a, str, goto_tag, ...) \
|
||||
|
||||
@@ -272,14 +272,9 @@ void EthernetComponent::setup() {
|
||||
#endif
|
||||
#ifdef USE_ETHERNET_JL1101
|
||||
case ETHERNET_TYPE_JL1101: {
|
||||
#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(6, 0, 0)
|
||||
// No registry component exists; generic PHY driver works for JL1101
|
||||
this->phy_ = esp_eth_phy_new_generic(&phy_config);
|
||||
#else
|
||||
// IDF < 5.4.2 or non-PlatformIO: uses custom ESPHome driver (esp_eth_phy_jl1101.c)
|
||||
// IDF 5.4.2+ with PlatformIO: uses builtin esp_eth_phy_new_jl1101()
|
||||
// PlatformIO (pioarduino): builtin esp_eth_phy_new_jl1101() on all IDF versions
|
||||
// Non-PlatformIO: custom ESPHome driver (esp_eth_phy_jl1101.c)
|
||||
this->phy_ = esp_eth_phy_new_jl1101(&phy_config);
|
||||
#endif
|
||||
break;
|
||||
}
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user