rp-rs / rp-hal-boards

Board Support Packages for RP2040 based PCBs
202 stars 82 forks source link

Basic ADC over DMA - help needed #7

Closed mryndzionek closed 1 year ago

mryndzionek commented 1 year ago

I'm trying to add basic ADC DMA capture. I've added ReadTarget for ADC like so:

impl ReadTarget for Adc {
    type ReceivedWord = u8;

    fn rx_treq() -> Option<u8> {
        Some(TREQ_SEL_A::ADC.into())
    }

    fn rx_address_count(&self) -> (u32, u32) {
        (&self.device.fifo as *const _ as u32, u32::MAX)
    }

    fn rx_increment(&self) -> bool {
        false
    }
}

The following code compiles now:

    let mut adc = Adc::new(pac.ADC, &mut pac.RESETS);

    let rx_buf = singleton!(: [u8; 5] = [0; 5]).unwrap();
    let rx_transfer = hal::dma::single_buffer::Config::new(ch0, adc, rx_buf).start();
    let (ch0, mut adc, rx_buf) = rx_transfer.wait();

It won't work however, as ADC conversion needs to be enabled just after the DMA channel has been setup, so it seems it needs to be done inside the start() (in single_buffer::Config) function. What would be the best way to achieve this, i.e. add device-specific 'actions' inside the single_buffer::Config? Does it require significant changes to the single_buffer traits?

mryndzionek commented 1 year ago

Sorry wrong repo...