2021-05-24 15:41:37 +00:00
|
|
|
#![macro_use]
|
|
|
|
|
2021-05-25 02:17:24 +00:00
|
|
|
#[cfg_attr(i2c_v1, path = "v1.rs")]
|
|
|
|
#[cfg_attr(i2c_v2, path = "v2.rs")]
|
2021-05-24 15:41:37 +00:00
|
|
|
mod _version;
|
|
|
|
pub use _version::*;
|
|
|
|
|
|
|
|
pub enum Error {
|
|
|
|
Bus,
|
|
|
|
Arbitration,
|
|
|
|
Nack,
|
2021-05-25 18:47:07 +00:00
|
|
|
Timeout,
|
|
|
|
Crc,
|
|
|
|
Overrun,
|
2021-05-24 15:41:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
pub(crate) mod sealed {
|
|
|
|
use super::*;
|
|
|
|
use crate::gpio::Pin;
|
|
|
|
|
|
|
|
pub trait Instance {
|
|
|
|
fn regs() -> &'static crate::pac::i2c::I2c;
|
|
|
|
}
|
|
|
|
|
|
|
|
pub trait SclPin<T: Instance>: Pin {
|
|
|
|
fn af_num(&self) -> u8;
|
|
|
|
}
|
|
|
|
|
|
|
|
pub trait SdaPin<T: Instance>: Pin {
|
|
|
|
fn af_num(&self) -> u8;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub trait Instance: sealed::Instance + 'static {}
|
|
|
|
|
|
|
|
pub trait SclPin<T: Instance>: sealed::SclPin<T> + 'static {}
|
|
|
|
|
|
|
|
pub trait SdaPin<T: Instance>: sealed::SdaPin<T> + 'static {}
|
|
|
|
|
|
|
|
macro_rules! impl_i2c {
|
|
|
|
($inst:ident) => {
|
|
|
|
impl crate::i2c::sealed::Instance for peripherals::$inst {
|
|
|
|
fn regs() -> &'static crate::pac::i2c::I2c {
|
|
|
|
&crate::pac::$inst
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl crate::i2c::Instance for peripherals::$inst {}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
macro_rules! impl_i2c_pin {
|
|
|
|
($inst:ident, $pin_func:ident, $pin:ident, $af:expr) => {
|
|
|
|
impl crate::i2c::$pin_func<peripherals::$inst> for peripherals::$pin {}
|
|
|
|
|
|
|
|
impl crate::i2c::sealed::$pin_func<peripherals::$inst> for peripherals::$pin {
|
|
|
|
fn af_num(&self) -> u8 {
|
|
|
|
$af
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|