diff --git a/esphome/components/ethernet/__init__.py b/esphome/components/ethernet/__init__.py index f6ca376681..bedc0a4c30 100644 --- a/esphome/components/ethernet/__init__.py +++ b/esphome/components/ethernet/__init__.py @@ -34,6 +34,7 @@ ETHERNET_TYPES = { "DP83848": EthernetType.ETHERNET_TYPE_DP83848, "IP101": EthernetType.ETHERNET_TYPE_IP101, "JL1101": EthernetType.ETHERNET_TYPE_JL1101, + "KSZ8081": EthernetType.ETHERNET_TYPE_KSZ8081, } emac_rmii_clock_mode_t = cg.global_ns.enum("emac_rmii_clock_mode_t") diff --git a/esphome/components/ethernet/ethernet_component.cpp b/esphome/components/ethernet/ethernet_component.cpp index 4792728a71..8eb4718f49 100644 --- a/esphome/components/ethernet/ethernet_component.cpp +++ b/esphome/components/ethernet/ethernet_component.cpp @@ -74,6 +74,10 @@ void EthernetComponent::setup() { phy = esp_eth_phy_new_jl1101(&phy_config); break; } + case ETHERNET_TYPE_KSZ8081: { + phy = esp_eth_phy_new_ksz8081(&phy_config); + break; + } default: { this->mark_failed(); return; @@ -140,7 +144,7 @@ void EthernetComponent::loop() { } void EthernetComponent::dump_config() { - std::string eth_type; + const char *eth_type; switch (this->type_) { case ETHERNET_TYPE_LAN8720: eth_type = "LAN8720"; @@ -158,6 +162,14 @@ void EthernetComponent::dump_config() { eth_type = "IP101"; break; + case ETHERNET_TYPE_JL1101: + eth_type = "JL1101"; + break; + + case ETHERNET_TYPE_KSZ8081: + eth_type = "KSZ8081"; + break; + default: eth_type = "Unknown"; break; @@ -170,7 +182,8 @@ void EthernetComponent::dump_config() { } ESP_LOGCONFIG(TAG, " MDC Pin: %u", this->mdc_pin_); ESP_LOGCONFIG(TAG, " MDIO Pin: %u", this->mdio_pin_); - ESP_LOGCONFIG(TAG, " Type: %s", eth_type.c_str()); + ESP_LOGCONFIG(TAG, " Type: %s", eth_type); + ESP_LOGCONFIG(TAG, " PHY addr: %u", this->phy_addr_); } float EthernetComponent::get_setup_priority() const { return setup_priority::WIFI; } diff --git a/esphome/components/ethernet/ethernet_component.h b/esphome/components/ethernet/ethernet_component.h index 872ed17044..0d9ebf29a8 100644 --- a/esphome/components/ethernet/ethernet_component.h +++ b/esphome/components/ethernet/ethernet_component.h @@ -14,11 +14,13 @@ namespace esphome { namespace ethernet { enum EthernetType { - ETHERNET_TYPE_LAN8720 = 0, + ETHERNET_TYPE_UNKNOWN = 0, + ETHERNET_TYPE_LAN8720, ETHERNET_TYPE_RTL8201, ETHERNET_TYPE_DP83848, ETHERNET_TYPE_IP101, ETHERNET_TYPE_JL1101, + ETHERNET_TYPE_KSZ8081, }; struct ManualIP { @@ -69,7 +71,7 @@ class EthernetComponent : public Component { int power_pin_{-1}; uint8_t mdc_pin_{23}; uint8_t mdio_pin_{18}; - EthernetType type_{ETHERNET_TYPE_LAN8720}; + EthernetType type_{ETHERNET_TYPE_UNKNOWN}; emac_rmii_clock_mode_t clk_mode_{EMAC_CLK_EXT_IN}; emac_rmii_clock_gpio_t clk_gpio_{EMAC_CLK_IN_GPIO}; optional manual_ip_{};