Struct stm32f4xx_hal::dma::Transfer
source · [−]pub struct Transfer<STREAM, const CHANNEL: u8, PERIPHERAL, DIRECTION, BUF> where
STREAM: Stream,
PERIPHERAL: PeriAddress, { /* private fields */ }
Expand description
DMA Transfer.
Implementations
sourceimpl<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<()>> where
F: FnOnce(BUF, CurrentBuffer) -> (BUF, T),
pub unsafe fn next_transfer_with<F, T>(
&mut self,
f: F
) -> Result<T, DMAError<()>> where
F: FnOnce(BUF, CurrentBuffer) -> (BUF, T),
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.
sourceimpl<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
sourceimpl<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<()>> where
F: FnOnce(BUF, CurrentBuffer) -> (BUF, T),
pub unsafe fn next_transfer_with<F, T>(
&mut self,
f: F
) -> Result<T, DMAError<()>> where
F: FnOnce(BUF, CurrentBuffer) -> (BUF, T),
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.
sourceimpl<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 where
F: FnOnce(BUF, CurrentBuffer) -> (BUF, T),
pub fn next_transfer_with<F, T>(&mut self, f: F) -> T where
F: FnOnce(BUF, CurrentBuffer) -> (BUF, 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.
sourceimpl<STREAM, const CHANNEL: u8, PERIPHERAL, DIR, BUF> Transfer<STREAM, CHANNEL, PERIPHERAL, DIR, BUF> where
STREAM: Stream,
ChannelX<CHANNEL>: Channel,
DIR: Direction,
PERIPHERAL: PeriAddress + DMASet<STREAM, CHANNEL, DIR>,
impl<STREAM, const CHANNEL: u8, PERIPHERAL, DIR, BUF> Transfer<STREAM, CHANNEL, PERIPHERAL, DIR, BUF> where
STREAM: Stream,
ChannelX<CHANNEL>: Channel,
DIR: Direction,
PERIPHERAL: PeriAddress + DMASet<STREAM, CHANNEL, DIR>,
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 clear_interrupts(&mut self)
pub fn clear_interrupts(&mut self)
Clear all interrupts for the DMA stream.
sourcepub fn clear_transfer_complete_interrupt(&mut self)
pub fn clear_transfer_complete_interrupt(&mut self)
Clear transfer complete interrupt (tcif) for the DMA stream.
sourcepub fn clear_half_transfer_interrupt(&mut self)
pub fn clear_half_transfer_interrupt(&mut self)
Clear half transfer interrupt (htif) for the DMA stream.
sourcepub fn clear_transfer_error_interrupt(&mut self)
pub fn clear_transfer_error_interrupt(&mut self)
Clear transfer error interrupt (teif) for the DMA stream.
sourcepub fn clear_direct_mode_error_interrupt(&mut self)
pub fn clear_direct_mode_error_interrupt(&mut self)
Clear direct mode error interrupt (dmeif) for the DMA stream.
sourcepub fn clear_fifo_error_interrupt(&mut self)
pub fn clear_fifo_error_interrupt(&mut self)
Clear fifo error interrupt (feif) for the DMA stream.
sourcepub unsafe fn get_stream(&mut self) -> &mut STREAM
pub unsafe fn get_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.
Trait Implementations
Auto Trait Implementations
impl<STREAM, const CHANNEL: u8, PERIPHERAL, DIRECTION, BUF> RefUnwindSafe for Transfer<STREAM, CHANNEL, PERIPHERAL, DIRECTION, BUF> where
BUF: RefUnwindSafe,
DIRECTION: RefUnwindSafe,
PERIPHERAL: RefUnwindSafe,
STREAM: RefUnwindSafe,
impl<STREAM, const CHANNEL: u8, PERIPHERAL, DIRECTION, BUF> Send for Transfer<STREAM, CHANNEL, PERIPHERAL, DIRECTION, BUF> where
BUF: Send,
DIRECTION: Send,
PERIPHERAL: Send,
STREAM: Send,
impl<STREAM, const CHANNEL: u8, PERIPHERAL, DIRECTION, BUF> Sync for Transfer<STREAM, CHANNEL, PERIPHERAL, DIRECTION, BUF> where
BUF: Sync,
DIRECTION: Sync,
PERIPHERAL: Sync,
STREAM: Sync,
impl<STREAM, const CHANNEL: u8, PERIPHERAL, DIRECTION, BUF> Unpin for Transfer<STREAM, CHANNEL, PERIPHERAL, DIRECTION, BUF> where
BUF: Unpin,
DIRECTION: Unpin,
PERIPHERAL: Unpin,
STREAM: Unpin,
impl<STREAM, const CHANNEL: u8, PERIPHERAL, DIRECTION, BUF> UnwindSafe for Transfer<STREAM, CHANNEL, PERIPHERAL, DIRECTION, BUF> where
BUF: UnwindSafe,
DIRECTION: UnwindSafe,
PERIPHERAL: UnwindSafe,
STREAM: UnwindSafe,
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more