mirror of
https://github.com/esphome/esphome.git
synced 2024-11-22 06:58:11 +01:00
Make SPI Ethernet (W5500) compatible with ESP-IDF v5 (#6778)
* change MAC PHY init order according to IDF examples * add idfv5 specific w5500 config init * esp_mac.h needs to be included directly starting with idf5 * Header fix * Couple tweaks --------- Co-authored-by: Keith Burzinski <kbx81x@gmail.com>
This commit is contained in:
parent
06996def72
commit
2b691ad5ad
2 changed files with 7 additions and 2 deletions
|
@ -98,11 +98,15 @@ void EthernetComponent::setup() {
|
||||||
.post_cb = nullptr,
|
.post_cb = nullptr,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#if USE_ESP_IDF && (ESP_IDF_VERSION_MAJOR >= 5)
|
||||||
|
eth_w5500_config_t w5500_config = ETH_W5500_DEFAULT_CONFIG(host, &devcfg);
|
||||||
|
#else
|
||||||
spi_device_handle_t spi_handle = nullptr;
|
spi_device_handle_t spi_handle = nullptr;
|
||||||
err = spi_bus_add_device(host, &devcfg, &spi_handle);
|
err = spi_bus_add_device(host, &devcfg, &spi_handle);
|
||||||
ESPHL_ERROR_CHECK(err, "SPI bus add device error");
|
ESPHL_ERROR_CHECK(err, "SPI bus add device error");
|
||||||
|
|
||||||
eth_w5500_config_t w5500_config = ETH_W5500_DEFAULT_CONFIG(spi_handle);
|
eth_w5500_config_t w5500_config = ETH_W5500_DEFAULT_CONFIG(spi_handle);
|
||||||
|
#endif
|
||||||
w5500_config.int_gpio_num = this->interrupt_pin_;
|
w5500_config.int_gpio_num = this->interrupt_pin_;
|
||||||
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_;
|
||||||
|
@ -614,14 +618,14 @@ void EthernetComponent::rtl8201_set_rmii_mode_(esp_eth_mac_t *mac) {
|
||||||
|
|
||||||
err = mac->read_phy_reg(mac, this->phy_addr_, RTL8201_RMSR_REG_ADDR, &(phy_rmii_mode));
|
err = mac->read_phy_reg(mac, this->phy_addr_, RTL8201_RMSR_REG_ADDR, &(phy_rmii_mode));
|
||||||
ESPHL_ERROR_CHECK(err, "Read PHY RMSR Register failed");
|
ESPHL_ERROR_CHECK(err, "Read PHY RMSR Register failed");
|
||||||
ESP_LOGV(TAG, "Hardware default RTL8201 RMII Mode Register is: 0x%04X", phy_rmii_mode);
|
ESP_LOGV(TAG, "Hardware default RTL8201 RMII Mode Register is: 0x%04" PRIX32, phy_rmii_mode);
|
||||||
|
|
||||||
err = mac->write_phy_reg(mac, this->phy_addr_, RTL8201_RMSR_REG_ADDR, 0x1FFA);
|
err = mac->write_phy_reg(mac, this->phy_addr_, RTL8201_RMSR_REG_ADDR, 0x1FFA);
|
||||||
ESPHL_ERROR_CHECK(err, "Setting Register 16 RMII Mode Setting failed");
|
ESPHL_ERROR_CHECK(err, "Setting Register 16 RMII Mode Setting failed");
|
||||||
|
|
||||||
err = mac->read_phy_reg(mac, this->phy_addr_, RTL8201_RMSR_REG_ADDR, &(phy_rmii_mode));
|
err = mac->read_phy_reg(mac, this->phy_addr_, RTL8201_RMSR_REG_ADDR, &(phy_rmii_mode));
|
||||||
ESPHL_ERROR_CHECK(err, "Read PHY RMSR Register failed");
|
ESPHL_ERROR_CHECK(err, "Read PHY RMSR Register failed");
|
||||||
ESP_LOGV(TAG, "Setting RTL8201 RMII Mode Register to: 0x%04X", phy_rmii_mode);
|
ESP_LOGV(TAG, "Setting RTL8201 RMII Mode Register to: 0x%04" PRIX32, phy_rmii_mode);
|
||||||
|
|
||||||
err = mac->write_phy_reg(mac, this->phy_addr_, 0x1f, 0x0);
|
err = mac->write_phy_reg(mac, this->phy_addr_, 0x1f, 0x0);
|
||||||
ESPHL_ERROR_CHECK(err, "Setting Page 0 failed");
|
ESPHL_ERROR_CHECK(err, "Setting Page 0 failed");
|
||||||
|
|
|
@ -10,6 +10,7 @@
|
||||||
#include "esp_eth.h"
|
#include "esp_eth.h"
|
||||||
#include "esp_eth_mac.h"
|
#include "esp_eth_mac.h"
|
||||||
#include "esp_netif.h"
|
#include "esp_netif.h"
|
||||||
|
#include "esp_mac.h"
|
||||||
|
|
||||||
namespace esphome {
|
namespace esphome {
|
||||||
namespace ethernet {
|
namespace ethernet {
|
||||||
|
|
Loading…
Reference in a new issue