pub struct I2c<'d, T: Instance, M: Mode, O: OperatingMode = Master> { /* private fields */ }Expand description
I2C driver.
Without the embassy feature, operations have no timeout and may wait
indefinitely if the bus or peripheral does not make progress.
Implementations§
Source§impl<'d, T: Instance, M: Mode> I2c<'d, T, M, Master>
impl<'d, T: Instance, M: Mode> I2c<'d, T, M, Master>
Sourcepub fn into_slave(
self,
slave_config: SlaveConfig,
) -> Result<I2c<'d, T, M, Slave>, Error>
pub fn into_slave( self, slave_config: SlaveConfig, ) -> Result<I2c<'d, T, M, Slave>, Error>
Switch this driver to slave mode.
The bus timing and timeout configured by the constructor are kept; only the own address and the slave control bits are reprogrammed.
Source§impl<'d, T: Instance> I2c<'d, T, Blocking, Slave>
impl<'d, T: Instance> I2c<'d, T, Blocking, Slave>
Sourcepub fn new_slave_blocking<const REMAP: u8>(
peri: Peri<'d, T>,
scl: Peri<'d, impl SclPin<T, REMAP>>,
sda: Peri<'d, impl SdaPin<T, REMAP>>,
freq: Hertz,
config: Config,
slave_config: SlaveConfig,
) -> Result<Self, Error>
pub fn new_slave_blocking<const REMAP: u8>( peri: Peri<'d, T>, scl: Peri<'d, impl SclPin<T, REMAP>>, sda: Peri<'d, impl SdaPin<T, REMAP>>, freq: Hertz, config: Config, slave_config: SlaveConfig, ) -> Result<Self, Error>
Create a new blocking I2C slave.
config.timeout bounds every blocking_* call.
Sourcepub fn blocking_listen(&mut self) -> Result<SlaveCommand, Error>
pub fn blocking_listen(&mut self) -> Result<SlaveCommand, Error>
Block until the master addresses this slave.
Sourcepub fn blocking_respond_to_write(
&mut self,
buf: &mut [u8],
) -> Result<usize, Error>
pub fn blocking_respond_to_write( &mut self, buf: &mut [u8], ) -> Result<usize, Error>
Receive bytes from a write transaction.
Returns the number of bytes stored in buf. Bytes beyond buf.len()
are acknowledged and discarded, so the bus is never held low waiting
for space.
Sourcepub fn blocking_respond_to_read(
&mut self,
data: &[u8],
) -> Result<SendStatus, Error>
pub fn blocking_respond_to_read( &mut self, data: &[u8], ) -> Result<SendStatus, Error>
Transmit bytes for a read transaction.
Data beyond data is padded with 0x00 until the master ends the
transaction, matching the reference manual’s slave transmitter flow.
Source§impl<'d, T: Instance> I2c<'d, T, Async, Slave>
impl<'d, T: Instance> I2c<'d, T, Async, Slave>
Sourcepub fn new_slave<const REMAP: u8>(
peri: Peri<'d, T>,
scl: Peri<'d, impl SclPin<T, REMAP>>,
sda: Peri<'d, impl SdaPin<T, REMAP>>,
_irq: impl Binding<T::EventInterrupt, EventInterruptHandler<T>> + Binding<T::ErrorInterrupt, ErrorInterruptHandler<T>> + 'd,
freq: Hertz,
config: Config,
slave_config: SlaveConfig,
) -> Result<Self, Error>
pub fn new_slave<const REMAP: u8>( peri: Peri<'d, T>, scl: Peri<'d, impl SclPin<T, REMAP>>, sda: Peri<'d, impl SdaPin<T, REMAP>>, _irq: impl Binding<T::EventInterrupt, EventInterruptHandler<T>> + Binding<T::ErrorInterrupt, ErrorInterruptHandler<T>> + 'd, freq: Hertz, config: Config, slave_config: SlaveConfig, ) -> Result<Self, Error>
Create a new interrupt-driven I2C slave.
config is accepted for symmetry with the master constructors. Its
timeout is stored but not applied: asynchronous operations wait for the
master indefinitely.
Sourcepub fn new_slave_with_dma<const REMAP: u8>(
peri: Peri<'d, T>,
scl: Peri<'d, impl SclPin<T, REMAP>>,
sda: Peri<'d, impl SdaPin<T, REMAP>>,
_irq: impl Binding<T::EventInterrupt, EventInterruptHandler<T>> + Binding<T::ErrorInterrupt, ErrorInterruptHandler<T>> + 'd,
tx_dma: Peri<'d, impl TxDma<T>>,
rx_dma: Peri<'d, impl RxDma<T>>,
freq: Hertz,
config: Config,
slave_config: SlaveConfig,
) -> Result<Self, Error>
pub fn new_slave_with_dma<const REMAP: u8>( peri: Peri<'d, T>, scl: Peri<'d, impl SclPin<T, REMAP>>, sda: Peri<'d, impl SdaPin<T, REMAP>>, _irq: impl Binding<T::EventInterrupt, EventInterruptHandler<T>> + Binding<T::ErrorInterrupt, ErrorInterruptHandler<T>> + 'd, tx_dma: Peri<'d, impl TxDma<T>>, rx_dma: Peri<'d, impl RxDma<T>>, freq: Hertz, config: Config, slave_config: SlaveConfig, ) -> Result<Self, Error>
Create a new I2C slave that uses DMA for the data phase.
As with new_slave, config is accepted for
symmetry with the master constructors; no asynchronous operation uses
the timeout.
Sourcepub async fn listen(&mut self) -> Result<SlaveCommand, Error>
pub async fn listen(&mut self) -> Result<SlaveCommand, Error>
Wait until the master addresses this slave.
Sourcepub async fn respond_to_write(&mut self, buf: &mut [u8]) -> Result<usize, Error>
pub async fn respond_to_write(&mut self, buf: &mut [u8]) -> Result<usize, Error>
Receive bytes from a write transaction.
Sourcepub async fn respond_to_read(
&mut self,
data: &[u8],
) -> Result<SendStatus, Error>
pub async fn respond_to_read( &mut self, data: &[u8], ) -> Result<SendStatus, Error>
Transmit bytes for a read transaction.
Source§impl<'d, T: Instance> I2c<'d, T, Async, Master>
impl<'d, T: Instance> I2c<'d, T, Async, Master>
Sourcepub fn new<const REMAP: u8>(
peri: Peri<'d, T>,
scl: Peri<'d, impl SclPin<T, REMAP>>,
sda: Peri<'d, impl SdaPin<T, REMAP>>,
_irq: impl Binding<T::EventInterrupt, EventInterruptHandler<T>> + Binding<T::ErrorInterrupt, ErrorInterruptHandler<T>> + 'd,
tx_dma: Peri<'d, impl TxDma<T>>,
rx_dma: Peri<'d, impl RxDma<T>>,
freq: Hertz,
config: Config,
) -> Self
pub fn new<const REMAP: u8>( peri: Peri<'d, T>, scl: Peri<'d, impl SclPin<T, REMAP>>, sda: Peri<'d, impl SdaPin<T, REMAP>>, _irq: impl Binding<T::EventInterrupt, EventInterruptHandler<T>> + Binding<T::ErrorInterrupt, ErrorInterruptHandler<T>> + 'd, tx_dma: Peri<'d, impl TxDma<T>>, rx_dma: Peri<'d, impl RxDma<T>>, freq: Hertz, config: Config, ) -> Self
Create a new I2C driver.
Source§impl<'d, T: Instance, M: Mode> I2c<'d, T, M, Master>
impl<'d, T: Instance, M: Mode> I2c<'d, T, M, Master>
Sourcepub fn blocking_read(&mut self, addr: u8, read: &mut [u8]) -> Result<(), Error>
pub fn blocking_read(&mut self, addr: u8, read: &mut [u8]) -> Result<(), Error>
Blocking read.
Sourcepub fn blocking_write(&mut self, addr: u8, write: &[u8]) -> Result<(), Error>
pub fn blocking_write(&mut self, addr: u8, write: &[u8]) -> Result<(), Error>
Blocking write.
Sourcepub fn blocking_write_read(
&mut self,
addr: u8,
write: &[u8],
read: &mut [u8],
) -> Result<(), Error>
pub fn blocking_write_read( &mut self, addr: u8, write: &[u8], read: &mut [u8], ) -> Result<(), Error>
Blocking write, restart, read.
Sourcepub fn blocking_transaction(
&mut self,
addr: u8,
operations: &mut [Operation<'_>],
) -> Result<(), Error>
pub fn blocking_transaction( &mut self, addr: u8, operations: &mut [Operation<'_>], ) -> Result<(), Error>
Blocking transaction with operations.
Consecutive operations of same type are merged. See transaction contract for details.
Source§impl<'d, T: Instance> I2c<'d, T, Async, Master>
impl<'d, T: Instance> I2c<'d, T, Async, Master>
Sourcepub async fn write_read(
&mut self,
address: u8,
write: &[u8],
read: &mut [u8],
) -> Result<(), Error>
pub async fn write_read( &mut self, address: u8, write: &[u8], read: &mut [u8], ) -> Result<(), Error>
Write, restart, read.
Sourcepub async fn transaction(
&mut self,
addr: u8,
operations: &mut [Operation<'_>],
) -> Result<(), Error>
pub async fn transaction( &mut self, addr: u8, operations: &mut [Operation<'_>], ) -> Result<(), Error>
Transaction with operations.
Consecutive operations of same type are merged. See transaction contract for details.
Trait Implementations§
Source§impl<'d, T: Instance, M: Mode> I2c for I2c<'d, T, M, Master>
impl<'d, T: Instance, M: Mode> I2c for I2c<'d, T, M, Master>
Source§fn write(&mut self, address: u8, write: &[u8]) -> Result<(), Self::Error>
fn write(&mut self, address: u8, write: &[u8]) -> Result<(), Self::Error>
address. Read moreSource§fn write_read(
&mut self,
address: u8,
write: &[u8],
read: &mut [u8],
) -> Result<(), Self::Error>
fn write_read( &mut self, address: u8, write: &[u8], read: &mut [u8], ) -> Result<(), Self::Error>
address and then reads enough bytes to fill read in a
single transaction. Read moreSource§fn transaction(
&mut self,
address: u8,
operations: &mut [Operation<'_>],
) -> Result<(), Self::Error>
fn transaction( &mut self, address: u8, operations: &mut [Operation<'_>], ) -> Result<(), Self::Error>
Source§impl<'d, T: Instance> I2c for I2c<'d, T, Async, Master>
impl<'d, T: Instance> I2c for I2c<'d, T, Async, Master>
Source§async fn write(&mut self, address: u8, write: &[u8]) -> Result<(), Self::Error>
async fn write(&mut self, address: u8, write: &[u8]) -> Result<(), Self::Error>
address. Read moreSource§async fn write_read(
&mut self,
address: u8,
write: &[u8],
read: &mut [u8],
) -> Result<(), Self::Error>
async fn write_read( &mut self, address: u8, write: &[u8], read: &mut [u8], ) -> Result<(), Self::Error>
address and then reads enough bytes to fill read in a
single transaction. Read more