Skip to content

Commit

Permalink
ESP32: Move the openthread platform config file to examples (project-…
Browse files Browse the repository at this point in the history
  • Loading branch information
wqx6 authored Jun 13, 2023
1 parent d6fbc62 commit 212142b
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 10 deletions.
9 changes: 9 additions & 0 deletions examples/all-clusters-app/esp32/main/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@
#endif

#if CONFIG_OPENTHREAD_ENABLED
#include <common/OpenthreadConfig.h>
#include <platform/ESP32/OpenthreadLauncher.h>
#include <platform/ThreadStackManager.h>
#endif

Expand Down Expand Up @@ -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");
Expand Down
9 changes: 9 additions & 0 deletions examples/all-clusters-minimal-app/esp32/main/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@
#endif

#if CONFIG_OPENTHREAD_ENABLED
#include <common/OpenthreadConfig.h>
#include <platform/ESP32/OpenthreadLauncher.h>
#include <platform/ThreadStackManager.h>
#endif

Expand Down Expand Up @@ -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");
Expand Down
12 changes: 12 additions & 0 deletions examples/lighting-app/esp32/main/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,11 @@
#include "Rpc.h"
#endif

#if CHIP_DEVICE_CONFIG_ENABLE_THREAD
#include <common/OpenthreadConfig.h>
#include <platform/ESP32/OpenthreadLauncher.h>
#endif

#include "DeviceWithDisplay.h"

#if CONFIG_ENABLE_ESP32_DEVICE_INFO_PROVIDER
Expand Down Expand Up @@ -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");
Expand Down
File renamed without changes.
1 change: 0 additions & 1 deletion src/platform/ESP32/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,6 @@ static_library("ESP32") {
"../OpenThread/GenericNetworkCommissioningThreadDriver.cpp",
"../OpenThread/GenericNetworkCommissioningThreadDriver.h",
"../OpenThread/OpenThreadUtils.cpp",
"OpenthreadConfig.h",
"OpenthreadLauncher.c",
"OpenthreadLauncher.h",
"ThreadStackManagerImpl.cpp",
Expand Down
19 changes: 10 additions & 9 deletions src/platform/ESP32/OpenthreadLauncher.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
* limitations under the License.
*/

#include "OpenthreadConfig.h"
#include "driver/uart.h"
#include "esp_event.h"
#include "esp_netif.h"
Expand All @@ -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)
{
Expand All @@ -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:
Expand All @@ -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;
}

Expand Down
4 changes: 4 additions & 0 deletions src/platform/ESP32/OpenthreadLauncher.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,14 @@

#pragma once

#include <esp_err.h>
#include <esp_openthread_types.h>

#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);

Expand Down

0 comments on commit 212142b

Please sign in to comment.