pub struct I2c<'d, DM: Mode, T = AnyI2c> { /* private fields */ }Expand description
I2C driver
Implementations§
Source§impl<'d, T, DM: Mode> I2c<'d, DM, T>where
T: Instance,
impl<'d, T, DM: Mode> I2c<'d, DM, T>where
T: Instance,
Sourcepub fn apply_config(&mut self, config: &Config) -> Result<(), ConfigError>
pub fn apply_config(&mut self, config: &Config) -> Result<(), ConfigError>
Applies a new configuration.
Sourcepub fn with_sda(
self,
sda: impl Peripheral<P = impl PeripheralOutput> + 'd,
) -> Self
pub fn with_sda( self, sda: impl Peripheral<P = impl PeripheralOutput> + 'd, ) -> Self
Connect a pin to the I2C SDA signal.
Sourcepub fn with_scl(
self,
scl: impl Peripheral<P = impl PeripheralOutput> + 'd,
) -> Self
pub fn with_scl( self, scl: impl Peripheral<P = impl PeripheralOutput> + 'd, ) -> Self
Connect a pin to the I2C SCL signal.
Source§impl<'d> I2c<'d, Blocking>
impl<'d> I2c<'d, Blocking>
Sourcepub fn new(i2c: impl Peripheral<P = impl Instance> + 'd, config: Config) -> Self
pub fn new(i2c: impl Peripheral<P = impl Instance> + 'd, config: Config) -> Self
Create a new I2C instance This will enable the peripheral but the peripheral won’t get automatically disabled when this gets dropped.
Source§impl<'d, T> I2c<'d, Blocking, T>where
T: Instance,
impl<'d, T> I2c<'d, Blocking, T>where
T: Instance,
Sourcepub fn new_typed(i2c: impl Peripheral<P = T> + 'd, config: Config) -> Self
pub fn new_typed(i2c: impl Peripheral<P = T> + 'd, config: Config) -> Self
Create a new I2C instance This will enable the peripheral but the peripheral won’t get automatically disabled when this gets dropped.
Sourcepub fn into_async(self) -> I2c<'d, Async, T>
pub fn into_async(self) -> I2c<'d, Async, T>
Configures the I2C peripheral to operate in asynchronous mode.
Sourcepub fn write(&mut self, address: u8, buffer: &[u8]) -> Result<(), Error>
pub fn write(&mut self, address: u8, buffer: &[u8]) -> Result<(), Error>
Writes bytes to slave with address address
Sourcepub fn read(&mut self, address: u8, buffer: &mut [u8]) -> Result<(), Error>
pub fn read(&mut self, address: u8, buffer: &mut [u8]) -> Result<(), Error>
Reads enough bytes from slave with address to fill buffer
Sourcepub fn write_read(
&mut self,
address: u8,
write_buffer: &[u8],
read_buffer: &mut [u8],
) -> Result<(), Error>
pub fn write_read( &mut self, address: u8, write_buffer: &[u8], read_buffer: &mut [u8], ) -> Result<(), Error>
Writes bytes to slave with address address and then reads enough bytes
to fill buffer in a single transaction
Sourcepub fn transaction<'a>(
&mut self,
address: u8,
operations: impl IntoIterator<Item = &'a mut Operation<'a>>,
) -> Result<(), Error>
pub fn transaction<'a>( &mut self, address: u8, operations: impl IntoIterator<Item = &'a mut Operation<'a>>, ) -> Result<(), Error>
Execute the provided operations on the I2C bus.
Transaction contract:
-
Before executing the first operation an ST is sent automatically. This is followed by SAD+R/W as appropriate.
-
Data from adjacent operations of the same type are sent after each other without an SP or SR.
-
Between adjacent operations of a different type an SR and SAD+R/W is sent.
-
After executing the last operation an SP is sent automatically.
-
If the last operation is a
Readthe master does not send an acknowledge for the last byte. -
ST= start condition -
SAD+R/W= slave address followed by bit 1 to indicate reading or 0 to indicate writing -
SR= repeated start condition -
SP= stop condition
Source§impl<'d, T> I2c<'d, Async, T>where
T: Instance,
impl<'d, T> I2c<'d, Async, T>where
T: Instance,
Sourcepub fn into_blocking(self) -> I2c<'d, Blocking, T>
pub fn into_blocking(self) -> I2c<'d, Blocking, T>
Configure the I2C peripheral to operate in blocking mode.
Sourcepub async fn write(&mut self, address: u8, buffer: &[u8]) -> Result<(), Error>
pub async fn write(&mut self, address: u8, buffer: &[u8]) -> Result<(), Error>
Writes bytes to slave with address address
Sourcepub async fn read(
&mut self,
address: u8,
buffer: &mut [u8],
) -> Result<(), Error>
pub async fn read( &mut self, address: u8, buffer: &mut [u8], ) -> Result<(), Error>
Reads enough bytes from slave with address to fill buffer
Sourcepub async fn write_read(
&mut self,
address: u8,
write_buffer: &[u8],
read_buffer: &mut [u8],
) -> Result<(), Error>
pub async fn write_read( &mut self, address: u8, write_buffer: &[u8], read_buffer: &mut [u8], ) -> Result<(), Error>
Writes bytes to slave with address address and then reads enough
bytes to fill buffer in a single transaction
Sourcepub async fn transaction<'a>(
&mut self,
address: u8,
operations: impl IntoIterator<Item = &'a mut Operation<'a>>,
) -> Result<(), Error>
pub async fn transaction<'a>( &mut self, address: u8, operations: impl IntoIterator<Item = &'a mut Operation<'a>>, ) -> Result<(), Error>
Execute the provided operations on the I2C bus as a single transaction.
Transaction contract:
-
Before executing the first operation an ST is sent automatically. This is followed by SAD+R/W as appropriate.
-
Data from adjacent operations of the same type are sent after each other without an SP or SR.
-
Between adjacent operations of a different type an SR and SAD+R/W is sent.
-
After executing the last operation an SP is sent automatically.
-
If the last operation is a
Readthe master does not send an acknowledge for the last byte. -
ST= start condition -
SAD+R/W= slave address followed by bit 1 to indicate reading or 0 to indicate writing -
SR= repeated start condition -
SP= stop condition
Trait Implementations§
Source§impl<T> I2c for I2c<'_, Async, T>where
T: Instance,
impl<T> I2c for I2c<'_, Async, T>where
T: Instance,
Source§async fn transaction(
&mut self,
address: u8,
operations: &mut [EhalOperation<'_>],
) -> Result<(), Self::Error>
async fn transaction( &mut self, address: u8, operations: &mut [EhalOperation<'_>], ) -> Result<(), Self::Error>
Source§impl<T, DM: Mode> I2c for I2c<'_, DM, T>where
T: Instance,
impl<T, DM: Mode> I2c for I2c<'_, DM, T>where
T: Instance,
Source§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<T> InterruptConfigurable for I2c<'_, Blocking, T>where
T: Instance,
impl<T> InterruptConfigurable for I2c<'_, Blocking, T>where
T: Instance,
Source§fn set_interrupt_handler(&mut self, handler: InterruptHandler)
fn set_interrupt_handler(&mut self, handler: InterruptHandler)
Source§impl<T: Instance, DM: Mode> SetConfig for I2c<'_, DM, T>
impl<T: Instance, DM: Mode> SetConfig for I2c<'_, DM, T>
Source§type ConfigError = ConfigError
type ConfigError = ConfigError
set_config fails.