mirror of
https://github.com/pschatzmann/arduino-audio-tools.git
synced 2024-09-21 10:27:27 +00:00
RP2040 PWM stop timer before begin
This commit is contained in:
parent
d573756fd9
commit
fc48d7848b
@ -26,7 +26,10 @@ class PWMAudioOutput : public AudioOutput {
|
||||
}
|
||||
}
|
||||
|
||||
virtual PWMConfig defaultConfig() { return pwm.defaultConfig(); }
|
||||
virtual PWMConfig defaultConfig(RxTxMode mode=TX_MODE) {
|
||||
if (mode!=TX_MODE) LOGE("mode not supported: using TX_MODE");
|
||||
return pwm.defaultConfig();
|
||||
}
|
||||
|
||||
PWMConfig config() { return audio_config; }
|
||||
|
||||
|
@ -188,7 +188,7 @@ class DriverPWMBase {
|
||||
LOGW("Could not write all data: %u -> %d", (unsigned int)size, result);
|
||||
}
|
||||
// activate the timer now - if not already done
|
||||
startTimer();
|
||||
if (!is_timer_started) startTimer();
|
||||
return result * decimation();
|
||||
}
|
||||
|
||||
|
@ -66,13 +66,10 @@ class PWMDriverRP2040 : public DriverPWMBase {
|
||||
TimerAlarmRepeating ticker;
|
||||
|
||||
virtual void startTimer() override {
|
||||
if (!is_timer_started) {
|
||||
TRACED();
|
||||
long wait_time = 1000000l / audio_config.sample_rate;
|
||||
ticker.setCallbackParameter(this);
|
||||
ticker.begin(defaultPWMAudioOutputCallbackPico, wait_time, US);
|
||||
is_timer_started = true;
|
||||
}
|
||||
ticker.begin(defaultPWMAudioOutputCallbackPico, audio_config.sample_rate, HZ);
|
||||
|
||||
is_timer_started = true;
|
||||
}
|
||||
|
||||
|
@ -38,6 +38,9 @@ class TimerAlarmRepeating {
|
||||
|
||||
bool begin(repeating_timer_callback_t callback_f, uint32_t time,
|
||||
TimeUnit unit = MS) {
|
||||
// stop timer if it is already active
|
||||
if (is_active) end();
|
||||
// start timer
|
||||
is_active = p_timer->begin(callback_f, time, unit);
|
||||
return is_active;
|
||||
}
|
||||
|
@ -38,6 +38,10 @@ class TimerAlarmRepeatingDriverBase {
|
||||
|
||||
protected:
|
||||
void* object = nullptr;
|
||||
|
||||
const char* toString(TimeUnit unit){
|
||||
return TimeUnitStr[(int)unit];
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace audio_tools
|
||||
|
@ -34,7 +34,7 @@ class TimerAlarmRepeatingDriverRP2040 : public TimerAlarmRepeatingDriverBase {
|
||||
bool begin(const my_repeating_timer_callback_t callback_f, uint32_t time,
|
||||
TimeUnit unit = MS) override {
|
||||
bool result = false;
|
||||
LOGI("timer time: %u %s", (unsigned int)time, unit == MS ? "ms" : "us");
|
||||
LOGI("timer time: %u %s", (unsigned int)time, toString(unit));
|
||||
this->instanceCallback = callback_f;
|
||||
|
||||
// we determine the time in microseconds
|
||||
|
Loading…
Reference in New Issue
Block a user