pub struct I2cScript { /* private fields */ }Expand description
An I2C bus that plays a script of transfers and replies.
Each transaction the driver issues is matched against the next step. A register
read (a write followed by a read in one transaction) consumes one
I2cStep::WriteRead; a plain write or read consumes a I2cStep::Write or
I2cStep::Read; a longer transaction consumes steps in order. A transfer that
does not match fails with ScriptError::Mismatch, which names the step and what
arrived, and a test ends by checking done so an unfinished
script is a failure too.
§Examples
use pamoja_hal::i2c::I2c;
use pamoja_hal::script::{I2cScript, I2cStep};
// A part at 0x48 whose 16-bit result register 0x00 reads 0x0C80.
let mut bus = I2cScript::new([
I2cStep::write(0x48, [0x01, 0x60, 0x20]),
I2cStep::write_read(0x48, [0x00], [0x0C, 0x80]),
]);
bus.write(0x48, &[0x01, 0x60, 0x20])?;
let mut result = [0u8; 2];
bus.write_read(0x48, &[0x00], &mut result)?;
assert_eq!(u16::from_be_bytes(result), 0x0C80);
assert!(bus.done());Implementations§
Trait Implementations§
Source§impl I2c for I2cScript
impl I2c for I2cScript
Source§fn transaction(
&mut self,
address: SevenBitAddress,
operations: &mut [Operation<'_>],
) -> Result<(), ScriptError>
fn transaction( &mut self, address: SevenBitAddress, operations: &mut [Operation<'_>], ) -> Result<(), ScriptError>
Execute the provided operations on the I2C bus. Read more
Auto Trait Implementations§
impl Freeze for I2cScript
impl RefUnwindSafe for I2cScript
impl Send for I2cScript
impl Sync for I2cScript
impl Unpin for I2cScript
impl UnsafeUnpin for I2cScript
impl UnwindSafe for I2cScript
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