2
0

network_driver_DM9051.c 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. #include "esp_eth.h"
  2. #include "network_ethernet.h"
  3. static EXT_RAM_ATTR network_ethernet_driver_t DM9051;
  4. static esp_err_t start(spi_device_handle_t spi_handle, eth_config_t* ethernet_config) {
  5. #ifdef CONFIG_ETH_SPI_ETHERNET_DM9051
  6. eth_phy_config_t phy_config = ETH_PHY_DEFAULT_CONFIG();
  7. eth_mac_config_t mac_config = ETH_MAC_DEFAULT_CONFIG();
  8. eth_dm9051_config_t eth_config = ETH_DM9051_DEFAULT_CONFIG(spi_handle);
  9. // we assume that isr has been installed already
  10. eth_config.int_gpio_num = ethernet_config->intr;
  11. phy_config.phy_addr = -1;
  12. phy_config.reset_gpio_num = ethernet_config->rst;
  13. esp_eth_mac_t* mac = esp_eth_mac_new_dm9051(&eth_config, &mac_config);
  14. esp_eth_phy_t* phy = esp_eth_phy_new_dm9051(&phy_config);
  15. esp_eth_config_t config = ETH_DEFAULT_CONFIG(mac, phy);
  16. return esp_eth_driver_install(&config, &DM9051.handle);
  17. #else
  18. return ESP_ERR_NOT_SUPPORTED;
  19. #endif
  20. }
  21. static void init_config(eth_config_t* ethernet_config) {
  22. DM9051.start = start;
  23. }
  24. network_ethernet_driver_t* DM9051_Detect(char* Driver) {
  25. if (!strcasestr(Driver, "DM9051"))
  26. return NULL;
  27. DM9051.rmii = true;
  28. DM9051.spi = false;
  29. #ifdef CONFIG_ETH_SPI_ETHERNET_DM9051
  30. DM9051.valid = true;
  31. #else
  32. DM9051.valid = false;
  33. #endif
  34. DM9051.init_config = init_config;
  35. return &DM9051;
  36. }