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
impl I2c
Sourcepub const MAX_TRANSFER_OPS: usize = 8
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.
Sourcepub fn write_read(
&mut self,
addr: u16,
write_buf: &[u8],
read_buf: &mut [u8],
) -> Result<()>
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).
Sourcepub fn transfer(&mut self, addr: u16, ops: &mut [Operation<'_>]) -> Result<()>
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.
Sourcepub unsafe fn register_target(
&mut self,
config: &'static mut i2c_target_config,
) -> Result<I2cTarget>
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.