summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeff Epler <jepler@gmail.com>2019-08-06 21:42:01 -0500
committerJeff Epler <jepler@gmail.com>2019-08-06 22:00:31 -0500
commit8b717955ba198ff38d5122a32f3a3c277bbb3738 (patch)
tree8378984f0fa4d6a5c2ea35ffd58d77478da1c781
parent6253f11503c5c8ac022bc0564d74060f2c8434b9 (diff)
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.
-rw-r--r--ports/atmel-samd/audio_dma.c19
-rw-r--r--ports/atmel-samd/audio_dma.h3
-rw-r--r--ports/atmel-samd/common-hal/audiobusio/PDMIn.c4
3 files changed, 20 insertions, 6 deletions
diff --git a/ports/atmel-samd/audio_dma.c b/ports/atmel-samd/audio_dma.c
index a34d5eca4..9b38e8bdd 100644
--- a/ports/atmel-samd/audio_dma.c
+++ b/ports/atmel-samd/audio_dma.c
@@ -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;
}
diff --git a/ports/atmel-samd/audio_dma.h b/ports/atmel-samd/audio_dma.h
index 53173c277..9d923c5ce 100644
--- a/ports/atmel-samd/audio_dma.h
+++ b/ports/atmel-samd/audio_dma.h
@@ -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);
diff --git a/ports/atmel-samd/common-hal/audiobusio/PDMIn.c b/ports/atmel-samd/common-hal/audiobusio/PDMIn.c
index 8b308b60b..da5c220a8 100644
--- a/ports/atmel-samd/common-hal/audiobusio/PDMIn.c
+++ b/ports/atmel-samd/common-hal/audiobusio/PDMIn.c
@@ -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);