57 lines
1.2 KiB
Rust
57 lines
1.2 KiB
Rust
#![macro_use]
|
|
|
|
use embassy::interrupt::Interrupt;
|
|
|
|
#[cfg_attr(i2c_v1, path = "v1.rs")]
|
|
#[cfg_attr(i2c_v2, path = "v2.rs")]
|
|
mod _version;
|
|
use crate::peripherals;
|
|
pub use _version::*;
|
|
|
|
#[derive(Debug)]
|
|
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
|
|
pub enum Error {
|
|
Bus,
|
|
Arbitration,
|
|
Nack,
|
|
Timeout,
|
|
Crc,
|
|
Overrun,
|
|
ZeroLengthTransfer,
|
|
}
|
|
|
|
pub(crate) mod sealed {
|
|
use super::*;
|
|
pub trait Instance: crate::rcc::RccPeripheral {
|
|
fn regs() -> crate::pac::i2c::I2c;
|
|
fn state() -> &'static State;
|
|
}
|
|
}
|
|
|
|
pub trait Instance: sealed::Instance + 'static {
|
|
type Interrupt: Interrupt;
|
|
}
|
|
|
|
pin_trait!(SclPin, Instance);
|
|
pin_trait!(SdaPin, Instance);
|
|
dma_trait!(RxDma, Instance);
|
|
dma_trait!(TxDma, Instance);
|
|
|
|
foreach_interrupt!(
|
|
($inst:ident, i2c, $block:ident, EV, $irq:ident) => {
|
|
impl sealed::Instance for peripherals::$inst {
|
|
fn regs() -> crate::pac::i2c::I2c {
|
|
crate::pac::$inst
|
|
}
|
|
|
|
fn state() -> &'static State {
|
|
static STATE: State = State::new();
|
|
&STATE
|
|
}
|
|
}
|
|
|
|
impl Instance for peripherals::$inst {
|
|
type Interrupt = crate::interrupt::$irq;
|
|
}
|
|
};
|
|
);
|