I2c

Struct I2c 

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

A Zephyr I2C controller device.

This wrapper maps to Zephyr’s blocking I2C controller API (i2c_write, i2c_read, i2c_write_read). All operations block the calling thread until the transfer completes.

Implementations§

Source§

impl I2c

Source

pub const MAX_TRANSFER_OPS: usize = 8

Maximum number of operations supported in a single transfer call.

transfer builds the underlying i2c_msg array on the stack so the bound is fixed at compile time. Increase this if longer transactions are needed.

Source

pub fn is_ready(&self) -> bool

Verify that the underlying I2C device is ready for use.

Source

pub fn write_read( &mut self, addr: u16, write_buf: &[u8], read_buf: &mut [u8], ) -> Result<()>

Write bytes to an I2C device, then read bytes back in a single transaction (RESTART between the write and read phases).

Source

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

Write bytes to an I2C device.

Source

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

Read bytes from an I2C device.

Source

pub fn transfer(&mut self, addr: u16, ops: &mut [Operation<'_>]) -> Result<()>

Perform a multi-stage I2C transaction.

Wraps Zephyr’s i2c_transfer, the general-purpose scatter/gather entry point. Each Operation becomes one i2c_msg; a RESTART is inserted between adjacent operations whose direction differs, and i2c_transfer itself appends a STOP after the final message.

Up to MAX_TRANSFER_OPS operations are supported per call; passing more returns Err(Error(E2BIG)). For simple cases prefer write, read, or write_read.

Source

pub unsafe fn register_target( &mut self, config: &'static mut i2c_target_config, ) -> Result<I2cTarget>

Register an I2C target on this bus (low-level).

Prefer I2cTargetData::register for a fully safe interface.

The caller must supply a fully initialised i2c_target_config (including the callbacks pointer and target address). The config and the callbacks it points to must remain valid for as long as the target is registered — typically they live in a static.

All callback function pointers in the i2c_target_callbacks struct are invoked from ISR context. The caller is responsible for providing the extern "C" callback implementations and managing any shared state they access.

Returns an I2cTarget handle that can be used to unregister.

§Safety

The config pointer must remain valid and unmodified until I2cTarget::unregister is called. The callback functions must be safe to call from ISR context.

Trait Implementations§

Source§

impl Send for I2c

Auto Trait Implementations§

§

impl Freeze for I2c

§

impl RefUnwindSafe for I2c

§

impl !Sync for I2c

§

impl Unpin 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> 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.