-
Notifications
You must be signed in to change notification settings - Fork 269
Description
Hia,
This is probably a misunderstanding; but I'm really not sure how to correctly handle the buffers used for DMA given their 'static
requirement that I seem to run into.
For example, given a struct that contains the buffer to be used with DMA
#[derive(Debug, Format)]
pub struct DMAExample{
buffer: [u32; 16],
}
impl DMAExample {
pub fn send<TO, CH>(&mut self, channel: CH, sm_tx: TO) -> (CH, TO)
where
CH: SingleChannel,
TO: WriteTarget<TransmittedWord = u32>,
{
let tx_transfer = rp2040_hal::dma::single_buffer::Config::new(channel, &self.buffer, sm_tx).start();
let (ch, _b, to) = tx_transfer.wait();
(ch, to)
}
}
The only way to get this to really work is to make self
'static
which isn't really viable with re-use.
This is because I run into rp2040_hal::dma::single_buffer::Config::new
requiring a 'static
lifetime on the ReadTarget.
Am I missing something that will allow any other lifetime around this? Trying to encapsulate the ownership nicely? Given that the transfer.wait() call returns the buffer, my original plan was to persist the transfer item into the object to retrieve it but can't get that far.
I assume I'm missing something obvious, but also can't seem to find any online examples that deal with this (i.e. dont just use the dma in the main entry function; but actually have the buffer stored elsewhere).