Skip to content

Commit 49f7862

Browse files
committed
feat(eth): Support phy address auto detection
1 parent ebca505 commit 49f7862

File tree

2 files changed

+11
-9
lines changed

2 files changed

+11
-9
lines changed

Diff for: libraries/Ethernet/src/ETH.cpp

+5-5
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ bool ETHClass::ethDetachBus(void * bus_pointer){
8282
}
8383

8484
#if CONFIG_ETH_USE_ESP32_EMAC
85-
bool ETHClass::begin(eth_phy_type_t type, uint8_t phy_addr, int mdc, int mdio, int power, eth_clock_mode_t clock_mode)
85+
bool ETHClass::begin(eth_phy_type_t type, int32_t phy_addr, int mdc, int mdio, int power, eth_clock_mode_t clock_mode)
8686
{
8787
esp_err_t ret = ESP_OK;
8888
if(_esp_netif != NULL){
@@ -168,7 +168,7 @@ bool ETHClass::begin(eth_phy_type_t type, uint8_t phy_addr, int mdc, int mdio, i
168168
esp_eth_config_t eth_config = ETH_DEFAULT_CONFIG(mac, phy);
169169
ret = esp_eth_driver_install(&eth_config, &_eth_handle);
170170
if(ret != ESP_OK){
171-
log_e("SPI Ethernet driver install failed: %d", ret);
171+
log_e("Ethernet driver install failed: %d", ret);
172172
return false;
173173
}
174174
if(_eth_handle == NULL){
@@ -340,7 +340,7 @@ esp_err_t ETHClass::eth_spi_write(uint32_t cmd, uint32_t addr, const void *data,
340340
}
341341
#endif
342342

343-
bool ETHClass::beginSPI(eth_phy_type_t type, uint8_t phy_addr, int cs, int irq, int rst,
343+
bool ETHClass::beginSPI(eth_phy_type_t type, int32_t phy_addr, int cs, int irq, int rst,
344344
#if ETH_SPI_SUPPORTS_CUSTOM
345345
SPIClass *spi,
346346
#endif
@@ -625,13 +625,13 @@ bool ETHClass::beginSPI(eth_phy_type_t type, uint8_t phy_addr, int cs, int irq,
625625
}
626626

627627
#if ETH_SPI_SUPPORTS_CUSTOM
628-
bool ETHClass::begin(eth_phy_type_t type, uint8_t phy_addr, int cs, int irq, int rst, SPIClass &spi, uint8_t spi_freq_mhz){
628+
bool ETHClass::begin(eth_phy_type_t type, int32_t phy_addr, int cs, int irq, int rst, SPIClass &spi, uint8_t spi_freq_mhz){
629629

630630
return beginSPI(type, phy_addr, cs, irq, rst, &spi, -1, -1, -1, SPI2_HOST, spi_freq_mhz);
631631
}
632632
#endif
633633

634-
bool ETHClass::begin(eth_phy_type_t type, uint8_t phy_addr, int cs, int irq, int rst, spi_host_device_t spi_host, int sck, int miso, int mosi, uint8_t spi_freq_mhz){
634+
bool ETHClass::begin(eth_phy_type_t type, int32_t phy_addr, int cs, int irq, int rst, spi_host_device_t spi_host, int sck, int miso, int mosi, uint8_t spi_freq_mhz){
635635

636636
return beginSPI(type, phy_addr, cs, irq, rst,
637637
#if ETH_SPI_SUPPORTS_CUSTOM

Diff for: libraries/Ethernet/src/ETH.h

+6-4
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,8 @@ typedef enum { ETH_CLOCK_GPIO0_IN, ETH_CLOCK_GPIO0_OUT, ETH_CLOCK_GPIO16_OUT, ET
8787
#define ETH_PHY_SPI_FREQ_MHZ 20
8888
#endif /* ETH_PHY_SPI_FREQ_MHZ */
8989

90+
#define ETH_PHY_ADDR_AUTO ESP_ETH_PHY_ADDR_AUTO
91+
9092
typedef enum {
9193
#if CONFIG_ETH_USE_ESP32_EMAC
9294
ETH_PHY_LAN8720, ETH_PHY_TLK110, ETH_PHY_RTL8201, ETH_PHY_DP83848, ETH_PHY_KSZ8041, ETH_PHY_KSZ8081,
@@ -109,12 +111,12 @@ class ETHClass {
109111
~ETHClass();
110112

111113
#if CONFIG_ETH_USE_ESP32_EMAC
112-
bool begin(eth_phy_type_t type, uint8_t phy_addr, int mdc, int mdio, int power, eth_clock_mode_t clk_mode);
114+
bool begin(eth_phy_type_t type, int32_t phy_addr, int mdc, int mdio, int power, eth_clock_mode_t clk_mode);
113115
#endif /* CONFIG_ETH_USE_ESP32_EMAC */
114116
#if ETH_SPI_SUPPORTS_CUSTOM
115-
bool begin(eth_phy_type_t type, uint8_t phy_addr, int cs, int irq, int rst, SPIClass &spi, uint8_t spi_freq_mhz=ETH_PHY_SPI_FREQ_MHZ);
117+
bool begin(eth_phy_type_t type, int32_t phy_addr, int cs, int irq, int rst, SPIClass &spi, uint8_t spi_freq_mhz=ETH_PHY_SPI_FREQ_MHZ);
116118
#endif
117-
bool begin(eth_phy_type_t type, uint8_t phy_addr, int cs, int irq, int rst, spi_host_device_t spi_host, int sck=-1, int miso=-1, int mosi=-1, uint8_t spi_freq_mhz=ETH_PHY_SPI_FREQ_MHZ);
119+
bool begin(eth_phy_type_t type, int32_t phy_addr, int cs, int irq, int rst, spi_host_device_t spi_host, int sck=-1, int miso=-1, int mosi=-1, uint8_t spi_freq_mhz=ETH_PHY_SPI_FREQ_MHZ);
118120

119121
bool begin(){
120122
#if defined(ETH_PHY_TYPE) && defined(ETH_PHY_ADDR)
@@ -208,7 +210,7 @@ class ETHClass {
208210
#endif /* CONFIG_ETH_USE_ESP32_EMAC */
209211

210212
static bool ethDetachBus(void * bus_pointer);
211-
bool beginSPI(eth_phy_type_t type, uint8_t phy_addr, int cs, int irq, int rst,
213+
bool beginSPI(eth_phy_type_t type, int32_t phy_addr, int cs, int irq, int rst,
212214
#if ETH_SPI_SUPPORTS_CUSTOM
213215
SPIClass * spi,
214216
#endif

0 commit comments

Comments
 (0)