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

58 lines
1.2 KiB
Rust
Raw Normal View History

2021-05-24 17:41:37 +02:00
#![macro_use]
use crate::interrupt::Interrupt;
#[cfg_attr(i2c_v1, path = "v1.rs")]
#[cfg_attr(i2c_v2, path = "v2.rs")]
2021-05-24 17:41:37 +02:00
mod _version;
use crate::peripherals;
2021-05-24 17:41:37 +02:00
pub use _version::*;
#[derive(Debug)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
2021-05-24 17:41:37 +02:00
pub enum Error {
Bus,
Arbitration,
Nack,
2021-05-25 20:47:07 +02:00
Timeout,
Crc,
Overrun,
2021-07-09 07:57:34 +02:00
ZeroLengthTransfer,
2021-05-24 17:41:37 +02:00
}
pub(crate) mod sealed {
use super::*;
pub trait Instance: crate::rcc::RccPeripheral {
2021-07-30 00:13:57 +02:00
fn regs() -> crate::pac::i2c::I2c;
fn state() -> &'static State;
2021-05-24 17:41:37 +02:00
}
}
pub trait Instance: sealed::Instance + 'static {
type Interrupt: Interrupt;
}
2021-05-24 17:41:37 +02:00
pin_trait!(SclPin, Instance);
pin_trait!(SdaPin, Instance);
dma_trait!(RxDma, Instance);
dma_trait!(TxDma, Instance);
foreach_interrupt!(
2021-07-30 00:13:57 +02:00
($inst:ident, i2c, $block:ident, EV, $irq:ident) => {
impl sealed::Instance for peripherals::$inst {
2021-07-30 00:13:57 +02:00
fn regs() -> crate::pac::i2c::I2c {
crate::pac::$inst
2021-05-24 17:41:37 +02:00
}
fn state() -> &'static State {
static STATE: State = State::new();
&STATE
}
2021-05-24 17:41:37 +02:00
}
impl Instance for peripherals::$inst {
2021-07-30 00:13:57 +02:00
type Interrupt = crate::interrupt::$irq;
}
2021-05-24 17:41:37 +02:00
};
);