Struct stm32_hal2::i2c::I2c
source · pub struct I2c<R> {
pub regs: R,
pub cfg: I2cConfig,
}
Expand description
Represents an Inter-Integrated Circuit (I2C) peripheral.
Fields§
§regs: R
§cfg: I2cConfig
Implementations§
source§impl<R> I2c<R>where
R: Deref<Target = RegisterBlock> + RccPeriph,
impl<R> I2c<R>where
R: Deref<Target = RegisterBlock> + RccPeriph,
sourcepub fn new(regs: R, cfg: I2cConfig, clocks: &Clocks) -> Self
pub fn new(regs: R, cfg: I2cConfig, clocks: &Clocks) -> Self
Initialize a I2C peripheral, including configuration register writes, and enabling and resetting
its RCC peripheral clock. freq
is in Hz.
sourcepub fn enable_smbus(&mut self) -> Result<(), Error>
pub fn enable_smbus(&mut self) -> Result<(), Error>
Enable SMBus support. See L44 RM, section 37.4.11: SMBus initialization
sourcepub fn read(&mut self, addr: u8, bytes: &mut [u8]) -> Result<(), Error>
pub fn read(&mut self, addr: u8, bytes: &mut [u8]) -> Result<(), Error>
Read multiple words to a buffer. Can return an error due to Bus, Arbitration, or NACK.
sourcepub fn write(&mut self, addr: u8, bytes: &[u8]) -> Result<(), Error>
pub fn write(&mut self, addr: u8, bytes: &[u8]) -> Result<(), Error>
Write an array of words. Can return an error due to Bus, Arbitration, or NACK.
sourcepub fn write_read(
&mut self,
addr: u8,
bytes: &[u8],
buffer: &mut [u8]
) -> Result<(), Error>
pub fn write_read( &mut self, addr: u8, bytes: &[u8], buffer: &mut [u8] ) -> Result<(), Error>
Write and read an array of words. Can return an error due to Bus, Arbitration, or NACK.
sourcepub unsafe fn write_dma(
&mut self,
addr: u8,
buf: &[u8],
autoend: bool,
channel: DmaChannel,
channel_cfg: ChannelCfg,
dma_periph: DmaPeriph
)
pub unsafe fn write_dma( &mut self, addr: u8, buf: &[u8], autoend: bool, channel: DmaChannel, channel_cfg: ChannelCfg, dma_periph: DmaPeriph )
Read data, using DMA. See L44 RM, 37.4.16: “Transmission using DMA”
Note that the channel
argument is unused on F3 and L4, since it is hard-coded,
and can’t be configured using the DMAMUX peripheral. (dma::mux()
fn).
For a single write, set autoend
to true
. For a write_read and other use cases,
set it to false
.
sourcepub unsafe fn read_dma(
&mut self,
addr: u8,
buf: &mut [u8],
channel: DmaChannel,
channel_cfg: ChannelCfg,
dma_periph: DmaPeriph
)
pub unsafe fn read_dma( &mut self, addr: u8, buf: &mut [u8], channel: DmaChannel, channel_cfg: ChannelCfg, dma_periph: DmaPeriph )
Read data, using DMA. See L44 RM, 37.4.16: “Reception using DMA”
Note that the channel
argument is unused on F3 and L4, since it is hard-coded,
and can’t be configured using the DMAMUX peripheral. (dma::mux()
fn).
sourcepub fn read_status(&self) -> u32
pub fn read_status(&self) -> u32
Print the (raw) contents of the status register.