From 257a99f4c68cd3cf132fdaba5b2c3c730b0e637b Mon Sep 17 00:00:00 2001 From: TD-er Date: Thu, 15 Feb 2024 14:19:01 +0100 Subject: [PATCH 1/4] [W5500] Support no-IRQ Requires this commit from ESP-IDF to be cherry picked: https://github.com/espressif/esp-idf/commit/fd0a1dc53c4cff99f04dfe658047f7c2e3e6d8ad --- libraries/Ethernet/src/ETH.cpp | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/libraries/Ethernet/src/ETH.cpp b/libraries/Ethernet/src/ETH.cpp index 92d91b40a1a..cd26adaedc2 100644 --- a/libraries/Ethernet/src/ETH.cpp +++ b/libraries/Ethernet/src/ETH.cpp @@ -149,6 +149,9 @@ bool ETHClass::begin(eth_phy_type_t type, uint8_t phy_addr, int mdc, int mdio, i case ETH_PHY_DP83848: phy = esp_eth_phy_new_dp83848(&phy_config); break; + case ETH_PHY_JL1101: + phy = esp_eth_phy_new_jl1101(&phy_config); + break; case ETH_PHY_KSZ8041: phy = esp_eth_phy_new_ksz80xx(&phy_config); break; @@ -351,7 +354,7 @@ bool ETHClass::beginSPI(eth_phy_type_t type, uint8_t phy_addr, int cs, int irq, log_w("ETH Already Started"); return true; } - if(cs < 0 || irq < 0){ + if(cs < 0 /*|| irq < 0*/){ log_e("CS and IRQ pins must be defined!"); return false; } @@ -447,6 +450,9 @@ bool ETHClass::beginSPI(eth_phy_type_t type, uint8_t phy_addr, int cs, int irq, if(type == ETH_PHY_W5500){ eth_w5500_config_t mac_config = ETH_W5500_DEFAULT_CONFIG(spi_host, &spi_devcfg); mac_config.int_gpio_num = _pin_irq; + if (_pin_irq < 0) { + mac_config.poll_period_ms = 10; + } #if ETH_SPI_SUPPORTS_CUSTOM if(_spi != NULL){ mac_config.custom_spi_driver.config = this; @@ -586,8 +592,9 @@ bool ETHClass::beginSPI(eth_phy_type_t type, uint8_t phy_addr, int cs, int irq, #if ETH_SPI_SUPPORTS_CUSTOM } #endif - if(!perimanSetPinBus(_pin_irq, ESP32_BUS_TYPE_ETHERNET_SPI, (void *)(this), -1, -1)){ goto err; } - + if(_pin_irq != -1){ + if(!perimanSetPinBus(_pin_irq, ESP32_BUS_TYPE_ETHERNET_SPI, (void *)(this), -1, -1)){ goto err; } + } if(_pin_sck != -1){ if(!perimanSetPinBus(_pin_sck, ESP32_BUS_TYPE_ETHERNET_SPI, (void *)(this), -1, -1)){ goto err; } } From 4ad6902876a5a624ac5f3db4ee8759f428dafa4d Mon Sep 17 00:00:00 2001 From: TD-er Date: Thu, 15 Feb 2024 14:27:37 +0100 Subject: [PATCH 2/4] Remove unrelated code to support ETH_PHY_JL1101 --- libraries/Ethernet/src/ETH.cpp | 3 --- 1 file changed, 3 deletions(-) diff --git a/libraries/Ethernet/src/ETH.cpp b/libraries/Ethernet/src/ETH.cpp index cd26adaedc2..71a6527bc37 100644 --- a/libraries/Ethernet/src/ETH.cpp +++ b/libraries/Ethernet/src/ETH.cpp @@ -149,9 +149,6 @@ bool ETHClass::begin(eth_phy_type_t type, uint8_t phy_addr, int mdc, int mdio, i case ETH_PHY_DP83848: phy = esp_eth_phy_new_dp83848(&phy_config); break; - case ETH_PHY_JL1101: - phy = esp_eth_phy_new_jl1101(&phy_config); - break; case ETH_PHY_KSZ8041: phy = esp_eth_phy_new_ksz80xx(&phy_config); break; From c83ab601f199e25cbc5a82b6287691abcedb7c36 Mon Sep 17 00:00:00 2001 From: TD-er Date: Thu, 15 Feb 2024 14:35:56 +0100 Subject: [PATCH 3/4] remove the commented check and fix the error message --- libraries/Ethernet/src/ETH.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libraries/Ethernet/src/ETH.cpp b/libraries/Ethernet/src/ETH.cpp index 71a6527bc37..71d0aeff55c 100644 --- a/libraries/Ethernet/src/ETH.cpp +++ b/libraries/Ethernet/src/ETH.cpp @@ -351,8 +351,8 @@ bool ETHClass::beginSPI(eth_phy_type_t type, uint8_t phy_addr, int cs, int irq, log_w("ETH Already Started"); return true; } - if(cs < 0 /*|| irq < 0*/){ - log_e("CS and IRQ pins must be defined!"); + if(cs < 0){ + log_e("CS pin must be defined!"); return false; } From 35d0cdc9ae84c8cf326b75ab60fb9598123c6042 Mon Sep 17 00:00:00 2001 From: Me No Dev Date: Thu, 22 Feb 2024 11:49:32 +0200 Subject: [PATCH 4/4] Guard feature to be enabled when IDF backports it to v5.1 --- libraries/Ethernet/src/ETH.cpp | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/libraries/Ethernet/src/ETH.cpp b/libraries/Ethernet/src/ETH.cpp index 71d0aeff55c..11d5d3cdea3 100644 --- a/libraries/Ethernet/src/ETH.cpp +++ b/libraries/Ethernet/src/ETH.cpp @@ -351,8 +351,13 @@ bool ETHClass::beginSPI(eth_phy_type_t type, uint8_t phy_addr, int cs, int irq, log_w("ETH Already Started"); return true; } +#if ETH_SPI_SUPPORTS_NO_IRQ if(cs < 0){ log_e("CS pin must be defined!"); +#else + if(cs < 0 || irq < 0){ + log_e("CS and IRQ pins must be defined!"); +#endif return false; } @@ -447,9 +452,11 @@ bool ETHClass::beginSPI(eth_phy_type_t type, uint8_t phy_addr, int cs, int irq, if(type == ETH_PHY_W5500){ eth_w5500_config_t mac_config = ETH_W5500_DEFAULT_CONFIG(spi_host, &spi_devcfg); mac_config.int_gpio_num = _pin_irq; +#if ETH_SPI_SUPPORTS_NO_IRQ if (_pin_irq < 0) { mac_config.poll_period_ms = 10; } +#endif #if ETH_SPI_SUPPORTS_CUSTOM if(_spi != NULL){ mac_config.custom_spi_driver.config = this; @@ -589,9 +596,13 @@ bool ETHClass::beginSPI(eth_phy_type_t type, uint8_t phy_addr, int cs, int irq, #if ETH_SPI_SUPPORTS_CUSTOM } #endif +#if ETH_SPI_SUPPORTS_NO_IRQ if(_pin_irq != -1){ +#endif if(!perimanSetPinBus(_pin_irq, ESP32_BUS_TYPE_ETHERNET_SPI, (void *)(this), -1, -1)){ goto err; } +#if ETH_SPI_SUPPORTS_NO_IRQ } +#endif if(_pin_sck != -1){ if(!perimanSetPinBus(_pin_sck, ESP32_BUS_TYPE_ETHERNET_SPI, (void *)(this), -1, -1)){ goto err; } }