8000 Merge pull request #5851 from dhalbert/pdmin-fix-7.1.x · jamesbowman/circuitpython@ea3c70a · GitHub
[go: up one dir, main page]

Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit ea3c70a

Browse files
authored
Merge pull request adafruit#5851 from dhalbert/pdmin-fix-7.1.x
PDMIn fix for SAMD: backport of adafruit#5842
2 parents 08d09ac + da702b2 commit ea3c70a

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

ports/atmel-samd/common-hal/audiobusio/PDMIn.c

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@
6666
#endif
6767

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

@@ -77,6 +77,7 @@ void pdmin_evsys_handler(void) {
7777
}
7878

7979
void pdmin_reset(void) {
80+
pdmin_dma_block_done = false;
8081
pdmin_event_channel = EVSYS_SYNCH_NUM;
8182

8283
while (I2S->SYNCBUSY.reg & I2S_SYNCBUSY_ENABLE) {}
@@ -409,6 +410,20 @@ uint32_t common_hal_audiobusio_pdmin_record_to_buffer(audiobusio_pdmin_obj_t* se
409410
init_event_channel_interrupt(pdmin_event_channel, CORE_GCLK, EVSYS_ID_GEN_DMAC_CH_0 + dma_channel);
410411
// Turn on serializer now to get it in sync with DMA.
411412
i2s_set_serializer_enable(self->serializer, true);
413+
414+
#ifdef SAM_D5X_E5X
415+
int irq = pdmin_event_channel < 4 ? EVSYS_0_IRQn + pdmin_event_channel : EVSYS_4_IRQn;
416+
// Only disable and clear on SAMD51 because the SAMD21 shares EVSYS with ticks.
417+
NVIC_DisableIRQ(irq);
418+
NVIC_ClearPendingIRQ(irq);
419+
#endif
420+
421+
#ifdef SAMD21
422+
int irq = EVSYS_IRQn;
423+
#endif
424+
425+
// Don't bother to disable when done. It doesn't hurt to leave it on.
426+
NVIC_EnableIRQ(irq);
412427
audio_dma_enable_channel(dma_channel);
413428

414429
// Record

ports/atmel-samd/supervisor/port.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -386,7 +386,7 @@ void reset_port(void) {
386386
audioout_reset();
387387
#endif
388388
#if CIRCUITPY_AUDIOBUSIO
389-
// pdmin_reset();
389+
pdmin_reset();
390390
#endif
391391
#if CIRCUITPY_AUDIOBUSIO_I2SOUT
392392
i2sout_reset();

0 commit comments

Comments
 (0)
0