Added espchrono_impl.cpp

This commit is contained in:
2021-04-15 21:45:31 +02:00
parent 368b64e800
commit fbd01e717b
2 changed files with 26 additions and 0 deletions

View File

@ -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)

25
src/espchrono_impl.cpp Normal file
View File

@ -0,0 +1,25 @@
// local includes
#include "espchrono.h"
// system includes
#include <time.h>
// esp-idf inlcludes
#include <esp_timer.h>
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<duration>(std::chrono::microseconds{esp_timer_get_time()})};
}