Skip to main content

I2cSlave

Struct I2cSlave 

Source
pub struct I2cSlave<'d, Dm: DriverMode> { /* private fields */ }
Expand description

I2C slave driver.

Implementations§

Source§

impl<'d> I2cSlave<'d, Blocking>

Source

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.

Source

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>

Source

pub fn into_blocking(self) -> I2cSlave<'d, Blocking>

Reconfigures the driver to operate in Blocking mode.

Pending requests are preserved.

Source

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.

Source

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>

Source

pub fn with_sda( self, sda: impl PeripheralInput<'d> + PeripheralOutput<'d>, ) -> Self

Connects a pin to the I2C SDA signal.

Source

pub fn with_scl( self, scl: impl PeripheralInput<'d> + PeripheralOutput<'d>, ) -> Self

Connects a pin to the I2C SCL signal.

Source

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.

Source

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.

Source

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.
Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<Dm: DriverMode> ErrorType for I2cSlave<'_, Dm>

Available on crate feature unstable only.
Source§

type Error = Error

Error type

Auto Trait Implementations§

§

impl<'d, Dm> !UnwindSafe for I2cSlave<'d, Dm>

§

impl<'d, Dm> Forget for I2cSlave<'d, Dm>

§

impl<'d, Dm> Freeze for I2cSlave<'d, Dm>
where PhantomData<Dm>: Freeze,

§

impl<'d, Dm> Move for I2cSlave<'d, Dm>

§

impl<'d, Dm> RefUnwindSafe for I2cSlave<'d, Dm>
where PhantomData<Dm>: RefUnwindSafe,

§

impl<'d, Dm> Send for I2cSlave<'d, Dm>
where PhantomData<Dm>: Send,

§

impl<'d, Dm> Sync for I2cSlave<'d, Dm>
where PhantomData<Dm>: Sync,

§

impl<'d, Dm> Unpin for I2cSlave<'d, Dm>
where PhantomData<Dm>: Unpin,

§

impl<'d, Dm> UnsafeUnpin for I2cSlave<'d, Dm>
where PhantomData<Dm>: UnsafeUnpin,

Blanket Implementations§

§

impl<T> Any for T
where T: 'static + ?Sized,

§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
§

impl<T> Borrow<T> for T
where T: ?Sized,

§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
§

impl<T> BorrowMut<T> for T
where T: ?Sized,

§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
§

impl<T> From<T> for T

§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T, U> Into<U> for T
where U: From<T>,

§

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> Same for T

Source§

type Output = T

Should always be Self
§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = !

The type returned in the event of a conversion error.
§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.