Remove app::utils helpers with zero fleet call sites after the app_common merge (as_u8s, hexdump, add_overflow/overflow_error, try_get/try_get_ref, constrain_value_in_range_static — a template-bounds reimplementation of std::clamp) and the unused app_clock milliseconds alias. This drops several heavy includes from a header every consumer compiles. Rewrite deferrer as a stdlib scope guard that owns the callable directly (template<F>, non-copyable/non-movable) instead of type-erasing through std::move_only_function/std::function, so it never heap-allocates. The 3 call sites (band max32664d) are unchanged via CTAD.
38 lines
1.1 KiB
C++
38 lines
1.1 KiB
C++
#pragma once
|
|
#include <chrono>
|
|
#include <cstdint>
|
|
#include <ratio>
|
|
|
|
#if defined(__ZEPHYR__)
|
|
#include <zephyr/kernel.h>
|
|
#elif defined(ESP_PLATFORM)
|
|
#include <esp_timer.h>
|
|
#else
|
|
#error "app_clock.hpp: unsupported platform (expected Zephyr or ESP-IDF)"
|
|
#endif
|
|
|
|
namespace app::utils {
|
|
/**
|
|
* @brief a monotonic clock with microsecond resolution
|
|
* @see https://en.cppreference.com/w/cpp/named_req/TrivialClock.html
|
|
* @see https://en.cppreference.com/w/cpp/named_req/Clock.html
|
|
*/
|
|
struct clock_t {
|
|
using rep = int64_t; // signed arithmetic type for tick count
|
|
using period = std::micro; // tick period in seconds (1/1000000)
|
|
using duration = std::chrono::duration<rep, period>;
|
|
using time_point = std::chrono::time_point<clock_t>;
|
|
static constexpr bool is_steady = true;
|
|
|
|
static time_point now() {
|
|
#if defined(__ZEPHYR__)
|
|
auto t = k_uptime_ticks();
|
|
auto dur = k_ticks_to_us_floor64(t);
|
|
return time_point(duration(static_cast<rep>(dur)));
|
|
#else
|
|
return time_point(duration(static_cast<rep>(esp_timer_get_time())));
|
|
#endif
|
|
}
|
|
};
|
|
}
|