Update Ethernet support
#include "eth_phy/phy_lan8720.h"
#include "soc/emac_reg_v2.h"
+
+
extern "C"
{
#include "lwip\netif.h"
@@ -27,6 +29,12 @@ extern struct netif * Esp32_find_netif(esp_interface_t esp_if);
#define CONFIG_PHY_SMI_MDIO_PIN 18
+// Uncomment one of these following lines to support switching of a power gpio used on some boards
+//#define CONFIG_PIN_PHY_POWER 12 // Olimex_POE
+//#define CONFIG_PIN_PHY_POWER 5 // Olimex_gateway revs newer than C
+
+
+
#ifdef CONFIG_PHY_LAN8720
#include "eth_phy/phy_lan8720.h"
#define DEFAULT_ETHERNET_PHY_CONFIG phy_lan8720_default_ethernet_config
@@ -54,6 +62,25 @@ static void eth_gpio_config_rmii(void)
phy_rmii_smi_configure_pins(PIN_SMI_MDC, PIN_SMI_MDIO);
}
+#ifdef CONFIG_PIN_PHY_POWER
+static void phy_device_power_enable_via_gpio(bool enable)
+{
+ if (!enable)
+ phy_lan8720_default_ethernet_config.phy_power_enable(false);
+
+ gpio_pad_select_gpio((gpio_num_t)CONFIG_PIN_PHY_POWER);
+ gpio_set_direction((gpio_num_t)CONFIG_PIN_PHY_POWER, GPIO_MODE_OUTPUT);
+ gpio_set_level((gpio_num_t)CONFIG_PIN_PHY_POWER, (int)enable);
+
+ // Allow the power up/down to take effect, min 300us
+ vTaskDelay(1);
+
+ if (enable)
+ phy_lan8720_default_ethernet_config.phy_power_enable(true);
+}
+#endif
+
+
esp_err_t Esp32_InitialiseEthernet( uint8_t * pMacAdr)
{
(void)pMacAdr;
@@ -65,23 +92,12 @@ esp_err_t Esp32_InitialiseEthernet( uint8_t * pMacAdr)
config.gpio_config = eth_gpio_config_rmii;
config.tcpip_input = tcpip_adapter_eth_input;
+#ifdef CONFIG_PIN_PHY_POWER
+ config.phy_power_enable = phy_device_power_enable_via_gpio;
+#endif
esp_err_t ret = esp_eth_init(&config);
if(ret != ESP_OK) return ret;
- // Test the RMII busy bit to try and see if Ethernet PHY is present/connected
- // ets_printf("Ethernet check status\n");
- // int x = 100, status = 0;
- // while( x > 0 )
- // {
- // ets_printf("Ethernet get status\n");
- // status = REG_GET_BIT(EMAC_GMACGMIIADDR_REG, EMAC_GMIIBUSY);
- // ets_printf("Ethernet status=%d\n", status);
- // if ( status == 0 ) break;
- // x--;
- // }
- // ets_printf("Ethernet status %d %d \n",x, status);
- // if ( status == 1) return ESP_FAIL;
-
// esp_eth_set_mac( pMacAdr ); // need later IDF
esp_eth_enable();
