From d50feebd2c274faadcc8f0beab3b750d94c9c99c Mon Sep 17 00:00:00 2001 From: Jeff Epler Date: Tue, 20 Apr 2021 13:33:11 -0500 Subject: [PATCH] atmel-sam: Factor out find_sync_event_channel_raise --- ports/atmel-samd/audio_dma.c | 14 +++++++++----- ports/atmel-samd/audio_dma.h | 2 ++ ports/atmel-samd/common-hal/audiobusio/PDMIn.c | 5 +---- 3 files changed, 12 insertions(+), 9 deletions(-) diff --git a/ports/atmel-samd/audio_dma.c b/ports/atmel-samd/audio_dma.c index 0fe71e6d5d..b18db9c67a 100644 --- a/ports/atmel-samd/audio_dma.c +++ b/ports/atmel-samd/audio_dma.c @@ -45,6 +45,14 @@ static volatile bool audio_dma_pending[AUDIO_DMA_CHANNEL_COUNT]; static bool audio_dma_allocated[AUDIO_DMA_CHANNEL_COUNT]; +uint8_t find_sync_event_channel_raise() { + uint8_t event_channel = find_sync_event_channel(); + if (event_channel >= EVSYS_SYNCH_NUM) { + mp_raise_RuntimeError(translate("All sync event channels in use")); + } + return event_channel; +} + uint8_t audio_dma_allocate_channel(void) { uint8_t channel; for (channel = 0; channel < AUDIO_DMA_CHANNEL_COUNT; channel++) { @@ -230,11 +238,7 @@ audio_dma_result audio_dma_setup_playback(audio_dma_t *dma, // We're likely double buffering so set up the block interrupts. turn_on_event_system(); - dma->event_channel = find_sync_event_channel(); - - if (dma->event_channel >= EVSYS_SYNCH_NUM) { - mp_raise_RuntimeError(translate("All sync event channels in use")); - } + dma->event_channel = find_sync_event_channel_raise(); init_event_channel_interrupt(dma->event_channel, CORE_GCLK, EVSYS_ID_GEN_DMAC_CH_0 + dma_channel); // We keep the audio_dma_t for internal use and the sample as a root pointer because it diff --git a/ports/atmel-samd/audio_dma.h b/ports/atmel-samd/audio_dma.h index 5506cff628..d6c766efb8 100644 --- a/ports/atmel-samd/audio_dma.h +++ b/ports/atmel-samd/audio_dma.h @@ -97,4 +97,6 @@ bool audio_dma_get_paused(audio_dma_t *dma); void audio_dma_background(void); +uint8_t find_sync_event_channel_raise(void); + #endif // MICROPY_INCLUDED_ATMEL_SAMD_AUDIO_DMA_H diff --git a/ports/atmel-samd/common-hal/audiobusio/PDMIn.c b/ports/atmel-samd/common-hal/audiobusio/PDMIn.c index 8911aef2f1..cbb50bec83 100644 --- a/ports/atmel-samd/common-hal/audiobusio/PDMIn.c +++ b/ports/atmel-samd/common-hal/audiobusio/PDMIn.c @@ -368,10 +368,7 @@ static uint16_t filter_sample(uint32_t pdm_samples[4]) { uint32_t common_hal_audiobusio_pdmin_record_to_buffer(audiobusio_pdmin_obj_t* self, uint16_t* output_buffer, uint32_t output_buffer_length) { uint8_t dma_channel = audio_dma_allocate_channel(); - uint8_t event_channel = find_sync_event_channel(); - if (event_channel >= EVSYS_SYNCH_NUM) { - mp_raise_RuntimeError(translate("All sync event channels in use")); - } + uint8_t event_channel = find_sync_event_channel_raise(); // We allocate two buffers on the stack to use for double buffering. const uint8_t samples_per_buffer = SAMPLES_PER_BUFFER;