embassy/embassy-stm32/src/i2c/mod.rs

74 lines
1.4 KiB
Rust
Raw Normal View History

2021-05-24 15:41:37 +00:00
#![macro_use]
use embassy::interrupt::Interrupt;
#[cfg_attr(i2c_v1, path = "v1.rs")]
#[cfg_attr(i2c_v2, path = "v2.rs")]
2021-05-24 15:41:37 +00:00
mod _version;
use crate::peripherals;
2021-05-24 15:41:37 +00:00
pub use _version::*;
#[derive(Debug)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
2021-05-24 15:41:37 +00:00
pub enum Error {
Bus,
Arbitration,
Nack,
2021-05-25 18:47:07 +00:00
Timeout,
Crc,
Overrun,
2021-07-09 05:57:34 +00:00
ZeroLengthTransfer,
2021-05-24 15:41:37 +00:00
}
pub(crate) mod sealed {
pub trait Instance: crate::rcc::RccPeripheral {
2021-07-29 22:13:57 +00:00
fn regs() -> crate::pac::i2c::I2c;
fn state_number() -> usize;
2021-05-24 15:41:37 +00:00
}
}
pub trait Instance: sealed::Instance + 'static {
type Interrupt: Interrupt;
}
2021-05-24 15:41:37 +00:00
pin_trait!(SclPin, Instance);
pin_trait!(SdaPin, Instance);
dma_trait!(RxDma, Instance);
dma_trait!(TxDma, Instance);
macro_rules! i2c_state {
(I2C1) => {
0
};
(I2C2) => {
1
};
(I2C3) => {
2
};
(I2C4) => {
3
};
(I2C5) => {
4
};
}
2021-07-29 22:13:57 +00:00
crate::pac::interrupts!(
($inst:ident, i2c, $block:ident, EV, $irq:ident) => {
impl sealed::Instance for peripherals::$inst {
2021-07-29 22:13:57 +00:00
fn regs() -> crate::pac::i2c::I2c {
crate::pac::$inst
2021-05-24 15:41:37 +00:00
}
fn state_number() -> usize {
i2c_state!($inst)
}
2021-05-24 15:41:37 +00:00
}
impl Instance for peripherals::$inst {
2021-07-29 22:13:57 +00:00
type Interrupt = crate::interrupt::$irq;
}
2021-05-24 15:41:37 +00:00
};
);