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
impl I2c
Sourcepub const unsafe fn from_handle(handle: ove_i2c_t) -> Self
pub const unsafe fn from_handle(handle: ove_i2c_t) -> Self
Wrap an existing ove_i2c_t handle.
§Safety
handlemust be a valid I2C handle returned by the substrate (typically via the board config / BSP layer).- The caller is responsible for ensuring no other
I2cwrapper 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.
Sourcepub fn raw(&self) -> ove_i2c_t
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.
Sourcepub fn write(&self, addr: u16, data: &[u8], timeout: Duration) -> Result<()>
pub fn write(&self, addr: u16, data: &[u8], timeout: Duration) -> Result<()>
Write data to an I2C device.
Sourcepub fn read(&self, addr: u16, buf: &mut [u8], timeout: Duration) -> Result<()>
pub fn read(&self, addr: u16, buf: &mut [u8], timeout: Duration) -> Result<()>
Read data from an I2C device.
Sourcepub fn write_read(
&self,
addr: u16,
tx: &[u8],
rx: &mut [u8],
timeout: Duration,
) -> Result<()>
pub fn write_read( &self, addr: u16, tx: &[u8], rx: &mut [u8], timeout: Duration, ) -> Result<()>
Combined write-then-read with I2C repeated start.
Sourcepub fn reg_write(
&self,
addr: u16,
reg: u8,
data: &[u8],
timeout: Duration,
) -> Result<()>
pub fn reg_write( &self, addr: u16, reg: u8, data: &[u8], timeout: Duration, ) -> Result<()>
Write to a single-byte-addressed register.
Trait Implementations§
Source§impl I2c for I2c
impl I2c for I2c
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 moreimpl 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> 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