Skip to content

Commit fe0b612

Browse files
tomcombriattfry-git
authored andcommitted
Async adc readings on rp2040 on DMA_IRQ_0 with shared handler
1 parent bf62495 commit fe0b612

File tree

2 files changed

+7
-6
lines changed

2 files changed

+7
-6
lines changed

MozziGuts_impl_RP2040.hpp

+5-4
Original file line numberDiff line numberDiff line change
@@ -102,14 +102,15 @@ void setupMozziADC(int8_t speed) {
102102
);
103103

104104
// we want notification, when a sample has arrived
105-
dma_channel_set_irq1_enabled(dma_chan, true);
106-
irq_add_shared_handler(DMA_IRQ_1, rp2040_adc_queue_handler, PICO_SHARED_IRQ_HANDLER_DEFAULT_ORDER_PRIORITY);
107-
irq_set_enabled(DMA_IRQ_1, true);
105+
dma_channel_set_irq0_enabled(dma_chan, true);
106+
irq_add_shared_handler(DMA_IRQ_0, rp2040_adc_queue_handler, PICO_SHARED_IRQ_HANDLER_DEFAULT_ORDER_PRIORITY);
107+
irq_set_enabled(DMA_IRQ_0, true);
108108
dma_channel_start(dma_chan);
109109
}
110110

111111
void rp2040_adc_queue_handler() {
112-
dma_hw->ints0 = 1u << rp2040_adc_dma_chan; // clear interrupt flag
112+
if (!dma_channel_get_irq0_status(rp2040_adc_dma_chan)) return; // shared handler may get called on unrelated events
113+
dma_channel_acknowledge_irq0(rp2040_adc_dma_chan); // clear interrupt flag
113114
//adc_run(false); // adc not running continuous
114115
//adc_fifo_drain(); // no need to drain fifo, the dma transfer did that
115116
dma_channel_set_trans_count(rp2040_adc_dma_chan, 1, true); // set up for another read

README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -291,13 +291,13 @@ on the RP2040 SDK API. Tested on a Pi Pico.
291291
- Wavetables and samples are not kept in progmem on this platform. While apparently speed (of the external flash) is not much of an issue, the data always seems to be copied into RAM, anyway.
292292
- Currently, two audio output modes exist (configurable in AudioConfigRP2040.h) in addition to using an user-defined `audioOutput` function, with the default being PWM_VIA_BARE_CHIP:
293293
- PWM_VIA_BARE_CHIP: PWM audio output on pin 0, by default, with 11 bits default output resolution
294-
- One timer interrupt (DMA_IRQ_1) and one DMA channel are claimed (number not hardcoded).
294+
- One non-exclusive timer interrupt (DMA_IRQ_0) and one DMA channel are claimed (number not hardcoded).
295295
- HIFI_MODE not yet implemented (although that should not be too hard to do).
296296
- EXTERNAL_DAC_VIA_I2S: I2S output to be connected to an external DAC
297297
- 16 bits resolution by default (configurable in AudioConfigRP2040.h), 8, 16, 24 (left aligned) and 32 resolution are available.
298298
- Both plain I2S and LSBJ_FORMAT (for the PT8211 for instance) are available (configurable in AudioConfigRP2040.h), default is LSBJ.
299299
- Outputs pins can be configured in AudioConfigRP2040.h. Default is BCK: 20, WS: 21, DATA: 22.
300-
- Two timer interrupts (DMA_IRQ_0 and DMA_IRQ_1) and two DMA channels are claimed (numbers not hardcoded).
300+
- One non-exclusive timer interrupts (DMA_IRQ_0) and two DMA channels are claimed (numbers not hardcoded).
301301
- At the time of writing, LSBJ is only available with github arduino-pico core.
302302
- Note that AUDIO_INPUT and mozziAnalogRead() return values in the RP2040's full ADC resolution of 0-4095 rather than AVR's 0-1023.
303303
- twi_nonblock is not ported

0 commit comments

Comments
 (0)