network_driver_W5500.c 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  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_SPI_ETHERNET_W5500
  5. eth_w5500_config_t eth_config = ETH_W5500_DEFAULT_CONFIG(spi_handle);
  6. eth_mac_config_t mac_config = ETH_MAC_DEFAULT_CONFIG();
  7. // we assume that isr has been installed already
  8. eth_config.int_gpio_num = ethernet_config->intr;
  9. return esp_eth_mac_new_w5500(&eth_config, &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_SPI_ETHERNET_W5500
  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_w5500(&phy_config);
  20. #else
  21. return NULL;
  22. #endif
  23. }
  24. static void init_config(eth_config_t* ethernet_config) {
  25. }
  26. static network_ethernet_driver_t W5500 = {
  27. .mac_new = mac_new,
  28. .phy_new = phy_new,
  29. .init_config = init_config,
  30. #ifdef CONFIG_ETH_SPI_ETHERNET_W5500
  31. .valid = true,
  32. #else
  33. .valid = false,
  34. #endif
  35. };
  36. network_ethernet_driver_t* W5500_Detect(char* Driver, network_ethernet_driver_t* Device) {
  37. if (!strcasestr(Driver, "W5500"))
  38. return NULL;
  39. return &W5500;
  40. }