Struct soft_i2c::SoftI2C

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

A software implementation of the I2C interface.

let scl = /* Initialize SCL pin as open drain mode*/; let sda = /* Initialize SDA pin as open drain mode*/; let delay = Delay::new(); /Delay need impl DelayNs trait/ let i2c = SoftI2C::new(scl, sda, delay);

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.