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>where
C: OutputPin,
D: BidirectionPin,
impl<C, D, const CLK_HZ: u32> SoftI2C<C, D, CLK_HZ>where
C: OutputPin,
D: BidirectionPin,
sourcepub fn new(scl: C, sda: D) -> Self
pub fn new(scl: C, sda: D) -> Self
Creates a new SoftI2C
instance with the given SCL and SDA pins.
sourcepub fn soft_i2c_write_read(
&mut self,
address: SoftI2CAddr,
write: &[u8],
read: &mut [u8],
) -> Result<(), SoftI2CError>
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
sourcepub fn soft_i2c_write(
&mut self,
address: SoftI2CAddr,
write: &[u8],
) -> Result<(), SoftI2CError>
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
sourcepub fn soft_i2c_read(
&mut self,
address: SoftI2CAddr,
read: &mut [u8],
) -> Result<(), SoftI2CError>
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>
impl<C: OutputPin, D: BidirectionPin, const CLK_HZ: u32> ErrorType for SoftI2C<C, D, CLK_HZ>
source§type Error = SoftI2CError
type Error = SoftI2CError
Error type
source§impl<C: OutputPin, D: BidirectionPin, const CLK_HZ: u32> I2c<u16> for SoftI2C<C, D, CLK_HZ>
impl<C: OutputPin, D: BidirectionPin, const CLK_HZ: u32> I2c<u16> for SoftI2C<C, D, CLK_HZ>
source§fn write(&mut self, address: u16, write: &[u8]) -> Result<(), Self::Error>
fn write(&mut self, address: u16, write: &[u8]) -> Result<(), Self::Error>
Writes bytes to slave with address
address
. Read moresource§impl<C: OutputPin, D: BidirectionPin, const CLK_HZ: u32> I2c for SoftI2C<C, D, CLK_HZ>
impl<C: OutputPin, D: BidirectionPin, const CLK_HZ: u32> I2c for SoftI2C<C, D, CLK_HZ>
source§fn write(&mut self, address: u8, write: &[u8]) -> Result<(), Self::Error>
fn write(&mut self, address: u8, write: &[u8]) -> Result<(), Self::Error>
Writes bytes to slave with address
address
. Read moreAuto Trait Implementations§
impl<C, D, const CLK_HZ: u32> Freeze for SoftI2C<C, D, CLK_HZ>
impl<C, D, const CLK_HZ: u32> RefUnwindSafe for SoftI2C<C, D, CLK_HZ>where
C: RefUnwindSafe,
D: RefUnwindSafe,
impl<C, D, const CLK_HZ: u32> Send for SoftI2C<C, D, CLK_HZ>
impl<C, D, const CLK_HZ: u32> Sync for SoftI2C<C, D, CLK_HZ>
impl<C, D, const CLK_HZ: u32> Unpin for SoftI2C<C, D, CLK_HZ>
impl<C, D, const CLK_HZ: u32> UnwindSafe for SoftI2C<C, D, CLK_HZ>where
C: UnwindSafe,
D: UnwindSafe,
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