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>

Create a new I2C slave instance.

Source

pub fn into_async(self) -> I2cSlave<'d, Async>

Reconfigures the driver to operate in Async mode.

Source§

impl<'d> I2cSlave<'d, Async>

Source

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

Reconfigures the driver to operate in Blocking mode.

Source§

impl<'d, Dm: DriverMode> I2cSlave<'d, Dm>

Source

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

Connect a pin to the I2C SDA signal.

Source

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

Connect a pin to the I2C SCL signal.

Source

pub fn apply_config(&mut self, config: &Config) -> Result<(), ConfigError>

Applies a new configuration.

Source§

impl<'d, Dm: DriverMode> I2cSlave<'d, Dm>

Source

pub fn listen(&mut self, buffer: &mut [u8]) -> Result<Command, Error>

Listens for a request from the master.

If the master writes to the slave, this method reads data into the provided buffer and returns Command::Write(len). If the master is requesting a read, it returns Command::Read with the SCL line stretched (held low).

Source

pub fn respond_to_read(&mut self, buffer: &[u8]) -> Result<ReadStatus, Error>

Responds to a master read request.

Writes the contents of buffer to the TX FIFO, clears the clock stretch, and waits for the transaction to complete.

Source§

impl<'d> I2cSlave<'d, Async>

Source

pub async fn listen_async( &mut self, buffer: &mut [u8], ) -> Result<Command, Error>

Listens for a request from the master asynchronously.

Source

pub async fn respond_to_read_async( &mut self, buffer: &[u8], ) -> Result<ReadStatus, Error>

Responds to a master read request asynchronously.

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> Freeze for I2cSlave<'d, Dm>
where PhantomData<Dm>: Freeze,

§

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 = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.