mirror of
https://github.com/esphome/esphome.git
synced 2025-09-26 23:22:21 +01:00
[ethernet] Add LAN8670 PHY support (#10874)
Co-authored-by: J. Nick Koston <nick@home-assistant.io>
This commit is contained in:
committed by
GitHub
parent
cef9cf49bf
commit
460eb219ba
@@ -2,9 +2,15 @@ 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_ESP32,
|
||||
VARIANT_ESP32C3,
|
||||
VARIANT_ESP32P4,
|
||||
VARIANT_ESP32S2,
|
||||
VARIANT_ESP32S3,
|
||||
)
|
||||
@@ -75,12 +81,14 @@ ETHERNET_TYPES = {
|
||||
"W5500": EthernetType.ETHERNET_TYPE_W5500,
|
||||
"OPENETH": EthernetType.ETHERNET_TYPE_OPENETH,
|
||||
"DM9051": EthernetType.ETHERNET_TYPE_DM9051,
|
||||
"LAN8670": EthernetType.ETHERNET_TYPE_LAN8670,
|
||||
}
|
||||
|
||||
# PHY types that need compile-time defines for conditional compilation
|
||||
_PHY_TYPE_TO_DEFINE = {
|
||||
"KSZ8081": "USE_ETHERNET_KSZ8081",
|
||||
"KSZ8081RNA": "USE_ETHERNET_KSZ8081",
|
||||
"LAN8670": "USE_ETHERNET_LAN8670",
|
||||
# Add other PHY types here only if they need conditional compilation
|
||||
}
|
||||
|
||||
@@ -136,6 +144,14 @@ def _validate(config):
|
||||
else:
|
||||
use_address = CORE.name + config[CONF_DOMAIN]
|
||||
config[CONF_USE_ADDRESS] = use_address
|
||||
|
||||
# Validate LAN8670 is only used with ESP32 classic or ESP32-P4
|
||||
if config[CONF_TYPE] == "LAN8670":
|
||||
variant = get_esp32_variant()
|
||||
if variant not in (VARIANT_ESP32, VARIANT_ESP32P4):
|
||||
raise cv.Invalid(
|
||||
f"LAN8670 PHY is only supported on ESP32 classic and ESP32-P4, not {variant}"
|
||||
)
|
||||
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:
|
||||
@@ -248,6 +264,7 @@ CONFIG_SCHEMA = cv.All(
|
||||
"W5500": SPI_SCHEMA,
|
||||
"OPENETH": BASE_SCHEMA,
|
||||
"DM9051": SPI_SCHEMA,
|
||||
"LAN8670": RMII_SCHEMA,
|
||||
},
|
||||
upper=True,
|
||||
),
|
||||
@@ -356,5 +373,9 @@ async def to_code(config):
|
||||
# Also disable WiFi/BT coexistence since WiFi is disabled
|
||||
add_idf_sdkconfig_option("CONFIG_SW_COEXIST_ENABLE", False)
|
||||
|
||||
if config[CONF_TYPE] == "LAN8670":
|
||||
# Add LAN867x 10BASE-T1S PHY support component
|
||||
add_idf_component(name="espressif/lan867x", ref="2.0.0")
|
||||
|
||||
if CORE.using_arduino:
|
||||
cg.add_library("WiFi", None)
|
||||
|
@@ -9,6 +9,10 @@
|
||||
#include <cinttypes>
|
||||
#include "esp_event.h"
|
||||
|
||||
#ifdef USE_ETHERNET_LAN8670
|
||||
#include "esp_eth_phy_lan867x.h"
|
||||
#endif
|
||||
|
||||
#ifdef USE_ETHERNET_SPI
|
||||
#include <driver/gpio.h>
|
||||
#include <driver/spi_master.h>
|
||||
@@ -200,6 +204,12 @@ void EthernetComponent::setup() {
|
||||
this->phy_ = esp_eth_phy_new_ksz80xx(&phy_config);
|
||||
break;
|
||||
}
|
||||
#ifdef USE_ETHERNET_LAN8670
|
||||
case ETHERNET_TYPE_LAN8670: {
|
||||
this->phy_ = esp_eth_phy_new_lan867x(&phy_config);
|
||||
break;
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
#ifdef USE_ETHERNET_SPI
|
||||
#if CONFIG_ETH_SPI_ETHERNET_W5500
|
||||
@@ -353,6 +363,12 @@ void EthernetComponent::dump_config() {
|
||||
eth_type = "DM9051";
|
||||
break;
|
||||
|
||||
#ifdef USE_ETHERNET_LAN8670
|
||||
case ETHERNET_TYPE_LAN8670:
|
||||
eth_type = "LAN8670";
|
||||
break;
|
||||
#endif
|
||||
|
||||
default:
|
||||
eth_type = "Unknown";
|
||||
break;
|
||||
|
@@ -28,6 +28,7 @@ enum EthernetType : uint8_t {
|
||||
ETHERNET_TYPE_W5500,
|
||||
ETHERNET_TYPE_OPENETH,
|
||||
ETHERNET_TYPE_DM9051,
|
||||
ETHERNET_TYPE_LAN8670,
|
||||
};
|
||||
|
||||
struct ManualIP {
|
||||
|
@@ -19,3 +19,7 @@ dependencies:
|
||||
- if: "target in [esp32h2, esp32p4]"
|
||||
zorxx/multipart-parser:
|
||||
version: 1.0.1
|
||||
espressif/lan867x:
|
||||
version: "2.0.0"
|
||||
rules:
|
||||
- if: "target in [esp32, esp32p4]"
|
||||
|
14
tests/components/ethernet/common-lan8670.yaml
Normal file
14
tests/components/ethernet/common-lan8670.yaml
Normal file
@@ -0,0 +1,14 @@
|
||||
ethernet:
|
||||
type: LAN8670
|
||||
mdc_pin: 23
|
||||
mdio_pin: 25
|
||||
clk:
|
||||
pin: 0
|
||||
mode: CLK_EXT_IN
|
||||
phy_addr: 0
|
||||
power_pin: 26
|
||||
manual_ip:
|
||||
static_ip: 192.168.178.56
|
||||
gateway: 192.168.178.1
|
||||
subnet: 255.255.255.0
|
||||
domain: .local
|
1
tests/components/ethernet/test-lan8670.esp32-ard.yaml
Normal file
1
tests/components/ethernet/test-lan8670.esp32-ard.yaml
Normal file
@@ -0,0 +1 @@
|
||||
<<: !include common-lan8670.yaml
|
1
tests/components/ethernet/test-lan8670.esp32-idf.yaml
Normal file
1
tests/components/ethernet/test-lan8670.esp32-idf.yaml
Normal file
@@ -0,0 +1 @@
|
||||
<<: !include common-lan8670.yaml
|
Reference in New Issue
Block a user