network_driver_LAN8720.c 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. #include "esp_eth.h"
  2. #include "network_ethernet.h"
  3. static esp_eth_mac_t* mac_new(spi_device_handle_t spi_handle, eth_config_t* ethernet_config) {
  4. #ifdef CONFIG_ETH_PHY_INTERFACE_RMII
  5. eth_mac_config_t mac_config = ETH_MAC_DEFAULT_CONFIG();
  6. mac_config.smi_mdc_gpio_num = ethernet_config->mdc;
  7. mac_config.smi_mdio_gpio_num = ethernet_config->mdio;
  8. mac_config.sw_reset_timeout_ms = 400;
  9. return esp_eth_mac_new_esp32(&mac_config);
  10. #else
  11. return NULL;
  12. #endif
  13. }
  14. static esp_eth_phy_t* phy_new(eth_config_t* ethernet_config) {
  15. #ifdef CONFIG_ETH_PHY_INTERFACE_RMII
  16. eth_phy_config_t phy_config = ETH_PHY_DEFAULT_CONFIG();
  17. phy_config.phy_addr = 1;
  18. phy_config.reset_gpio_num = ethernet_config->rst;
  19. return esp_eth_phy_new_lan8720(&phy_config);
  20. #else
  21. return NULL;
  22. #endif
  23. }
  24. static void init_config(eth_config_t* ethernet_config) {
  25. #ifdef CONFIG_ETH_PHY_INTERFACE_RMII
  26. #else
  27. return NULL;
  28. #endif
  29. }
  30. static network_ethernet_driver_t LAN8720 = {
  31. .mac_new = mac_new,
  32. .phy_new = phy_new,
  33. .init_config = init_config,
  34. #ifdef CONFIG_ETH_PHY_INTERFACE_RMII
  35. .valid = true,
  36. #else
  37. .valid = false,
  38. #endif
  39. };
  40. network_ethernet_driver_t* LAN8720_Detect(char* Driver) {
  41. if (!strcasestr(Driver, "LAN8720"))
  42. return NULL;
  43. return &LAN8720;
  44. }