diff --git a/esphome/components/ethernet/__init__.py b/esphome/components/ethernet/__init__.py index ab760a9b6c..2dc3c47a5a 100644 --- a/esphome/components/ethernet/__init__.py +++ b/esphome/components/ethernet/__init__.py @@ -1,7 +1,12 @@ import logging + from esphome import pins import esphome.codegen as cg -from esphome.components.esp32 import add_idf_sdkconfig_option, get_esp32_variant +from esphome.components.esp32 import ( + add_idf_component, + add_idf_sdkconfig_option, + get_esp32_variant, +) from esphome.components.esp32.const import ( VARIANT_ESP32C3, VARIANT_ESP32S2, @@ -65,6 +70,7 @@ ETHERNET_TYPES = { "KSZ8081RNA": EthernetType.ETHERNET_TYPE_KSZ8081RNA, "W5500": EthernetType.ETHERNET_TYPE_W5500, "OPENETH": EthernetType.ETHERNET_TYPE_OPENETH, + "LAN867X": EthernetType.ETHERNET_TYPE_LAN867X, } SPI_ETHERNET_TYPES = ["W5500"] @@ -131,6 +137,9 @@ def _validate(config): else: use_address = CORE.name + config[CONF_DOMAIN] config[CONF_USE_ADDRESS] = use_address + if config.get(CONF_TYPE) == "LAN867X": + validator = cv.require_framework_version(esp_idf=cv.Version(5, 3, 0)) + validator(config) if config[CONF_TYPE] in SPI_ETHERNET_TYPES: if _is_framework_spi_polling_mode_supported(): if CONF_POLLING_INTERVAL in config and CONF_INTERRUPT_PIN in config: @@ -175,6 +184,7 @@ PHY_REGISTER_SCHEMA = cv.Schema( cv.Optional(CONF_PAGE_ID): cv.hex_int, } ) + RMII_SCHEMA = BASE_SCHEMA.extend( cv.Schema( { @@ -221,6 +231,7 @@ CONFIG_SCHEMA = cv.All( "JL1101": RMII_SCHEMA, "KSZ8081": RMII_SCHEMA, "KSZ8081RNA": RMII_SCHEMA, + "LAN867X": RMII_SCHEMA, "W5500": SPI_SCHEMA, "OPENETH": BASE_SCHEMA, }, @@ -277,6 +288,17 @@ async def to_code(config): var = cg.new_Pvariable(config[CONF_ID]) await cg.register_component(var, config) + if config[CONF_TYPE] == "LAN867X": + add_idf_component( + name="esp-eth-drivers", + repo="https://github.com/espressif/esp-eth-drivers.git", + ref="master", + path="lan867x", + ) + add_idf_sdkconfig_option("CONFIG_GPIO_CTRL_FUNC_IN_IRAM", True) + add_idf_sdkconfig_option("CONFIG_ETHERNET_INTERNAL_SUPPORT", True) + add_idf_sdkconfig_option("CONFIG_ETHERNET_PHY_LAN867X", True) + if config[CONF_TYPE] == "W5500": cg.add(var.set_clk_pin(config[CONF_CLK_PIN])) cg.add(var.set_miso_pin(config[CONF_MISO_PIN])) diff --git a/esphome/components/ethernet/ethernet_component.cpp b/esphome/components/ethernet/ethernet_component.cpp index 08f5fa6642..1f2b5b298e 100644 --- a/esphome/components/ethernet/ethernet_component.cpp +++ b/esphome/components/ethernet/ethernet_component.cpp @@ -191,6 +191,12 @@ void EthernetComponent::setup() { this->phy_ = esp_eth_phy_new_w5500(&phy_config); break; } +#endif +#if ESP_IDF_VERSION_MAJOR >= 5 && ESP_IDF_VERSION_MINOR >= 3 + case ETHERNET_TYPE_LAN867X: { + this->phy_ = esp_eth_phy_new_lan867x(&phy_config); + break; + } #endif default: { this->mark_failed(); @@ -318,6 +324,10 @@ void EthernetComponent::dump_config() { eth_type = "OPENETH"; break; + case ETHERNET_TYPE_LAN867X: + eth_type = "LAN867X"; + break; + default: eth_type = "Unknown"; break; diff --git a/esphome/components/ethernet/ethernet_component.h b/esphome/components/ethernet/ethernet_component.h index fb178431d5..a500c706d8 100644 --- a/esphome/components/ethernet/ethernet_component.h +++ b/esphome/components/ethernet/ethernet_component.h @@ -12,6 +12,10 @@ #include "esp_netif.h" #include "esp_mac.h" +#if ESP_IDF_VERSION_MAJOR >= 5 && ESP_IDF_VERSION_MINOR >= 3 +#include "esp_eth_phy_lan867x.h" +#endif + namespace esphome { namespace ethernet { @@ -26,6 +30,7 @@ enum EthernetType { ETHERNET_TYPE_KSZ8081RNA, ETHERNET_TYPE_W5500, ETHERNET_TYPE_OPENETH, + ETHERNET_TYPE_LAN867X, }; struct ManualIP {