pub struct Transfer<STREAM, const CHANNEL: u8, PERIPHERAL, DIRECTION, BUF>where
STREAM: Stream,
PERIPHERAL: PeriAddress,{ /* private fields */ }
Expand description
DMA Transfer.
Implementations§
source§impl<STREAM, const CHANNEL: u8, PERIPHERAL, BUF> Transfer<STREAM, CHANNEL, PERIPHERAL, MemoryToPeripheral, BUF>where
STREAM: Stream,
ChannelX<CHANNEL>: Channel,
PERIPHERAL: PeriAddress + DMASet<STREAM, CHANNEL, MemoryToPeripheral>,
BUF: ReadBuffer<Word = <PERIPHERAL as PeriAddress>::MemSize>,
impl<STREAM, const CHANNEL: u8, PERIPHERAL, BUF> Transfer<STREAM, CHANNEL, PERIPHERAL, MemoryToPeripheral, BUF>where
STREAM: Stream,
ChannelX<CHANNEL>: Channel,
PERIPHERAL: PeriAddress + DMASet<STREAM, CHANNEL, MemoryToPeripheral>,
BUF: ReadBuffer<Word = <PERIPHERAL as PeriAddress>::MemSize>,
sourcepub fn init_memory_to_peripheral(
stream: STREAM,
peripheral: PERIPHERAL,
buf: BUF,
double_buf: Option<BUF>,
config: DmaConfig,
) -> Self
pub fn init_memory_to_peripheral( stream: STREAM, peripheral: PERIPHERAL, buf: BUF, double_buf: Option<BUF>, config: DmaConfig, ) -> Self
Configures the DMA stream to the correct channel for the peripheral, configures source and
destination and applies supplied configuration. If double buffering is enabled, the
number of transfers will be the minimum length of memory
and double_buf
.
§Panics
- When double buffering is enabled but the
double_buf
argument isNone
.
sourcepub fn next_transfer(
&mut self,
new_buf: BUF,
) -> Result<(BUF, CurrentBuffer), DMAError<BUF>>
pub fn next_transfer( &mut self, new_buf: BUF, ) -> Result<(BUF, CurrentBuffer), DMAError<BUF>>
Changes the buffer and restarts or continues a double buffer transfer. This must be called
immediately after a transfer complete event if using double buffering, otherwise you might
lose data. Returns the old buffer together with its CurrentBuffer
. If an error occurs,
this method will return the new buffer with the error.
This method will clear the transfer complete flag on entry, it will also clear it again if
an overrun occurs during its execution. Moreover, if an overrun occurs, the stream will be
disabled and the transfer error flag will be set. This method can be called before the end
of an ongoing transfer only if not using double buffering, in that case, the current
transfer will be canceled and a new one will be started. A NotReady
error will be returned
if this method is called before the end of a transfer while double buffering.
sourcepub unsafe fn next_transfer_with<F, T>(
&mut self,
f: F,
) -> Result<T, DMAError<()>>
pub unsafe fn next_transfer_with<F, T>( &mut self, f: F, ) -> Result<T, DMAError<()>>
Changes the buffer and restarts or continues a double buffer transfer. This must be called
immediately after a transfer complete event if using double buffering, otherwise you might
lose data. The closure must return (BUF, T)
where BUF
is the new buffer to be used. This
method can be called before the end of an ongoing transfer only if not using double
buffering, in that case, the current transfer will be canceled and a new one will be
started. A NotReady
error will be returned if this method is called before the end of a
transfer while double buffering and the closure won’t be executed.
§Panics
This method will panic when double buffering if one or both of the following conditions happen:
- The new buffer’s length is smaller than the one used in the
init
method. - The closure
f
takes too long to return and a buffer overrun occurs.
§Safety
Memory corruption might occur in the previous buffer, the one passed to the closure, if an overrun occurs in double buffering mode.
source§impl<STREAM, const CHANNEL: u8, PERIPHERAL, BUF> Transfer<STREAM, CHANNEL, PERIPHERAL, PeripheralToMemory, BUF>where
STREAM: Stream,
ChannelX<CHANNEL>: Channel,
PERIPHERAL: PeriAddress + DMASet<STREAM, CHANNEL, PeripheralToMemory> + SafePeripheralRead,
BUF: WriteBuffer<Word = <PERIPHERAL as PeriAddress>::MemSize>,
impl<STREAM, const CHANNEL: u8, PERIPHERAL, BUF> Transfer<STREAM, CHANNEL, PERIPHERAL, PeripheralToMemory, BUF>where
STREAM: Stream,
ChannelX<CHANNEL>: Channel,
PERIPHERAL: PeriAddress + DMASet<STREAM, CHANNEL, PeripheralToMemory> + SafePeripheralRead,
BUF: WriteBuffer<Word = <PERIPHERAL as PeriAddress>::MemSize>,
sourcepub fn peripheral(&self) -> &PERIPHERAL
pub fn peripheral(&self) -> &PERIPHERAL
Access the owned peripheral for reading
source§impl<STREAM, const CHANNEL: u8, PERIPHERAL, BUF> Transfer<STREAM, CHANNEL, PERIPHERAL, PeripheralToMemory, BUF>where
STREAM: Stream,
ChannelX<CHANNEL>: Channel,
PERIPHERAL: PeriAddress + DMASet<STREAM, CHANNEL, PeripheralToMemory>,
BUF: WriteBuffer<Word = <PERIPHERAL as PeriAddress>::MemSize>,
impl<STREAM, const CHANNEL: u8, PERIPHERAL, BUF> Transfer<STREAM, CHANNEL, PERIPHERAL, PeripheralToMemory, BUF>where
STREAM: Stream,
ChannelX<CHANNEL>: Channel,
PERIPHERAL: PeriAddress + DMASet<STREAM, CHANNEL, PeripheralToMemory>,
BUF: WriteBuffer<Word = <PERIPHERAL as PeriAddress>::MemSize>,
sourcepub fn init_peripheral_to_memory(
stream: STREAM,
peripheral: PERIPHERAL,
buf: BUF,
double_buf: Option<BUF>,
config: DmaConfig,
) -> Self
pub fn init_peripheral_to_memory( stream: STREAM, peripheral: PERIPHERAL, buf: BUF, double_buf: Option<BUF>, config: DmaConfig, ) -> Self
Configures the DMA stream to the correct channel for the peripheral, configures source and
destination and applies supplied configuration. If double buffering is enabled, the
number of transfers will be the minimum length of memory
and double_buf
.
§Panics
- When double buffering is enabled but the
double_buf
argument isNone
.
sourcepub fn next_transfer(
&mut self,
new_buf: BUF,
) -> Result<(BUF, CurrentBuffer), DMAError<BUF>>
pub fn next_transfer( &mut self, new_buf: BUF, ) -> Result<(BUF, CurrentBuffer), DMAError<BUF>>
Changes the buffer and restarts or continues a double buffer transfer. This must be called
immediately after a transfer complete event if using double buffering, otherwise you might
lose data. Returns the old buffer together with its CurrentBuffer
. If an error occurs,
this method will return the new buffer with the error.
This method will clear the transfer complete flag on entry, it will also clear it again if
an overrun occurs during its execution. Moreover, if an overrun occurs, the stream will be
disabled and the transfer error flag will be set. This method can be called before the end
of an ongoing transfer only if not using double buffering, in that case, the current
transfer will be canceled and a new one will be started. A NotReady
error will be returned
if this method is called before the end of a transfer while double buffering.
sourcepub unsafe fn next_transfer_with<F, T>(
&mut self,
f: F,
) -> Result<T, DMAError<()>>
pub unsafe fn next_transfer_with<F, T>( &mut self, f: F, ) -> Result<T, DMAError<()>>
Changes the buffer and restarts or continues a double buffer transfer. This must be called
immediately after a transfer complete event if using double buffering, otherwise you might
lose data. The closure must return (BUF, T)
where BUF
is the new buffer to be used. This
method can be called before the end of an ongoing transfer only if not using double
buffering, in that case, the current transfer will be canceled and a new one will be
started. A NotReady
error will be returned if this method is called before the end of a
transfer while double buffering and the closure won’t be executed.
§Panics
This method will panic when double buffering if one or both of the following conditions happen:
- The new buffer’s length is smaller than the one used in the
init
method. - The closure
f
takes too long to return and a buffer overrun occurs.
§Safety
Memory corruption might occur in the previous buffer, the one passed to the closure, if an overrun occurs in double buffering mode.
source§impl<STREAM, const CHANNEL: u8, PERIPHERAL, BUF, S> Transfer<STREAM, CHANNEL, PERIPHERAL, MemoryToMemory<S>, BUF>where
STREAM: Stream,
ChannelX<CHANNEL>: Channel,
PERIPHERAL: PeriAddress + DMASet<STREAM, CHANNEL, MemoryToMemory<S>>,
MemoryToMemory<S>: PeriAddress,
BUF: WriteBuffer<Word = <PERIPHERAL as PeriAddress>::MemSize>,
impl<STREAM, const CHANNEL: u8, PERIPHERAL, BUF, S> Transfer<STREAM, CHANNEL, PERIPHERAL, MemoryToMemory<S>, BUF>where
STREAM: Stream,
ChannelX<CHANNEL>: Channel,
PERIPHERAL: PeriAddress + DMASet<STREAM, CHANNEL, MemoryToMemory<S>>,
MemoryToMemory<S>: PeriAddress,
BUF: WriteBuffer<Word = <PERIPHERAL as PeriAddress>::MemSize>,
sourcepub fn init_memory_to_memory(
stream: STREAM,
peripheral: PERIPHERAL,
buf: BUF,
double_buf: BUF,
config: DmaConfig,
) -> Self
pub fn init_memory_to_memory( stream: STREAM, peripheral: PERIPHERAL, buf: BUF, double_buf: BUF, config: DmaConfig, ) -> Self
Configures the DMA stream to the correct channel for the peripheral, configures source and
destination and applies supplied configuration. In a memory to memory transfer,
the double_buf
argument is the source of the data. If double buffering is enabled, the
number of transfers will be the minimum length of memory
and double_buf
.
§Panics
- When the FIFO is disabled or double buffering is enabled in
DmaConfig
while initializing a memory to memory transfer.
sourcepub fn next_transfer(
&mut self,
new_buf: BUF,
) -> Result<(BUF, CurrentBuffer), DMAError<BUF>>
pub fn next_transfer( &mut self, new_buf: BUF, ) -> Result<(BUF, CurrentBuffer), DMAError<BUF>>
Changes the buffer and restarts.Returns the old buffer together with its CurrentBuffer
. If
an error occurs, this method will return the new buffer with the error.
This method will clear the transfer complete flag on entry. This method can be called before the end of an ongoing transfer, in that case, the current transfer will be canceled and a new one will be started.
sourcepub fn next_transfer_with<F, T>(&mut self, f: F) -> T
pub fn next_transfer_with<F, T>(&mut self, f: F) -> T
Changes the buffer and restarts a transfer. This must be called
The closure must return (BUF, T)
where BUF
is the new buffer to be used. This
method can be called before the end of an ongoing transfer,
in that case, the current transfer will be canceled and a new one will be
started.
source§impl<STREAM, const CHANNEL: u8, PERIPHERAL, DIR, BUF> Transfer<STREAM, CHANNEL, PERIPHERAL, DIR, BUF>
impl<STREAM, const CHANNEL: u8, PERIPHERAL, DIR, BUF> Transfer<STREAM, CHANNEL, PERIPHERAL, DIR, BUF>
sourcepub fn start<F>(&mut self, f: F)where
F: FnOnce(&mut PERIPHERAL),
pub fn start<F>(&mut self, f: F)where
F: FnOnce(&mut PERIPHERAL),
Starts the transfer, the closure will be executed right after enabling the stream.
sourcepub fn pause<F>(&mut self, f: F)where
F: FnOnce(&mut PERIPHERAL),
pub fn pause<F>(&mut self, f: F)where
F: FnOnce(&mut PERIPHERAL),
Pauses the dma stream, the closure will be executed right before disabling the stream.
sourcepub fn release(self) -> (STREAM, PERIPHERAL, BUF, Option<BUF>)
pub fn release(self) -> (STREAM, PERIPHERAL, BUF, Option<BUF>)
Stops the stream and returns the underlying resources.
sourcepub fn number_of_transfers(&self) -> u16
pub fn number_of_transfers(&self) -> u16
Get the number of remaining transfers (ndt) of the underlying DMA stream.
sourcepub unsafe fn stream(&mut self) -> &mut STREAM
pub unsafe fn stream(&mut self) -> &mut STREAM
Get the underlying stream of the transfer.
§Safety
This implementation relies on several configurations points in order to be sound, this method can void that. The use of this method is completely discouraged, only use it if you know the internals of this API in its entirety.