Struct embedded_c_sdk_bind_hal::soft_i2c::SoftI2C

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

A software implementation of the I2C interface.

§Examples

use crate::gpio::{BidirectionPin, BidirectionPinMode};
use crate::tick::Delay;
 
let scl = /* Initialize SCL pin */;
let sda = /* Initialize SDA pin */;
let i2c = SoftI2C::new(scl, sda);

Implementations§

source§

impl<C, D, const CLK_HZ: u32> SoftI2C<C, D, CLK_HZ>

source

pub fn new(scl: C, sda: D) -> 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<C: OutputPin, D: BidirectionPin, const CLK_HZ: u32> ErrorType for SoftI2C<C, D, CLK_HZ>

source§

type Error = SoftI2CError

Error type
source§

impl<C: OutputPin, D: BidirectionPin, const CLK_HZ: u32> I2c<u16> for SoftI2C<C, D, 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<C: OutputPin, D: BidirectionPin, const CLK_HZ: u32> I2c for SoftI2C<C, D, 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<C, D, const CLK_HZ: u32> Freeze for SoftI2C<C, D, CLK_HZ>
where C: Freeze, D: Freeze,

§

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

§

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

§

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

§

impl<C, D, const CLK_HZ: u32> Unpin for SoftI2C<C, D, CLK_HZ>
where C: Unpin, D: Unpin,

§

impl<C, D, const CLK_HZ: u32> UnwindSafe for SoftI2C<C, D, CLK_HZ>
where C: UnwindSafe, D: UnwindSafe,

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.