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§

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>,

source

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 is None.
source

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.

source

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.

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>,

source

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>,

source

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 is None.
source

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.

source

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.

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>,

source

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.
source

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.

source

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.

source§

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>,

source

pub fn start<F>(&mut self, f: F)

Starts the transfer, the closure will be executed right after enabling the stream.

source

pub fn pause<F>(&mut self, f: F)

Pauses the dma stream, the closure will be executed right before disabling the stream.

source

pub fn release(self) -> (STREAM, PERIPHERAL, BUF, Option<BUF>)

Stops the stream and returns the underlying resources.

source

pub fn number_of_transfers(&self) -> u16

Get the number of remaining transfers (ndt) of the underlying DMA stream.

source

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.

source

pub fn wait(&self)

Wait for the transfer to complete.

Trait Implementations§

source§

impl<STREAM, const CHANNEL: u8, PERIPHERAL, DIR, BUF> ClearFlags for Transfer<STREAM, CHANNEL, PERIPHERAL, DIR, BUF>
where STREAM: Stream, ChannelX<CHANNEL>: Channel, DIR: Direction, PERIPHERAL: PeriAddress + DMASet<STREAM, CHANNEL, DIR>,

§

type Flag = DmaFlag

Enum of manually clearable flags
source§

fn clear_flags(&mut self, flags: impl Into<BitFlags<DmaFlag>>)

Clear interrupts flags with Self::Flagss Read more
source§

fn clear_all_flags(&mut self)

Clears all interrupts flags
source§

impl<STREAM, const CHANNEL: u8, PERIPHERAL, DIR, BUF> Drop for Transfer<STREAM, CHANNEL, PERIPHERAL, DIR, BUF>
where STREAM: Stream, PERIPHERAL: PeriAddress,

source§

fn drop(&mut self)

Executes the destructor for this type. Read more
source§

impl<STREAM, const CHANNEL: u8, PERIPHERAL, DIR, BUF> ReadFlags for Transfer<STREAM, CHANNEL, PERIPHERAL, DIR, BUF>
where STREAM: Stream, ChannelX<CHANNEL>: Channel, DIR: Direction, PERIPHERAL: PeriAddress + DMASet<STREAM, CHANNEL, DIR>,

§

type Flag = DmaFlag

Enum of bit flags
source§

fn flags(&self) -> BitFlags<DmaFlag>

Get all interrupts flags a once.
source§

impl<STREAM, const CHANNEL: u8, PERIPHERAL, BUF> RxISR for Transfer<STREAM, CHANNEL, PERIPHERAL, PeripheralToMemory, BUF>
where STREAM: Stream, PERIPHERAL: PeriAddress + DMASet<STREAM, CHANNEL, PeripheralToMemory> + RxISR,

source§

fn is_idle(&self) -> bool

Return true if the line idle status is set

source§

fn is_rx_not_empty(&self) -> bool

Return true if the rx register is not empty (and can be read)

source§

fn clear_idle_interrupt(&self)

Clear idle line interrupt flag

source§

impl<STREAM, const CHANNEL: u8, PERIPHERAL, DIR, BUF> StreamISR for Transfer<STREAM, CHANNEL, PERIPHERAL, DIR, BUF>
where STREAM: Stream, ChannelX<CHANNEL>: Channel, DIR: Direction, PERIPHERAL: PeriAddress + DMASet<STREAM, CHANNEL, DIR>,

source§

fn clear_transfer_complete(&mut self)

Clear transfer complete interrupt (tcif) for the DMA stream.
source§

fn clear_half_transfer(&mut self)

Clear half transfer interrupt flag (htif) for the DMA stream.
source§

fn clear_transfer_error(&mut self)

Clear transfer error interrupt flag (teif) for the DMA stream.
source§

fn clear_direct_mode_error(&mut self)

Clear direct mode error interrupt flag (dmeif) for the DMA stream.
source§

fn clear_fifo_error(&mut self)

Clear fifo error interrupt flag (feif) for the DMA stream.
source§

fn is_transfer_complete(&self) -> bool

Get transfer complete flag.
source§

fn is_half_transfer(&self) -> bool

Get half transfer flag.
source§

fn is_transfer_error(&self) -> bool

Get transfer error flag
source§

fn is_direct_mode_error(&self) -> bool

Get direct mode error flag
source§

fn is_fifo_error(&self) -> bool

Get fifo error flag

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§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.