Skip to content

Commit 6691cdb

Browse files
authored
Merge branch 'master' into feature/network_refactoring
2 parents 6ce26e9 + aed7b4f commit 6691cdb

File tree

2 files changed

+19
-9
lines changed

2 files changed

+19
-9
lines changed

libraries/Ethernet/src/ETH.cpp

+13-5
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ bool ETHClass::ethDetachBus(void * bus_pointer){
171171
}
172172

173173
#if CONFIG_ETH_USE_ESP32_EMAC
174-
bool ETHClass::begin(eth_phy_type_t type, uint8_t phy_addr, int mdc, int mdio, int power, eth_clock_mode_t clock_mode)
174+
bool ETHClass::begin(eth_phy_type_t type, int32_t phy_addr, int mdc, int mdio, int power, eth_clock_mode_t clock_mode)
175175
{
176176
esp_err_t ret = ESP_OK;
177177
if(_eth_index > 2){
@@ -180,6 +180,10 @@ bool ETHClass::begin(eth_phy_type_t type, uint8_t phy_addr, int mdc, int mdio, i
180180
if(_esp_netif != NULL){
181181
return true;
182182
}
183+
if(phy_addr < ETH_PHY_ADDR_AUTO){
184+
log_e("Invalid PHY address: %d, set to ETH_PHY_ADDR_AUTO for auto detection", phy_addr);
185+
return false;
186+
}
183187
perimanSetBusDeinit(ESP32_BUS_TYPE_ETHERNET_RMII, ETHClass::ethDetachBus);
184188
perimanSetBusDeinit(ESP32_BUS_TYPE_ETHERNET_CLK, ETHClass::ethDetachBus);
185189
perimanSetBusDeinit(ESP32_BUS_TYPE_ETHERNET_MCD, ETHClass::ethDetachBus);
@@ -265,7 +269,7 @@ bool ETHClass::begin(eth_phy_type_t type, uint8_t phy_addr, int mdc, int mdio, i
265269
esp_eth_config_t eth_config = ETH_DEFAULT_CONFIG(mac, phy);
266270
ret = esp_eth_driver_install(&eth_config, &_eth_handle);
267271
if(ret != ESP_OK){
268-
log_e("SPI Ethernet driver install failed: %d", ret);
272+
log_e("Ethernet driver install failed: %d", ret);
269273
return false;
270274
}
271275
if(_eth_handle == NULL){
@@ -443,7 +447,7 @@ esp_err_t ETHClass::eth_spi_write(uint32_t cmd, uint32_t addr, const void *data,
443447
}
444448
#endif
445449

446-
bool ETHClass::beginSPI(eth_phy_type_t type, uint8_t phy_addr, int cs, int irq, int rst,
450+
bool ETHClass::beginSPI(eth_phy_type_t type, int32_t phy_addr, int cs, int irq, int rst,
447451
#if ETH_SPI_SUPPORTS_CUSTOM
448452
SPIClass *spi,
449453
#endif
@@ -463,6 +467,10 @@ bool ETHClass::beginSPI(eth_phy_type_t type, uint8_t phy_addr, int cs, int irq,
463467
#endif
464468
return false;
465469
}
470+
if(phy_addr < ETH_PHY_ADDR_AUTO){
471+
log_e("Invalid PHY address: %d, set to ETH_PHY_ADDR_AUTO for auto detection", phy_addr);
472+
return false;
473+
}
466474

467475
perimanSetBusDeinit(ESP32_BUS_TYPE_ETHERNET_SPI, ETHClass::ethDetachBus);
468476

@@ -743,13 +751,13 @@ bool ETHClass::beginSPI(eth_phy_type_t type, uint8_t phy_addr, int cs, int irq,
743751
}
744752

745753
#if ETH_SPI_SUPPORTS_CUSTOM
746-
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){
754+
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){
747755

748756
return beginSPI(type, phy_addr, cs, irq, rst, &spi, -1, -1, -1, SPI2_HOST, spi_freq_mhz);
749757
}
750758
#endif
751759

752-
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){
760+
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){
753761

754762
return beginSPI(type, phy_addr, cs, irq, rst,
755763
#if ETH_SPI_SUPPORTS_CUSTOM

libraries/Ethernet/src/ETH.h

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

92+
#define ETH_PHY_ADDR_AUTO ESP_ETH_PHY_ADDR_AUTO
93+
9294
typedef enum {
9395
#if CONFIG_ETH_USE_ESP32_EMAC
9496
ETH_PHY_LAN8720, ETH_PHY_TLK110, ETH_PHY_RTL8201, ETH_PHY_DP83848, ETH_PHY_KSZ8041, ETH_PHY_KSZ8081,
@@ -111,12 +113,12 @@ class ETHClass: public ESP_Network_Interface {
111113
~ETHClass();
112114

113115
#if CONFIG_ETH_USE_ESP32_EMAC
114-
bool begin(eth_phy_type_t type, uint8_t phy_addr, int mdc, int mdio, int power, eth_clock_mode_t clk_mode);
116+
bool begin(eth_phy_type_t type, int32_t phy_addr, int mdc, int mdio, int power, eth_clock_mode_t clk_mode);
115117
#endif /* CONFIG_ETH_USE_ESP32_EMAC */
116118
#if ETH_SPI_SUPPORTS_CUSTOM
117-
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);
119+
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);
118120
#endif
119-
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);
121+
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);
120122

121123
bool begin(){
122124
#if defined(ETH_PHY_TYPE) && defined(ETH_PHY_ADDR)
@@ -188,7 +190,7 @@ class ETHClass: public ESP_Network_Interface {
188190
#endif /* CONFIG_ETH_USE_ESP32_EMAC */
189191

190192
static bool ethDetachBus(void * bus_pointer);
191-
bool beginSPI(eth_phy_type_t type, uint8_t phy_addr, int cs, int irq, int rst,
193+
bool beginSPI(eth_phy_type_t type, int32_t phy_addr, int cs, int irq, int rst,
192194
#if ETH_SPI_SUPPORTS_CUSTOM
193195
SPIClass * spi,
194196
#endif

0 commit comments

Comments
 (0)