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,

source

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.

source

pub fn enable_smbus(&mut self) -> Result<(), Error>

Enable SMBus support. See L44 RM, section 37.4.11: SMBus initialization

source

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.

source

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.

source

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.

source

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.

source

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).

source

pub fn read_status(&self) -> u32

Print the (raw) contents of the status register.

Auto Trait Implementations§

§

impl<R> RefUnwindSafe for I2c<R>
where R: RefUnwindSafe,

§

impl<R> Send for I2c<R>
where R: Send,

§

impl<R> Sync for I2c<R>
where R: Sync,

§

impl<R> Unpin for I2c<R>
where R: Unpin,

§

impl<R> UnwindSafe for I2c<R>
where R: 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>,

§

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.