embassy/embassy-stm32/src/traits.rs
2022-04-27 01:16:14 +02:00

65 lines
1.8 KiB
Rust

#![macro_use]
macro_rules! pin_trait {
($signal:ident, $instance:path) => {
pub trait $signal<T: $instance>: crate::gpio::Pin {
fn af_num(&self) -> u8;
}
};
}
macro_rules! pin_trait_impl {
(crate::$mod:ident::$trait:ident, $instance:ident, $pin:ident, $af:expr) => {
impl crate::$mod::$trait<crate::peripherals::$instance> for crate::peripherals::$pin {
fn af_num(&self) -> u8 {
$af
}
}
};
}
// ====================
macro_rules! dma_trait {
($signal:ident, $instance:path) => {
pub trait $signal<T: $instance>: crate::dma::Channel {
fn request(&self) -> crate::dma::Request;
}
};
}
#[allow(unused)]
macro_rules! dma_trait_impl {
// DMAMUX
(crate::$mod:ident::$trait:ident, $instance:ident, {dmamux: $dmamux:ident}, $request:expr) => {
impl<T> crate::$mod::$trait<crate::peripherals::$instance> for T
where
T: crate::dma::MuxChannel<Mux = crate::dma::$dmamux>,
{
fn request(&self) -> crate::dma::Request {
$request
}
}
};
// DMAMUX
(crate::$mod:ident::$trait:ident, $instance:ident, {dma: $dma:ident}, $request:expr) => {
impl<T> crate::$mod::$trait<crate::peripherals::$instance> for T
where
T: crate::dma::Channel,
{
fn request(&self) -> crate::dma::Request {
$request
}
}
};
// DMA/GPDMA, without DMAMUX
(crate::$mod:ident::$trait:ident, $instance:ident, {channel: $channel:ident}, $request:expr) => {
impl crate::$mod::$trait<crate::peripherals::$instance> for crate::peripherals::$channel {
fn request(&self) -> crate::dma::Request {
$request
}
}
};
}