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.
This commit is contained in:
Angus Gratton 2019-08-13 15:11:46 +10:00 committed by Angus Gratton
parent f58d2ea34d
commit e32d27e7e8
5 changed files with 51 additions and 22 deletions

View File

@ -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")

View File

@ -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

View File

@ -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

View File

@ -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;

View File

@ -16,7 +16,6 @@
#include <string.h>
#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)