network_driver_LAN8720.c 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. #include "esp_eth.h"
  2. #include "network_ethernet.h"
  3. static EXT_RAM_ATTR network_ethernet_driver_t LAN8720;
  4. static EXT_RAM_ATTR esp_netif_config_t cfg_rmii;
  5. static EXT_RAM_ATTR esp_netif_inherent_config_t esp_netif_config;
  6. static esp_err_t start(spi_device_handle_t spi_handle, eth_config_t* ethernet_config) {
  7. #ifdef CONFIG_ETH_PHY_INTERFACE_RMII
  8. eth_phy_config_t phy_config = ETH_PHY_DEFAULT_CONFIG();
  9. eth_mac_config_t mac_config = ETH_MAC_DEFAULT_CONFIG();
  10. mac_config.smi_mdc_gpio_num = ethernet_config->mdc;
  11. mac_config.smi_mdio_gpio_num = ethernet_config->mdio;
  12. phy_config.phy_addr = 1;
  13. phy_config.reset_gpio_num = ethernet_config->rst;
  14. esp_eth_mac_t* mac = esp_eth_mac_new_esp32(&mac_config);
  15. esp_eth_phy_t* phy = esp_eth_phy_new_lan8720(&phy_config);
  16. esp_eth_config_t config = ETH_DEFAULT_CONFIG(mac, phy);
  17. return esp_eth_driver_install(&config, &LAN8720.handle);
  18. #else
  19. return ESP_ERR_NOT_SUPPORTED;
  20. #endif
  21. }
  22. static void init_config(eth_config_t* ethernet_config) {
  23. esp_netif_inherent_config_t loc_esp_netif_config = ESP_NETIF_INHERENT_DEFAULT_ETH();
  24. memcpy(&esp_netif_config, &loc_esp_netif_config, sizeof(loc_esp_netif_config));
  25. cfg_rmii.base = &esp_netif_config,
  26. cfg_rmii.stack = ESP_NETIF_NETSTACK_DEFAULT_ETH;
  27. LAN8720.cfg_netif = &cfg_rmii;
  28. LAN8720.start = start;
  29. }
  30. network_ethernet_driver_t* LAN8720_Detect(char* Driver) {
  31. if (!strcasestr(Driver, "LAN8720"))
  32. return NULL;
  33. #ifdef CONFIG_ETH_PHY_INTERFACE_RMII
  34. LAN8720.valid = true;
  35. #else
  36. LAN8720.valid = false;
  37. #endif
  38. LAN8720.rmii = true;
  39. LAN8720.spi = false;
  40. LAN8720.init_config = init_config;
  41. return &LAN8720;
  42. }