64 lines
1.3 KiB
Rust
Raw Normal View History

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