pub struct SpiScript { /* private fields */ }Expand description
An SPI device that plays a script of transfers and replies.
The device is the bus plus the part’s chip select, so a transaction is one
chip-select assertion and each operation inside it consumes one step. A delay
operation consumes nothing. A transfer that does not match fails with
SpiScriptError::Mismatch, and a test ends by checking
done.
§Examples
use pamoja_hal::script::{SpiScript, SpiStep};
use pamoja_hal::spi::{Operation, SpiDevice};
// A Bosch part read over SPI: the control byte 0xD0 with its read bit set, then
// the chip id shifted out.
let mut device = SpiScript::new([SpiStep::write([0xD0]), SpiStep::read([0x60])]);
let mut id = [0u8; 1];
device.transaction(&mut [Operation::Write(&[0xD0]), Operation::Read(&mut id)])?;
assert_eq!(id, [0x60]);
assert!(device.done());Implementations§
Trait Implementations§
Source§impl SpiDevice for SpiScript
impl SpiDevice for SpiScript
Source§fn transaction(
&mut self,
operations: &mut [Operation<'_, u8>],
) -> Result<(), SpiScriptError>
fn transaction( &mut self, operations: &mut [Operation<'_, u8>], ) -> Result<(), SpiScriptError>
Perform a transaction against the device. Read more
§fn read(&mut self, buf: &mut [Word]) -> Result<(), Self::Error>
fn read(&mut self, buf: &mut [Word]) -> Result<(), Self::Error>
Do a read within a transaction. Read more
§fn write(&mut self, buf: &[Word]) -> Result<(), Self::Error>
fn write(&mut self, buf: &[Word]) -> Result<(), Self::Error>
Do a write within a transaction. Read more
Auto Trait Implementations§
impl Freeze for SpiScript
impl RefUnwindSafe for SpiScript
impl Send for SpiScript
impl Sync for SpiScript
impl Unpin for SpiScript
impl UnsafeUnpin for SpiScript
impl UnwindSafe for SpiScript
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