diff --git a/esphome/components/ethernet/__init__.py b/esphome/components/ethernet/__init__.py index 302a7c0e7c..5fde2cf02e 100644 --- a/esphome/components/ethernet/__init__.py +++ b/esphome/components/ethernet/__init__.py @@ -13,6 +13,7 @@ from esphome.components.esp32.const import ( VARIANT_ESP32P4, VARIANT_ESP32S2, VARIANT_ESP32S3, + VARIANT_ESP32C6, ) from esphome.components.network import IPAddress from esphome.components.spi import CONF_INTERFACE_INDEX, get_spi_interface @@ -174,6 +175,12 @@ def _validate(config): f"({CORE.target_framework} {CORE.data[KEY_CORE][KEY_FRAMEWORK_VERSION]}), " f"'{CONF_INTERRUPT_PIN}' is a required option for [ethernet]." ) + if CORE.using_esp_idf and CONF_INTERFACE not in config: + variant = get_esp32_variant() + if variant in (VARIANT_ESP32C3, VARIANT_ESP32S2, VARIANT_ESP32S3, VARIANT_ESP32C6): + config[CONF_INTERFACE] = "spi2" + else: + config[CONF_INTERFACE] = "spi3" elif config[CONF_TYPE] != "OPENETH": if CONF_CLK_MODE in config: LOGGER.warning( @@ -357,11 +364,7 @@ async def to_code(config): "spi2": spi_host_device_t.SPI2_HOST, "spi3": spi_host_device_t.SPI3_HOST, } - cg.add( - var.set_interface( - map[config[CONF_INTERFACE]] - ) - ) + cg.add(var.set_interface(map[config[CONF_INTERFACE]])) add_idf_sdkconfig_option("CONFIG_ETH_USE_SPI_ETHERNET", True) add_idf_sdkconfig_option( f"CONFIG_ETH_SPI_ETHERNET_{config[CONF_TYPE]}", True diff --git a/esphome/components/ethernet/ethernet_component.cpp b/esphome/components/ethernet/ethernet_component.cpp index f2a91bfdf9..7861c5683a 100644 --- a/esphome/components/ethernet/ethernet_component.cpp +++ b/esphome/components/ethernet/ethernet_component.cpp @@ -87,17 +87,7 @@ void EthernetComponent::setup() { .intr_flags = 0, }; -#if defined(USE_ESP32_VARIANT_ESP32C3) || defined(USE_ESP32_VARIANT_ESP32S2) || defined(USE_ESP32_VARIANT_ESP32S3) || \ - defined(USE_ESP32_VARIANT_ESP32C6) - auto host = SPI2_HOST; -#else - auto host = SPI3_HOST; -#endif -#ifdef USE_ESP_IDF - if (this->interface_ != SPI_HOST_MAX) { - host = this->interface_; - } -#endif + auto host = this->interface_; err = spi_bus_initialize(host, &buscfg, SPI_DMA_CH_AUTO); ESPHL_ERROR_CHECK(err, "SPI bus initialize error");