mirror of
https://github.com/esphome/esphome.git
synced 2026-09-28 15:30:21 +00:00
remove ESP-IDF guard around ethernet interface
__init__.py new interface config is already guarded by config[CONF_TYPE] in SPI_ETHERNET_TYPES in (only) such cases, _validate will provide a default if one not in config _final_validate will use this to check for collision with spi component to_code will generate #define USE_ETHERNET_SPI ethernet_component.cpp #ifdef USE_ETHERNET_SPI is the guard we want. we don't need (and don't want) #ifdef ESP-IDF ethernet_component.h no need for using SPIInterface = spi_host_device_t; just use spi_host_device_t remove ESP_IDF guards they are all nested under USE_ETHERNET_SPI guards
This commit is contained in:
@@ -175,7 +175,7 @@ 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:
|
||||
if CONF_INTERFACE not in config:
|
||||
variant = get_esp32_variant()
|
||||
if variant in (
|
||||
VARIANT_ESP32C3,
|
||||
@@ -262,10 +262,7 @@ SPI_SCHEMA = BASE_SCHEMA.extend(
|
||||
cv.Optional(CONF_CLOCK_SPEED, default="26.67MHz"): cv.All(
|
||||
cv.frequency, cv.int_range(int(8e6), int(80e6))
|
||||
),
|
||||
cv.Optional(CONF_INTERFACE): cv.All(
|
||||
cv.only_with_framework("esp-idf"),
|
||||
cv.one_of(*SPI_INTERFACE_MAP.keys()),
|
||||
),
|
||||
cv.Optional(CONF_INTERFACE): cv.one_of(*SPI_INTERFACE_MAP.keys()),
|
||||
# Set default value (SPI_ETHERNET_DEFAULT_POLLING_INTERVAL) at _validate()
|
||||
cv.Optional(CONF_POLLING_INTERVAL): cv.All(
|
||||
cv.positive_time_period_milliseconds,
|
||||
@@ -300,14 +297,7 @@ def _final_validate(config):
|
||||
if config[CONF_TYPE] not in SPI_ETHERNET_TYPES:
|
||||
return
|
||||
if spi_configs := fv.full_config.get().get(CONF_SPI):
|
||||
if CORE.using_esp_idf and CONF_INTERFACE in config:
|
||||
spi_host = SPI_INTERFACE_MAP[config[CONF_INTERFACE]]
|
||||
else:
|
||||
variant = get_esp32_variant()
|
||||
if variant in (VARIANT_ESP32C3, VARIANT_ESP32S2, VARIANT_ESP32S3):
|
||||
spi_host = "SPI2_HOST"
|
||||
else:
|
||||
spi_host = "SPI3_HOST"
|
||||
spi_host = SPI_INTERFACE_MAP[config[CONF_INTERFACE]]
|
||||
for spi_conf in spi_configs:
|
||||
if (index := spi_conf.get(CONF_INTERFACE_INDEX)) is not None:
|
||||
interface = get_spi_interface(index)
|
||||
|
||||
@@ -385,7 +385,6 @@ void EthernetComponent::dump_config() {
|
||||
" MOSI Pin: %u\n"
|
||||
" CS Pin: %u",
|
||||
this->clk_pin_, this->miso_pin_, this->mosi_pin_, this->cs_pin_);
|
||||
#ifdef USE_ESP_IDF
|
||||
{
|
||||
constexpr std::array<char const *const, SPI_HOST_MAX> values{"spi1", "spi2", "spi3"};
|
||||
char const *const value{this->interface_ < values.size() ? values[this->interface_] : nullptr};
|
||||
@@ -393,7 +392,6 @@ void EthernetComponent::dump_config() {
|
||||
ESP_LOGCONFIG(TAG, " Interface: %s", value);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
#ifdef USE_ETHERNET_SPI_POLLING_SUPPORT
|
||||
if (this->polling_interval_ != 0) {
|
||||
ESP_LOGCONFIG(TAG, " Polling Interval: %lu ms", this->polling_interval_);
|
||||
@@ -678,9 +676,7 @@ void EthernetComponent::set_cs_pin(uint8_t cs_pin) { this->cs_pin_ = cs_pin; }
|
||||
void EthernetComponent::set_interrupt_pin(uint8_t interrupt_pin) { this->interrupt_pin_ = interrupt_pin; }
|
||||
void EthernetComponent::set_reset_pin(uint8_t reset_pin) { this->reset_pin_ = reset_pin; }
|
||||
void EthernetComponent::set_clock_speed(int clock_speed) { this->clock_speed_ = clock_speed; }
|
||||
#ifdef USE_ESP_IDF
|
||||
void EthernetComponent::set_interface(SPIInterface interface) { this->interface_ = interface; }
|
||||
#endif
|
||||
void EthernetComponent::set_interface(spi_host_device_t interface) { this->interface_ = interface; }
|
||||
#ifdef USE_ETHERNET_SPI_POLLING_SUPPORT
|
||||
void EthernetComponent::set_polling_interval(uint32_t polling_interval) { this->polling_interval_ = polling_interval; }
|
||||
#endif
|
||||
|
||||
@@ -9,8 +9,6 @@
|
||||
|
||||
#include "driver/spi_master.h"
|
||||
|
||||
using SPIInterface = spi_host_device_t;
|
||||
|
||||
#endif // USE_ESP_IDF
|
||||
|
||||
#ifdef USE_ESP32
|
||||
@@ -78,9 +76,7 @@ class EthernetComponent : public Component {
|
||||
void set_interrupt_pin(uint8_t interrupt_pin);
|
||||
void set_reset_pin(uint8_t reset_pin);
|
||||
void set_clock_speed(int clock_speed);
|
||||
#ifdef USE_ESP_IDF
|
||||
void set_interface(SPIInterface interface);
|
||||
#endif
|
||||
void set_interface(spi_host_device_t interface);
|
||||
#ifdef USE_ETHERNET_SPI_POLLING_SUPPORT
|
||||
void set_polling_interval(uint32_t polling_interval);
|
||||
#endif
|
||||
@@ -135,9 +131,7 @@ class EthernetComponent : public Component {
|
||||
int reset_pin_{-1};
|
||||
int phy_addr_spi_{-1};
|
||||
int clock_speed_;
|
||||
#ifdef USE_ESP_IDF
|
||||
SPIInterface interface_{SPI_HOST_MAX}; // Default to invalid, will be set based on ESP32 variant
|
||||
#endif
|
||||
spi_host_device_t interface_;
|
||||
#ifdef USE_ETHERNET_SPI_POLLING_SUPPORT
|
||||
uint32_t polling_interval_{0};
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user