samd: audio_dma_stop: don't free invalid channel

audio_dma_stop can be reached twice in normal usage of AudioOut.

This may bear further investigation, but stop it here, by making the
function check for a previously freed channel number.  This also prevents
the event channel from being disabled twice.

The first stop location is from audio_dma_get_playing, when the buffers
are exhausted; the second is from common_hal_audioio_audioout_stop when
checking the 'playing' flag.
crypto-aes
Jeff Epler 4 years ago
parent 8b717955ba
commit 39c64bf83c

@ -270,10 +270,13 @@ audio_dma_result audio_dma_setup_playback(audio_dma_t* dma,
}
void audio_dma_stop(audio_dma_t* dma) {
audio_dma_disable_channel(dma->dma_channel);
disable_event_channel(dma->event_channel);
MP_STATE_PORT(playing_audio)[dma->dma_channel] = NULL;
audio_dma_state[dma->dma_channel] = NULL;
uint8_t channel = dma->dma_channel;
if (channel < AUDIO_DMA_CHANNEL_COUNT) {
audio_dma_disable_channel(channel);
disable_event_channel(dma->event_channel);
MP_STATE_PORT(playing_audio)[channel] = NULL;
audio_dma_state[channel] = NULL;
}
dma->dma_channel = AUDIO_DMA_CHANNEL_COUNT;
}

Loading…
Cancel
Save