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>
impl<'a> Spi<'a>
Sourcepub fn read<T>(&mut self) -> Twhere
T: Readable,
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>());
Sourcepub fn write<T>(&mut self, value: T)where
T: Writable,
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§
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more