pub struct I2cSlave<'d, Dm: DriverMode> { /* private fields */ }Expand description
I2C slave driver.
Implementations§
Source§impl<'d> I2cSlave<'d, Blocking>
impl<'d> I2cSlave<'d, Blocking>
Sourcepub fn new(i2c: impl Instance + 'd, config: Config) -> Result<Self, ConfigError>
pub fn new(i2c: impl Instance + 'd, config: Config) -> Result<Self, ConfigError>
Creates a new I2C slave instance in Blocking mode.
§Errors
ConfigError::AddressInvalid when the address is not a valid 7-bit address.
Sourcepub fn into_async(self) -> I2cSlave<'d, Async>
pub fn into_async(self) -> I2cSlave<'d, Async>
Reconfigures the driver to operate in Async mode.
Pending requests are preserved.
Source§impl<'d> I2cSlave<'d, Async>
impl<'d> I2cSlave<'d, Async>
Sourcepub fn into_blocking(self) -> I2cSlave<'d, Blocking>
pub fn into_blocking(self) -> I2cSlave<'d, Blocking>
Reconfigures the driver to operate in Blocking mode.
Pending requests are preserved.
Sourcepub async fn listen_async(
&mut self,
buffer: &mut [u8],
) -> Result<Command, Error>
pub async fn listen_async( &mut self, buffer: &mut [u8], ) -> Result<Command, Error>
Listens for a request from the master asynchronously.
See Self::listen for the receive behavior and errors.
§Cancellation Safety
Canceling after this operation consumes receive data resets the controller and discards pending requests. Otherwise, cancellation does not reset the controller. The master must retry discarded requests. The receive buffer can contain partial data.
Sourcepub async fn respond_to_read_async(
&mut self,
buffer: &[u8],
) -> Result<ReadStatus, Error>
pub async fn respond_to_read_async( &mut self, buffer: &[u8], ) -> Result<ReadStatus, Error>
Responds to a master read request asynchronously.
See Self::respond_to_read for the response behavior and errors.
§Cancellation Safety
Dropping an unpolled future does not change the controller. Canceling a pending operation after its first poll resets the controller and discards pending requests. The master must retry these requests.
Source§impl<'d, Dm: DriverMode> I2cSlave<'d, Dm>
impl<'d, Dm: DriverMode> I2cSlave<'d, Dm>
Sourcepub fn with_sda(
self,
sda: impl PeripheralInput<'d> + PeripheralOutput<'d>,
) -> Self
pub fn with_sda( self, sda: impl PeripheralInput<'d> + PeripheralOutput<'d>, ) -> Self
Connects a pin to the I2C SDA signal.
Sourcepub fn with_scl(
self,
scl: impl PeripheralInput<'d> + PeripheralOutput<'d>,
) -> Self
pub fn with_scl( self, scl: impl PeripheralInput<'d> + PeripheralOutput<'d>, ) -> Self
Connects a pin to the I2C SCL signal.
Sourcepub fn apply_config(&mut self, config: &Config) -> Result<(), ConfigError>
pub fn apply_config(&mut self, config: &Config) -> Result<(), ConfigError>
Applies a new configuration.
A valid configuration resets the controller and discards pending requests. The master must retry these requests. Invalid configurations preserve the current settings and FIFO contents.
§Errors
ConfigError::AddressInvalid when the address is not a valid 7-bit address.
Sourcepub fn listen(&mut self, buffer: &mut [u8]) -> Result<Command, Error>
pub fn listen(&mut self, buffer: &mut [u8]) -> Result<Command, Error>
Listens for a request from the master.
Receives writes into buffer and returns Command::Write with the number
of received bytes at STOP or repeated START. Address-only write probes are ignored.
Extra bytes are discarded if buffer is too small.
Returns Command::Read for a read request and holds SCL low until
Self::respond_to_read supplies the response.
Pending receive data is preserved between calls.
The controller stretches SCL at each write byte’s ACK until this method consumes the byte.
If a bus error is detected when this method starts, it resets the controller and discards pending data.
§Errors
Error::Overflow when the receive buffer is too small or the RX FIFO overflows.
The error is reported after STOP or repeated START.
Error::Timeout when a hardware bus timeout is detected.
Error::ArbitrationLost when arbitration is lost.
Sourcepub fn respond_to_read(&mut self, buffer: &[u8]) -> Result<ReadStatus, Error>
pub fn respond_to_read(&mut self, buffer: &[u8]) -> Result<ReadStatus, Error>
Responds to a master read request.
A listen operation must first return Command::Read.
Sends data from buffer and releases SCL clock stretching.
Completes when the master sends a NACK.
Data is padded with 0xff if the master reads past the end of buffer.
§Errors
Error::ResponseTooLong when more than 65,535 provided bytes remain unread.
The response completes, but the remaining count cannot fit in ReadStatus::LeftoverBytes.
Error::ReadAborted when the master ends the read without a NACK.
The controller resets and discards pending requests.
The master must retry these requests.
Error::Timeout when a hardware bus timeout is detected.
Error::ArbitrationLost when arbitration is lost.
Trait Implementations§
Source§impl<'d, Dm: Debug + DriverMode> Debug for I2cSlave<'d, Dm>
Available on crate feature unstable only.
impl<'d, Dm: Debug + DriverMode> Debug for I2cSlave<'d, Dm>
unstable only.