atmel-sam: Factor out find_sync_event_channel_raise
This commit is contained in:
parent
4dcbdac97e
commit
d50feebd2c
@ -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
|
||||
|
@ -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
|
||||
|
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user