Skip to main content

I2c

Struct I2c 

Source
pub struct I2c { /* private fields */ }
Expand description

I2C bus master.

Wraps an opaque ove_i2c_t handle provided by the board configuration (the substrate manages the handle’s lifetime; the binding does not own it). Construct via I2c::from_handle with a handle obtained from the BSP layer or board descriptor.

Implementations§

Source§

impl I2c

Source

pub const unsafe fn from_handle(handle: ove_i2c_t) -> Self

Wrap an existing ove_i2c_t handle.

§Safety
  • handle must be a valid I2C handle returned by the substrate (typically via the board config / BSP layer).
  • The caller is responsible for ensuring no other I2c wrapper exists for the same handle concurrently — the substrate serialises bus access internally, but constructing two wrappers with conflicting trait-impl state is a logic error.
Source

pub fn raw(&self) -> ove_i2c_t

Return the underlying handle. Useful when bridging into the raw FFI for an operation the binding hasn’t surfaced.

Source

pub fn write(&self, addr: u16, data: &[u8], timeout: Duration) -> Result<()>

Write data to an I2C device.

Source

pub fn read(&self, addr: u16, buf: &mut [u8], timeout: Duration) -> Result<()>

Read data from an I2C device.

Source

pub fn write_read( &self, addr: u16, tx: &[u8], rx: &mut [u8], timeout: Duration, ) -> Result<()>

Combined write-then-read with I2C repeated start.

Source

pub fn reg_write( &self, addr: u16, reg: u8, data: &[u8], timeout: Duration, ) -> Result<()>

Write to a single-byte-addressed register.

Source

pub fn reg_read( &self, addr: u16, reg: u8, buf: &mut [u8], timeout: Duration, ) -> Result<()>

Read from a single-byte-addressed register.

Source

pub fn probe(&self, addr: u16, timeout: Duration) -> Result<()>

Probe for a device at the given address (zero-length write, check ACK).

Trait Implementations§

Source§

impl Clone for I2c

Source§

fn clone(&self) -> I2c

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 Debug for I2c

Source§

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

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

impl ErrorType for I2c

Source§

type Error = Error

Error type
Source§

impl I2c for I2c

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
Source§

impl Copy for I2c

Auto Trait Implementations§

§

impl Freeze for I2c

§

impl RefUnwindSafe for I2c

§

impl !Send for I2c

§

impl !Sync for I2c

§

impl Unpin for I2c

§

impl UnsafeUnpin for I2c

§

impl UnwindSafe for I2c

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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.