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
19 : public AudioTimerDriverBase {
20 public:
22 end();
23 if (rtsp_timer != nullptr) {
24 LOGD("esp_timer_delete");
26 rtsp_timer = nullptr;
27 }
28 }
29
33
37
40 TimeUnit unit = MS) override {
41 TRACED();
42
43 // we determine the time in microseconds
44 switch (unit) {
45 case MS:
46 time_us = time * 1000;
47 break;
48 case US:
49 time_us = time;
50 break;
51 case HZ:
52 // convert hz to time in us
54 break;
55 }
56 LOGI("Timer every: %u us", time_us);
57
58 if (rtsp_timer == nullptr) {
60 timer_args.callback = callback_f;
61 timer_args.name = "rtsp_timer";
63 // select the dispatch method
65#if CONFIG_ESP_TIMER_SUPPORTS_ISR_DISPATCH_METHOD
66 timer_args.dispatch_method = ESP_TIMER_ISR;
67#else
68 LOGW("ESP_TIMER_ISR dispatch method not supported, using ESP_TIMER_TASK");
69 timer_args.dispatch_method = ESP_TIMER_TASK;
70#endif
71 } else {
72 timer_args.dispatch_method = ESP_TIMER_TASK;
73 }
74
75 LOGD("esp_timer_create: %p", timer_args.arg);
77 if (rc != ESP_OK) {
78 LOGE("Could not create timer: %d", rc);
79 return false;
80 }
81 }
82
86 }
87
88 LOGD("esp_timer_start_periodic");
90
91 if (rc != ESP_OK) {
92 LOGE("Could not start timer: %d", rc);
93 return false;
94 }
95
96 return true;
97 }
98
100 bool end() override {
101 TRACED();
103 LOGD("esp_timer_stop");
105 }
106 return true;
107 }
108
109 protected:
113};
114
117
118
119} // namespace audio_tools
120
121#endif
122
#define LOGW(...)
Definition AudioLoggerIDF.h:29
#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:238
Repeating Timer functions for repeated execution: Plaease use the typedef AudioTimer.
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:112
void setIsSave(bool is_save) override
Not used.
Definition AudioTimerESP32.h:30
uint64_t time_us
Definition AudioTimerESP32.h:111
esp_timer_handle_t rtsp_timer
Definition AudioTimerESP32.h:110
virtual ~AudioTimerDriverESP32()
Definition AudioTimerESP32.h:21
void setTimerFunction(TimerFunction function) override
Definition AudioTimerESP32.h:34
bool end() override
ends the timer and if necessary the task
Definition AudioTimerESP32.h:100
bool begin(repeating_timer_callback_t callback_f, uint32_t time, TimeUnit unit=MS) override
Starts the alarm timer.
Definition AudioTimerESP32.h:39
TimeUnit
Time Units.
Definition AudioTypes.h:44
@ US
Definition AudioTypes.h:44
@ HZ
Definition AudioTypes.h:44
@ MS
Definition AudioTypes.h:44
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:508