pub struct Twim<'d, T: Instance> { /* private fields */ }
Expand description
TWI driver.
Implementations§
Source§impl<'d, T: Instance> Twim<'d, T>
impl<'d, T: Instance> Twim<'d, T>
Sourcepub fn new(
twim: Peri<'d, T>,
_irq: impl Binding<T::Interrupt, InterruptHandler<T>> + 'd,
sda: Peri<'d, impl GpioPin>,
scl: Peri<'d, impl GpioPin>,
config: Config,
tx_ram_buffer: &'d mut [u8],
) -> Self
pub fn new( twim: Peri<'d, T>, _irq: impl Binding<T::Interrupt, InterruptHandler<T>> + 'd, sda: Peri<'d, impl GpioPin>, scl: Peri<'d, impl GpioPin>, config: Config, tx_ram_buffer: &'d mut [u8], ) -> Self
Create a new TWI driver.
tx_ram_buffer
is required if any write operations will be performed with data that is not in RAM.
Usually this is static data that the compiler locates in flash instead of RAM. The tx_ram_buffer
needs to be at least as large as the largest write operation that will be executed with a buffer
that is not in RAM. If all write operations will be performed from RAM, an empty buffer (&[]
) may
be used.
Sourcepub fn blocking_transaction(
&mut self,
address: u8,
operations: &mut [Operation<'_>],
) -> Result<(), Error>
pub fn blocking_transaction( &mut self, address: u8, operations: &mut [Operation<'_>], ) -> Result<(), Error>
Execute the provided operations on the I2C bus.
Each buffer must have a length of at most 255 bytes on the nRF52832 and at most 65535 bytes on the nRF52840.
Consecutive Operation::Read
s are not supported due to hardware
limitations.
An Operation::Write
following an Operation::Read
must have a
non-empty buffer.
Sourcepub fn blocking_transaction_timeout(
&mut self,
address: u8,
operations: &mut [Operation<'_>],
timeout: Duration,
) -> Result<(), Error>
pub fn blocking_transaction_timeout( &mut self, address: u8, operations: &mut [Operation<'_>], timeout: Duration, ) -> Result<(), Error>
Execute the provided operations on the I2C bus with timeout.
See [blocking_transaction
].
Sourcepub async fn transaction(
&mut self,
address: u8,
operations: &mut [Operation<'_>],
) -> Result<(), Error>
pub async fn transaction( &mut self, address: u8, operations: &mut [Operation<'_>], ) -> Result<(), Error>
Execute the provided operations on the I2C bus.
Each buffer must have a length of at most 255 bytes on the nRF52832 and at most 65535 bytes on the nRF52840.
Consecutive Operation::Read
s are not supported due to hardware
limitations.
An Operation::Write
following an Operation::Read
must have a
non-empty buffer.
Sourcepub fn blocking_write(
&mut self,
address: u8,
buffer: &[u8],
) -> Result<(), Error>
pub fn blocking_write( &mut self, address: u8, buffer: &[u8], ) -> Result<(), Error>
Write to an I2C slave.
The buffer must have a length of at most 255 bytes on the nRF52832 and at most 65535 bytes on the nRF52840.
Sourcepub fn blocking_read(
&mut self,
address: u8,
buffer: &mut [u8],
) -> Result<(), Error>
pub fn blocking_read( &mut self, address: u8, buffer: &mut [u8], ) -> Result<(), Error>
Read from an I2C slave.
The buffer must have a length of at most 255 bytes on the nRF52832 and at most 65535 bytes on the nRF52840.
Sourcepub fn blocking_write_read(
&mut self,
address: u8,
wr_buffer: &[u8],
rd_buffer: &mut [u8],
) -> Result<(), Error>
pub fn blocking_write_read( &mut self, address: u8, wr_buffer: &[u8], rd_buffer: &mut [u8], ) -> Result<(), Error>
Write data to an I2C slave, then read data from the slave without triggering a stop condition between the two.
The buffers must have a length of at most 255 bytes on the nRF52832 and at most 65535 bytes on the nRF52840.
Sourcepub fn blocking_write_timeout(
&mut self,
address: u8,
buffer: &[u8],
timeout: Duration,
) -> Result<(), Error>
pub fn blocking_write_timeout( &mut self, address: u8, buffer: &[u8], timeout: Duration, ) -> Result<(), Error>
Write to an I2C slave with timeout.
See [blocking_write
].
Sourcepub fn blocking_read_timeout(
&mut self,
address: u8,
buffer: &mut [u8],
timeout: Duration,
) -> Result<(), Error>
pub fn blocking_read_timeout( &mut self, address: u8, buffer: &mut [u8], timeout: Duration, ) -> Result<(), Error>
Read from an I2C slave.
The buffer must have a length of at most 255 bytes on the nRF52832 and at most 65535 bytes on the nRF52840.
Sourcepub fn blocking_write_read_timeout(
&mut self,
address: u8,
wr_buffer: &[u8],
rd_buffer: &mut [u8],
timeout: Duration,
) -> Result<(), Error>
pub fn blocking_write_read_timeout( &mut self, address: u8, wr_buffer: &[u8], rd_buffer: &mut [u8], timeout: Duration, ) -> Result<(), Error>
Write data to an I2C slave, then read data from the slave without triggering a stop condition between the two.
The buffers must have a length of at most 255 bytes on the nRF52832 and at most 65535 bytes on the nRF52840.
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>
Read from an I2C slave.
The buffer must have a length of at most 255 bytes on the nRF52832 and at most 65535 bytes on the nRF52840.
Sourcepub async fn write(&mut self, address: u8, buffer: &[u8]) -> Result<(), Error>
pub async fn write(&mut self, address: u8, buffer: &[u8]) -> Result<(), Error>
Write to an I2C slave.
The buffer must have a length of at most 255 bytes on the nRF52832 and at most 65535 bytes on the nRF52840.
Sourcepub async fn write_read(
&mut self,
address: u8,
wr_buffer: &[u8],
rd_buffer: &mut [u8],
) -> Result<(), Error>
pub async fn write_read( &mut self, address: u8, wr_buffer: &[u8], rd_buffer: &mut [u8], ) -> Result<(), Error>
Write data to an I2C slave, then read data from the slave without triggering a stop condition between the two.
The buffers must have a length of at most 255 bytes on the nRF52832 and at most 65535 bytes on the nRF52840.
Trait Implementations§
Source§impl<'d, T: Instance> I2c for Twim<'d, T>
impl<'d, T: Instance> I2c for Twim<'d, T>
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<'d, T: Instance> I2c for Twim<'d, T>
impl<'d, T: Instance> I2c for Twim<'d, T>
Source§async fn transaction(
&mut self,
address: u8,
operations: &mut [Operation<'_>],
) -> Result<(), Self::Error>
async fn transaction( &mut self, address: u8, operations: &mut [Operation<'_>], ) -> Result<(), Self::Error>
Source§impl<'d, T: Instance> SetConfig for Twim<'d, T>
impl<'d, T: Instance> SetConfig for Twim<'d, T>
Source§type ConfigError = ()
type ConfigError = ()
set_config
fails.