2021-05-24 17:41:37 +02:00
|
|
|
#![macro_use]
|
|
|
|
|
2022-06-11 05:08:57 +02:00
|
|
|
use crate::interrupt::Interrupt;
|
2021-07-18 06:07:34 +02:00
|
|
|
|
2021-05-25 04:17:24 +02:00
|
|
|
#[cfg_attr(i2c_v1, path = "v1.rs")]
|
|
|
|
#[cfg_attr(i2c_v2, path = "v2.rs")]
|
2021-05-24 17:41:37 +02:00
|
|
|
mod _version;
|
2022-02-10 21:38:03 +01:00
|
|
|
use crate::peripherals;
|
2021-05-24 17:41:37 +02:00
|
|
|
pub use _version::*;
|
|
|
|
|
2022-01-26 22:39:06 +01:00
|
|
|
#[derive(Debug)]
|
2021-07-09 00:53:47 +02:00
|
|
|
#[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 {
|
2022-02-26 01:23:17 +01:00
|
|
|
use super::*;
|
2022-02-10 21:38:03 +01:00
|
|
|
pub trait Instance: crate::rcc::RccPeripheral {
|
2021-07-30 00:13:57 +02:00
|
|
|
fn regs() -> crate::pac::i2c::I2c;
|
2022-02-26 01:23:17 +01:00
|
|
|
fn state() -> &'static State;
|
2021-05-24 17:41:37 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-07-18 06:07:34 +02:00
|
|
|
pub trait Instance: sealed::Instance + 'static {
|
|
|
|
type Interrupt: Interrupt;
|
|
|
|
}
|
2021-05-24 17:41:37 +02:00
|
|
|
|
2022-02-10 21:38:03 +01:00
|
|
|
pin_trait!(SclPin, Instance);
|
|
|
|
pin_trait!(SdaPin, Instance);
|
|
|
|
dma_trait!(RxDma, Instance);
|
|
|
|
dma_trait!(TxDma, Instance);
|
2021-07-18 06:07:34 +02:00
|
|
|
|
2022-02-26 01:40:43 +01:00
|
|
|
foreach_interrupt!(
|
2021-07-30 00:13:57 +02:00
|
|
|
($inst:ident, i2c, $block:ident, EV, $irq:ident) => {
|
2021-06-03 20:25:17 +02:00
|
|
|
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
|
|
|
}
|
2021-07-18 06:07:34 +02:00
|
|
|
|
2022-02-26 01:23:17 +01:00
|
|
|
fn state() -> &'static State {
|
|
|
|
static STATE: State = State::new();
|
|
|
|
&STATE
|
2021-07-18 06:07:34 +02:00
|
|
|
}
|
2021-05-24 17:41:37 +02:00
|
|
|
}
|
|
|
|
|
2021-07-18 06:07:34 +02:00
|
|
|
impl Instance for peripherals::$inst {
|
2021-07-30 00:13:57 +02:00
|
|
|
type Interrupt = crate::interrupt::$irq;
|
2021-07-18 06:07:34 +02:00
|
|
|
}
|
2021-05-24 17:41:37 +02:00
|
|
|
};
|
2021-06-03 17:09:29 +02:00
|
|
|
);
|