75#if CONFIG_ESP_TIMER_SUPPORTS_ISR_DISPATCH_METHOD || __DOXYGEN__
84 std::string_view
name =
"";
89#ifdef CONFIG_COMPILER_CXX_EXCEPTIONS
131#ifdef CONFIG_COMPILER_CXX_EXCEPTIONS
156 template<
typename Rep,
typename Period>
159 const std::chrono::duration<Rep, Period>&
timeout,
160 std::move_only_function<
void()> callback
183 template<
typename Rep,
typename Period>
261 template<
typename Rep,
typename Period>
264 const std::chrono::duration<Rep, Period>&
interval,
265 std::move_only_function<
void()> callback
288 template<
typename Rep,
typename Period>
315 template<
typename Rep,
typename Period>
318 const std::chrono::duration<Rep, Period>&
timeout,
319 std::move_only_function<
void()> callback
321 auto t =
make(std::move(
cfg), std::move(callback));
351 template<
typename Rep,
typename Period>
385 auto t =
make(std::move(
cfg), std::move(callback));
389 auto r =
t->try_start_once(time);
420 auto r =
t->try_start_once(time);
446 template<
typename Rep,
typename Period>
449 const std::chrono::duration<Rep, Period>&
interval,
450 std::move_only_function<
void()> callback
452 auto t =
make(std::move(
cfg), std::move(callback));
482 template<
typename Rep,
typename Period>
485 const std::chrono::duration<Rep, Period>&
interval,
486 void (*callback)(
void*),
525#ifdef CONFIG_COMPILER_CXX_EXCEPTIONS
535 template<
typename Rep,
typename Period>
569 template<
typename Rep,
typename Period>
587 template<
typename Rep,
typename Period>
589 if (_handle ==
nullptr) {
606 if (_handle ==
nullptr) {
645 template<
typename Rep,
typename Period>
647 if (_handle ==
nullptr) {
671#ifdef CONFIG_COMPILER_CXX_EXCEPTIONS
681 template<
typename Rep,
typename Period>
699 template<
typename Rep,
typename Period>
701 if (_handle ==
nullptr) {
729#ifdef CONFIG_COMPILER_CXX_EXCEPTIONS
746 if (_handle ==
nullptr) {
769 if (_handle ==
nullptr) {
785 if (_handle ==
nullptr) {
786 return std::chrono::microseconds{0};
803 if (_handle ==
nullptr) {
804 return clock::time_point::max();
808 return clock::time_point::max();
810 if (
expiry >
static_cast<uint64_t>(std::numeric_limits<int64_t>::max())) {
811 return clock::time_point::max();
839 return std::chrono::duration_cast<std::chrono::microseconds>(
d).count();
842 static void trampoline(
void*
arg);
Task lifecycle management.
High-resolution timer with microsecond precision.
timer(const config &cfg, std::move_only_function< void()> callback)
Creates a timer with a std::move_only_function callback.
const std::string & name() const noexcept
Returns the timer name.
esp_err_t try_stop_isr()
Stops the timer (ISR-compatible).
static clock::time_point next_alarm()
Returns the time of the next scheduled timer event.
result< void > try_start_once(const std::chrono::duration< Rep, Period > &timeout)
Starts the timer as a one-shot timer.
std::chrono::microseconds period() const noexcept
Returns the period of a periodic timer.
void start_once(clock::time_point time)
Starts the timer as a one-shot timer at an absolute time.
static timer start_once(config cfg, clock::time_point time, void(*callback)(void *), void *arg)
Creates and starts a one-shot timer at an absolute time with a raw function pointer callback.
static result< timer > try_start_once(config cfg, clock::time_point time, std::move_only_function< void()> callback)
Creates and starts a one-shot timer at an absolute time with a std::move_only_function callback.
timer(const timer &)=delete
static result< timer > make(config cfg, void(*callback)(void *), void *arg)
Creates a timer with a raw function pointer callback.
clock::time_point expiry_time() const noexcept
Returns the absolute expiry time for a one-shot timer.
static timer start_once(config cfg, clock::time_point time, std::move_only_function< void()> callback)
Creates and starts a one-shot timer at an absolute time with a std::move_only_function callback.
result< void > try_start_once(clock::time_point time)
Starts the timer as a one-shot timer at an absolute time.
timer & operator=(timer &&other) noexcept
esp_err_t try_restart_isr(uint64_t timeout_us)
Restarts the timer with a new timeout (ISR-compatible).
static result< timer > try_start_once(config cfg, clock::time_point time, void(*callback)(void *), void *arg)
Creates and starts a one-shot timer at an absolute time with a raw function pointer callback.
esp_err_t try_start_periodic_isr(uint64_t interval_us)
Starts the timer as a periodic timer (ISR-compatible).
timer(timer &&other) noexcept
esp_err_t try_start_once_isr(uint64_t timeout_us)
Starts the timer as a one-shot timer (ISR-compatible).
void start_periodic(const std::chrono::duration< Rep, Period > &interval)
Starts the timer as a periodic timer.
static result< timer > try_start_once(config cfg, const std::chrono::duration< Rep, Period > &timeout, std::move_only_function< void()> callback)
Creates and starts a one-shot timer with a std::move_only_function callback.
static result< timer > make(config cfg, std::move_only_function< void()> callback)
Creates a timer with a std::move_only_function callback.
static result< timer > try_start_periodic(config cfg, const std::chrono::duration< Rep, Period > &interval, std::move_only_function< void()> callback)
Creates and starts a periodic timer with a std::move_only_function callback.
void start_once(const std::chrono::duration< Rep, Period > &timeout)
Starts the timer as a one-shot timer.
esp_timer_handle_t idf_handle() const noexcept
Returns the underlying ESP-IDF timer handle.
static timer start_periodic(config cfg, const std::chrono::duration< Rep, Period > &interval, void(*callback)(void *), void *arg)
Creates and starts a periodic timer with a raw function pointer callback.
result< void > try_stop()
Stops the timer.
bool is_active() const noexcept
Checks if the timer is currently running.
void stop()
Stops the timer.
void restart(const std::chrono::duration< Rep, Period > &timeout)
Restarts the timer with a new timeout.
static result< timer > try_start_once(config cfg, const std::chrono::duration< Rep, Period > &timeout, void(*callback)(void *), void *arg)
Creates and starts a one-shot timer with a raw function pointer callback.
timer & operator=(const timer &)=delete
static timer start_once(config cfg, const std::chrono::duration< Rep, Period > &timeout, void(*callback)(void *), void *arg)
Creates and starts a one-shot timer with a raw function pointer callback.
result< void > try_start_periodic(const std::chrono::duration< Rep, Period > &interval)
Starts the timer as a periodic timer.
result< void > try_restart(const std::chrono::duration< Rep, Period > &timeout)
Restarts the timer with a new timeout.
static result< timer > try_start_periodic(config cfg, const std::chrono::duration< Rep, Period > &interval, void(*callback)(void *), void *arg)
Creates and starts a periodic timer with a raw function pointer callback.
~timer()
Destroys the timer.
dispatch_method
Callback dispatch type.
@ task
Callback runs in high-priority timer task (default)
static timer start_periodic(config cfg, const std::chrono::duration< Rep, Period > &interval, std::move_only_function< void()> callback)
Creates and starts a periodic timer with a std::move_only_function callback.
static timer start_once(config cfg, const std::chrono::duration< Rep, Period > &timeout, std::move_only_function< void()> callback)
Creates and starts a one-shot timer with a std::move_only_function callback.
constexpr std::unexpected< std::error_code > error(E e) noexcept
Creates an unexpected error from an error code enum.
T unwrap(result< T > result)
Throws a std::system_error if the result is an error.
@ invalid_state
Invalid state.
@ timeout
Operation timed out.
std::expected< T, std::error_code > result
result type wrapping a value or error code.
result< void > wrap(esp_err_t e)
Wraps an esp_err_t into a result<void>.
Monotonic clock based on boot time.
static constexpr bool is_steady
std::chrono::time_point< clock > time_point
static time_point now() noexcept
Returns the current time.
std::chrono::microseconds duration
Timer configuration parameters.
bool skip_unhandled_events
Skip events if callback busy.
enum dispatch_method dispatch
Callback dispatch type.
std::string_view name
Timer name for debugging.