samd: audio_dma: wrap dma_{en,dis}able_channel and add error checking

It turns out the "disable" error will fire in practice, we'll fix that
next.
This commit is contained in:
Jeff Epler 2019-08-06 21:42:01 -05:00
parent 6253f11503
commit 8b717955ba
3 changed files with 20 additions and 6 deletions

View File

@ -50,6 +50,18 @@ uint8_t find_free_audio_dma_channel(void) {
return channel;
}
void audio_dma_disable_channel(uint8_t channel) {
if (channel >= AUDIO_DMA_CHANNEL_COUNT)
mp_raise_RuntimeError(translate("Internal error: disable invalid dma channel"));
dma_disable_channel(channel);
}
void audio_dma_enable_channel(uint8_t channel) {
if (channel >= AUDIO_DMA_CHANNEL_COUNT)
mp_raise_RuntimeError(translate("Internal error: enable invalid dma channel"));
dma_enable_channel(channel);
}
void audio_dma_convert_signed(audio_dma_t* dma, uint8_t* buffer, uint32_t buffer_length,
uint8_t** output_buffer, uint32_t* output_buffer_length,
uint8_t* output_spacing) {
@ -252,17 +264,16 @@ audio_dma_result audio_dma_setup_playback(audio_dma_t* dma,
}
dma_configure(dma_channel, dma_trigger_source, true);
dma_enable_channel(dma_channel);
audio_dma_enable_channel(dma_channel);
return AUDIO_DMA_OK;
}
void audio_dma_stop(audio_dma_t* dma) {
dma_disable_channel(dma->dma_channel);
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;
dma->dma_channel = AUDIO_DMA_CHANNEL_COUNT;
}
@ -291,7 +302,7 @@ void audio_dma_reset(void) {
for (uint8_t i = 0; i < AUDIO_DMA_CHANNEL_COUNT; i++) {
audio_dma_state[i] = NULL;
audio_dma_pending[i] = false;
dma_disable_channel(i);
audio_dma_disable_channel(i);
dma_descriptor(i)->BTCTRL.bit.VALID = false;
MP_STATE_PORT(playing_audio)[i] = NULL;
}

View File

@ -83,6 +83,9 @@ audio_dma_result audio_dma_setup_playback(audio_dma_t* dma,
bool output_signed,
uint32_t output_register_address,
uint8_t dma_trigger_source);
void audio_dma_disable_channel(uint8_t channel);
void audio_dma_enable_channel(uint8_t channel);
void audio_dma_stop(audio_dma_t* dma);
bool audio_dma_get_playing(audio_dma_t* dma);
void audio_dma_pause(audio_dma_t* dma);

View File

@ -385,7 +385,7 @@ uint32_t common_hal_audiobusio_pdmin_record_to_buffer(audiobusio_pdmin_obj_t* se
init_event_channel_interrupt(event_channel, CORE_GCLK, EVSYS_ID_GEN_DMAC_CH_0 + dma_channel);
// Turn on serializer now to get it in sync with DMA.
i2s_set_serializer_enable(self->serializer, true);
dma_enable_channel(dma_channel);
audio_dma_enable_channel(dma_channel);
// Record
uint32_t buffers_processed = 0;
@ -466,7 +466,7 @@ uint32_t common_hal_audiobusio_pdmin_record_to_buffer(audiobusio_pdmin_obj_t* se
}
disable_event_channel(event_channel);
dma_disable_channel(dma_channel);
audio_dma_disable_channel(dma_channel);
// Turn off serializer, but leave clock on, to avoid mic startup delay.
i2s_set_serializer_enable(self->serializer, false);