2
0

network_driver_LAN8720.c 1.2 KB

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