From 292d0259d9ab21a79432616244480c3d49193fcf Mon Sep 17 00:00:00 2001 From: Tomasz Duda Date: Tue, 29 Oct 2024 08:00:50 +0100 Subject: [PATCH] fix --- esphome/components/logger/logger.h | 1 + esphome/components/zephyr/helpers.cpp | 15 +++++++++++++++ esphome/components/zephyr/preferences.cpp | 1 + 3 files changed, 17 insertions(+) create mode 100644 esphome/components/zephyr/helpers.cpp diff --git a/esphome/components/logger/logger.h b/esphome/components/logger/logger.h index a3aaadb137..c2f07914c7 100644 --- a/esphome/components/logger/logger.h +++ b/esphome/components/logger/logger.h @@ -22,6 +22,7 @@ #endif // USE_ESP_IDF #ifdef USE_ZEPHYR +#include struct device; #endif diff --git a/esphome/components/zephyr/helpers.cpp b/esphome/components/zephyr/helpers.cpp new file mode 100644 index 0000000000..f57463aabd --- /dev/null +++ b/esphome/components/zephyr/helpers.cpp @@ -0,0 +1,15 @@ +#include "esphome/core/helpers.h" +#include + +namespace esphome { +Mutex::Mutex() { + auto mutex = new k_mutex(); + this->handle_ = mutex; + k_mutex_init(mutex); +} +Mutex::~Mutex() { delete static_cast(this->handle_); } +void Mutex::lock() { k_mutex_lock(static_cast(this->handle_), K_FOREVER); } +bool Mutex::try_lock() { return k_mutex_lock(static_cast(this->handle_), K_NO_WAIT) == 0; } +void Mutex::unlock() { k_mutex_unlock(static_cast(this->handle_)); } +uint32_t random_uint32() { return rand(); } +} // namespace esphome \ No newline at end of file diff --git a/esphome/components/zephyr/preferences.cpp b/esphome/components/zephyr/preferences.cpp index bd528193b0..d702366044 100644 --- a/esphome/components/zephyr/preferences.cpp +++ b/esphome/components/zephyr/preferences.cpp @@ -1,5 +1,6 @@ #ifdef USE_ZEPHYR +#include #include "esphome/core/preferences.h" #include "esphome/core/log.h" #include