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]
E: Element,
pub fn new<B>(buffer: &'static Buffer<B>) -> Option<Self> where
B: AsMutSlice<Element = E>,
[src]
B: AsMutSlice<Element = E>,
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]
B: AsMutSlice<Element = E>,
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]
B: AsMutSlice<Element = E>,
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]
fn as_mut_slice(&mut self) -> &mut [E]
[src]
impl<E: Element> AsRef<[E]> for Linear<E>
[src]
impl<E: Element> AsSlice for Linear<E>
[src]
impl<E: Debug> Debug for Linear<E>
[src]
impl<E: Element> Send for Linear<E>
[src]
Auto Trait Implementations
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
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]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,