[nrf52, core] nrf52 core based on zephyr (#7049)

Co-authored-by: Jesse Hills <3060199+jesserockz@users.noreply.github.com>
Co-authored-by: Samuel Sieb <samuel-github@sieb.net>
Co-authored-by: Tomasz Duda <tomaszduda23@gmai.com>
Co-authored-by: J. Nick Koston <nick@koston.org>
This commit is contained in:
tomaszduda23
2025-07-16 13:00:21 +12:00
committed by GitHub
co-authored by Jesse Hills Samuel Sieb Tomasz Duda J. Nick Koston
parent eb81b8a1c8
commit 5d9cba3dce
32 changed files with 1250 additions and 17 deletions
+16 -3
View File
@@ -2,13 +2,15 @@
#include "esphome/core/log.h"
#ifdef USE_HOST
#include <sys/time.h>
#elif defined(USE_ZEPHYR)
#include <zephyr/posix/time.h>
#else
#include "lwip/opt.h"
#endif
#ifdef USE_ESP8266
#include "sys/time.h"
#endif
#ifdef USE_RP2040
#if defined(USE_RP2040) || defined(USE_ZEPHYR)
#include <sys/time.h>
#endif
#include <cerrno>
@@ -22,11 +24,22 @@ static const char *const TAG = "time";
RealTimeClock::RealTimeClock() = default;
void RealTimeClock::synchronize_epoch_(uint32_t epoch) {
ESP_LOGVV(TAG, "Got epoch %" PRIu32, epoch);
// Update UTC epoch time.
#ifdef USE_ZEPHYR
struct timespec ts;
ts.tv_nsec = 0;
ts.tv_sec = static_cast<time_t>(epoch);
int ret = clock_settime(CLOCK_REALTIME, &ts);
if (ret != 0) {
ESP_LOGW(TAG, "clock_settime() failed with code %d", ret);
}
#else
struct timeval timev {
.tv_sec = static_cast<time_t>(epoch), .tv_usec = 0,
};
ESP_LOGVV(TAG, "Got epoch %" PRIu32, epoch);
struct timezone tz = {0, 0};
int ret = settimeofday(&timev, &tz);
if (ret == EINVAL) {
@@ -43,7 +56,7 @@ void RealTimeClock::synchronize_epoch_(uint32_t epoch) {
if (ret != 0) {
ESP_LOGW(TAG, "setimeofday() failed with code %d", ret);
}
#endif
auto time = this->now();
ESP_LOGD(TAG, "Synchronized time: %04d-%02d-%02d %02d:%02d:%02d", time.year, time.month, time.day_of_month, time.hour,
time.minute, time.second);