mirror of
https://github.com/esphome/esphome.git
synced 2026-07-10 17:05:36 +00:00
[openthread] move esp functions into correct file (#14588)
This commit is contained in:
@@ -1,7 +1,6 @@
|
||||
#include "esphome/core/defines.h"
|
||||
#ifdef USE_OPENTHREAD
|
||||
#include "openthread.h"
|
||||
#include "esp_openthread.h"
|
||||
|
||||
#include <freertos/portmacro.h>
|
||||
|
||||
@@ -51,7 +50,7 @@ void OpenThreadComponent::on_state_changed_(otChangedFlags flags, void *context)
|
||||
auto *self = static_cast<OpenThreadComponent *>(context);
|
||||
// This runs on the OpenThread task thread with the OT lock held,
|
||||
// so we can safely call otThreadGetDeviceRole directly.
|
||||
otInstance *instance = esp_openthread_get_instance();
|
||||
otInstance *instance = self->get_openthread_instance_();
|
||||
otDeviceRole role = otThreadGetDeviceRole(instance);
|
||||
self->connected_ = role >= OT_DEVICE_ROLE_CHILD;
|
||||
}
|
||||
@@ -233,16 +232,12 @@ bool OpenThreadComponent::teardown() {
|
||||
otSrpClientClearHostAndServices(instance);
|
||||
otSrpClientBuffersFreeAllServices(instance);
|
||||
global_openthread_component = nullptr;
|
||||
#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 5, 0)
|
||||
ESP_LOGD(TAG, "Exit main loop ");
|
||||
int error = esp_openthread_mainloop_exit();
|
||||
int error = this->openthread_stop_();
|
||||
if (error != ESP_OK) {
|
||||
ESP_LOGW(TAG, "Failed attempt to stop main loop %d", error);
|
||||
this->teardown_complete_ = true;
|
||||
}
|
||||
#else
|
||||
this->teardown_complete_ = true;
|
||||
#endif
|
||||
}
|
||||
return this->teardown_complete_;
|
||||
}
|
||||
|
||||
@@ -44,6 +44,8 @@ class OpenThreadComponent : public Component {
|
||||
protected:
|
||||
std::optional<otIp6Address> get_omr_address_(InstanceLock &lock);
|
||||
static void on_state_changed_(otChangedFlags flags, void *context);
|
||||
otInstance *get_openthread_instance_();
|
||||
int openthread_stop_();
|
||||
std::function<void()> factory_reset_external_callback_;
|
||||
#if CONFIG_OPENTHREAD_MTD
|
||||
uint32_t poll_period_{0};
|
||||
|
||||
@@ -190,6 +190,8 @@ void OpenThreadComponent::ot_main() {
|
||||
vTaskDelete(NULL);
|
||||
}
|
||||
|
||||
int OpenThreadComponent::openthread_stop_() { return esp_openthread_mainloop_exit(); }
|
||||
|
||||
network::IPAddresses OpenThreadComponent::get_ip_addresses() {
|
||||
network::IPAddresses addresses;
|
||||
struct esp_ip6_addr if_ip6s[CONFIG_LWIP_IPV6_NUM_ADDRESSES];
|
||||
@@ -204,6 +206,9 @@ network::IPAddresses OpenThreadComponent::get_ip_addresses() {
|
||||
return addresses;
|
||||
}
|
||||
|
||||
// not thread safe, only use in read-only use cases
|
||||
otInstance *OpenThreadComponent::get_openthread_instance_() { return esp_openthread_get_instance(); }
|
||||
|
||||
std::optional<InstanceLock> InstanceLock::try_acquire(int delay) {
|
||||
if (esp_openthread_lock_acquire(delay)) {
|
||||
return InstanceLock();
|
||||
|
||||
Reference in New Issue
Block a user