Skip to main content

SpiScript

Struct SpiScript 

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

Source§

impl SpiScript

Source

pub fn new(steps: impl IntoIterator<Item = SpiStep>) -> SpiScript

Creates a device that expects steps in order.

§Arguments
  • steps - the transfers the driver is expected to make, and their replies.
§Returns

The scripted device.

Source

pub fn done(&self) -> bool

Reports whether every step has been consumed.

§Returns

true once the driver has made every transfer the script expected.

Source

pub fn remaining(&self) -> usize

Reports how many steps remain.

§Returns

The number of steps the driver has not yet reached.

Source

pub fn consumed(&self) -> usize

Reports how many steps the driver has consumed.

§Returns

The number of steps matched or faulted so far.

Trait Implementations§

Source§

impl Clone for SpiScript

Source§

fn clone(&self) -> SpiScript

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for SpiScript

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for SpiScript

Source§

fn default() -> SpiScript

Returns the “default value” for a type. Read more
Source§

impl ErrorType for SpiScript

Source§

type Error = SpiScriptError

Error type.
Source§

impl SpiDevice for SpiScript

Source§

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>

Do a read within a transaction. Read more
§

fn write(&mut self, buf: &[Word]) -> Result<(), Self::Error>

Do a write within a transaction. Read more
§

fn transfer( &mut self, read: &mut [Word], write: &[Word], ) -> Result<(), Self::Error>

Do a transfer within a transaction. Read more
§

fn transfer_in_place(&mut self, buf: &mut [Word]) -> Result<(), Self::Error>

Do an in-place transfer within a transaction. Read more

Auto Trait Implementations§

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.