SPI

Struct SPI 

Source
pub struct SPI<Miso, Mosi, Sck, Timer>
where Miso: InputPin, Mosi: OutputPin, Sck: OutputPin, Timer: CountDown + Periodic,
{ /* private fields */ }
Expand description

A Full-Duplex SPI implementation, takes 3 pins, and a timer running at 2x the desired SPI frequency.

Implementations§

Source§

impl<Miso, Mosi, Sck, Timer, E> SPI<Miso, Mosi, Sck, Timer>
where Miso: InputPin<Error = E>, Mosi: OutputPin<Error = E>, Sck: OutputPin<Error = E>, Timer: CountDown + Periodic,

Source

pub fn new(mode: Mode, miso: Miso, mosi: Mosi, sck: Sck, timer: Timer) -> Self

Create instance

Source

pub fn set_bit_order(&mut self, order: BitOrder)

Set transmission bit order

Source

pub fn access_timer<F>(&mut self, f: F)
where F: FnOnce(Timer) -> Timer,

Allows for an access to the timer type. This can be used to change the speed.

In closure you get ownership of the timer so you can destruct it and build it up again if necessary.

§Example
spi.access_timer(|mut timer| {
   timer.set_freq(4.mhz());
   timer
});

Trait Implementations§

Source§

impl<Miso, Mosi, Sck, Timer, E> FullDuplex<u8> for SPI<Miso, Mosi, Sck, Timer>
where Miso: InputPin<Error = E>, Mosi: OutputPin<Error = E>, Sck: OutputPin<Error = E>, Timer: CountDown + Periodic,

Source§

type Error = Error<E>

An enumeration of SPI errors
Source§

fn read(&mut self) -> Result<u8, Self::Error>

Reads the word stored in the shift register Read more
Source§

fn send(&mut self, byte: u8) -> Result<(), Self::Error>

Sends a word to the slave
Source§

impl<Miso, Mosi, Sck, Timer, E> Default<u8> for SPI<Miso, Mosi, Sck, Timer>
where Miso: InputPin<Error = E>, Mosi: OutputPin<Error = E>, Sck: OutputPin<Error = E>, Timer: CountDown + Periodic,

Source§

impl<Miso, Mosi, Sck, Timer, E> Default<u8> for SPI<Miso, Mosi, Sck, Timer>
where Miso: InputPin<Error = E>, Mosi: OutputPin<Error = E>, Sck: OutputPin<Error = E>, Timer: CountDown + Periodic,

Auto Trait Implementations§

§

impl<Miso, Mosi, Sck, Timer> Freeze for SPI<Miso, Mosi, Sck, Timer>
where Miso: Freeze, Mosi: Freeze, Sck: Freeze, Timer: Freeze,

§

impl<Miso, Mosi, Sck, Timer> RefUnwindSafe for SPI<Miso, Mosi, Sck, Timer>
where Miso: RefUnwindSafe, Mosi: RefUnwindSafe, Sck: RefUnwindSafe, Timer: RefUnwindSafe,

§

impl<Miso, Mosi, Sck, Timer> Send for SPI<Miso, Mosi, Sck, Timer>
where Miso: Send, Mosi: Send, Sck: Send, Timer: Send,

§

impl<Miso, Mosi, Sck, Timer> Sync for SPI<Miso, Mosi, Sck, Timer>
where Miso: Sync, Mosi: Sync, Sck: Sync, Timer: Sync,

§

impl<Miso, Mosi, Sck, Timer> Unpin for SPI<Miso, Mosi, Sck, Timer>
where Miso: Unpin, Mosi: Unpin, Sck: Unpin, Timer: Unpin,

§

impl<Miso, Mosi, Sck, Timer> UnwindSafe for SPI<Miso, Mosi, Sck, Timer>
where Miso: UnwindSafe, Mosi: UnwindSafe, Sck: UnwindSafe, Timer: 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>,

Source§

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

Source§

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.
Source§

impl<W, S> Transfer<W> for S
where S: Default<W>, W: Clone,

Source§

type Error = <S as FullDuplex<W>>::Error

Error type
Source§

fn transfer<'w>( &mut self, words: &'w mut [W], ) -> Result<&'w [W], <S as FullDuplex<W>>::Error>

Sends words to the slave. Returns the words received from the slave
Source§

impl<W, S> Write<W> for S
where S: Default<W>, W: Clone,

Source§

type Error = <S as FullDuplex<W>>::Error

Error type
Source§

fn write(&mut self, words: &[W]) -> Result<(), <S as FullDuplex<W>>::Error>

Sends words to the slave, ignoring all the incoming words