pub struct I2c<C: AnyConfig, D = NoneT> { /* private fields */ }
Expand description
Abstraction over a I2C peripheral, allowing to perform I2C transactions.
Implementations§
Source§impl<C: AnyConfig, D> I2c<C, D>
impl<C: AnyConfig, D> I2c<C, D>
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 with_dma_channel<Chan: AnyChannel<Status = Ready>>(
self,
channel: Chan,
) -> I2c<C, Chan>
pub fn with_dma_channel<Chan: AnyChannel<Status = Ready>>( self, channel: Chan, ) -> I2c<C, Chan>
Attach a DMA channel to this I2c
. Its
embedded_hal::i2c::I2c
implementation will
use DMA to carry out its transactions.
Source§impl<C, D, S> I2c<C, D>
impl<C, D, S> I2c<C, D>
Sourcepub fn take_dma_channel(self) -> (I2c<C, NoneT>, D)
pub fn take_dma_channel(self) -> (I2c<C, NoneT>, D)
Reclaim the DMA channel. Any subsequent I2C operations will no longer use DMA.
Source§impl<C: AnyConfig> I2c<C>
impl<C: AnyConfig> I2c<C>
Sourcepub fn init_dma_transfer(&mut self) -> Result<I2cBusReady, Error>
👎Deprecated since 0.19.0: Use I2c::with_dma_channel
instead. You will have access to DMA-enabled embedded-hal
implementations.
pub fn init_dma_transfer(&mut self) -> Result<I2cBusReady, Error>
I2c::with_dma_channel
instead. You will have access to DMA-enabled embedded-hal
implementations.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>(
self,
address: u8,
_ready_token: I2cBusReady,
buf: B,
channel: Ch,
) -> Transfer<Channel<Ch::Id, Busy>, BufferPair<Self, B>>
👎Deprecated since 0.19.0: Use I2c::with_dma_channel
instead. You will have access to DMA-enabled embedded-hal
implementations.
pub fn receive_with_dma<Ch, B>( self, address: u8, _ready_token: I2cBusReady, buf: B, channel: Ch, ) -> Transfer<Channel<Ch::Id, Busy>, BufferPair<Self, B>>
I2c::with_dma_channel
instead. You will have access to DMA-enabled embedded-hal
implementations.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>(
self,
address: u8,
_ready_token: I2cBusReady,
buf: B,
channel: Ch,
) -> Transfer<Channel<Ch::Id, Busy>, BufferPair<B, Self>>
👎Deprecated since 0.19.0: Use I2c::with_dma_chahnnel
instead. You will have access to DMA-enabled embedded-hal
implementations.
pub fn send_with_dma<Ch, B>( self, address: u8, _ready_token: I2cBusReady, buf: B, channel: Ch, ) -> Transfer<Channel<Ch::Id, Busy>, BufferPair<B, Self>>
I2c::with_dma_chahnnel
instead. You will have access to DMA-enabled embedded-hal
implementations.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 moreSource§impl<C, D, S> I2c for I2c<C, D>
impl<C, D, S> I2c for I2c<C, D>
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