mirror of
https://github.com/esphome/esphome.git
synced 2026-09-28 23:40:25 +00:00
moved ethernet interface choice entirely to config
verified that default choices that were made in C++ are still made now, in config. that is, c3, c6, s2 and s3 variants choose spi2 and everything else (h2) chooses spi3. these default choices can be overridden by explicit config grep -H board idf.* idf.c3.yaml: board: esp32-c3-devkitm-1 idf.c6.yaml: board: esp32-c6-devkitc-1 idf.h2.yaml: board: esp32-h2-devkitm-1 idf.s2.yaml: board: esp32-s2-saola-1 idf.s3.yaml: board: esp32-s3-devkitc-1 for y in idf.*; do esphome config $y 2>/dev/null | grep ' interface'; echo $y; done interface: spi2 idf.c3.yaml interface: spi2 idf.c6.yaml interface: spi3 idf.h2.yaml interface: spi2 idf.s2.yaml interface: spi2 idf.s3.yaml
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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");
|
||||
|
||||
Reference in New Issue
Block a user