Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ADC fifo DMA #636

Merged
merged 7 commits into from
Jul 12, 2023
Merged

ADC fifo DMA #636

merged 7 commits into from
Jul 12, 2023

Conversation

nilclass
Copy link
Contributor

@nilclass nilclass commented Jun 24, 2023

DMA support for free-running ADC capture.

The basic API looks like this:

// without DMA:
let adc_fifo = adc.build_fifo()
    .something_something()
    .start();

do_something_with_fifo(adc_fifo);

// with DMA:
let adc_fifo = adc.build_fifo()
    .something_something()
    .enable_dma()
    .prepare();

let transfer = dma::single_buffer::Config::new(dma.ch0, adc_fifo.dma_read_target(), some_write_target).start();
adc_fifo.resume();

do_something_else_while_dma_does_all_the_work();

To enable this functionality, the following methods were added:

  • AdcFifoBuilder::enable_dma: sets FCS.DREQ_EN = 1 and FCS.THRESH = 1
  • AdcFifoBuilder::prepare: same as start, but does not set CS.START_MANY just yet
  • AdcFifo::resume / AdcFifo::pause: control if capturing is active (CS.START_MANY) without reconfiguring the FIFO in any other way
  • AdcFifo::is_paused: can be used to check the current state
  • AdcFifo::clear: reads the FIFO until empty, discarding values
  • AdcFifo::dma_read_target: returns a struct that implements dma::ReadTarget, and can be used to construct the transfer. (If dma::ReadTarget were implemented on AdcFifo directly, it wouldn't be possible to resume() the FIFO after starting the DMA transfer, because the transfer would take ownership of the AdcFifo)

The method first enables the FIFO, sets FCS.THRESH = 1 and FCS.DREQ_EN = 1.

Afterwards the given closure is called with an appropriate
`dma::ReadTarget`, yielding either 8-bit or 16-bit samples (depending
on `FCS.SHIFT`).

The closure must start a DMA transfer and return it.

Finally CS.START_MANY is set, and a `AdcFifo` together with the DMA
transfer is returned.
Also adds methods to `pause` and `resume` FIFO capturing.
@nilclass nilclass marked this pull request as ready for review July 6, 2023 08:08
@jannic jannic added the breaking change This pull request contains a SemVer breaking change label Jul 8, 2023
@jannic jannic added this to the 0.9.0 milestone Jul 8, 2023
Copy link
Member

@jannic jannic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I finally found the time to actually try it out on hardware.
LGTM, and thanks for contributing!

@jannic jannic added the enhancement New feature or request label Jul 11, 2023
@jannic jannic merged commit f324a30 into rp-rs:main Jul 12, 2023
8 checks passed
@9names 9names mentioned this pull request Jul 12, 2023
@nilclass nilclass deleted the adc-fifo-dma branch July 12, 2023 10:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
breaking change This pull request contains a SemVer breaking change enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants