Struct avr_tester::Spi

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

Provides access to the SPI interface.

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

Implementations§

source§

impl<'a> Spi<'a>

source

pub fn read<T>(&mut self) -> Twhere 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 try_read_byte(&mut self) -> Option<u8>

Retrieves a single byte from AVR.

As compared to Self::read(), when the buffer is empty, this function returns None instead of panicking.

When this function returns None, it will continue to return None at least up until the next call to AvrTester::run(), since that’s when AvrTester “pulls” bytes from the simulated AVR.

See also: Self::read().

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

source§

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

source§

impl Writer for Spi<'_>

source§

fn write_byte(&mut self, value: u8)

Auto Trait Implementations§

§

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

const: unstable · source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

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

const: unstable · source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

const: unstable · source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

const: unstable · 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 Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
const: unstable · 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.
const: unstable · source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.