Struct atsamd_hal::sercom::i2c::I2c
source · pub struct I2c<C: AnyConfig> { /* private fields */ }
Expand description
Abstraction over a I2C peripheral, allowing to perform I2C transactions.
Implementations§
source§impl<C: AnyConfig> I2c<C>
impl<C: AnyConfig> I2c<C>
sourcepub fn data_ptr(&self) -> *mut Word
pub fn data_ptr(&self) -> *mut Word
Obtain a pointer to the DATA
register. Necessary for DMA transfers.
sourcepub fn read_flags(&self) -> Flags
pub fn read_flags(&self) -> Flags
Read the interrupt flags
sourcepub fn clear_flags(&mut self, flags: Flags)
pub fn clear_flags(&mut self, flags: Flags)
Clear interrupt status flags
sourcepub fn enable_interrupts(&mut self, flags: Flags)
pub fn enable_interrupts(&mut self, flags: Flags)
Enable interrupts for the specified flags.
sourcepub fn disable_interrupts(&mut self, flags: Flags)
pub fn disable_interrupts(&mut self, flags: Flags)
Disable interrupts for the specified flags.
sourcepub fn read_status(&self) -> Status
pub fn read_status(&self) -> Status
Read the status flags
sourcepub fn clear_status(&mut self, status: Status)
pub fn clear_status(&mut self, status: Status)
Clear the status flags
sourcepub fn reconfigure<F>(&mut self, update: F)where
F: FnOnce(&mut SpecificConfig<C>),
pub fn reconfigure<F>(&mut self, update: F)where
F: FnOnce(&mut SpecificConfig<C>),
Reconfigure the I2C peripheral.
Calling this method will temporarily disable the SERCOM peripheral, as some registers are enable-protected. This may interrupt any ongoing transactions.
use atsamd_hal::sercom::i2c::I2c;
i2c.reconfigure(|c| c.set_run_in_standby(false));
source§impl<C: AnyConfig> I2c<C>
impl<C: AnyConfig> I2c<C>
sourcepub fn init_dma_transfer(&mut self) -> Result<I2cBusReady, Error>
pub fn init_dma_transfer(&mut self) -> Result<I2cBusReady, Error>
Initialize the bus to start receiving with DMA.
In reality, this function only checks whether or not the I2C bus is
ready to accept a new transaction. A call to init_dma_transfer
should immediately be followed by a call to send_with_dma
or
receive_with_dma
.
// Assume `i2c` is a fully configured `I2c`, and `chan0` a fully configured `dmac::Channel`.
let token = i2c.init_dma_transfer()?;
i2c.send_with_dma(ADDRESS, token, buf_src, chan0, |_| {});
sourcepub fn receive_with_dma<Ch, B, W>(
self,
address: u8,
_ready_token: I2cBusReady,
buf: B,
channel: Ch,
waker: W
) -> Transfer<Channel<Ch::Id, Busy>, BufferPair<Self, B>, W>where
Ch: AnyChannel<Status = Ready>,
B: Buffer<Beat = Word> + 'static,
W: FnOnce(CallbackStatus) + 'static,
pub fn receive_with_dma<Ch, B, W>(
self,
address: u8,
_ready_token: I2cBusReady,
buf: B,
channel: Ch,
waker: W
) -> Transfer<Channel<Ch::Id, Busy>, BufferPair<Self, B>, W>where
Ch: AnyChannel<Status = Ready>,
B: Buffer<Beat = Word> + 'static,
W: FnOnce(CallbackStatus) + 'static,
Transform an I2c
into a DMA Transfer
) and
start receiving into the provided buffer. The buffer length must be 255
bytes or shorter.
It is recommended that you check for errors after the transfer is
complete by calling read_status
.
sourcepub fn send_with_dma<Ch, B, W>(
self,
address: u8,
_ready_token: I2cBusReady,
buf: B,
channel: Ch,
waker: W
) -> Transfer<Channel<Ch::Id, Busy>, BufferPair<B, Self>, W>where
Ch: AnyChannel<Status = Ready>,
B: Buffer<Beat = Word> + 'static,
W: FnOnce(CallbackStatus) + 'static,
pub fn send_with_dma<Ch, B, W>(
self,
address: u8,
_ready_token: I2cBusReady,
buf: B,
channel: Ch,
waker: W
) -> Transfer<Channel<Ch::Id, Busy>, BufferPair<B, Self>, W>where
Ch: AnyChannel<Status = Ready>,
B: Buffer<Beat = Word> + 'static,
W: FnOnce(CallbackStatus) + 'static,
Transform an I2c
into a DMA Transfer
) and
start sending the provided buffer. The buffer length must be 255 bytes
or shorter.
It is recommended that you check for errors after the transfer is
complete by calling read_status
.
Trait Implementations§
source§impl<C: AnyConfig> Buffer for I2c<C>
impl<C: AnyConfig> Buffer for I2c<C>
source§fn dma_ptr(&mut self) -> *mut Self::Beat
fn dma_ptr(&mut self) -> *mut Self::Beat
source§fn incrementing(&self) -> bool
fn incrementing(&self) -> bool
source§fn buffer_len(&self) -> usize
fn buffer_len(&self) -> usize
source§impl<C: AnyConfig> I2c for I2c<C>
impl<C: AnyConfig> I2c for I2c<C>
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§fn write(&mut self, address: u8, bytes: &[u8]) -> Result<(), Self::Error>
fn write(&mut self, address: u8, bytes: &[u8]) -> Result<(), Self::Error>
address
. Read more