Struct Spi

Source
pub struct Spi<'a> { /* private fields */ }
Expand description

Provides access to the SPI.

See: Spi::read() and Spi::write().

Implementations§

Source§

impl<'a> Spi<'a>

Source

pub fn read<T>(&mut self) -> T
where T: Readable,

Retrieves a value from AVR.

See: Readable. See also: Self::try_read_byte().

§Examples
let mut avr = avr();

// Retrieves a single byte:
// (when the input buffer is empty, panics.)
assert_eq!(72, avr.spi0().read::<u8>());

// Retrieves the entire buffer:
// (when it's empty, returns an empty vector.)
assert_eq!(vec![72, 101, 108, 108, 111], avr.spi0().read::<Vec<u8>>());

// Retrieves `n` bytes from the buffer:
// (when there's not enough bytes, panics.)
assert_eq!([72, 101, 108, 108, 111], avr.spi0().read::<[u8; 5]>());

// Retrieves the entire input buffer and converts it into string:
// (when it's empty, returns an empty string.)
assert_eq!("Hello", avr.spi0().read::<String>());
Source

pub fn write<T>(&mut self, value: T)
where T: Writable,

Transmits a value to AVR.

See: Writable.

§Examples
let mut avr = avr();

// Transmits a single byte:
avr.spi0().write(123);

// Transmits many bytes:
avr.spi0().write([10, 20, 30]);

// Transmits a string:
avr.spi0().write("Hello!");

// Strings are transmitted as a series of their bytes, so the above is
// equivalent to:
avr.spi0().write([72, 101, 108, 108, 111, 33]);
//                H   e    l    l    o    !

Trait Implementations§

Source§

impl Reader for Spi<'_>

Source§

fn read_byte(&mut self) -> u8

Reads a byte from the AVR; when the buffer is empty, panics.
Source§

fn try_read_byte(&mut self) -> Option<u8>

Reads a byte from the AVR; when the buffer is empty, returns None.
Source§

impl Writer for Spi<'_>

Source§

fn write_byte(&mut self, value: u8)

Auto Trait Implementations§

§

impl<'a> Freeze for Spi<'a>

§

impl<'a> !RefUnwindSafe for Spi<'a>

§

impl<'a> !Send for Spi<'a>

§

impl<'a> !Sync for Spi<'a>

§

impl<'a> Unpin for Spi<'a>

§

impl<'a> !UnwindSafe for Spi<'a>

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.