921780e6bf
- Move typelevel interrupts to a special-purpose mod: `embassy_xx::interrupt::typelevel`. - Reexport the PAC interrupt enum in `embassy_xx::interrupt`. This has a few advantages: - The `embassy_xx::interrupt` module is now more "standard". - It works with `cortex-m` functions for manipulating interrupts, for example. - It works with RTIC. - the interrupt enum allows holding value that can be "any interrupt at runtime", this can't be done with typelevel irqs. - When "const-generics on enums" is stable, we can remove the typelevel interrupts without disruptive changes to `embassy_xx::interrupt`.
64 lines
1.3 KiB
Rust
64 lines
1.3 KiB
Rust
#![macro_use]
|
|
|
|
use crate::interrupt;
|
|
|
|
#[cfg_attr(i2c_v1, path = "v1.rs")]
|
|
#[cfg_attr(i2c_v2, path = "v2.rs")]
|
|
mod _version;
|
|
pub use _version::*;
|
|
|
|
#[cfg(feature = "time")]
|
|
mod timeout;
|
|
#[cfg(feature = "time")]
|
|
pub use timeout::*;
|
|
|
|
use crate::peripherals;
|
|
|
|
#[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::typelevel::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::typelevel::$irq;
|
|
}
|
|
};
|
|
);
|