Add KSZ8081 support. (#4668)

Co-authored-by: Your Name <you@example.com>
This commit is contained in:
Fabian 2023-04-12 23:22:08 +02:00 committed by GitHub
parent b5fbe0b145
commit 0547f2a931
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 20 additions and 4 deletions

View file

@ -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")

View file

@ -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; }

View file

@ -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<ManualIP> manual_ip_{};