Struct imxrt_hal::dma::Linear[][src]

pub struct Linear<E> { /* fields omitted */ }

A linear DMA buffer

The DMA controller interprets the memory as a normal array. Use as_elements() to read from the buffer, or as_mut_elements() to read and write from the buffer.

Use set_transfer_len() to specify how many elements in this buffer should be used to satisfy a DMA transfer. By default, the transfer length is equal to the size of the underlying buffer. If your DMA transfer is transferring more, or fewer, elements than expected, ensure that you’re calling set_transfer_len().

The Linear adapter will “own” the Buffer provided on construction. However, when it’s dropped, Linear will not release ownership. Either keep the object alive, or use the new_unchecked() method to construct a new Linear adapter over the same buffer.

use imxrt_hal::dma;

static DMA1_BUFFER: dma::Buffer<[u8; 256]> = dma::Buffer::new([0; 256]);

let mut linear = dma::Linear::new(&DMA1_BUFFER).unwrap();
// DMA1_BUFFER is owned by linear. If we try to use it again,
// it returns None.
assert!(dma::Linear::new(&DMA1_BUFFER).is_none());

// Fill the first 6 elements, and mark them for transfer
linear.as_mut_elements()[..6].copy_from_slice(&[1, 2, 3, 4, 5, 6]);
linear.set_transfer_len(6);

Implementations

impl<E> Linear<E> where
    E: Element
[src]

pub fn new<B>(buffer: &'static Buffer<B>) -> Option<Self> where
    B: AsMutSlice<Element = E>, 
[src]

Create a new Linear DMA buffer that takes ownership of the memory wrapped by buffer

If the constructor has exclusive ownership of buffer, returns Some(Linear). Returns None if the buffer is already owned.

pub unsafe fn new_unchecked<B>(buffer: &'static Buffer<B>) -> Self where
    B: AsMutSlice<Element = E>, 
[src]

Create a Linear DMA buffer without checking the ownership of the supplied buffer

Safety

Using this method may result in two, mutable references to static memory, which may cause memory unsafey. Caller must ensure that the provided buffer is no longer owned.

pub unsafe fn from_raw<B>(raw: &mut B) -> Self where
    B: AsMutSlice<Element = E>, 
[src]

Create a Linear DMA buffer without any concern to ownership or memory lifetime

Safety

The caller must guarantee that the lifetime of raw is greater than the lifetime of all DMA transfers that use the memory. The caller must guarantee that there are no other mutable references to this memory.

use imxrt_hal::dma;

let mut my_buffer: [u32; 128] = [0; 128];
// my_buffer is stack-allocated, so we need to ensure that the lifetime of
// our linear memory doesn't outlive my_buffer
let linear = unsafe { dma::Linear::from_raw(&mut my_buffer) };

pub fn as_elements(&self) -> &[E][src]

Returns a slice to the elements in the linear buffer

The slice’s length is the whole backing buffer, not the length specified in set_transfer_len().

pub fn as_mut_elements(&mut self) -> &mut [E][src]

Returns a mutable slice to the elements in the linear buffer

The slice’s length is the whole backing buffer, not the length specified in set_transfer_len().

pub fn set_transfer_len(&mut self, len: usize)[src]

Set the number of elements that will be used in a DMA transfer

The transfer len specifies how many elements, starting from the front of the linear memory, will be sent during a DMA transfer. Or, it indicates how many elements should be received from a DMA transfer.

len is capped at the maximum size of the backing buffer.

Trait Implementations

impl<E: Element> AsMut<[E]> for Linear<E>[src]

impl<E: Element> AsMutSlice for Linear<E>[src]

impl<E: Element> AsRef<[E]> for Linear<E>[src]

impl<E: Element> AsSlice for Linear<E>[src]

type Element = E

The element type of the slice view

impl<E: Debug> Debug for Linear<E>[src]

impl<E: Element> Send for Linear<E>[src]

Auto Trait Implementations

impl<E> !Sync for Linear<E>

impl<E> Unpin for Linear<E>

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> Same<T> for T

type Output = T

Should always be Self

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.