I2C

Struct I2C 

Source
pub struct I2C<const CLK_HZ: u32> { /* private fields */ }
Expand description

Implementation of the I2C interface.

Implementations§

Source§

impl<const CLK_HZ: u32> I2C<CLK_HZ>

Source

pub fn new(bus: I2CBusId, flags: Option<u32>) -> Self

Creates a new I2C instance.

Source

pub fn blocking_write_read( &mut self, address: I2CAddr, write: &[u8], read: &mut [u8], ) -> Result<(), I2CError>

Writes bytes and reads bytes over the I2C bus.

§Examples
let mut buffer = [0; 4];
i2c.blocking_write_read(I2CAddr::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 blocking_write( &mut self, address: I2CAddr, write: &[u8], ) -> Result<(), I2CError>

Writes bytes over the I2C bus.

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

pub fn blocking_read( &mut self, address: I2CAddr, read: &mut [u8], ) -> Result<(), I2CError>

Reads bytes over the I2C bus.

§Examples
let mut buffer = [0; 4];
i2c.blocking_read(I2CAddr::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<const CLK_HZ: u32> Clone for I2C<CLK_HZ>

Source§

fn clone(&self) -> I2C<CLK_HZ>

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<const CLK_HZ: u32> Debug for I2C<CLK_HZ>

Source§

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

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

impl<const CLK_HZ: u32> Drop for I2C<CLK_HZ>

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

impl<const CLK_HZ: u32> ErrorType for I2C<CLK_HZ>

Source§

type Error = I2CError

Error type
Source§

impl<const CLK_HZ: u32> I2c<u16> for I2C<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<const CLK_HZ: u32> I2c for I2C<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<const CLK_HZ: u32> Freeze for I2C<CLK_HZ>

§

impl<const CLK_HZ: u32> RefUnwindSafe for I2C<CLK_HZ>

§

impl<const CLK_HZ: u32> Send for I2C<CLK_HZ>

§

impl<const CLK_HZ: u32> Sync for I2C<CLK_HZ>

§

impl<const CLK_HZ: u32> Unpin for I2C<CLK_HZ>

§

impl<const CLK_HZ: u32> UnwindSafe for I2C<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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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.