diff --git a/examples/all-clusters-app/esp32/main/main.cpp b/examples/all-clusters-app/esp32/main/main.cpp index 6d9c4e2c488af4..4f4450c882767c 100644 --- a/examples/all-clusters-app/esp32/main/main.cpp +++ b/examples/all-clusters-app/esp32/main/main.cpp @@ -51,6 +51,8 @@ #endif #if CONFIG_OPENTHREAD_ENABLED +#include +#include #include #endif @@ -192,6 +194,13 @@ extern "C" void app_main() ESP_LOGE(TAG, "GetAppTask().StartAppTask() failed : %" CHIP_ERROR_FORMAT, error.Format()); } #if CHIP_DEVICE_CONFIG_ENABLE_THREAD + esp_openthread_platform_config_t config = { + .radio_config = ESP_OPENTHREAD_DEFAULT_RADIO_CONFIG(), + .host_config = ESP_OPENTHREAD_DEFAULT_HOST_CONFIG(), + .port_config = ESP_OPENTHREAD_DEFAULT_PORT_CONFIG(), + }; + set_openthread_platform_config(&config); + if (DeviceLayer::ThreadStackMgr().InitThreadStack() != CHIP_NO_ERROR) { ESP_LOGE(TAG, "Failed to initialize Thread stack"); diff --git a/examples/all-clusters-minimal-app/esp32/main/main.cpp b/examples/all-clusters-minimal-app/esp32/main/main.cpp index 989c221f6de5f9..f62a30a71d7a96 100644 --- a/examples/all-clusters-minimal-app/esp32/main/main.cpp +++ b/examples/all-clusters-minimal-app/esp32/main/main.cpp @@ -52,6 +52,8 @@ #endif #if CONFIG_OPENTHREAD_ENABLED +#include +#include #include #endif @@ -186,6 +188,13 @@ extern "C" void app_main() } #if CHIP_DEVICE_CONFIG_ENABLE_THREAD + esp_openthread_platform_config_t config = { + .radio_config = ESP_OPENTHREAD_DEFAULT_RADIO_CONFIG(), + .host_config = ESP_OPENTHREAD_DEFAULT_HOST_CONFIG(), + .port_config = ESP_OPENTHREAD_DEFAULT_PORT_CONFIG(), + }; + set_openthread_platform_config(&config); + if (DeviceLayer::ThreadStackMgr().InitThreadStack() != CHIP_NO_ERROR) { ESP_LOGE(TAG, "Failed to initialize Thread stack"); diff --git a/examples/lighting-app/esp32/main/main.cpp b/examples/lighting-app/esp32/main/main.cpp index 283140c0ca6f40..a33d783a98439c 100644 --- a/examples/lighting-app/esp32/main/main.cpp +++ b/examples/lighting-app/esp32/main/main.cpp @@ -46,6 +46,11 @@ #include "Rpc.h" #endif +#if CHIP_DEVICE_CONFIG_ENABLE_THREAD +#include +#include +#endif + #include "DeviceWithDisplay.h" #if CONFIG_ENABLE_ESP32_DEVICE_INFO_PROVIDER @@ -158,6 +163,13 @@ extern "C" void app_main() SetDeviceAttestationCredentialsProvider(get_dac_provider()); #if CHIP_DEVICE_CONFIG_ENABLE_THREAD + esp_openthread_platform_config_t config = { + .radio_config = ESP_OPENTHREAD_DEFAULT_RADIO_CONFIG(), + .host_config = ESP_OPENTHREAD_DEFAULT_HOST_CONFIG(), + .port_config = ESP_OPENTHREAD_DEFAULT_PORT_CONFIG(), + }; + set_openthread_platform_config(&config); + if (ThreadStackMgr().InitThreadStack() != CHIP_NO_ERROR) { ESP_LOGE(TAG, "Failed to initialize Thread stack"); diff --git a/src/platform/ESP32/OpenthreadConfig.h b/examples/platform/esp32/common/OpenthreadConfig.h similarity index 100% rename from src/platform/ESP32/OpenthreadConfig.h rename to examples/platform/esp32/common/OpenthreadConfig.h diff --git a/src/platform/ESP32/BUILD.gn b/src/platform/ESP32/BUILD.gn index 6532efbec4fda3..1d27940db829fa 100644 --- a/src/platform/ESP32/BUILD.gn +++ b/src/platform/ESP32/BUILD.gn @@ -153,7 +153,6 @@ static_library("ESP32") { "../OpenThread/GenericNetworkCommissioningThreadDriver.cpp", "../OpenThread/GenericNetworkCommissioningThreadDriver.h", "../OpenThread/OpenThreadUtils.cpp", - "OpenthreadConfig.h", "OpenthreadLauncher.c", "OpenthreadLauncher.h", "ThreadStackManagerImpl.cpp", diff --git a/src/platform/ESP32/OpenthreadLauncher.c b/src/platform/ESP32/OpenthreadLauncher.c index 5c5bf6c9beea9b..7183767016bb89 100644 --- a/src/platform/ESP32/OpenthreadLauncher.c +++ b/src/platform/ESP32/OpenthreadLauncher.c @@ -15,7 +15,6 @@ * limitations under the License. */ -#include "OpenthreadConfig.h" #include "driver/uart.h" #include "esp_event.h" #include "esp_netif.h" @@ -31,7 +30,8 @@ #include "openthread/logging.h" #include "openthread/tasklet.h" -static esp_netif_t * openthread_netif = NULL; +static esp_netif_t * openthread_netif = NULL; +static esp_openthread_platform_config_t * s_platform_config = NULL; static esp_netif_t * init_openthread_netif(const esp_openthread_platform_config_t * config) { @@ -55,6 +55,11 @@ static void ot_task_worker(void * context) vTaskDelete(NULL); } +void set_openthread_platform_config(esp_openthread_platform_config_t * config) +{ + s_platform_config = config; +} + esp_err_t openthread_init_stack(void) { // Used eventfds: @@ -67,15 +72,11 @@ esp_err_t openthread_init_stack(void) ESP_ERROR_CHECK(esp_netif_init()); ESP_ERROR_CHECK(esp_vfs_eventfd_register(&eventfd_config)); - esp_openthread_platform_config_t config = { - .radio_config = ESP_OPENTHREAD_DEFAULT_RADIO_CONFIG(), - .host_config = ESP_OPENTHREAD_DEFAULT_HOST_CONFIG(), - .port_config = ESP_OPENTHREAD_DEFAULT_PORT_CONFIG(), - }; + assert(s_platform_config); // Initialize the OpenThread stack - ESP_ERROR_CHECK(esp_openthread_init(&config)); + ESP_ERROR_CHECK(esp_openthread_init(s_platform_config)); // Initialize the esp_netif bindings - openthread_netif = init_openthread_netif(&config); + openthread_netif = init_openthread_netif(s_platform_config); return ESP_OK; } diff --git a/src/platform/ESP32/OpenthreadLauncher.h b/src/platform/ESP32/OpenthreadLauncher.h index c562bfa34220ec..6817a4dc5afb80 100644 --- a/src/platform/ESP32/OpenthreadLauncher.h +++ b/src/platform/ESP32/OpenthreadLauncher.h @@ -17,10 +17,14 @@ #pragma once +#include +#include + #ifdef __cplusplus extern "C" { #endif +void set_openthread_platform_config(esp_openthread_platform_config_t * config); esp_err_t openthread_init_stack(void); esp_err_t openthread_launch_task(void);