From 648bcc7a87d90b7aec0dec024a3a707e3d8a46c3 Mon Sep 17 00:00:00 2001 From: morris Date: Thu, 9 Jul 2020 21:49:07 +0800 Subject: [PATCH] ethernet: add ksz8041 in basic ethernet example --- components/esp_eth/include/esp_eth_phy.h | 23 ++++++++++--------- components/esp_eth/src/esp_eth_phy_ksz8041.c | 3 ++- .../ethernet/basic/main/Kconfig.projbuild | 6 +++++ .../basic/main/ethernet_example_main.c | 2 ++ 4 files changed, 22 insertions(+), 12 deletions(-) diff --git a/components/esp_eth/include/esp_eth_phy.h b/components/esp_eth/include/esp_eth_phy.h index f74d8c72e0..b3aa39b438 100644 --- a/components/esp_eth/include/esp_eth_phy.h +++ b/components/esp_eth/include/esp_eth_phy.h @@ -240,6 +240,17 @@ esp_eth_phy_t *esp_eth_phy_new_lan8720(const eth_phy_config_t *config); */ esp_eth_phy_t *esp_eth_phy_new_dp83848(const eth_phy_config_t *config); +/** +* @brief Create a PHY instance of KSZ8041 +* +* @param[in] config: configuration of PHY +* +* @return +* - instance: create PHY instance successfully +* - NULL: create PHY instance failed because some error occurred +*/ +esp_eth_phy_t *esp_eth_phy_new_ksz8041(const eth_phy_config_t *config); + #if CONFIG_ETH_SPI_ETHERNET_DM9051 /** * @brief Create a PHY instance of DM9051 @@ -251,18 +262,8 @@ esp_eth_phy_t *esp_eth_phy_new_dp83848(const eth_phy_config_t *config); * - NULL: create PHY instance failed because some error occurred */ esp_eth_phy_t *esp_eth_phy_new_dm9051(const eth_phy_config_t *config); - -/** -* @brief Create a PHY instance of KSZ8041 -* -* @param[in] config: configuration of PHY -* -* @return -* - instance: create PHY instance successfully -* - NULL: create PHY instance failed because some error occurred -*/ -esp_eth_phy_t *esp_eth_phy_new_ksz8041(const eth_phy_config_t *config); #endif + #ifdef __cplusplus } #endif diff --git a/components/esp_eth/src/esp_eth_phy_ksz8041.c b/components/esp_eth/src/esp_eth_phy_ksz8041.c index 2442851054..a421b1ae08 100644 --- a/components/esp_eth/src/esp_eth_phy_ksz8041.c +++ b/components/esp_eth/src/esp_eth_phy_ksz8041.c @@ -20,6 +20,7 @@ #include "freertos/FreeRTOS.h" #include "freertos/task.h" #include "driver/gpio.h" +#include "esp_rom_gpio.h" static const char *TAG = "ksz8041"; #define PHY_CHECK(a, str, goto_tag, ...) \ @@ -166,7 +167,7 @@ static esp_err_t ksz8041_reset_hw(esp_eth_phy_t *phy) { phy_ksz8041_t *ksz8041 = __containerof(phy, phy_ksz8041_t, parent); if (ksz8041->reset_gpio_num >= 0) { - gpio_pad_select_gpio(ksz8041->reset_gpio_num); + esp_rom_gpio_pad_select_gpio(ksz8041->reset_gpio_num); gpio_set_direction(ksz8041->reset_gpio_num, GPIO_MODE_OUTPUT); gpio_set_level(ksz8041->reset_gpio_num, 0); gpio_set_level(ksz8041->reset_gpio_num, 1); diff --git a/examples/ethernet/basic/main/Kconfig.projbuild b/examples/ethernet/basic/main/Kconfig.projbuild index 99e573e49e..331720b266 100644 --- a/examples/ethernet/basic/main/Kconfig.projbuild +++ b/examples/ethernet/basic/main/Kconfig.projbuild @@ -52,6 +52,12 @@ menu "Example Configuration" help DP83848 is a single port 10/100Mb/s Ethernet Physical Layer Transceiver. Goto http://www.ti.com/product/DP83848J for more information about it. + + config EXAMPLE_ETH_PHY_KSZ8041 + bool "KSZ8041" + help + The KSZ8041 is a single supply 10Base-T/100Base-TX Physical Layer Transceiver. + Goto https://www.microchip.com/wwwproducts/en/KSZ8041 for more information about it. endchoice config EXAMPLE_ETH_MDC_GPIO diff --git a/examples/ethernet/basic/main/ethernet_example_main.c b/examples/ethernet/basic/main/ethernet_example_main.c index 59c81ef996..1455a5b577 100644 --- a/examples/ethernet/basic/main/ethernet_example_main.c +++ b/examples/ethernet/basic/main/ethernet_example_main.c @@ -93,6 +93,8 @@ void app_main(void) esp_eth_phy_t *phy = esp_eth_phy_new_lan8720(&phy_config); #elif CONFIG_EXAMPLE_ETH_PHY_DP83848 esp_eth_phy_t *phy = esp_eth_phy_new_dp83848(&phy_config); +#elif CONFIG_EXAMPLE_ETH_PHY_KSZ8041 + esp_eth_phy_t *phy = esp_eth_phy_new_ksz8041(&phy_config); #endif #elif CONFIG_EXAMPLE_USE_DM9051 gpio_install_isr_service(0);