Skip to content

Commit 987e144

Browse files
DejinChenrestyled-commits
authored andcommittedJul 31, 2024
ESP32: added config for Wi-Fi, Thread, and Ethernet network drivers. (project-chip#34052)
* ESP32: added config for Wi-Fi, Thread, and Ethernet network commissioning drivers * Update README.md * Restyled * Restyled by prettier-markdown * Fix CI --------- Co-authored-by: Restyled.io <commits@restyled.io>
1 parent b07e06f commit 987e144

File tree

8 files changed

+125
-23
lines changed

8 files changed

+125
-23
lines changed
 

‎config/esp32/components/chip/CMakeLists.txt

+3
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,9 @@ endif()
224224

225225
if (CONFIG_ENABLE_MATTER_OVER_THREAD)
226226
chip_gn_arg_append("chip_enable_openthread" "true")
227+
if (CONFIG_THREAD_NETWORK_COMMISSIONING_DRIVER)
228+
chip_gn_arg_append("chip_device_config_thread_network_endpoint_id" ${CONFIG_THREAD_NETWORK_ENDPOINT_ID})
229+
endif()
227230
else()
228231
chip_gn_arg_append("chip_enable_openthread" "false")
229232
endif()

‎config/esp32/components/chip/Kconfig

+54
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,12 @@ menu "CHIP Core"
157157
help
158158
Option to enable/disable CHIP log level filtering APIs.
159159

160+
config ENABLE_CHIP_DATA_MODEL
161+
bool "Enable CHIP data model"
162+
default y
163+
help
164+
Option to enable/disable CHIP data model.
165+
160166
endmenu # "General Options"
161167

162168
menu "Networking Options"
@@ -1289,4 +1295,52 @@ menu "CHIP Device Layer"
12891295

12901296
endmenu
12911297

1298+
menu "Network Commissioning Driver Endpoint Id"
1299+
config THREAD_NETWORK_COMMISSIONING_DRIVER
1300+
bool "Use the generic Thread network commissioning driver"
1301+
depends on ENABLE_MATTER_OVER_THREAD && ENABLE_CHIP_DATA_MODEL
1302+
default y
1303+
help
1304+
Option to enable/disable the use of generic Thread network commissioning driver.
1305+
1306+
config THREAD_NETWORK_ENDPOINT_ID
1307+
int "Endpoint Id for Thread network"
1308+
depends on THREAD_NETWORK_COMMISSIONING_DRIVER
1309+
range 0 65534
1310+
default 0
1311+
help
1312+
The endpoint id for the generic Thread network commissioning driver.
1313+
1314+
config WIFI_NETWORK_COMMISSIONING_DRIVER
1315+
bool "Use ESP Wi-Fi network commissioning driver"
1316+
depends on (ENABLE_WIFI_STATION || ENABLE_WIFI_AP) && ENABLE_CHIP_DATA_MODEL
1317+
default y
1318+
help
1319+
Option to enable/disable the use of ESP Wi-Fi network commissioning driver.
1320+
1321+
config WIFI_NETWORK_ENDPOINT_ID
1322+
int "Endpoint Id for Wi-Fi network"
1323+
depends on WIFI_NETWORK_COMMISSIONING_DRIVER
1324+
range 0 65534
1325+
default 0
1326+
help
1327+
The endpoint id for the ESP Wi-Fi network commissioning driver.
1328+
1329+
config ETHERNET_NETWORK_COMMISSIONING_DRIVER
1330+
bool "Use ESP Ethernet network commissioning driver"
1331+
depends on ENABLE_ETHERNET_TELEMETRY && ENABLE_CHIP_DATA_MODEL
1332+
default y
1333+
help
1334+
Option to enable/disable the use of ESP Ethernet network commissioning driver.
1335+
1336+
config ETHERNET_NETWORK_ENDPOINT_ID
1337+
int "Endpoint Id for Ethernet network"
1338+
depends on ETHERNET_NETWORK_COMMISSIONING_DRIVER
1339+
range 0 65534
1340+
default 0
1341+
help
1342+
The endpoint id for the ESP Ethernet network commissioning driver.
1343+
1344+
endmenu
1345+
12921346
endmenu

‎examples/all-clusters-app/esp32/README.md

+12-6
Original file line numberDiff line numberDiff line change
@@ -47,14 +47,20 @@ NetworkCommissioning Endpoint can be used to manage the driver of extra network
4747
interface.
4848

4949
For ESP32-C6 DevKits, if `CHIP_DEVICE_CONFIG_ENABLE_WIFI` and
50-
`CHIP_DEVICE_CONFIG_ENABLE_THREAD` are both enabled, the NetworkCommissioning
51-
cluster in Endpoint 0 will be used for Thread network driver and the same
52-
cluster on Endpoint 65534 will be used for Wi-Fi network driver.
50+
`CHIP_DEVICE_CONFIG_ENABLE_THREAD` are both enabled, please set
51+
`CONFIG_THREAD_NETWORK_ENDPOINT_ID` to 0 and set
52+
`CONFIG_WIFI_NETWORK_ENDPOINT_ID` to 65534, which presents that the
53+
NetworkCommissioning cluster in Endpoint 0 will be used for Thread network
54+
driver and the same cluster on Endpoint 65534 will be used for Wi-Fi network
55+
driver. Or vice versa.
5356

5457
For ESP32-Ethernet-Kits, if `CHIP_DEVICE_CONFIG_ENABLE_WIFI` and
55-
`CHIP_DEVICE_CONFIG_ENABLE_ETHERNET` are both enabled, the NetworkCommissioning
56-
cluster in Endpoint 0 will be used for Ethernet network driver and the same
57-
cluster on Endpoint 65534 will be used for Wi-Fi network driver.
58+
`CHIP_DEVICE_CONFIG_ENABLE_ETHERNET` are both enabled, please set
59+
`CONFIG_ETHERNET_NETWORK_ENDPOINT_ID` to 0 and set
60+
`CONFIG_WIFI_NETWORK_ENDPOINT_ID` to 65534, which presents that the
61+
NetworkCommissioning cluster in Endpoint 0 will be used for Ethernet network
62+
driver and the same cluster on Endpoint 65534 will be used for Wi-Fi network
63+
driver. Or vice versa.
5864

5965
---
6066

‎examples/persistent-storage/esp32/sdkconfig.defaults

+3
Original file line numberDiff line numberDiff line change
@@ -32,3 +32,6 @@ CONFIG_DEVICE_PRODUCT_ID=0x8009
3232

3333
# Enable HKDF in mbedtls
3434
CONFIG_MBEDTLS_HKDF_C=y
35+
36+
# Disable CHIP data model
37+
CONFIG_ENABLE_CHIP_DATA_MODEL=n

‎examples/platform/esp32/common/Esp32AppServer.cpp

+1-17
Original file line numberDiff line numberDiff line change
@@ -51,19 +51,6 @@ using namespace chip::DeviceLayer;
5151
static constexpr char TAG[] = "ESP32Appserver";
5252

5353
namespace {
54-
#if CHIP_DEVICE_CONFIG_ENABLE_WIFI
55-
#if CHIP_DEVICE_CONFIG_ENABLE_THREAD || CHIP_DEVICE_CONFIG_ENABLE_ETHERNET
56-
constexpr chip::EndpointId kNetworkCommissioningEndpointWiFi = 0xFFFE;
57-
#else
58-
constexpr chip::EndpointId kNetworkCommissioningEndpointWiFi = 0;
59-
#endif
60-
app::Clusters::NetworkCommissioning::Instance
61-
sWiFiNetworkCommissioningInstance(kNetworkCommissioningEndpointWiFi, &(NetworkCommissioning::ESPWiFiDriver::GetInstance()));
62-
#endif // CHIP_DEVICE_CONFIG_ENABLE_WIFI
63-
#if CHIP_DEVICE_CONFIG_ENABLE_ETHERNET
64-
static app::Clusters::NetworkCommissioning::Instance
65-
sEthernetNetworkCommissioningInstance(0 /* Endpoint Id */, &(NetworkCommissioning::ESPEthernetDriver::GetInstance()));
66-
#endif
6754

6855
#if CONFIG_TEST_EVENT_TRIGGER_ENABLED
6956
static uint8_t sTestEventTriggerEnableKey[TestEventTriggerDelegate::kEnableKeyLength] = { 0x00, 0x11, 0x22, 0x33, 0x44, 0x55,
@@ -150,14 +137,11 @@ void Esp32AppServer::Init(AppDelegate * sAppDelegate)
150137
chip::Server::GetInstance().Init(initParams);
151138

152139
#if CHIP_DEVICE_CONFIG_ENABLE_WIFI
153-
sWiFiNetworkCommissioningInstance.Init();
154140
#ifdef CONFIG_ENABLE_CHIP_SHELL
155141
chip::Shell::SetWiFiDriver(&(chip::DeviceLayer::NetworkCommissioning::ESPWiFiDriver::GetInstance()));
156142
#endif
157143
#endif
158-
#if CHIP_DEVICE_CONFIG_ENABLE_ETHERNET
159-
sEthernetNetworkCommissioningInstance.Init();
160-
#endif
144+
161145
#if CHIP_DEVICE_CONFIG_ENABLE_THREAD
162146
if (chip::DeviceLayer::ConnectivityMgr().IsThreadProvisioned() &&
163147
(chip::Server::GetInstance().GetFabricTable().FabricCount() != 0))

‎examples/shell/esp32/sdkconfig.defaults

+3
Original file line numberDiff line numberDiff line change
@@ -41,3 +41,6 @@ CONFIG_ENABLE_CHIP_SHELL=y
4141

4242
# Enable HKDF in mbedtls
4343
CONFIG_MBEDTLS_HKDF_C=y
44+
45+
# Disable CHIP data model
46+
CONFIG_ENABLE_CHIP_DATA_MODEL=n

‎src/platform/ESP32/CHIPDevicePlatformConfig.h

+15
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,9 @@
5050

5151
#ifdef CONFIG_ENABLE_MATTER_OVER_THREAD
5252
#define CHIP_DEVICE_CONFIG_ENABLE_THREAD CONFIG_ENABLE_MATTER_OVER_THREAD
53+
#ifndef CONFIG_THREAD_NETWORK_COMMISSIONING_DRIVER
54+
#define _NO_NETWORK_COMMISSIONING_DRIVER_ 1
55+
#endif
5356
#else
5457
#define CHIP_DEVICE_CONFIG_ENABLE_THREAD 0
5558
#endif // CONFIG_ENABLE_MATTER_OVER_THREAD
@@ -164,3 +167,15 @@
164167
#define CHIP_DEVICE_CONFIG_BG_TASK_PRIORITY CONFIG_BG_CHIP_TASK_PRIORITY
165168
#define CHIP_DEVICE_CONFIG_BG_MAX_EVENT_QUEUE_SIZE CONFIG_BG_MAX_EVENT_QUEUE_SIZE
166169
#define CHIP_DEVICE_CONFIG_BG_TASK_STACK_SIZE CONFIG_BG_CHIP_TASK_STACK_SIZE
170+
171+
#ifdef CONFIG_WIFI_NETWORK_COMMISSIONING_DRIVER
172+
#define CHIP_DEVICE_CONFIG_WIFI_NETWORK_DRIVER CONFIG_WIFI_NETWORK_COMMISSIONING_DRIVER
173+
#else
174+
#define CHIP_DEVICE_CONFIG_WIFI_NETWORK_DRIVER 0
175+
#endif // CONFIG_WIFI_NETWORK_COMMISSIONING_DRIVER
176+
177+
#ifdef CONFIG_ETHERNET_NETWORK_COMMISSIONING_DRIVER
178+
#define CHIP_DEVICE_CONFIG_ETHERNET_NETWORK_DRIVER CONFIG_ETHERNET_NETWORK_COMMISSIONING_DRIVER
179+
#else
180+
#define CHIP_DEVICE_CONFIG_ETHERNET_NETWORK_DRIVER 0
181+
#endif // CONFIG_ETHERNET_NETWORK_COMMISSIONING_DRIVER

‎src/platform/ESP32/ConnectivityManagerImpl.cpp

+34
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,11 @@
3939
#include <platform/internal/GenericConnectivityManagerImpl_WiFi.ipp>
4040
#endif
4141

42+
#include <app/clusters/network-commissioning/network-commissioning.h>
4243
#include <esp_wifi.h>
4344
#include <lib/support/CodeUtils.h>
4445
#include <lib/support/logging/CHIPLogging.h>
46+
#include <platform/ESP32/NetworkCommissioningDriver.h>
4547
#include <platform/internal/BLEManager.h>
4648

4749
using namespace ::chip;
@@ -53,6 +55,18 @@ namespace chip {
5355
namespace DeviceLayer {
5456

5557
ConnectivityManagerImpl ConnectivityManagerImpl::sInstance;
58+
59+
#if CHIP_DEVICE_CONFIG_ENABLE_WIFI && CHIP_DEVICE_CONFIG_WIFI_NETWORK_DRIVER
60+
app::Clusters::NetworkCommissioning::Instance
61+
sWiFiNetworkCommissioningInstance(CONFIG_WIFI_NETWORK_ENDPOINT_ID /* Endpoint Id */,
62+
&(NetworkCommissioning::ESPWiFiDriver::GetInstance()));
63+
#endif
64+
65+
#if CHIP_DEVICE_CONFIG_ENABLE_ETHERNET && CHIP_DEVICE_CONFIG_ETHERNET_NETWORK_DRIVER
66+
app::Clusters::NetworkCommissioning::Instance
67+
sEthernetNetworkCommissioningInstance(CONFIG_ETHERNET_NETWORK_ENDPOINT_ID /* Endpoint Id */,
68+
&(NetworkCommissioning::ESPEthernetDriver::GetInstance()));
69+
#endif
5670
// ==================== ConnectivityManager Platform Internal Methods ====================
5771

5872
CHIP_ERROR ConnectivityManagerImpl::_Init()
@@ -62,10 +76,30 @@ CHIP_ERROR ConnectivityManagerImpl::_Init()
6276
#endif
6377
#if CHIP_DEVICE_CONFIG_ENABLE_WIFI
6478
InitWiFi();
79+
#if CHIP_DEVICE_CONFIG_WIFI_NETWORK_DRIVER
80+
sWiFiNetworkCommissioningInstance.Init();
81+
#endif // CHIP_DEVICE_CONFIG_WIFI_NETWORK_DRIVER
6582
#endif
6683
#if CHIP_DEVICE_CONFIG_ENABLE_ETHERNET
6784
InitEthernet();
85+
#if CHIP_DEVICE_CONFIG_ETHERNET_NETWORK_DRIVER
86+
sEthernetNetworkCommissioningInstance.Init();
87+
#endif // CHIP_DEVICE_CONFIG_ETHERNET_NETWORK_DRIVER
6888
#endif
89+
90+
#if defined(CONFIG_WIFI_NETWORK_ENDPOINT_ID) && defined(CONFIG_THREAD_NETWORK_ENDPOINT_ID)
91+
static_assert(CONFIG_WIFI_NETWORK_ENDPOINT_ID != CONFIG_THREAD_NETWORK_ENDPOINT_ID,
92+
"Wi-Fi network endpoint id and Thread network endpoint id should not be the same.");
93+
#endif
94+
#if defined(CONFIG_WIFI_NETWORK_ENDPOINT_ID) && defined(CONFIG_ETHERNET_NETWORK_ENDPOINT_ID)
95+
static_assert(CONFIG_WIFI_NETWORK_ENDPOINT_ID != CONFIG_ETHERNET_NETWORK_ENDPOINT_ID,
96+
"Wi-Fi network endpoint id and Ethernet network endpoint id should not be the same.");
97+
#endif
98+
#if defined(CONFIG_THREAD_NETWORK_ENDPOINT_ID) && defined(CONFIG_ETHERNET_NETWORK_ENDPOINT_ID)
99+
static_assert(CONFIG_THREAD_NETWORK_ENDPOINT_ID != CONFIG_ETHERNET_NETWORK_ENDPOINT_ID,
100+
"Thread network endpoint id and Ethernet network endpoint id should not be the same.");
101+
#endif
102+
69103
return CHIP_NO_ERROR;
70104
}
71105

0 commit comments

Comments
 (0)