summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorScott Shawcroft <scott.shawcroft@gmail.com>2018-05-02 15:15:25 -0700
committerScott Shawcroft <scott.shawcroft@gmail.com>2018-05-02 15:15:25 -0700
commit22b7cd3d519255f9d7c72c5265d3da0a68de638c (patch)
tree8265360208c2100cdbf1d32b3581a7f9a70f0c30
parentcfea51ec68504710ee683e77fada7adf4c3cffd4 (diff)
Fix 8 bit recordings on CPX.
The DMA trigger source was incorrect when using serializer 1 on the SAMD21. Playback register was incorrect for 8 bit as well. Now fixed.
-rw-r--r--ports/atmel-samd/audio_dma.c9
-rw-r--r--ports/atmel-samd/common-hal/audiobusio/PDMIn.c7
-rw-r--r--ports/atmel-samd/shared_dma.c4
3 files changed, 17 insertions, 3 deletions
diff --git a/ports/atmel-samd/audio_dma.c b/ports/atmel-samd/audio_dma.c
index 227a2e188..b468acf51 100644
--- a/ports/atmel-samd/audio_dma.c
+++ b/ports/atmel-samd/audio_dma.c
@@ -274,11 +274,16 @@ audio_dma_result audio_dma_setup_playback(audio_dma_t* dma,
MP_STATE_PORT(playing_audio)[dma->dma_channel] = dma->sample;
}
- dma->beat_size = 1;
- dma->bytes_per_sample = 1;
+
if (audiosample_bits_per_sample(sample) == 16) {
dma->beat_size = 2;
dma->bytes_per_sample = 2;
+ } else {
+ dma->beat_size = 1;
+ dma->bytes_per_sample = 1;
+ if (single_channel) {
+ output_register_address += 1;
+ }
}
// Transfer both channels at once.
if (!single_channel && audiosample_channel_count(sample) == 2) {
diff --git a/ports/atmel-samd/common-hal/audiobusio/PDMIn.c b/ports/atmel-samd/common-hal/audiobusio/PDMIn.c
index 7788335d1..8cf86421c 100644
--- a/ports/atmel-samd/common-hal/audiobusio/PDMIn.c
+++ b/ports/atmel-samd/common-hal/audiobusio/PDMIn.c
@@ -371,7 +371,12 @@ uint32_t common_hal_audiobusio_pdmin_record_to_buffer(audiobusio_pdmin_obj_t* se
setup_dma(self, output_buffer_length, dma_descriptor(dma_channel), &second_descriptor,
words_per_buffer, words_per_sample, first_buffer, second_buffer);
- dma_configure(dma_channel, I2S_DMAC_ID_RX_0, true);
+ uint8_t trigger_source = I2S_DMAC_ID_RX_0;
+ #ifdef SAMD21
+ trigger_source += self->serializer;
+ #endif
+
+ dma_configure(dma_channel, trigger_source, true);
init_event_channel_interrupt(event_channel, CORE_GCLK, EVSYS_ID_GEN_DMAC_CH_0 + dma_channel);
dma_enable_channel(dma_channel);
diff --git a/ports/atmel-samd/shared_dma.c b/ports/atmel-samd/shared_dma.c
index 88c89abee..a7c27a46e 100644
--- a/ports/atmel-samd/shared_dma.c
+++ b/ports/atmel-samd/shared_dma.c
@@ -99,6 +99,8 @@ void dma_enable_channel(uint8_t channel_number) {
common_hal_mcu_disable_interrupts();
/** Select the DMA channel and clear software trigger */
DMAC->CHID.reg = DMAC_CHID_ID(channel_number);
+ // Clear any previous interrupts.
+ DMAC->CHINTFLAG.reg = DMAC_CHINTFLAG_MASK;
DMAC->CHCTRLA.bit.ENABLE = true;
common_hal_mcu_enable_interrupts();
#endif
@@ -106,6 +108,8 @@ void dma_enable_channel(uint8_t channel_number) {
#ifdef SAMD51
DmacChannel* channel = &DMAC->Channel[channel_number];
channel->CHCTRLA.bit.ENABLE = true;
+ // Clear any previous interrupts.
+ channel->CHINTFLAG.reg = DMAC_CHINTFLAG_MASK;
#endif
}