I2CMasterDma

Struct I2CMasterDma 

Source
pub struct I2CMasterDma<I2C, TX_TRANSFER, RX_TRANSFER>
where I2C: Instance,
{ /* private fields */ }
Expand description

I2c abstraction that can work in non-blocking mode by using DMA

The struct should be used for sending/receiving bytes to/from slave device in non-blocking mode. A client must follow these requirements to use that feature:

  • Enable interrupts DMAx_STREAMy used for transmit and another DMAq_STREAMp used for receive.
  • In these interrupts call handle_dma_interrupt; defined in trait I2CMasterHandleIT
  • Enable interrupts I2Cx_ER for handling errors and call handle_error_interrupt in corresponding handler; defined in trait I2CMasterHandleIT

The struct can be also used to send/receive bytes in blocking mode with methods: write, read, write_read.

Implementations§

Source§

impl<I2C, TX_TRANSFER, RX_TRANSFER> I2CMasterDma<I2C, TX_TRANSFER, RX_TRANSFER>
where I2C: Instance, TX_TRANSFER: DMATransfer<&'static [u8]>, RX_TRANSFER: DMATransfer<&'static mut [u8]>,

Common implementation

Source

pub fn busy(&self) -> bool

Checks if there is communication in progress

Source

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

Reads in blocking mode but if i2c is busy returns WouldBlock and do nothing

Source

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

Write and then read in blocking mode but if i2c is busy returns WouldBlock and do nothing

Source

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

Write in blocking mode but if i2c is busy returns WouldBlock and do nothing

Trait Implementations§

Source§

impl<I2C, TX_TRANSFER, RX_TRANSFER> ErrorType for I2CMasterDma<I2C, TX_TRANSFER, RX_TRANSFER>
where I2C: Instance, TX_TRANSFER: DMATransfer<&'static [u8]>, RX_TRANSFER: DMATransfer<&'static mut [u8]>,

Source§

type Error = Error

Error type
Source§

impl<I2C, RX_STREAM, const RX_CH: u8> I2CMasterHandleIT for I2CMasterDma<I2C, NoDMA, RxDMA<I2C, RX_STREAM, RX_CH>>
where I2C: Instance, RX_STREAM: Stream, ChannelX<RX_CH>: Channel, Rx<I2C>: DMASet<RX_STREAM, RX_CH, PeripheralToMemory>,

Source§

impl<I2C, TX_STREAM, const TX_CH: u8> I2CMasterHandleIT for I2CMasterDma<I2C, TxDMA<I2C, TX_STREAM, TX_CH>, NoDMA>
where I2C: Instance, TX_STREAM: Stream, ChannelX<TX_CH>: Channel, Tx<I2C>: DMASet<TX_STREAM, TX_CH, MemoryToPeripheral>,

Source§

impl<I2C, TX_STREAM, const TX_CH: u8, RX_STREAM, const RX_CH: u8> I2CMasterHandleIT for I2CMasterDma<I2C, TxDMA<I2C, TX_STREAM, TX_CH>, RxDMA<I2C, RX_STREAM, RX_CH>>
where I2C: Instance, TX_STREAM: Stream, ChannelX<TX_CH>: Channel, Tx<I2C>: DMASet<TX_STREAM, TX_CH, MemoryToPeripheral>, RX_STREAM: Stream, ChannelX<RX_CH>: Channel, Rx<I2C>: DMASet<RX_STREAM, RX_CH, PeripheralToMemory>,

Only for both TX and RX DMA I2c

Source§

impl<I2C, TX_TRANSFER, RX_STREAM, const RX_CH: u8> I2CMasterReadDMA for I2CMasterDma<I2C, TX_TRANSFER, RxDMA<I2C, RX_STREAM, RX_CH>>
where I2C: Instance, RX_STREAM: Stream, ChannelX<RX_CH>: Channel, Rx<I2C>: DMASet<RX_STREAM, RX_CH, PeripheralToMemory>, TX_TRANSFER: DMATransfer<&'static [u8]>,

Source§

unsafe fn read_dma( &mut self, addr: u8, buf: &mut [u8], callback: Option<I2cCompleteCallback>, ) -> Result<(), Error>

Reads bytes from slave device with address addr in non-blocking mode and writes these bytes in buf Read more
Source§

impl<I2C, TX_STREAM, const TX_CH: u8, RX_TRANSFER> I2CMasterWriteDMA for I2CMasterDma<I2C, TxDMA<I2C, TX_STREAM, TX_CH>, RX_TRANSFER>
where I2C: Instance, TX_STREAM: Stream, ChannelX<TX_CH>: Channel, Tx<I2C>: DMASet<TX_STREAM, TX_CH, MemoryToPeripheral>, RX_TRANSFER: DMATransfer<&'static mut [u8]>,

Source§

unsafe fn write_dma( &mut self, addr: u8, bytes: &[u8], callback: Option<I2cCompleteCallback>, ) -> Result<(), Error>

Writes bytes to slave with address addr in non-blocking mode Read more
Source§

impl<I2C, TX_STREAM, const TX_CH: u8, RX_STREAM, const RX_CH: u8> I2CMasterWriteReadDMA for I2CMasterDma<I2C, TxDMA<I2C, TX_STREAM, TX_CH>, RxDMA<I2C, RX_STREAM, RX_CH>>
where I2C: Instance, TX_STREAM: Stream, ChannelX<TX_CH>: Channel, Tx<I2C>: DMASet<TX_STREAM, TX_CH, MemoryToPeripheral>, RX_STREAM: Stream, ChannelX<RX_CH>: Channel, Rx<I2C>: DMASet<RX_STREAM, RX_CH, PeripheralToMemory>,

Source§

unsafe fn write_read_dma( &mut self, addr: u8, bytes: &[u8], buf: &mut [u8], callback: Option<I2cCompleteCallback>, ) -> Result<(), Error>

Writes bytes to slave with address addr in non-blocking mode and then generate ReStart and receive a bytes from a same device Read more
Source§

impl<I2C, TX_TRANSFER, RX_TRANSFER> I2c for I2CMasterDma<I2C, TX_TRANSFER, RX_TRANSFER>
where I2C: Instance, TX_TRANSFER: DMATransfer<&'static [u8]>, RX_TRANSFER: DMATransfer<&'static mut [u8]>,

Source§

fn transaction( &mut self, addr: 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

Auto Trait Implementations§

§

impl<I2C, TX_TRANSFER, RX_TRANSFER> Freeze for I2CMasterDma<I2C, TX_TRANSFER, RX_TRANSFER>
where TX_TRANSFER: Freeze, RX_TRANSFER: Freeze, I2C: Freeze, <I2C as I2cCommon>::Scl: Freeze, <I2C as I2cCommon>::Sda: Freeze,

§

impl<I2C, TX_TRANSFER, RX_TRANSFER> RefUnwindSafe for I2CMasterDma<I2C, TX_TRANSFER, RX_TRANSFER>
where TX_TRANSFER: RefUnwindSafe, RX_TRANSFER: RefUnwindSafe, I2C: RefUnwindSafe, <I2C as I2cCommon>::Scl: RefUnwindSafe, <I2C as I2cCommon>::Sda: RefUnwindSafe,

§

impl<I2C, TX_TRANSFER, RX_TRANSFER> Send for I2CMasterDma<I2C, TX_TRANSFER, RX_TRANSFER>
where TX_TRANSFER: Send, RX_TRANSFER: Send, I2C: Send, <I2C as I2cCommon>::Scl: Send, <I2C as I2cCommon>::Sda: Send,

§

impl<I2C, TX_TRANSFER, RX_TRANSFER> Sync for I2CMasterDma<I2C, TX_TRANSFER, RX_TRANSFER>
where TX_TRANSFER: Sync, RX_TRANSFER: Sync, I2C: Sync, <I2C as I2cCommon>::Scl: Sync, <I2C as I2cCommon>::Sda: Sync,

§

impl<I2C, TX_TRANSFER, RX_TRANSFER> Unpin for I2CMasterDma<I2C, TX_TRANSFER, RX_TRANSFER>
where TX_TRANSFER: Unpin, RX_TRANSFER: Unpin, I2C: Unpin, <I2C as I2cCommon>::Scl: Unpin, <I2C as I2cCommon>::Sda: Unpin,

§

impl<I2C, TX_TRANSFER, RX_TRANSFER> UnwindSafe for I2CMasterDma<I2C, TX_TRANSFER, RX_TRANSFER>
where TX_TRANSFER: UnwindSafe, RX_TRANSFER: UnwindSafe, I2C: UnwindSafe, <I2C as I2cCommon>::Scl: UnwindSafe, <I2C as I2cCommon>::Sda: UnwindSafe,

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.