[][src]Struct lpc11xx_async_hal::i2c::Driver

pub struct Driver { /* fields omitted */ }

Async I2C driver for LPC11xx microcontrollers.

This driver allows taking control of the I2C bus as a master and executing read/write commands on the bus to arbitrary device addresses. Repeated start is supported in the form of transactions, which are a sequence of commands separated by repeated start conditions.

Methods

impl Driver[src]

pub fn initialize(i2c: I2CDevice, options: Options) -> Self[src]

Initialize the driver. See UM10398 15.2 for prerequisites.

pub fn into_inner(self) -> I2CDevice[src]

Relinquishes ownership of the underlying peripheral.

pub async fn probe<'_>(&'_ mut self, address: Address) -> bool[src]

Probes a particular I2C address to determine if a slave is present.

This is equivalent to writing a zero-length message to that slave. This method will automatically retry indefinitely in the case of arbitration loss for convenience.

pub async fn exec_command<'_, '_>(
    &'_ mut self,
    command: Command<'_>
) -> Result<(), Error>
[src]

Executes a single command on the bus.

This is implemented as a transaction containing that single command.

pub async fn exec_transaction<'_, '_, '_>(
    &'_ mut self,
    commands: &'_ [Command<'_>]
) -> Result<(), Error>
[src]

Executes a transaction on the bus as an sequence of commands.

I2C semantics

Each command will be separated by a repeated start condition on the bus. If you want a start/stop condition instead, use multiple transactions, which will also give other masters a chance to acquire the bus.

The transaction fails with an error as soon as an address or data byte in any command is not acknowledged by a slave. The transaction completes when all commands complete.

WARNING: many simple I2C slave devices will not respond to write commands until a stop condition (not a repeated start) is observed on the bus. Read your I2C device's datasheet to find out what it expects.

Example

Sending some bytes and receiving back from a device:

let address = Address::from_right_justified_byte(0xa);

let mut response = [0; 4];

let commands = [
    // send some bytes to the device
    Command::Write(address, &[0x12, 0x34, 0x56, 0x78]),
    // receive some response bytes back from the device
    Command::Read(address, &mut response)
];

if let Err(error) = i2c.exec_transaction(&commands).await {
    // handle error (e.g. address not acknowledged)
} else {
    // read contents of the response buffer
}

pub fn handle_interrupt(&mut self)[src]

Handles an active peripheral interrupt.

pub unsafe fn handle_interrupt_unchecked()[src]

Equivalent to handle_interrupt but you must guarantee that there are currently no live references to the driver.

Trait Implementations

impl Debug for Driver[src]

Auto Trait Implementations

impl Unpin for Driver

impl !Sync for Driver

impl Send for Driver

Blanket Implementations

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> From<T> for T[src]

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Same<T> for T

type Output = T

Should always be Self