From e32d27e7e8287b485f5aca88969ba508de812ef2 Mon Sep 17 00:00:00 2001 From: Angus Gratton Date: Tue, 13 Aug 2019 15:11:46 +1000 Subject: [PATCH] esp_eth: Add CONFIG_ETH_ENABLED flag to enable/disable ethernet at build time Always enabled by default, as SPI/Ethernet support is enabled by default. --- components/esp_eth/CMakeLists.txt | 42 ++++++++++++------- components/esp_eth/Kconfig | 9 +++- components/lwip/CMakeLists.txt | 5 ++- components/tcpip_adapter/event_handlers.c | 6 +-- components/tcpip_adapter/tcpip_adapter_lwip.c | 11 ++++- 5 files changed, 51 insertions(+), 22 deletions(-) diff --git a/components/esp_eth/CMakeLists.txt b/components/esp_eth/CMakeLists.txt index 3829df1885..3eb2d02a0c 100644 --- a/components/esp_eth/CMakeLists.txt +++ b/components/esp_eth/CMakeLists.txt @@ -1,20 +1,30 @@ -set(esp_eth_srcs "src/esp_eth.c" - "src/esp_eth_phy_dp83848.c" - "src/esp_eth_phy_ip101.c" - "src/esp_eth_phy_lan8720.c" - "src/esp_eth_phy_rtl8201.c") +set(srcs) # If ethernet disabled in Kconfig, this is a config-only component +set(include) +set(linker) -if(CONFIG_ETH_USE_ESP32_EMAC) - list(APPEND esp_eth_srcs "src/esp_eth_mac_esp32.c") +if(CONFIG_ETH_ENABLED) + set(srcs "src/esp_eth.c") + set(include "include") + set(linker "linker.lf") + + if(CONFIG_ETH_USE_ESP32_EMAC) + list(APPEND srcs "src/esp_eth_mac_esp32.c" + "src/esp_eth_phy_dp83848.c" + "src/esp_eth_phy_ip101.c" + "src/esp_eth_phy_lan8720.c" + "src/esp_eth_phy_rtl8201.c" + ) + endif() + + if(CONFIG_ETH_SPI_ETHERNET_DM9051) + list(APPEND srcs "src/esp_eth_mac_dm9051.c" + "src/esp_eth_phy_dm9051.c") + endif() endif() -if(CONFIG_ETH_SPI_ETHERNET_DM9051) - list(APPEND esp_eth_srcs "src/esp_eth_mac_dm9051.c" - "src/esp_eth_phy_dm9051.c") -endif() +idf_component_register(SRCS "${srcs}" + INCLUDE_DIRS ${include} + LDFRAGMENTS ${linker} + REQUIRES "esp_event" + PRIV_REQUIRES "tcpip_adapter" "driver" "log") -idf_component_register(SRCS "${esp_eth_srcs}" - INCLUDE_DIRS "include" - LDFRAGMENTS "linker.lf" - REQUIRES "esp_event" - PRIV_REQUIRES "tcpip_adapter" "driver" "log") diff --git a/components/esp_eth/Kconfig b/components/esp_eth/Kconfig index 40e7ee36dc..615b8a2e26 100644 --- a/components/esp_eth/Kconfig +++ b/components/esp_eth/Kconfig @@ -1,9 +1,15 @@ menu "Ethernet" + # Invisible item that is enabled if any Ethernet + # selection is made + config ETH_ENABLED + bool + menuconfig ETH_USE_ESP32_EMAC depends on IDF_TARGET_ESP32 bool "Support ESP32 internal EMAC controller" default y + select ETH_ENABLED help ESP32 integrates a 10/100M Ethernet MAC controller. @@ -132,8 +138,9 @@ menu "Ethernet" menuconfig ETH_USE_SPI_ETHERNET bool "Support SPI to Ethernet Module" default y + select ETH_ENABLED help - ESP-IDF can also support some SPI-Ethernet module. + ESP-IDF can also support some SPI-Ethernet modules. if ETH_USE_SPI_ETHERNET menuconfig ETH_SPI_ETHERNET_DM9051 diff --git a/components/lwip/CMakeLists.txt b/components/lwip/CMakeLists.txt index df4bb7f3aa..f32072ee82 100644 --- a/components/lwip/CMakeLists.txt +++ b/components/lwip/CMakeLists.txt @@ -87,7 +87,6 @@ set(srcs "port/esp32/freertos/sys_arch.c" "port/esp32/netif/dhcp_state.c" "port/esp32/netif/nettestif.c" - "port/esp32/netif/ethernetif.c" "port/esp32/netif/wlanif.c") if(CONFIG_LWIP_PPP_SUPPORT) @@ -124,6 +123,10 @@ if(CONFIG_LWIP_PPP_SUPPORT) "lwip/src/netif/ppp/polarssl/sha1.c") endif() +if(CONFIG_ETH_ENABLED) + list(APPEND srcs "port/esp32/netif/ethernetif.c") +endif() + idf_component_register(SRCS "${srcs}" INCLUDE_DIRS "${include_dirs}" LDFRAGMENTS linker.lf diff --git a/components/tcpip_adapter/event_handlers.c b/components/tcpip_adapter/event_handlers.c index 48b7ccc182..299dc990a0 100644 --- a/components/tcpip_adapter/event_handlers.c +++ b/components/tcpip_adapter/event_handlers.c @@ -17,7 +17,7 @@ #include "esp_event.h" #include "esp_wifi.h" #include "esp_private/wifi.h" -#if CONFIG_IDF_TARGET_ESP32 +#if CONFIG_ETH_ENABLED #include "esp_eth.h" #endif #include "esp_err.h" @@ -43,7 +43,7 @@ static void handle_sta_stop(void *arg, esp_event_base_t base, int32_t event_id, static void handle_sta_connected(void *arg, esp_event_base_t base, int32_t event_id, void *data); static void handle_sta_disconnected(void *arg, esp_event_base_t base, int32_t event_id, void *data); static void handle_sta_got_ip(void *arg, esp_event_base_t base, int32_t event_id, void *data); -#if CONFIG_IDF_TARGET_ESP32 +#if CONFIG_ETH_ENABLED static void handle_eth_start(void *arg, esp_event_base_t base, int32_t event_id, void *data); static void handle_eth_stop(void *arg, esp_event_base_t base, int32_t event_id, void *data); static void handle_eth_connected(void *arg, esp_event_base_t base, int32_t event_id, void *data); @@ -266,7 +266,7 @@ esp_err_t tcpip_adapter_clear_default_wifi_handlers(void) return ESP_OK; } -#if CONFIG_IDF_TARGET_ESP32 +#if CONFIG_ETH_ENABLED esp_err_t tcpip_adapter_set_default_eth_handlers(void) { esp_err_t err; diff --git a/components/tcpip_adapter/tcpip_adapter_lwip.c b/components/tcpip_adapter/tcpip_adapter_lwip.c index 237b082a34..35df8cdcfc 100644 --- a/components/tcpip_adapter/tcpip_adapter_lwip.c +++ b/components/tcpip_adapter/tcpip_adapter_lwip.c @@ -16,7 +16,6 @@ #include #include "tcpip_adapter_internal.h" - #if CONFIG_TCPIP_LWIP #include "lwip/inet.h" @@ -32,7 +31,9 @@ #include "lwip/netif.h" #endif #include "netif/wlanif.h" +#ifdef CONFIG_ETH_ENABLED #include "netif/ethernetif.h" +#endif #include "netif/nettestif.h" #include "dhcpserver/dhcpserver.h" @@ -227,8 +228,12 @@ static esp_err_t tcpip_adapter_start(tcpip_adapter_if_t tcpip_if, uint8_t *mac, esp_err_t tcpip_adapter_eth_start(uint8_t *mac, tcpip_adapter_ip_info_t *ip_info, void *args) { +#ifdef CONFIG_ETH_ENABLED esp_netif_init_fn[TCPIP_ADAPTER_IF_ETH] = ethernetif_init; return tcpip_adapter_start(TCPIP_ADAPTER_IF_ETH, mac, ip_info, args); +#else + return ESP_ERR_NOT_SUPPORTED; +#endif } esp_err_t tcpip_adapter_sta_start(uint8_t *mac, tcpip_adapter_ip_info_t *ip_info) @@ -1115,8 +1120,12 @@ static esp_err_t tcpip_adapter_dhcpc_stop_api(tcpip_adapter_api_msg_t *msg) esp_err_t tcpip_adapter_eth_input(void *buffer, uint16_t len, void *eb) { +#ifdef CONFIG_ETH_ENABLED ethernetif_input(esp_netif[TCPIP_ADAPTER_IF_ETH], buffer, len); return ESP_OK; +#else + return ESP_ERR_NOT_SUPPORTED; +#endif } esp_err_t tcpip_adapter_sta_input(void *buffer, uint16_t len, void *eb)