Adjust pin-names to FooPin.
Move common bits up to spi/mod.rs. Isolate the RNG interrupt in a sub-module to avoid conflict with the const.
This commit is contained in:
@ -6,6 +6,12 @@ mod spi;
|
||||
|
||||
pub use spi::*;
|
||||
|
||||
pub enum Error {
|
||||
Framing,
|
||||
Crc,
|
||||
Overrun,
|
||||
}
|
||||
|
||||
// TODO move upwards in the tree
|
||||
pub enum ByteOrder {
|
||||
LsbFirst,
|
||||
@ -32,3 +38,64 @@ impl Default for Config {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) mod sealed {
|
||||
use super::*;
|
||||
use crate::gpio::Pin;
|
||||
use embassy::util::AtomicWaker;
|
||||
|
||||
pub trait Instance {
|
||||
fn regs() -> &'static crate::pac::spi::Spi;
|
||||
}
|
||||
|
||||
pub trait SckPin<T: Instance>: Pin {
|
||||
const AF: u8;
|
||||
fn af(&self) -> u8 {
|
||||
Self::AF
|
||||
}
|
||||
}
|
||||
|
||||
pub trait MosiPin<T: Instance>: Pin {
|
||||
const AF: u8;
|
||||
fn af(&self) -> u8 {
|
||||
Self::AF
|
||||
}
|
||||
}
|
||||
|
||||
pub trait MisoPin<T: Instance>: Pin {
|
||||
const AF: u8;
|
||||
fn af(&self) -> u8 {
|
||||
Self::AF
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub trait Instance: sealed::Instance + 'static {}
|
||||
|
||||
pub trait SckPin<T: Instance>: sealed::SckPin<T> + 'static {}
|
||||
|
||||
pub trait MosiPin<T: Instance>: sealed::MosiPin<T> + 'static {}
|
||||
|
||||
pub trait MisoPin<T: Instance>: sealed::MisoPin<T> + 'static {}
|
||||
|
||||
macro_rules! impl_spi {
|
||||
($inst:ident, $clk:ident) => {
|
||||
impl crate::spi::sealed::Instance for peripherals::$inst {
|
||||
fn regs() -> &'static crate::pac::spi::Spi {
|
||||
&crate::pac::$inst
|
||||
}
|
||||
}
|
||||
|
||||
impl crate::spi::Instance for peripherals::$inst {}
|
||||
};
|
||||
}
|
||||
|
||||
macro_rules! impl_spi_pin {
|
||||
($inst:ident, $pin_func:ident, $pin:ident, $af:expr) => {
|
||||
impl crate::spi::$pin_func<peripherals::$inst> for peripherals::$pin {}
|
||||
|
||||
impl crate::spi::sealed::$pin_func<peripherals::$inst> for peripherals::$pin {
|
||||
const AF: u8 = $af;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
Reference in New Issue
Block a user