From fbd01e717b56e9a4c76cc2fe58c757bbf410dd4c Mon Sep 17 00:00:00 2001 From: 0xFEEDC0DE64 Date: Thu, 15 Apr 2021 21:45:31 +0200 Subject: [PATCH] Added espchrono_impl.cpp --- CMakeLists.txt | 1 + src/espchrono_impl.cpp | 25 +++++++++++++++++++++++++ 2 files changed, 26 insertions(+) create mode 100644 src/espchrono_impl.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 0cd2546..7dbc3ad 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -4,6 +4,7 @@ set(headers set(sources src/espchrono.cpp + src/espchrono_impl.cpp ) idf_component_register(INCLUDE_DIRS src SRCS ${headers} ${sources} REQUIRES freertos esp_system cpputils date) diff --git a/src/espchrono_impl.cpp b/src/espchrono_impl.cpp new file mode 100644 index 0000000..48d4509 --- /dev/null +++ b/src/espchrono_impl.cpp @@ -0,0 +1,25 @@ +// local includes +#include "espchrono.h" + +// system includes +#include + +// esp-idf inlcludes +#include + +using namespace std::chrono_literals; + +// actual implementations used on the ESP32 + +auto espchrono::utc_clock::now() noexcept -> time_point +{ + timeval tv; + gettimeofday(&tv, NULL); + seconds32 seconds{tv.tv_sec}; + return time_point{seconds}; +} + +auto espchrono::millis_clock::now() noexcept -> time_point +{ + return time_point{std::chrono::floor(std::chrono::microseconds{esp_timer_get_time()})}; +}