3 #if defined(ARDUINO_ARCH_RENESAS)
4 #include "AudioTools/CoreAudio/AudioTimer/AudioTimerBase.h"
6 #include "IRQManager.h"
10 typedef void (*my_repeating_timer_callback_t)(
void *obj);
28 bool begin(
const my_repeating_timer_callback_t callback_f, uint32_t time,
31 LOGI(
"timer time: %u %s", (
unsigned int)time, TimeUnitStr[unit]);
32 this->instanceCallback = callback_f;
38 rate = AudioTime::toRateMs(time);
41 rate = AudioTime::toRateUs(time);
47 LOGE(
"Undefined Unit");
50 if (rate < 550 || rate > 100000) {
51 LOGE(
"Unsupported rate: %f hz", rate);
54 LOGI(
"rate is %f hz", rate);
62 LOGI(
"Using %s", timer_type == 1 ?
"AGT" :
"GPT")
63 timer_active = timer_type == 1 ? startAGTTimer(rate) : startGPTTimer(rate);
67 inline static void staticCallback(timer_callback_args_t *ptr) {
70 self->instanceCallback(self->object);
82 void setTimer(
int timer)
override { timer_type = timer; }
86 my_repeating_timer_callback_t instanceCallback =
nullptr;
87 uint8_t timer_type = 0;
88 bool timer_active =
false;
91 bool startAGTTimer(
float rate) {
93 uint8_t timer_type = AGT_TIMER;
95 int timer_channel = 1;
96 audio_timer.begin(TIMER_MODE_PERIODIC, timer_type, timer_channel,
97 rate * 2.0, 0.0f, staticCallback,
this);
98 IRQManager::getInstance().addPeripheral(IRQ_AGT, audio_timer.get_cfg());
100 bool result = audio_timer.start();
105 bool startGPTTimer(
float rate) {
107 uint8_t timer_type = GPT_TIMER;
108 int8_t tindex = FspTimer::get_available_timer(timer_type);
110 LOGE(
"Using pwm reserved timer");
111 tindex = FspTimer::get_available_timer(timer_type,
true);
117 FspTimer::force_use_of_pwm_reserved_timer();
118 LOGI(
"timer idx: %d", tindex);
119 if (!audio_timer.begin(TIMER_MODE_PERIODIC, timer_type, tindex, rate, 0.0f,
120 staticCallback,
this)) {
125 if (!audio_timer.setup_overflow_irq()) {
126 LOGE(
"error:setup_overflow_irq");
130 if (!audio_timer.open()) {
134 if (!audio_timer.start()) {
TimeUnit
Time Units.
Definition: AudioTypes.h:45