esp_hal::i2c::master

Struct I2c

Source
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,

Source

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

Applies a new configuration.

Source

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

Connect a pin to the I2C SDA signal.

Source

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>

Source

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,

Source

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.

Source

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

Configures the I2C peripheral to operate in asynchronous mode.

Source

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

Writes bytes to slave with address address

Source

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

Reads enough bytes from slave with address to fill buffer

Source

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

Source

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 Read the 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,

Source

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

Configure the I2C peripheral to operate in blocking mode.

Source

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

Writes bytes to slave with address address

Source

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

Reads enough bytes from slave with address to fill buffer

Source

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

Source

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 Read the 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, DM: Mode> ErrorType for I2c<'_, DM, T>

Source§

type Error = Error

Error type
Source§

impl<T> I2c for I2c<'_, Async, T>
where T: Instance,

Source§

async fn transaction( &mut self, address: u8, operations: &mut [EhalOperation<'_>], ) -> Result<(), Self::Error>

Execute the provided operations on the I2C bus as a single transaction. Read more
Source§

async fn read(&mut self, address: A, read: &mut [u8]) -> Result<(), Self::Error>

Reads enough bytes from slave with address to fill buffer. Read more
Source§

async fn write(&mut self, address: A, write: &[u8]) -> Result<(), Self::Error>

Writes bytes to slave with address address. Read more
Source§

async fn write_read( &mut self, address: A, write: &[u8], read: &mut [u8], ) -> Result<(), Self::Error>

Writes bytes to slave with address address and then reads enough bytes to fill read in a single transaction. Read more
Source§

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>

Execute the provided operations on the I2C bus. Read more
Source§

fn read(&mut self, address: A, read: &mut [u8]) -> Result<(), Self::Error>

Reads enough bytes from slave with address to fill read. Read more
Source§

fn write(&mut self, address: A, write: &[u8]) -> Result<(), Self::Error>

Writes bytes to slave with address address. Read more
Source§

fn write_read( &mut self, address: A, write: &[u8], read: &mut [u8], ) -> Result<(), Self::Error>

Writes bytes to slave with address address and then reads enough bytes to fill read in a single transaction. Read more
Source§

impl<T> InterruptConfigurable for I2c<'_, Blocking, T>
where T: Instance,

Source§

fn set_interrupt_handler(&mut self, handler: InterruptHandler)

Set the interrupt handler Read more
Source§

impl<T: Instance, DM: Mode> SetConfig for I2c<'_, DM, T>

Source§

type Config = Config

The configuration type used by this driver.
Source§

type ConfigError = ConfigError

The error type that can occur if set_config fails.
Source§

fn set_config(&mut self, config: &Self::Config) -> Result<(), Self::ConfigError>

Set the configuration of the driver.
Source§

impl<T> Read for I2c<'_, Blocking, T>
where T: Instance,

Source§

type Error = Error

Error type
Source§

fn read(&mut self, address: u8, buffer: &mut [u8]) -> Result<(), Self::Error>

Reads enough bytes from slave with address to fill buffer Read more
Source§

impl<T> Write for I2c<'_, Blocking, T>
where T: Instance,

Source§

type Error = Error

Error type
Source§

fn write(&mut self, addr: u8, bytes: &[u8]) -> Result<(), Self::Error>

Writes bytes to slave with address address Read more
Source§

impl<T> WriteRead for I2c<'_, Blocking, T>
where T: Instance,

Source§

type Error = Error

Error type
Source§

fn write_read( &mut self, address: u8, bytes: &[u8], buffer: &mut [u8], ) -> Result<(), Self::Error>

Writes bytes to slave with address address and then reads enough bytes to fill buffer in a single transaction Read more

Auto Trait Implementations§

§

impl<'d, DM, T> Freeze for I2c<'d, DM, T>
where T: Freeze,

§

impl<'d, DM, T> RefUnwindSafe for I2c<'d, DM, T>

§

impl<'d, DM, T> Send for I2c<'d, DM, T>
where T: Send, DM: Send,

§

impl<'d, DM, T> Sync for I2c<'d, DM, T>
where T: Sync, DM: Sync,

§

impl<'d, DM, T> Unpin for I2c<'d, DM, T>
where T: Unpin, DM: Unpin,

§

impl<'d, DM, T = AnyI2c> !UnwindSafe for I2c<'d, DM, T>

Blanket Implementations§

Source§

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

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

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

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

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

Source§

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

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

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

Source§

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, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

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

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

Performs the conversion.
Source§

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

Source§

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

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

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

Performs the conversion.