Skip to content

Commit

Permalink
Changed ADC timer to shared IRQ instead of exclusive for RP2040, smal…
Browse files Browse the repository at this point in the history
…l fix in DMA channels attribution for ADC readings
  • Loading branch information
tomcombriat authored and tfry-git committed Jan 11, 2023
1 parent a6b043d commit bf62495
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
4 changes: 3 additions & 1 deletion MozziGuts_impl_RP2040.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ void setupMozziADC(int8_t speed) {
);

uint dma_chan = dma_claim_unused_channel(true);
rp2040_adc_dma_chan = dma_chan;
static dma_channel_config cfg = dma_channel_get_default_config(dma_chan);

// Reading from constant address, writing to incrementing byte addresses
Expand All @@ -102,8 +103,9 @@ void setupMozziADC(int8_t speed) {

// we want notification, when a sample has arrived
dma_channel_set_irq1_enabled(dma_chan, true);
irq_set_exclusive_handler(DMA_IRQ_1, rp2040_adc_queue_handler);
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_start(dma_chan);
}

void rp2040_adc_queue_handler() {
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
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 hardware alarm and one DMA channel are claimed (number not hardcoded).
- One timer interrupt (DMA_IRQ_1) 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 hardware alarms and two DMA channels are claimed.
- Two timer interrupts (DMA_IRQ_0 and DMA_IRQ_1) 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 bf62495

Please sign in to comment.