Skip to content

Commit

Permalink
Async adc readings on rp2040 on DMA_IRQ_0 with shared handler
Browse files Browse the repository at this point in the history
  • Loading branch information
tomcombriat authored and tfry-git committed Jan 11, 2023
1 parent bf62495 commit fe0b612
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
9 changes: 5 additions & 4 deletions MozziGuts_impl_RP2040.hpp
Expand Up @@ -102,14 +102,15 @@ void setupMozziADC(int8_t speed) {
);

// we want notification, when a sample has arrived
dma_channel_set_irq1_enabled(dma_chan, true);
irq_add_shared_handler(DMA_IRQ_1, rp2040_adc_queue_handler, PICO_SHARED_IRQ_HANDLER_DEFAULT_ORDER_PRIORITY);
irq_set_enabled(DMA_IRQ_1, true);
dma_channel_set_irq0_enabled(dma_chan, true);
irq_add_shared_handler(DMA_IRQ_0, rp2040_adc_queue_handler, PICO_SHARED_IRQ_HANDLER_DEFAULT_ORDER_PRIORITY);
irq_set_enabled(DMA_IRQ_0, true);
dma_channel_start(dma_chan);
}

void rp2040_adc_queue_handler() {
dma_hw->ints0 = 1u << rp2040_adc_dma_chan; // clear interrupt flag
if (!dma_channel_get_irq0_status(rp2040_adc_dma_chan)) return; // shared handler may get called on unrelated events
dma_channel_acknowledge_irq0(rp2040_adc_dma_chan); // clear interrupt flag
//adc_run(false); // adc not running continuous
//adc_fifo_drain(); // no need to drain fifo, the dma transfer did that
dma_channel_set_trans_count(rp2040_adc_dma_chan, 1, true); // set up for another read
Expand Down
4 changes: 2 additions & 2 deletions README.md
Expand Up @@ -291,13 +291,13 @@ on the RP2040 SDK API. Tested on a Pi Pico.
- 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.
- 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:
- PWM_VIA_BARE_CHIP: PWM audio output on pin 0, by default, with 11 bits default output resolution
- One timer interrupt (DMA_IRQ_1) and one DMA channel are claimed (number not hardcoded).
- One non-exclusive timer interrupt (DMA_IRQ_0) and one DMA channel are claimed (number not hardcoded).
- HIFI_MODE not yet implemented (although that should not be too hard to do).
- EXTERNAL_DAC_VIA_I2S: I2S output to be connected to an external DAC
- 16 bits resolution by default (configurable in AudioConfigRP2040.h), 8, 16, 24 (left aligned) and 32 resolution are available.
- Both plain I2S and LSBJ_FORMAT (for the PT8211 for instance) are available (configurable in AudioConfigRP2040.h), default is LSBJ.
- Outputs pins can be configured in AudioConfigRP2040.h. Default is BCK: 20, WS: 21, DATA: 22.
- Two timer interrupts (DMA_IRQ_0 and DMA_IRQ_1) and two DMA channels are claimed (numbers not hardcoded).
- One non-exclusive timer interrupts (DMA_IRQ_0) and two DMA channels are claimed (numbers not hardcoded).
- At the time of writing, LSBJ is only available with github arduino-pico core.
- Note that AUDIO_INPUT and mozziAnalogRead() return values in the RP2040's full ADC resolution of 0-4095 rather than AVR's 0-1023.
- twi_nonblock is not ported
Expand Down

0 comments on commit fe0b612

Please sign in to comment.