feat: add support for W5500 SPI Ethernet in gateway

- Introduced configuration options for wired Ethernet support in Kconfig and sdkconfig.
- Implemented Ethernet initialization and event handling in GatewayNetworkService.
- Enhanced app_main to manage Ethernet alongside Wi-Fi.
- Updated GatewayRuntime to store Ethernet information.
- Modified CMakeLists and include files to accommodate new Ethernet dependencies.
- Ensured backward compatibility by allowing Ethernet initialization failures to be ignored.

Signed-off-by: Tony <tonylu@tony-cloud.com>
This commit is contained in:
Tony
2026-05-12 08:42:10 +08:00
parent 36d10702da
commit 626f86ec4e
10 changed files with 600 additions and 17 deletions
@@ -8,6 +8,10 @@
#include "esp_err.h"
#include "esp_event.h"
#include "esp_eth.h"
#include "esp_eth_mac.h"
#include "esp_eth_netif_glue.h"
#include "esp_eth_phy.h"
#include "esp_http_server.h"
#include "esp_netif.h"
#include "esp_now.h"
@@ -26,6 +30,8 @@ struct DaliRawFrame;
struct GatewayNetworkServiceConfig {
bool wifi_enabled{true};
bool ethernet_enabled{false};
bool ethernet_ignore_init_failure{false};
bool espnow_setup_enabled{true};
bool espnow_setup_startup_enabled{false};
bool smartconfig_enabled{true};
@@ -35,6 +41,17 @@ struct GatewayNetworkServiceConfig {
bool udp_enabled{true};
uint16_t http_port{80};
uint16_t udp_port{2020};
int ethernet_spi_host{1};
int ethernet_spi_sclk_gpio{14};
int ethernet_spi_mosi_gpio{13};
int ethernet_spi_miso_gpio{12};
int ethernet_spi_cs_gpio{15};
int ethernet_spi_int_gpio{4};
uint32_t ethernet_poll_period_ms{0};
uint8_t ethernet_spi_clock_mhz{36};
int ethernet_phy_reset_gpio{5};
int ethernet_phy_addr{1};
uint32_t ethernet_rx_task_stack_size{3072};
int status_led_gpio{-1};
bool status_led_active_high{true};
int boot_button_gpio{-1};
@@ -66,12 +83,17 @@ class GatewayNetworkService {
static esp_err_t HandleLedOnGet(httpd_req_t* req);
static esp_err_t HandleLedOffGet(httpd_req_t* req);
static esp_err_t HandleJqJsGet(httpd_req_t* req);
static void HandleEthernetEvent(void* arg, esp_event_base_t event_base, int32_t event_id,
void* event_data);
static void HandleWifiEvent(void* arg, esp_event_base_t event_base, int32_t event_id,
void* event_data);
static void HandleEspNowReceive(const esp_now_recv_info_t* info, const uint8_t* data,
int data_len);
esp_err_t ensureNetworkStack();
esp_err_t startEthernet();
esp_err_t probeEthernetStartup();
void stopEthernet();
esp_err_t startWifi();
esp_err_t startSetupAp();
esp_err_t startSmartconfig();
@@ -89,6 +111,7 @@ class GatewayNetworkService {
void bootButtonTaskLoop();
void handleGatewayNotification(const std::vector<uint8_t>& frame);
void handleWifiControl(uint8_t mode);
void handleEthernetEvent(esp_event_base_t event_base, int32_t event_id, void* event_data);
void handleWifiEvent(esp_event_base_t event_base, int32_t event_id, void* event_data);
void handleEspNowReceive(const esp_now_recv_info_t* info, const uint8_t* data, int data_len);
void handleSetupUartFrame(int setup_id, const std::vector<uint8_t>& frame);
@@ -106,8 +129,15 @@ class GatewayNetworkService {
GatewayBridgeService* bridge_service_{nullptr};
bool started_{false};
httpd_handle_t http_server_{nullptr};
esp_netif_t* eth_netif_{nullptr};
esp_netif_t* wifi_sta_netif_{nullptr};
esp_netif_t* wifi_ap_netif_{nullptr};
esp_eth_handle_t eth_handle_{nullptr};
esp_eth_mac_t* eth_mac_{nullptr};
esp_eth_phy_t* eth_phy_{nullptr};
esp_eth_netif_glue_handle_t eth_glue_{nullptr};
bool ethernet_started_{false};
bool ethernet_event_handlers_registered_{false};
bool wifi_started_{false};
bool wifi_event_handlers_registered_{false};
bool setup_ap_started_{false};