arduino-audio-tools
Loading...
Searching...
No Matches
AudioTimerESP32.h
Go to the documentation of this file.
1#pragma once
2
3#if defined(ESP32)
4#include <esp_task_wdt.h>
5#include "esp_timer.h"
7
8namespace audio_tools {
9
20 public:
22 end();
23 LOGD("esp_timer_delete");
25 }
26
30
34
37 TimeUnit unit = MS) override {
38 TRACED();
39
40 // we determine the time in microseconds
41 switch (unit) {
42 case MS:
43 time_us = time * 1000;
44 break;
45 case US:
46 time_us = time;
47 break;
48 case HZ:
49 // convert hz to time in us
51 break;
52 }
53 LOGI("Timer every: %u us", time_us);
54
55 if (!initialized) {
57 timer_args.callback = callback_f;
58 timer_args.name = "rtsp_timer";
60 // select the dispatch method
62#if CONFIG_ESP_TIMER_SUPPORTS_ISR_DISPATCH_METHOD
63 timer_args.dispatch_method = ESP_TIMER_ISR;
64#endif
65 } else {
66 timer_args.dispatch_method = ESP_TIMER_TASK;
67 }
68
69 LOGD("esp_timer_create: %p", timer_args.arg);
71 if (rc != ESP_OK) {
72 LOGE("Could not create timer: %d", rc);
73 return false;
74 }
75 }
76
78 if (!started) {
79 LOGD("esp_timer_start_periodic");
81 } else {
82 LOGD("esp_timer_restart");
84 }
85 if (rc != ESP_OK) {
86 LOGE("Could not start timer: %d", rc);
87 return false;
88 }
89
90 initialized = true;
91 started = true;
92 return true;
93 }
94
96 bool end() override {
97 TRACED();
98 if (started) {
99 LOGD("esp_timer_stop");
101 }
102 started = false;
103 return true;
104 }
105
106 protected:
108 bool started = false;
109 bool initialized = false;
112};
113
116
117
118} // namespace audio_tools
119
120#endif
#define TRACED()
Definition AudioLoggerIDF.h:31
#define LOGI(...)
Definition AudioLoggerIDF.h:28
#define LOGD(...)
Definition AudioLoggerIDF.h:27
#define LOGE(...)
Definition AudioLoggerIDF.h:30
static uint32_t toTimeUs(uint32_t samplingRate, uint8_t limit=10)
converts sampling rate to delay in microseconds (μs)
Definition AudioTypes.h:242
Repeating Timer functions for repeated execution: Plaease use the typedef TimerAlarmRepeating.
Definition AudioTimerAVR.h:19
Definition AudioTimerBase.h:22
void * callbackParameter()
Definition AudioTimerBase.h:32
Repeating Timer functions for simple scheduling of repeated execution using esp_timer_create()
Definition AudioTimerESP32.h:19
TimerFunction timer_function
Definition AudioTimerESP32.h:111
bool started
Definition AudioTimerESP32.h:108
void setIsSave(bool is_save) override
Not used.
Definition AudioTimerESP32.h:27
uint64_t time_us
Definition AudioTimerESP32.h:110
esp_timer_handle_t rtsp_timer
Definition AudioTimerESP32.h:107
virtual ~TimerAlarmRepeatingDriverESP32()
Definition AudioTimerESP32.h:21
void setTimerFunction(TimerFunction function) override
Definition AudioTimerESP32.h:31
bool end() override
ends the timer and if necessary the task
Definition AudioTimerESP32.h:96
bool initialized
Definition AudioTimerESP32.h:109
bool begin(repeating_timer_callback_t callback_f, uint32_t time, TimeUnit unit=MS) override
Starts the alarm timer.
Definition AudioTimerESP32.h:36
TimeUnit
Time Units.
Definition AudioTypes.h:48
@ US
Definition AudioTypes.h:48
@ HZ
Definition AudioTypes.h:48
@ MS
Definition AudioTypes.h:48
Generic Implementation of sound input and output for desktop environments using portaudio.
Definition AudioCodecsBase.h:10
TimerFunction
Definition AudioTimerBase.h:16
@ TimerCallbackInThread
Definition AudioTimerBase.h:18
@ DirectTimerCallback
Definition AudioTimerBase.h:17
void(* repeating_timer_callback_t)(void *obj)
Definition AudioTimerAVR.h:7
size_t writeData(Print *p_out, T *data, int samples, int maxSamples=512)
Definition AudioTypes.h:512