Skip to content

Fixes SAMD PDMIn #5842

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 12, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion ports/atmel-samd/common-hal/audiobusio/PDMIn.c
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@
#endif

// Set by interrupt handler when DMA block has finished transferring.
static bool pdmin_dma_block_done;
static volatile bool pdmin_dma_block_done;
// Event channel used to trigger interrupt. Set to invalid value EVSYS_SYNCH_NUM when not in use.
static uint8_t pdmin_event_channel;

Expand All @@ -77,6 +77,7 @@ void pdmin_evsys_handler(void) {
}

void pdmin_reset(void) {
pdmin_dma_block_done = false;
pdmin_event_channel = EVSYS_SYNCH_NUM;

while (I2S->SYNCBUSY.reg & I2S_SYNCBUSY_ENABLE) {}
Expand Down Expand Up @@ -409,6 +410,20 @@ uint32_t common_hal_audiobusio_pdmin_record_to_buffer(audiobusio_pdmin_obj_t* se
init_event_channel_interrupt(pdmin_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);

#ifdef SAM_D5X_E5X
int irq = pdmin_event_channel < 4 ? EVSYS_0_IRQn + pdmin_event_channel : EVSYS_4_IRQn;
// Only disable and clear on SAMD51 because the SAMD21 shares EVSYS with ticks.
NVIC_DisableIRQ(irq);
NVIC_ClearPendingIRQ(irq);
#endif

#ifdef SAMD21
int irq = EVSYS_IRQn;
#endif

// Don't bother to disable when done. It doesn't hurt to leave it on.
NVIC_EnableIRQ(irq);
audio_dma_enable_channel(dma_channel);

// Record
Expand Down
2 changes: 1 addition & 1 deletion ports/atmel-samd/supervisor/port.c
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,7 @@ void reset_port(void) {
audioout_reset();
#endif
#if CIRCUITPY_AUDIOBUSIO
// pdmin_reset();
pdmin_reset();
#endif
#if CIRCUITPY_AUDIOBUSIO_I2SOUT
i2sout_reset();
Expand Down