3#if defined(ESP32) && defined(ARDUINO)
4#include <esp_task_wdt.h>
6#include "AudioTools/CoreAudio/AudioTimer/AudioTimerBase.h"
18class TimerAlarmRepeatingDriverESP32
19 :
public TimerAlarmRepeatingDriverBase {
21 virtual ~TimerAlarmRepeatingDriverESP32() {
23 LOGD(
"esp_timer_delete");
24 esp_timer_delete(rtsp_timer);
27 void setIsSave(
bool is_save)
override {
28 setTimerFunction(is_save ? TimerCallbackInThread : DirectTimerCallback);
31 void setTimerFunction(TimerFunction function)
override {
32 timer_function = function;
36 bool begin(repeating_timer_callback_t callback_f, uint32_t time,
43 time_us = time * 1000;
53 LOGI(
"Timer every: %u us", time_us);
56 esp_timer_create_args_t timer_args;
57 timer_args.callback = callback_f;
58 timer_args.name =
"rtsp_timer";
59 timer_args.arg = callbackParameter();
61 if (timer_function == DirectTimerCallback) {
62#if CONFIG_ESP_TIMER_SUPPORTS_ISR_DISPATCH_METHOD
63 timer_args.dispatch_method = ESP_TIMER_ISR;
66 timer_args.dispatch_method = ESP_TIMER_TASK;
69 LOGD(
"esp_timer_create: %p", timer_args.arg);
70 esp_err_t rc = esp_timer_create(&timer_args, &rtsp_timer);
72 LOGE(
"Could not create timer: %d", rc);
77 esp_err_t rc = ESP_OK;
79 LOGD(
"esp_timer_start_periodic");
80 rc = esp_timer_start_periodic(rtsp_timer, time_us);
82 LOGD(
"esp_timer_restart");
83 rc = esp_timer_restart(rtsp_timer, time_us);
86 LOGE(
"Could not start timer: %d", rc);
99 LOGD(
"esp_timer_stop");
100 esp_timer_stop(rtsp_timer);
107 esp_timer_handle_t rtsp_timer =
nullptr;
108 bool started =
false;
109 bool initialized =
false;
110 uint64_t time_us = 0;
111 TimerFunction timer_function = TimerCallbackInThread;
TimeUnit
Time Units.
Definition AudioTypes.h:46