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:
@@ -380,6 +380,109 @@ config GATEWAY_SMARTCONFIG_TIMEOUT_SEC
|
||||
help
|
||||
Timeout passed to ESP-IDF smartconfig before provisioning restarts internally.
|
||||
|
||||
config GATEWAY_ETHERNET_SUPPORTED
|
||||
bool "Wired Ethernet gateway transport is supported"
|
||||
default y
|
||||
select ETH_USE_SPI_ETHERNET
|
||||
select ETH_SPI_ETHERNET_W5500
|
||||
help
|
||||
Enables the ESP-IDF Ethernet driver path for wired gateway networking. The
|
||||
native gateway currently provisions a W5500 SPI Ethernet controller and
|
||||
exposes the same HTTP, UDP, KNXnet/IP, BACnet/IP, Modbus TCP, and cloud
|
||||
services over the wired netif.
|
||||
|
||||
config GATEWAY_START_ETHERNET_ENABLED
|
||||
bool "Start wired Ethernet at startup"
|
||||
depends on GATEWAY_ETHERNET_SUPPORTED
|
||||
default y
|
||||
help
|
||||
Starts the configured W5500 Ethernet netif during boot and uses DHCP for
|
||||
address assignment. Disable this when the board is built without Ethernet
|
||||
hardware even though the firmware keeps Ethernet support compiled in.
|
||||
|
||||
config GATEWAY_ETHERNET_IGNORE_INIT_FAILURE
|
||||
bool "Ignore wired Ethernet init failures"
|
||||
depends on GATEWAY_START_ETHERNET_ENABLED
|
||||
default y
|
||||
help
|
||||
Continues booting if the W5500 Ethernet controller is missing, held in
|
||||
reset, miswired, or otherwise fails ESP-IDF Ethernet driver startup.
|
||||
Disable this for strict hardware bring-up where Ethernet failure should
|
||||
abort application startup.
|
||||
|
||||
menu "Gateway Wired Ethernet"
|
||||
depends on GATEWAY_ETHERNET_SUPPORTED
|
||||
|
||||
config GATEWAY_ETHERNET_W5500_SPI_HOST
|
||||
int "W5500 SPI host number"
|
||||
range 1 2
|
||||
default 1
|
||||
help
|
||||
SPI host used for the W5500 Ethernet controller. On ESP32-S3, host 1 maps
|
||||
to SPI2 and host 2 maps to SPI3; do not use host 0 because it is reserved
|
||||
by flash/PSRAM.
|
||||
|
||||
config GATEWAY_ETHERNET_W5500_SCLK_GPIO
|
||||
int "W5500 SPI SCLK GPIO"
|
||||
range 0 48
|
||||
default 14
|
||||
|
||||
config GATEWAY_ETHERNET_W5500_MOSI_GPIO
|
||||
int "W5500 SPI MOSI GPIO"
|
||||
range 0 48
|
||||
default 13
|
||||
|
||||
config GATEWAY_ETHERNET_W5500_MISO_GPIO
|
||||
int "W5500 SPI MISO GPIO"
|
||||
range 0 48
|
||||
default 12
|
||||
|
||||
config GATEWAY_ETHERNET_W5500_CS_GPIO
|
||||
int "W5500 SPI CS GPIO"
|
||||
range 0 48
|
||||
default 15
|
||||
|
||||
config GATEWAY_ETHERNET_W5500_INT_GPIO
|
||||
int "W5500 interrupt GPIO"
|
||||
range -1 48
|
||||
default 4
|
||||
help
|
||||
W5500 interrupt pin. Set to -1 to disable interrupt mode and poll RX
|
||||
status periodically.
|
||||
|
||||
config GATEWAY_ETHERNET_W5500_POLL_PERIOD_MS
|
||||
int "W5500 polling period ms"
|
||||
range 0 1000
|
||||
default 0
|
||||
help
|
||||
Polling interval used when the W5500 interrupt pin is disabled. A value of
|
||||
0 keeps interrupt mode when an interrupt GPIO is configured; if the
|
||||
interrupt GPIO is -1, the gateway falls back to 100 ms polling.
|
||||
|
||||
config GATEWAY_ETHERNET_W5500_CLOCK_MHZ
|
||||
int "W5500 SPI clock MHz"
|
||||
range 5 80
|
||||
default 36
|
||||
|
||||
config GATEWAY_ETHERNET_PHY_RESET_GPIO
|
||||
int "Ethernet PHY reset GPIO"
|
||||
range -1 48
|
||||
default 5
|
||||
help
|
||||
GPIO used to reset the W5500 PHY. Set to -1 to disable hardware reset.
|
||||
|
||||
config GATEWAY_ETHERNET_PHY_ADDR
|
||||
int "Ethernet PHY address"
|
||||
range 0 31
|
||||
default 1
|
||||
|
||||
config GATEWAY_ETHERNET_RX_TASK_STACK_SIZE
|
||||
int "Ethernet RX task stack bytes"
|
||||
range 2048 8192
|
||||
default 3072
|
||||
|
||||
endmenu
|
||||
|
||||
config GATEWAY_BRIDGE_SUPPORTED
|
||||
bool "dali_cpp bridge runtime is supported"
|
||||
default y
|
||||
@@ -411,7 +514,7 @@ choice GATEWAY_MODBUS_DEFAULT_TRANSPORT
|
||||
|
||||
config GATEWAY_MODBUS_DEFAULT_TRANSPORT_TCP
|
||||
bool "TCP server"
|
||||
depends on GATEWAY_WIFI_SUPPORTED
|
||||
depends on GATEWAY_WIFI_SUPPORTED || GATEWAY_ETHERNET_SUPPORTED
|
||||
|
||||
config GATEWAY_MODBUS_DEFAULT_TRANSPORT_RTU
|
||||
bool "RTU server on UART"
|
||||
@@ -488,7 +591,7 @@ config GATEWAY_MODBUS_SERIAL_RS485_DE_PIN
|
||||
|
||||
config GATEWAY_BACNET_BRIDGE_SUPPORTED
|
||||
bool "BACnet/IP bridge is supported"
|
||||
depends on GATEWAY_BRIDGE_SUPPORTED && GATEWAY_WIFI_SUPPORTED
|
||||
depends on GATEWAY_BRIDGE_SUPPORTED && (GATEWAY_WIFI_SUPPORTED || GATEWAY_ETHERNET_SUPPORTED)
|
||||
default n
|
||||
help
|
||||
Enables BACnet bridge configuration, binding discovery, and the bacnet-stack BACnet/IP server adapter.
|
||||
@@ -503,7 +606,7 @@ config GATEWAY_START_BACNET_BRIDGE_ENABLED
|
||||
|
||||
config GATEWAY_KNX_BRIDGE_SUPPORTED
|
||||
bool "KNX to DALI bridge is supported"
|
||||
depends on GATEWAY_BRIDGE_SUPPORTED && GATEWAY_WIFI_SUPPORTED
|
||||
depends on GATEWAY_BRIDGE_SUPPORTED && (GATEWAY_WIFI_SUPPORTED || GATEWAY_ETHERNET_SUPPORTED)
|
||||
default n
|
||||
help
|
||||
Enables the gateway-owned KNX group-address router and KNXnet/IP TP/IP
|
||||
@@ -595,7 +698,7 @@ config GATEWAY_BRIDGE_KNX_TASK_PRIORITY
|
||||
|
||||
config GATEWAY_CLOUD_BRIDGE_SUPPORTED
|
||||
bool "MQTT cloud bridge is supported"
|
||||
depends on GATEWAY_BRIDGE_SUPPORTED && GATEWAY_WIFI_SUPPORTED
|
||||
depends on GATEWAY_BRIDGE_SUPPORTED && (GATEWAY_WIFI_SUPPORTED || GATEWAY_ETHERNET_SUPPORTED)
|
||||
default y
|
||||
help
|
||||
Enables per-channel DaliCloudBridge provisioning and MQTT downlink execution.
|
||||
|
||||
@@ -96,6 +96,54 @@
|
||||
#define CONFIG_GATEWAY_SMARTCONFIG_TIMEOUT_SEC 60
|
||||
#endif
|
||||
|
||||
#ifndef CONFIG_GATEWAY_ETHERNET_IGNORE_INIT_FAILURE
|
||||
#define CONFIG_GATEWAY_ETHERNET_IGNORE_INIT_FAILURE 0
|
||||
#endif
|
||||
|
||||
#ifndef CONFIG_GATEWAY_ETHERNET_W5500_SPI_HOST
|
||||
#define CONFIG_GATEWAY_ETHERNET_W5500_SPI_HOST 1
|
||||
#endif
|
||||
|
||||
#ifndef CONFIG_GATEWAY_ETHERNET_W5500_SCLK_GPIO
|
||||
#define CONFIG_GATEWAY_ETHERNET_W5500_SCLK_GPIO 14
|
||||
#endif
|
||||
|
||||
#ifndef CONFIG_GATEWAY_ETHERNET_W5500_MOSI_GPIO
|
||||
#define CONFIG_GATEWAY_ETHERNET_W5500_MOSI_GPIO 13
|
||||
#endif
|
||||
|
||||
#ifndef CONFIG_GATEWAY_ETHERNET_W5500_MISO_GPIO
|
||||
#define CONFIG_GATEWAY_ETHERNET_W5500_MISO_GPIO 12
|
||||
#endif
|
||||
|
||||
#ifndef CONFIG_GATEWAY_ETHERNET_W5500_CS_GPIO
|
||||
#define CONFIG_GATEWAY_ETHERNET_W5500_CS_GPIO 15
|
||||
#endif
|
||||
|
||||
#ifndef CONFIG_GATEWAY_ETHERNET_W5500_INT_GPIO
|
||||
#define CONFIG_GATEWAY_ETHERNET_W5500_INT_GPIO 4
|
||||
#endif
|
||||
|
||||
#ifndef CONFIG_GATEWAY_ETHERNET_W5500_POLL_PERIOD_MS
|
||||
#define CONFIG_GATEWAY_ETHERNET_W5500_POLL_PERIOD_MS 0
|
||||
#endif
|
||||
|
||||
#ifndef CONFIG_GATEWAY_ETHERNET_W5500_CLOCK_MHZ
|
||||
#define CONFIG_GATEWAY_ETHERNET_W5500_CLOCK_MHZ 36
|
||||
#endif
|
||||
|
||||
#ifndef CONFIG_GATEWAY_ETHERNET_PHY_RESET_GPIO
|
||||
#define CONFIG_GATEWAY_ETHERNET_PHY_RESET_GPIO 5
|
||||
#endif
|
||||
|
||||
#ifndef CONFIG_GATEWAY_ETHERNET_PHY_ADDR
|
||||
#define CONFIG_GATEWAY_ETHERNET_PHY_ADDR 1
|
||||
#endif
|
||||
|
||||
#ifndef CONFIG_GATEWAY_ETHERNET_RX_TASK_STACK_SIZE
|
||||
#define CONFIG_GATEWAY_ETHERNET_RX_TASK_STACK_SIZE 3072
|
||||
#endif
|
||||
|
||||
#ifndef CONFIG_GATEWAY_BRIDGE_MODBUS_TASK_STACK_SIZE
|
||||
#define CONFIG_GATEWAY_BRIDGE_MODBUS_TASK_STACK_SIZE 6144
|
||||
#endif
|
||||
@@ -199,12 +247,24 @@ constexpr bool kWifiSupported = true;
|
||||
constexpr bool kWifiSupported = false;
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_GATEWAY_ETHERNET_SUPPORTED
|
||||
constexpr bool kEthernetSupported = true;
|
||||
#else
|
||||
constexpr bool kEthernetSupported = false;
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_GATEWAY_START_WIFI_STA_ENABLED
|
||||
constexpr bool kWifiStartupEnabled = true;
|
||||
#else
|
||||
constexpr bool kWifiStartupEnabled = false;
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_GATEWAY_START_ETHERNET_ENABLED
|
||||
constexpr bool kEthernetStartupEnabled = true;
|
||||
#else
|
||||
constexpr bool kEthernetStartupEnabled = false;
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_GATEWAY_BLE_SUPPORTED
|
||||
constexpr bool kBleSupported = true;
|
||||
#else
|
||||
@@ -642,7 +702,7 @@ extern "C" void app_main(void) {
|
||||
"gateway",
|
||||
kWifiSupported,
|
||||
kBleSupported,
|
||||
true,
|
||||
kEthernetSupported,
|
||||
kEspnowSetupSupported,
|
||||
kUsbSetupStartupEnabled,
|
||||
};
|
||||
@@ -678,10 +738,11 @@ extern "C" void app_main(void) {
|
||||
ESP_ERROR_CHECK(s_cache->start());
|
||||
|
||||
gateway::GatewayControllerConfig controller_config;
|
||||
const bool network_transport_supported = profile.enable_wifi || profile.enable_eth;
|
||||
controller_config.setup_supported = true;
|
||||
controller_config.ble_supported = profile.enable_ble;
|
||||
controller_config.wifi_supported = profile.enable_wifi;
|
||||
controller_config.ip_router_supported = profile.enable_wifi || profile.enable_eth;
|
||||
controller_config.ip_router_supported = network_transport_supported;
|
||||
controller_config.internal_scene_supported = true;
|
||||
controller_config.internal_group_supported = true;
|
||||
|
||||
@@ -715,14 +776,14 @@ extern "C" void app_main(void) {
|
||||
bridge_config.bridge_enabled = true;
|
||||
bridge_config.modbus_enabled = kModbusBridgeSupported;
|
||||
bridge_config.modbus_startup_enabled = kModbusBridgeSupported && kModbusBridgeStartupEnabled;
|
||||
bridge_config.bacnet_enabled = profile.enable_wifi && kBacnetBridgeSupported;
|
||||
bridge_config.bacnet_startup_enabled = profile.enable_wifi && kBacnetBridgeSupported &&
|
||||
bridge_config.bacnet_enabled = network_transport_supported && kBacnetBridgeSupported;
|
||||
bridge_config.bacnet_startup_enabled = network_transport_supported && kBacnetBridgeSupported &&
|
||||
kBacnetBridgeStartupEnabled;
|
||||
bridge_config.knx_enabled = profile.enable_wifi && kKnxBridgeSupported;
|
||||
bridge_config.knx_startup_enabled = profile.enable_wifi && kKnxBridgeSupported &&
|
||||
bridge_config.knx_enabled = network_transport_supported && kKnxBridgeSupported;
|
||||
bridge_config.knx_startup_enabled = network_transport_supported && kKnxBridgeSupported &&
|
||||
kKnxBridgeStartupEnabled;
|
||||
bridge_config.cloud_enabled = profile.enable_wifi && kCloudBridgeSupported;
|
||||
bridge_config.cloud_startup_enabled = profile.enable_wifi && kCloudBridgeSupported &&
|
||||
bridge_config.cloud_enabled = network_transport_supported && kCloudBridgeSupported;
|
||||
bridge_config.cloud_startup_enabled = network_transport_supported && kCloudBridgeSupported &&
|
||||
kCloudBridgeStartupEnabled;
|
||||
bridge_config.modbus_task_stack_size =
|
||||
static_cast<uint32_t>(CONFIG_GATEWAY_BRIDGE_MODBUS_TASK_STACK_SIZE);
|
||||
@@ -796,6 +857,12 @@ extern "C" void app_main(void) {
|
||||
if (profile.enable_wifi || profile.enable_eth) {
|
||||
gateway::GatewayNetworkServiceConfig network_config;
|
||||
network_config.wifi_enabled = profile.enable_wifi && kWifiStartupEnabled;
|
||||
network_config.ethernet_enabled = profile.enable_eth && kEthernetStartupEnabled;
|
||||
#if CONFIG_GATEWAY_ETHERNET_IGNORE_INIT_FAILURE
|
||||
network_config.ethernet_ignore_init_failure = true;
|
||||
#else
|
||||
network_config.ethernet_ignore_init_failure = false;
|
||||
#endif
|
||||
network_config.espnow_setup_enabled = profile.enable_espnow;
|
||||
network_config.espnow_setup_startup_enabled =
|
||||
profile.enable_espnow && kEspnowSetupStartupEnabled;
|
||||
@@ -815,6 +882,20 @@ extern "C" void app_main(void) {
|
||||
#endif
|
||||
network_config.http_port = static_cast<uint16_t>(CONFIG_GATEWAY_NETWORK_HTTP_PORT);
|
||||
network_config.udp_port = static_cast<uint16_t>(CONFIG_GATEWAY_NETWORK_UDP_PORT);
|
||||
network_config.ethernet_spi_host = CONFIG_GATEWAY_ETHERNET_W5500_SPI_HOST;
|
||||
network_config.ethernet_spi_sclk_gpio = CONFIG_GATEWAY_ETHERNET_W5500_SCLK_GPIO;
|
||||
network_config.ethernet_spi_mosi_gpio = CONFIG_GATEWAY_ETHERNET_W5500_MOSI_GPIO;
|
||||
network_config.ethernet_spi_miso_gpio = CONFIG_GATEWAY_ETHERNET_W5500_MISO_GPIO;
|
||||
network_config.ethernet_spi_cs_gpio = CONFIG_GATEWAY_ETHERNET_W5500_CS_GPIO;
|
||||
network_config.ethernet_spi_int_gpio = CONFIG_GATEWAY_ETHERNET_W5500_INT_GPIO;
|
||||
network_config.ethernet_poll_period_ms =
|
||||
static_cast<uint32_t>(CONFIG_GATEWAY_ETHERNET_W5500_POLL_PERIOD_MS);
|
||||
network_config.ethernet_spi_clock_mhz =
|
||||
static_cast<uint8_t>(CONFIG_GATEWAY_ETHERNET_W5500_CLOCK_MHZ);
|
||||
network_config.ethernet_phy_reset_gpio = CONFIG_GATEWAY_ETHERNET_PHY_RESET_GPIO;
|
||||
network_config.ethernet_phy_addr = CONFIG_GATEWAY_ETHERNET_PHY_ADDR;
|
||||
network_config.ethernet_rx_task_stack_size =
|
||||
static_cast<uint32_t>(CONFIG_GATEWAY_ETHERNET_RX_TASK_STACK_SIZE);
|
||||
network_config.status_led_gpio = CONFIG_GATEWAY_STATUS_LED_GPIO;
|
||||
network_config.boot_button_gpio = CONFIG_GATEWAY_BOOT_BUTTON_GPIO;
|
||||
network_config.boot_button_long_press_ms = CONFIG_GATEWAY_BOOT_BUTTON_LONG_PRESS_MS;
|
||||
|
||||
@@ -656,6 +656,26 @@ CONFIG_GATEWAY_SMARTCONFIG_SUPPORTED=y
|
||||
# CONFIG_GATEWAY_START_ESPNOW_SETUP_ENABLED is not set
|
||||
# CONFIG_GATEWAY_START_SMARTCONFIG_ENABLED is not set
|
||||
CONFIG_GATEWAY_SMARTCONFIG_TIMEOUT_SEC=60
|
||||
CONFIG_GATEWAY_ETHERNET_SUPPORTED=y
|
||||
CONFIG_GATEWAY_START_ETHERNET_ENABLED=y
|
||||
CONFIG_GATEWAY_ETHERNET_IGNORE_INIT_FAILURE=y
|
||||
|
||||
#
|
||||
# Gateway Wired Ethernet
|
||||
#
|
||||
CONFIG_GATEWAY_ETHERNET_W5500_SPI_HOST=1
|
||||
CONFIG_GATEWAY_ETHERNET_W5500_SCLK_GPIO=14
|
||||
CONFIG_GATEWAY_ETHERNET_W5500_MOSI_GPIO=13
|
||||
CONFIG_GATEWAY_ETHERNET_W5500_MISO_GPIO=12
|
||||
CONFIG_GATEWAY_ETHERNET_W5500_CS_GPIO=15
|
||||
CONFIG_GATEWAY_ETHERNET_W5500_INT_GPIO=4
|
||||
CONFIG_GATEWAY_ETHERNET_W5500_POLL_PERIOD_MS=0
|
||||
CONFIG_GATEWAY_ETHERNET_W5500_CLOCK_MHZ=36
|
||||
CONFIG_GATEWAY_ETHERNET_PHY_RESET_GPIO=5
|
||||
CONFIG_GATEWAY_ETHERNET_PHY_ADDR=1
|
||||
CONFIG_GATEWAY_ETHERNET_RX_TASK_STACK_SIZE=3072
|
||||
# end of Gateway Wired Ethernet
|
||||
|
||||
CONFIG_GATEWAY_BRIDGE_SUPPORTED=y
|
||||
CONFIG_GATEWAY_MODBUS_BRIDGE_SUPPORTED=y
|
||||
# CONFIG_GATEWAY_START_MODBUS_BRIDGE_ENABLED is not set
|
||||
|
||||
@@ -12,4 +12,7 @@ CONFIG_BT_NIMBLE_ENABLED=y
|
||||
|
||||
CONFIG_ETH_ENABLED=y
|
||||
CONFIG_ETH_USE_SPI_ETHERNET=y
|
||||
CONFIG_ETH_SPI_ETHERNET_W5500=y
|
||||
CONFIG_ETH_SPI_ETHERNET_W5500=y
|
||||
CONFIG_GATEWAY_ETHERNET_SUPPORTED=y
|
||||
CONFIG_GATEWAY_START_ETHERNET_ENABLED=y
|
||||
CONFIG_GATEWAY_ETHERNET_IGNORE_INIT_FAILURE=y
|
||||
Reference in New Issue
Block a user