mirror of https://github.com/esphome/esphome.git
[ethernet] Add DM9051 support
Fixes https://github.com/esphome/feature-requests/issues/2427 Tested on an ETH01-Evo board using ethernet: type: DM9051 clk_pin: GPIO07 mosi_pin: GPIO10 miso_pin: GPIO03 cs_pin: GPIO09 interrupt_pin: GPIO08 reset_pin: GPIO06 clock_speed: 20MHz A number of read errors was observed with 26 MHz (default) or higher clock speeds. This might be a board specific problem. Signed-off-by: Bjørn Mork <bjorn@mork.no>
This commit is contained in:
parent
3db2bb7229
commit
73afc8ec5e
|
@ -54,9 +54,10 @@ ETHERNET_TYPES = {
|
|||
"KSZ8081": EthernetType.ETHERNET_TYPE_KSZ8081,
|
||||
"KSZ8081RNA": EthernetType.ETHERNET_TYPE_KSZ8081RNA,
|
||||
"W5500": EthernetType.ETHERNET_TYPE_W5500,
|
||||
"DM9051": EthernetType.ETHERNET_TYPE_DM9051,
|
||||
}
|
||||
|
||||
SPI_ETHERNET_TYPES = ["W5500"]
|
||||
SPI_ETHERNET_TYPES = ["W5500", "DM9051"]
|
||||
|
||||
emac_rmii_clock_mode_t = cg.global_ns.enum("emac_rmii_clock_mode_t")
|
||||
emac_rmii_clock_gpio_t = cg.global_ns.enum("emac_rmii_clock_gpio_t")
|
||||
|
@ -158,6 +159,7 @@ CONFIG_SCHEMA = cv.All(
|
|||
"KSZ8081": RMII_SCHEMA,
|
||||
"KSZ8081RNA": RMII_SCHEMA,
|
||||
"W5500": SPI_SCHEMA,
|
||||
"DM9051": SPI_SCHEMA,
|
||||
},
|
||||
upper=True,
|
||||
),
|
||||
|
@ -203,7 +205,7 @@ async def to_code(config):
|
|||
var = cg.new_Pvariable(config[CONF_ID])
|
||||
await cg.register_component(var, config)
|
||||
|
||||
if config[CONF_TYPE] == "W5500":
|
||||
if config[CONF_TYPE] in SPI_ETHERNET_TYPES:
|
||||
cg.add(var.set_clk_pin(config[CONF_CLK_PIN]))
|
||||
cg.add(var.set_miso_pin(config[CONF_MISO_PIN]))
|
||||
cg.add(var.set_mosi_pin(config[CONF_MOSI_PIN]))
|
||||
|
@ -218,6 +220,7 @@ async def to_code(config):
|
|||
if CORE.using_esp_idf:
|
||||
add_idf_sdkconfig_option("CONFIG_ETH_USE_SPI_ETHERNET", True)
|
||||
add_idf_sdkconfig_option("CONFIG_ETH_SPI_ETHERNET_W5500", True)
|
||||
add_idf_sdkconfig_option("CONFIG_ETH_SPI_ETHERNET_DM9051", True)
|
||||
else:
|
||||
cg.add(var.set_phy_addr(config[CONF_PHY_ADDR]))
|
||||
cg.add(var.set_mdc_pin(config[CONF_MDC_PIN]))
|
||||
|
|
|
@ -107,19 +107,22 @@ void EthernetComponent::setup() {
|
|||
|
||||
#if USE_ESP_IDF && (ESP_IDF_VERSION_MAJOR >= 5)
|
||||
eth_w5500_config_t w5500_config = ETH_W5500_DEFAULT_CONFIG(host, &devcfg);
|
||||
eth_dm9051_config_t dm9051_config = ETH_DM9051_DEFAULT_CONFIG(host, &devcfg);
|
||||
#else
|
||||
spi_device_handle_t spi_handle = nullptr;
|
||||
err = spi_bus_add_device(host, &devcfg, &spi_handle);
|
||||
ESPHL_ERROR_CHECK(err, "SPI bus add device error");
|
||||
|
||||
eth_w5500_config_t w5500_config = ETH_W5500_DEFAULT_CONFIG(spi_handle);
|
||||
eth_dm9051_config_t dm9051_config = ETH_DM9051_DEFAULT_CONFIG(spi_handle);
|
||||
#endif
|
||||
w5500_config.int_gpio_num = this->interrupt_pin_;
|
||||
dm9051_config.int_gpio_num = this->interrupt_pin_;
|
||||
phy_config.phy_addr = this->phy_addr_spi_;
|
||||
phy_config.reset_gpio_num = this->reset_pin_;
|
||||
|
||||
esp_eth_mac_t *mac = esp_eth_mac_new_w5500(&w5500_config, &mac_config);
|
||||
#else
|
||||
esp_eth_mac_t *mac = nullptr;
|
||||
#else // USE_ETHERNET_SPI
|
||||
phy_config.phy_addr = this->phy_addr_;
|
||||
phy_config.reset_gpio_num = this->power_pin_;
|
||||
|
||||
|
@ -139,7 +142,7 @@ void EthernetComponent::setup() {
|
|||
|
||||
esp_eth_mac_t *mac = esp_eth_mac_new_esp32(&mac_config);
|
||||
#endif
|
||||
#endif
|
||||
#endif // USE_ETHERNET_SPI
|
||||
|
||||
switch (this->type_) {
|
||||
#if CONFIG_ETH_USE_ESP32_EMAC
|
||||
|
@ -175,9 +178,15 @@ void EthernetComponent::setup() {
|
|||
#endif
|
||||
#ifdef USE_ETHERNET_SPI
|
||||
case ETHERNET_TYPE_W5500: {
|
||||
mac = esp_eth_mac_new_w5500(&w5500_config, &mac_config);
|
||||
this->phy_ = esp_eth_phy_new_w5500(&phy_config);
|
||||
break;
|
||||
}
|
||||
case ETHERNET_TYPE_DM9051: {
|
||||
mac = esp_eth_mac_new_dm9051(&dm9051_config, &mac_config);
|
||||
this->phy_ = esp_eth_phy_new_dm9051(&phy_config);
|
||||
break;
|
||||
}
|
||||
#endif
|
||||
default: {
|
||||
this->mark_failed();
|
||||
|
@ -301,6 +310,10 @@ void EthernetComponent::dump_config() {
|
|||
eth_type = "W5500";
|
||||
break;
|
||||
|
||||
case ETHERNET_TYPE_DM9051:
|
||||
eth_type = "DM9051";
|
||||
break;
|
||||
|
||||
default:
|
||||
eth_type = "Unknown";
|
||||
break;
|
||||
|
|
|
@ -25,6 +25,7 @@ enum EthernetType {
|
|||
ETHERNET_TYPE_KSZ8081,
|
||||
ETHERNET_TYPE_KSZ8081RNA,
|
||||
ETHERNET_TYPE_W5500,
|
||||
ETHERNET_TYPE_DM9051,
|
||||
};
|
||||
|
||||
struct ManualIP {
|
||||
|
|
|
@ -0,0 +1,14 @@
|
|||
ethernet:
|
||||
type: DM9051
|
||||
clk_pin: GPIO19
|
||||
mosi_pin: GPIO21
|
||||
miso_pin: GPIO23
|
||||
cs_pin: GPIO18
|
||||
interrupt_pin: GPIO36
|
||||
reset_pin: GPIO22
|
||||
clock_speed: 10Mhz
|
||||
manual_ip:
|
||||
static_ip: 192.168.178.56
|
||||
gateway: 192.168.178.1
|
||||
subnet: 255.255.255.0
|
||||
domain: .local
|
|
@ -0,0 +1,14 @@
|
|||
ethernet:
|
||||
type: DM9051
|
||||
clk_pin: GPIO19
|
||||
mosi_pin: GPIO21
|
||||
miso_pin: GPIO23
|
||||
cs_pin: GPIO18
|
||||
interrupt_pin: GPIO36
|
||||
reset_pin: GPIO22
|
||||
clock_speed: 10Mhz
|
||||
manual_ip:
|
||||
static_ip: 192.168.178.56
|
||||
gateway: 192.168.178.1
|
||||
subnet: 255.255.255.0
|
||||
domain: .local
|
Loading…
Reference in New Issue