Merge pull request #4809 from DavePutz/issue_4266

Fix for Issue #4266 - second PWMAudioOut interferes with the first one
This commit is contained in:
Jeff Epler 2021-06-03 19:08:28 -05:00 committed by GitHub
commit a99eba35b8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 5 additions and 2 deletions

View File

@ -352,6 +352,8 @@ bool audio_dma_get_paused(audio_dma_t *dma) {
void audio_dma_init(audio_dma_t *dma) { void audio_dma_init(audio_dma_t *dma) {
dma->first_buffer = NULL; dma->first_buffer = NULL;
dma->second_buffer = NULL; dma->second_buffer = NULL;
dma->channel[0] = NUM_DMA_CHANNELS;
dma->channel[1] = NUM_DMA_CHANNELS;
} }
void audio_dma_deinit(audio_dma_t *dma) { void audio_dma_deinit(audio_dma_t *dma) {
@ -368,7 +370,6 @@ bool audio_dma_get_playing(audio_dma_t *dma) {
} }
if (!dma_channel_is_busy(dma->channel[0]) && if (!dma_channel_is_busy(dma->channel[0]) &&
!dma_channel_is_busy(dma->channel[1])) { !dma_channel_is_busy(dma->channel[1])) {
audio_dma_stop(dma);
return false; return false;
} }

View File

@ -102,6 +102,7 @@ void common_hal_audiopwmio_pwmaudioout_construct(audiopwmio_pwmaudioout_obj_t *s
} }
audio_dma_init(&self->dma); audio_dma_init(&self->dma);
self->pacing_timer = NUM_DMA_TIMERS;
self->quiescent_value = quiescent_value; self->quiescent_value = quiescent_value;
} }
@ -126,6 +127,7 @@ void common_hal_audiopwmio_pwmaudioout_deinit(audiopwmio_pwmaudioout_obj_t *self
} }
void common_hal_audiopwmio_pwmaudioout_play(audiopwmio_pwmaudioout_obj_t *self, mp_obj_t sample, bool loop) { void common_hal_audiopwmio_pwmaudioout_play(audiopwmio_pwmaudioout_obj_t *self, mp_obj_t sample, bool loop) {
if (common_hal_audiopwmio_pwmaudioout_get_playing(self)) { if (common_hal_audiopwmio_pwmaudioout_get_playing(self)) {
common_hal_audiopwmio_pwmaudioout_stop(self); common_hal_audiopwmio_pwmaudioout_stop(self);
} }
@ -135,8 +137,8 @@ void common_hal_audiopwmio_pwmaudioout_play(audiopwmio_pwmaudioout_obj_t *self,
for (size_t i = 0; i < NUM_DMA_TIMERS; i++) { for (size_t i = 0; i < NUM_DMA_TIMERS; i++) {
if (dma_hw->timer[i] == 0) { if (dma_hw->timer[i] == 0) {
pacing_timer = i; pacing_timer = i;
break;
} }
break;
} }
if (pacing_timer == NUM_DMA_TIMERS) { if (pacing_timer == NUM_DMA_TIMERS) {
mp_raise_RuntimeError(translate("No DMA pacing timer found")); mp_raise_RuntimeError(translate("No DMA pacing timer found"));