pub trait I2c<'a> {
// Required methods
fn initialize(
&mut self,
callback: impl FnMut(Event) + 'a,
) -> Result<(), i32>;
fn uninitialize(&mut self) -> Result<(), i32>;
fn master_transmit(
&mut self,
addr: u32,
data: &[u8],
xfer_pending: bool,
) -> Result<(), i32>;
fn master_receive(
&mut self,
addr: u32,
data: &mut [u8],
xfer_pending: bool,
) -> Result<(), i32>;
fn slave_transmit(&mut self, data: &[u8]) -> Result<(), i32>;
fn slave_receive(&mut self, data: &mut [u8]) -> Result<(), i32>;
fn get_data_count(&self) -> Result<u32, i32>;
fn set_bus_speed(&mut self, speed: BusSpeed) -> Result<(), i32>;
fn set_own_address(&mut self, address: u32) -> Result<(), i32>;
fn clear_bus(&mut self) -> Result<(), i32>;
fn abort_transfer(&mut self) -> Result<(), i32>;
fn get_status(&self) -> Status;
}Expand description
A trait that defines a standard interface for an I2C driver.
Required Methods§
Sourcefn initialize(&mut self, callback: impl FnMut(Event) + 'a) -> Result<(), i32>
fn initialize(&mut self, callback: impl FnMut(Event) + 'a) -> Result<(), i32>
Initializes the I2C peripheral.
The provided callback will be invoked to signal communication events.
Sourcefn uninitialize(&mut self) -> Result<(), i32>
fn uninitialize(&mut self) -> Result<(), i32>
De-initializes the I2C peripheral.
Sourcefn master_transmit(
&mut self,
addr: u32,
data: &[u8],
xfer_pending: bool,
) -> Result<(), i32>
fn master_transmit( &mut self, addr: u32, data: &[u8], xfer_pending: bool, ) -> Result<(), i32>
Transmits data as an I2C master.
§Arguments
addr- 7-bit slave address.data- The data buffer to transmit.xfer_pending- If true, a STOP condition is not generated after the transfer, allowing for a subsequent transfer to the same or different device.
Sourcefn master_receive(
&mut self,
addr: u32,
data: &mut [u8],
xfer_pending: bool,
) -> Result<(), i32>
fn master_receive( &mut self, addr: u32, data: &mut [u8], xfer_pending: bool, ) -> Result<(), i32>
Receives data as an I2C master.
§Arguments
addr- 7-bit slave address.data- A mutable buffer to store the received data.xfer_pending- If true, a repeated START is generated after the transfer, instead of a STOP condition.
Sourcefn get_data_count(&self) -> Result<u32, i32>
fn get_data_count(&self) -> Result<u32, i32>
Gets the number of bytes transferred in the last transaction.
Sourcefn set_bus_speed(&mut self, speed: BusSpeed) -> Result<(), i32>
fn set_bus_speed(&mut self, speed: BusSpeed) -> Result<(), i32>
Sets the bus speed for the I2C communication.
Sourcefn set_own_address(&mut self, address: u32) -> Result<(), i32>
fn set_own_address(&mut self, address: u32) -> Result<(), i32>
Sets the slave address for the I2C peripheral when in slave mode.
Sourcefn abort_transfer(&mut self) -> Result<(), i32>
fn abort_transfer(&mut self) -> Result<(), i32>
Aborts an ongoing I2C transfer.
Sourcefn get_status(&self) -> Status
fn get_status(&self) -> Status
Gets the current status of the I2C peripheral.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.