Struct SoftI2C

Source
pub struct SoftI2C<'a, C, D, Delay, const CLK_HZ: u32> { /* private fields */ }
Expand description

A software implementation of the I2C interface.

Implementations§

Source§

impl<'a, C, D, Delay, const CLK_HZ: u32> SoftI2C<'a, C, D, Delay, CLK_HZ>
where C: OutputPin, D: OpenDrainPin, Delay: DelayNs,

Source

pub fn new(scl: &'a mut C, sda: &'a mut D, delay: &'a mut Delay) -> Self

Creates a new SoftI2C instance with the given SCL and SDA pins.

Source

pub fn soft_i2c_write_read( &mut self, address: SoftI2CAddr, write: &[u8], read: &mut [u8], ) -> Result<(), SoftI2CError>

Writes bytes and reads bytes over the I2C bus.

§Examples
let mut buffer = [0; 4];
i2c.soft_i2c_write_read(SoftI2CAddr::SevenBitAddress(0x48), &[0x00, 0x01], &mut buffer)?;
assert_eq!(buffer, [0x02, 0x03, 0x04, 0x05]);
Master: ST SAD+W     O0     O1     ... OM     SR SAD+R        MAK    MAK ...    NMAK SP
Slave:           SAK    SAK    SAK ...    SAK          SAK I0     I1     ... IN
Source

pub fn soft_i2c_write( &mut self, address: SoftI2CAddr, write: &[u8], ) -> Result<(), SoftI2CError>

Writes bytes over the I2C bus.

§Examples
i2c.soft_i2c_write(SoftI2CAddr::SevenBitAddress(0x48), &[0x00, 0x01])?;
Master: ST SAD+W     B0     B1     ... BN     SP
Slave:           SAK    SAK    SAK ...    SAK
Source

pub fn soft_i2c_read( &mut self, address: SoftI2CAddr, read: &mut [u8], ) -> Result<(), SoftI2CError>

Reads bytes over the I2C bus.

§Examples
let mut buffer = [0; 4];
i2c.soft_i2c_read(SoftI2CAddr::SevenBitAddress(0x48), &mut buffer)?;
assert_eq!(buffer, [0x02, 0x03, 0x04, 0x05]);
Master: ST SAD+R        MAK    MAK ...    NMAK SP
Slave:           SAK B0     B1     ... BN

Trait Implementations§

Source§

impl<'a, C: Debug, D: Debug, Delay: Debug, const CLK_HZ: u32> Debug for SoftI2C<'a, C, D, Delay, CLK_HZ>

Source§

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

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

impl<'a, C: OutputPin, D: OpenDrainPin, Delay: DelayNs, const CLK_HZ: u32> ErrorType for SoftI2C<'a, C, D, Delay, CLK_HZ>

Source§

type Error = SoftI2CError

Error type
Source§

impl<'a, C: OutputPin, D: OpenDrainPin, Delay: DelayNs, const CLK_HZ: u32> I2c<u16> for SoftI2C<'a, C, D, Delay, CLK_HZ>

Source§

fn read(&mut self, address: u16, read: &mut [u8]) -> Result<(), Self::Error>

Reads enough bytes from slave with address to fill read. Read more
Source§

fn write(&mut self, address: u16, write: &[u8]) -> Result<(), Self::Error>

Writes bytes to slave with address address. Read more
Source§

fn write_read( &mut self, address: u16, write: &[u8], read: &mut [u8], ) -> Result<(), Self::Error>

Writes bytes to slave with address address and then reads enough bytes to fill read in a single transaction. Read more
Source§

fn transaction( &mut self, address: u16, operations: &mut [Operation<'_>], ) -> Result<(), Self::Error>

Execute the provided operations on the I2C bus. Read more
Source§

impl<'a, C: OutputPin, D: OpenDrainPin, Delay: DelayNs, const CLK_HZ: u32> I2c for SoftI2C<'a, C, D, Delay, CLK_HZ>

Source§

fn read(&mut self, address: u8, read: &mut [u8]) -> Result<(), Self::Error>

Reads enough bytes from slave with address to fill read. Read more
Source§

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

Writes bytes to slave with address address. Read more
Source§

fn write_read( &mut self, address: u8, write: &[u8], read: &mut [u8], ) -> Result<(), Self::Error>

Writes bytes to slave with address address and then reads enough bytes to fill read in a single transaction. Read more
Source§

fn transaction( &mut self, address: u8, operations: &mut [Operation<'_>], ) -> Result<(), Self::Error>

Execute the provided operations on the I2C bus. Read more

Auto Trait Implementations§

§

impl<'a, C, D, Delay, const CLK_HZ: u32> Freeze for SoftI2C<'a, C, D, Delay, CLK_HZ>

§

impl<'a, C, D, Delay, const CLK_HZ: u32> RefUnwindSafe for SoftI2C<'a, C, D, Delay, CLK_HZ>

§

impl<'a, C, D, Delay, const CLK_HZ: u32> Send for SoftI2C<'a, C, D, Delay, CLK_HZ>
where C: Send, D: Send, Delay: Send,

§

impl<'a, C, D, Delay, const CLK_HZ: u32> Sync for SoftI2C<'a, C, D, Delay, CLK_HZ>
where C: Sync, D: Sync, Delay: Sync,

§

impl<'a, C, D, Delay, const CLK_HZ: u32> Unpin for SoftI2C<'a, C, D, Delay, CLK_HZ>

§

impl<'a, C, D, Delay, const CLK_HZ: u32> !UnwindSafe for SoftI2C<'a, C, D, Delay, CLK_HZ>

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