mirror of
https://github.com/esphome/esphome.git
synced 2024-11-23 15:38:11 +01:00
[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
baea9a9a96
commit
48f6f72d78
4 changed files with 61 additions and 6 deletions
|
@ -65,9 +65,10 @@ ETHERNET_TYPES = {
|
||||||
"KSZ8081RNA": EthernetType.ETHERNET_TYPE_KSZ8081RNA,
|
"KSZ8081RNA": EthernetType.ETHERNET_TYPE_KSZ8081RNA,
|
||||||
"W5500": EthernetType.ETHERNET_TYPE_W5500,
|
"W5500": EthernetType.ETHERNET_TYPE_W5500,
|
||||||
"OPENETH": EthernetType.ETHERNET_TYPE_OPENETH,
|
"OPENETH": EthernetType.ETHERNET_TYPE_OPENETH,
|
||||||
|
"DM9051": EthernetType.ETHERNET_TYPE_DM9051,
|
||||||
}
|
}
|
||||||
|
|
||||||
SPI_ETHERNET_TYPES = ["W5500"]
|
SPI_ETHERNET_TYPES = ["W5500", "DM9051"]
|
||||||
SPI_ETHERNET_DEFAULT_POLLING_INTERVAL = TimePeriodMilliseconds(milliseconds=10)
|
SPI_ETHERNET_DEFAULT_POLLING_INTERVAL = TimePeriodMilliseconds(milliseconds=10)
|
||||||
|
|
||||||
emac_rmii_clock_mode_t = cg.global_ns.enum("emac_rmii_clock_mode_t")
|
emac_rmii_clock_mode_t = cg.global_ns.enum("emac_rmii_clock_mode_t")
|
||||||
|
@ -223,6 +224,7 @@ CONFIG_SCHEMA = cv.All(
|
||||||
"KSZ8081RNA": RMII_SCHEMA,
|
"KSZ8081RNA": RMII_SCHEMA,
|
||||||
"W5500": SPI_SCHEMA,
|
"W5500": SPI_SCHEMA,
|
||||||
"OPENETH": BASE_SCHEMA,
|
"OPENETH": BASE_SCHEMA,
|
||||||
|
"DM9051": SPI_SCHEMA,
|
||||||
},
|
},
|
||||||
upper=True,
|
upper=True,
|
||||||
),
|
),
|
||||||
|
@ -279,7 +281,7 @@ async def to_code(config):
|
||||||
var = cg.new_Pvariable(config[CONF_ID])
|
var = cg.new_Pvariable(config[CONF_ID])
|
||||||
await cg.register_component(var, config)
|
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_clk_pin(config[CONF_CLK_PIN]))
|
||||||
cg.add(var.set_miso_pin(config[CONF_MISO_PIN]))
|
cg.add(var.set_miso_pin(config[CONF_MISO_PIN]))
|
||||||
cg.add(var.set_mosi_pin(config[CONF_MOSI_PIN]))
|
cg.add(var.set_mosi_pin(config[CONF_MOSI_PIN]))
|
||||||
|
@ -296,7 +298,12 @@ async def to_code(config):
|
||||||
|
|
||||||
cg.add_define("USE_ETHERNET_SPI")
|
cg.add_define("USE_ETHERNET_SPI")
|
||||||
add_idf_sdkconfig_option("CONFIG_ETH_USE_SPI_ETHERNET", True)
|
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_W5500", config[CONF_TYPE] == "W5500"
|
||||||
|
)
|
||||||
|
add_idf_sdkconfig_option(
|
||||||
|
"CONFIG_ETH_SPI_ETHERNET_DM9051", config[CONF_TYPE] == "DM9051"
|
||||||
|
)
|
||||||
elif config[CONF_TYPE] == "OPENETH":
|
elif config[CONF_TYPE] == "OPENETH":
|
||||||
cg.add_define("USE_ETHERNET_OPENETH")
|
cg.add_define("USE_ETHERNET_OPENETH")
|
||||||
add_idf_sdkconfig_option("CONFIG_ETH_USE_OPENETH", True)
|
add_idf_sdkconfig_option("CONFIG_ETH_USE_OPENETH", True)
|
||||||
|
|
|
@ -106,7 +106,8 @@ void EthernetComponent::setup() {
|
||||||
.post_cb = nullptr,
|
.post_cb = nullptr,
|
||||||
};
|
};
|
||||||
|
|
||||||
#if USE_ESP_IDF && (ESP_IDF_VERSION_MAJOR >= 5)
|
#if CONFIG_ETH_SPI_ETHERNET_W5500
|
||||||
|
#if ESP_IDF_VERSION_MAJOR >= 5
|
||||||
eth_w5500_config_t w5500_config = ETH_W5500_DEFAULT_CONFIG(host, &devcfg);
|
eth_w5500_config_t w5500_config = ETH_W5500_DEFAULT_CONFIG(host, &devcfg);
|
||||||
#else
|
#else
|
||||||
spi_device_handle_t spi_handle = nullptr;
|
spi_device_handle_t spi_handle = nullptr;
|
||||||
|
@ -119,10 +120,28 @@ void EthernetComponent::setup() {
|
||||||
#ifdef USE_ETHERNET_SPI_POLLING_SUPPORT
|
#ifdef USE_ETHERNET_SPI_POLLING_SUPPORT
|
||||||
w5500_config.poll_period_ms = this->polling_interval_;
|
w5500_config.poll_period_ms = this->polling_interval_;
|
||||||
#endif
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if CONFIG_ETH_SPI_ETHERNET_DM9051
|
||||||
|
#if ESP_IDF_VERSION_MAJOR >= 5
|
||||||
|
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_dm9051_config_t dm9051_config = ETH_DM9051_DEFAULT_CONFIG(spi_handle);
|
||||||
|
#endif
|
||||||
|
dm9051_config.int_gpio_num = this->interrupt_pin_;
|
||||||
|
#ifdef USE_ETHERNET_SPI_POLLING_SUPPORT
|
||||||
|
dm9051_config.poll_period_ms = this->polling_interval_;
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
phy_config.phy_addr = this->phy_addr_spi_;
|
phy_config.phy_addr = this->phy_addr_spi_;
|
||||||
phy_config.reset_gpio_num = this->reset_pin_;
|
phy_config.reset_gpio_num = this->reset_pin_;
|
||||||
|
|
||||||
esp_eth_mac_t *mac = esp_eth_mac_new_w5500(&w5500_config, &mac_config);
|
esp_eth_mac_t *mac = nullptr;
|
||||||
#elif defined(USE_ETHERNET_OPENETH)
|
#elif defined(USE_ETHERNET_OPENETH)
|
||||||
esp_eth_mac_t *mac = esp_eth_mac_new_openeth(&mac_config);
|
esp_eth_mac_t *mac = esp_eth_mac_new_openeth(&mac_config);
|
||||||
#else
|
#else
|
||||||
|
@ -145,7 +164,7 @@ void EthernetComponent::setup() {
|
||||||
|
|
||||||
esp_eth_mac_t *mac = esp_eth_mac_new_esp32(&mac_config);
|
esp_eth_mac_t *mac = esp_eth_mac_new_esp32(&mac_config);
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif // USE_ETHERNET_SPI
|
||||||
|
|
||||||
switch (this->type_) {
|
switch (this->type_) {
|
||||||
#ifdef USE_ETHERNET_OPENETH
|
#ifdef USE_ETHERNET_OPENETH
|
||||||
|
@ -187,10 +206,20 @@ void EthernetComponent::setup() {
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
#ifdef USE_ETHERNET_SPI
|
#ifdef USE_ETHERNET_SPI
|
||||||
|
#if CONFIG_ETH_SPI_ETHERNET_W5500
|
||||||
case ETHERNET_TYPE_W5500: {
|
case ETHERNET_TYPE_W5500: {
|
||||||
|
mac = esp_eth_mac_new_w5500(&w5500_config, &mac_config);
|
||||||
this->phy_ = esp_eth_phy_new_w5500(&phy_config);
|
this->phy_ = esp_eth_phy_new_w5500(&phy_config);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
#if CONFIG_ETH_SPI_ETHERNET_DM9051
|
||||||
|
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
|
||||||
#endif
|
#endif
|
||||||
default: {
|
default: {
|
||||||
this->mark_failed();
|
this->mark_failed();
|
||||||
|
@ -318,6 +347,10 @@ void EthernetComponent::dump_config() {
|
||||||
eth_type = "OPENETH";
|
eth_type = "OPENETH";
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case ETHERNET_TYPE_DM9051:
|
||||||
|
eth_type = "DM9051";
|
||||||
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
eth_type = "Unknown";
|
eth_type = "Unknown";
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -26,6 +26,7 @@ enum EthernetType {
|
||||||
ETHERNET_TYPE_KSZ8081RNA,
|
ETHERNET_TYPE_KSZ8081RNA,
|
||||||
ETHERNET_TYPE_W5500,
|
ETHERNET_TYPE_W5500,
|
||||||
ETHERNET_TYPE_OPENETH,
|
ETHERNET_TYPE_OPENETH,
|
||||||
|
ETHERNET_TYPE_DM9051,
|
||||||
};
|
};
|
||||||
|
|
||||||
struct ManualIP {
|
struct ManualIP {
|
||||||
|
|
14
tests/components/ethernet/test-dm9051.esp32-idf.yaml
Normal file
14
tests/components/ethernet/test-dm9051.esp32-idf.yaml
Normal file
|
@ -0,0 +1,14 @@
|
||||||
|
ethernet:
|
||||||
|
type: DM9051
|
||||||
|
clk_pin: 19
|
||||||
|
mosi_pin: 21
|
||||||
|
miso_pin: 23
|
||||||
|
cs_pin: 18
|
||||||
|
interrupt_pin: 36
|
||||||
|
reset_pin: 22
|
||||||
|
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 a new issue