pub struct SpiFuture<S, B, SS = NoneT, W = fn()>where
    S: CheckBufLen,
    B: AsRef<[u8]> + AsMut<[u8]> + 'static,
    SS: ControlSS,
    W: FnOnce() + 'static,{ /* private fields */ }
Expand description

A Future-like interface for SPI transactions

See the module-level documentation for more details.

Implementations§

source§

impl<S, B> SpiFuture<S, B, NoneT, fn()>where S: CheckBufLen, B: AsRef<[u8]> + AsMut<[u8]> + 'static,

source

pub fn new(spi: S, buf: B) -> SpiFuture<S, B, NoneT, fn()>

Create a new SpiFuture with no SS pin or waker

source§

impl<S, B, W> SpiFuture<S, B, NoneT, W>where S: CheckBufLen, B: AsRef<[u8]> + AsMut<[u8]> + 'static, W: FnOnce() + 'static,

source

pub fn with_ss<SS>(self, pin: SS) -> SpiFuture<S, B, SS, W>where SS: SomePin + OutputPin<Error = Infallible>,

Add an SS pin to the SpiFuture

This function changes the SS type, so it must take an owned self.

source§

impl<S, B, SS> SpiFuture<S, B, SS, fn()>where S: CheckBufLen, B: AsRef<[u8]> + AsMut<[u8]> + 'static, SS: ControlSS,

source

pub fn with_waker<W>(self, waker: W) -> SpiFuture<S, B, SS, W>where W: FnOnce() + 'static,

Add a waker to the SpiFuture

This function changes the waker type, so it must take an owned self.

source§

impl<S, B, SS, W> SpiFuture<S, B, SS, W>where S: CheckBufLen, B: AsRef<[u8]> + AsMut<[u8]> + 'static, SS: ControlSS, W: FnOnce() + 'static,

source

pub fn start(&mut self)

Start the SpiFuture transaction

This will assert the SS pin, if present, and enable the DRE and RXC interrupts.

source

pub fn send(&mut self) -> Result<(), Error>

Send the next set of bytes from the buffer

This method should be called from the DRE interrupt handler. Once all bytes of the transaction have been sent, this function will automatically disable the DRE interrupt.

source

pub fn recv(&mut self) -> Result<(), Error>

Received the next set of bytes and write them to the buffer

This method should be called from the RXC interrupt handler. Once all bytes of the transaction have been received, this function will automatically disable the RXC interrupt, deassert the SS pin (if present), and call the waker (if present).

source

pub fn poll(&self) -> Poll<&[u8]>

Poll the SpiFuture

This function will return Poll::Pending until all bytes have been received. When the transaction is complete, it will return Poll::Ready with a reference to the completed buffer.

source

pub fn free(self) -> Result<(S, B, SS), SpiFuture<S, B, SS, W>>

Consume the SpiFuture and free its components

If the transaction is complete, this function will consume the SpiFuture and return the Spi object, the buffer, and the SS pin, if present.

If the transaction is not complete, it will return Err(self).

source

pub unsafe fn free_unchecked(self) -> (S, B, SS)

Consume the SpiFuture and free its components without checking for completion

Ending the transaction prematurely could leave the Spi in an inconsistent state. It is not safe to call this function unless the transaction is complete.

Auto Trait Implementations§

§

impl<S, B, SS, W> RefUnwindSafe for SpiFuture<S, B, SS, W>where B: RefUnwindSafe, S: RefUnwindSafe, SS: RefUnwindSafe, W: RefUnwindSafe,

§

impl<S, B, SS, W> Send for SpiFuture<S, B, SS, W>where B: Send, S: Send, SS: Send, W: Send,

§

impl<S, B, SS, W> Sync for SpiFuture<S, B, SS, W>where B: Sync, S: Sync, SS: Sync, W: Sync,

§

impl<S, B, SS, W> Unpin for SpiFuture<S, B, SS, W>where B: Unpin, S: Unpin, SS: Unpin, W: Unpin,

§

impl<S, B, SS, W> UnwindSafe for SpiFuture<S, B, SS, W>where B: UnwindSafe, S: UnwindSafe, SS: UnwindSafe, W: UnwindSafe,

Blanket Implementations§

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere 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 Twhere 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> Same<T> for T

§

type Output = T

Should always be Self
source§

impl<T, U> TryFrom<U> for Twhere 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 Twhere 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.