Struct imxrt_hal::lpi2c::Lpi2c

source ·
pub struct Lpi2c<P, const N: u8> { /* private fields */ }
Expand description

An LPI2C driver.

Use this driver to communicate with I2C devices. This driver implements various embedded-hal I2C traits, and you should prefer these implementations for their ease of use.

See the module-level documentation for an example of how to construct this driver.

Implementations§

source§

impl<SCL, SDA, const N: u8> Lpi2c<Pins<SCL, SDA>, N>
where SCL: Pin<Signal = Scl, Module = Const<N>>, SDA: Pin<Signal = Sda, Module = Const<N>>,

source

pub fn new(lpi2c: Instance<N>, pins: Pins<SCL, SDA>, timings: &Timing) -> Self

Create an LPI2C driver from an LPI2C instance and a pair of pins.

When this call returns, the LPI2C pins are configured for their LPI2C functions, the controller is enabled after reset, and the driver is using the provided timing configuration for the clock.

source§

impl<const N: u8> Lpi2c<(), N>

source

pub fn without_pins(lpi2c: Instance<N>, timings: &Timing) -> Self

Create an I2C driver from an LPI2C instance.

This is similar to new(), but it does not configure pins. You’re responsible for configuring pins, and for making sure the pin configuration doesn’t change while this driver is in use.

source§

impl<P, const N: u8> Lpi2c<P, N>

source

pub const N: u8 = N

The peripheral instance.

source

pub fn is_controller_enabled(&self) -> bool

Indicates if the controller is (true) or is not (false) enabled.

source

pub fn set_controller_enable(&mut self, enable: bool)

Enable (true) or disable (false) the controller.

source

pub fn reset_controller(&mut self)

Reset the controller.

Note that this may not not reset all peripheral state, like the controller enabled state.

source

pub fn release(self) -> (Instance<N>, P)

Release the LPI2C components.

This does not change any component state; it releases the components as-is. If you need to obtain the registers in a known, good state, consider calling methods like reset_controller() before releasing the registers.

source

pub fn controller_status(&self) -> ControllerStatus

Read the controller status bits.

source

pub fn clear_controller_status(&self, status: ControllerStatus)

Clear the controller status bits that are set high.

The implementation will clear any read-only bits, so it’s OK to pass in ControllerStatus::all().

source

pub fn clear_fifo(&mut self)

Resets the transmit and receive FIFOs.

source

pub fn enqueue_controller_command(&self, command: ControllerCommand)

Enqueue a command into the controller transmit data register.

enqueue_controller_command does not check that the FIFO can hold the command. Check for the transmit data flag in the status response to understand the FIFO’s state.

source

pub fn read_data_register(&self) -> Option<u8>

Read the controller receive data register.

Returns None if there is no data in the receive FIFO.

source

pub fn disabled<R>(&mut self, func: impl FnOnce(&mut Disabled<'_, N>) -> R) -> R

Temporarily disable the LPI2C peripheral.

The handle to a Disabled driver lets you modify LPI2C settings that require a fully disabled peripheral.

source

pub fn pins(&self) -> &P

Borrow the pins.

source

pub fn pins_mut(&mut self) -> &mut P

Exclusively borrow the pins.

source

pub fn interrupts(&self) -> Interrupts

Returns the bitflags that indicate enabled or disabled LPI2C interrupts.

source

pub fn set_interrupts(&self, interrupts: Interrupts)

Enable or disable LPI2C interrupts.

source

pub fn watermark(&self, direction: Direction) -> u8

Returns the watermark level for the given direction.

source

pub fn controller_fifo_status(&self) -> ControllerFifoStatus

Returns the FIFO status.

Trait Implementations§

source§

impl<P, const N: u8> Transactional for Lpi2c<P, N>

§

type Error = ControllerStatus

Error type
source§

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

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

impl<P, const N: u8> TransactionalIter for Lpi2c<P, N>

§

type Error = ControllerStatus

Error type
source§

fn exec_iter<'a, O>( &mut self, address: u8, operations: O ) -> Result<(), Self::Error>
where O: IntoIterator<Item = Operation<'a>>,

Execute the provided operations on the I2C bus (iterator version). Read more
source§

impl<P, const N: u8> WriteIter for Lpi2c<P, N>

§

type Error = ControllerStatus

Error type
source§

fn write<B>(&mut self, address: u8, bytes: B) -> Result<(), Self::Error>
where B: IntoIterator<Item = u8>,

Writes bytes to slave with address address Read more
source§

impl<P, const N: u8> WriteIterRead for Lpi2c<P, N>

§

type Error = ControllerStatus

Error type
source§

fn write_iter_read<B>( &mut self, address: u8, bytes: B, buffer: &mut [u8] ) -> Result<(), Self::Error>
where B: IntoIterator<Item = u8>,

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

impl<P, const N: u8> Read for Lpi2c<P, N>

§

type Error = ControllerStatus

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<P, const N: u8> Write for Lpi2c<P, N>

§

type Error = ControllerStatus

Error type
source§

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

Writes bytes to slave with address address Read more
source§

impl<P, const N: u8> WriteRead for Lpi2c<P, N>

§

type Error = ControllerStatus

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<P, const N: u8> !RefUnwindSafe for Lpi2c<P, N>

§

impl<P, const N: u8> Send for Lpi2c<P, N>
where P: Send,

§

impl<P, const N: u8> !Sync for Lpi2c<P, N>

§

impl<P, const N: u8> Unpin for Lpi2c<P, N>
where P: Unpin,

§

impl<P, const N: u8> !UnwindSafe for Lpi2c<P, N>

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

§

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

§

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.