stm32: move dma trait impls from macrotables to build.rs
This commit is contained in:
parent
bc053404ca
commit
b4abb1f5c2
@ -1,6 +1,6 @@
|
||||
use proc_macro2::TokenStream;
|
||||
use quote::{format_ident, quote};
|
||||
use std::collections::HashSet;
|
||||
use std::collections::{HashMap, HashSet};
|
||||
use std::env;
|
||||
use std::fs;
|
||||
use std::path::PathBuf;
|
||||
@ -230,6 +230,61 @@ fn main() {
|
||||
})
|
||||
}
|
||||
|
||||
// ========
|
||||
// Generate dma_trait_impl!
|
||||
|
||||
let signals: HashMap<_, _> = [
|
||||
// (kind, signal) => trait
|
||||
(("usart", "RX"), quote!(crate::usart::RxDma)),
|
||||
(("usart", "TX"), quote!(crate::usart::TxDma)),
|
||||
(("spi", "RX"), quote!(crate::spi::RxDma)),
|
||||
(("spi", "TX"), quote!(crate::spi::TxDma)),
|
||||
(("i2c", "RX"), quote!(crate::i2c::RxDma)),
|
||||
(("i2c", "TX"), quote!(crate::i2c::TxDma)),
|
||||
(("dcmi", "DCMI"), quote!(crate::dcmi::FrameDma)),
|
||||
(("dcmi", "PSSI"), quote!(crate::dcmi::FrameDma)),
|
||||
]
|
||||
.into();
|
||||
|
||||
for p in METADATA.peripherals {
|
||||
if let Some(regs) = &p.registers {
|
||||
let mut dupe = HashSet::new();
|
||||
for ch in p.dma_channels {
|
||||
// Some chips have multiple request numbers for the same (peri, signal, channel) combos.
|
||||
// Ignore the dupes, picking the first one. Otherwise this causes conflicting trait impls
|
||||
let key = (ch.signal, ch.channel);
|
||||
if !dupe.insert(key) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if let Some(tr) = signals.get(&(regs.kind, ch.signal)) {
|
||||
let peri = format_ident!("{}", p.name);
|
||||
|
||||
let channel = if let Some(channel) = &ch.channel {
|
||||
let channel = format_ident!("{}", channel);
|
||||
quote!({channel: #channel})
|
||||
} else if let Some(dmamux) = &ch.dmamux {
|
||||
let dmamux = format_ident!("{}", dmamux);
|
||||
quote!({dmamux: #dmamux})
|
||||
} else {
|
||||
unreachable!();
|
||||
};
|
||||
|
||||
let request = if let Some(request) = ch.request {
|
||||
let request = request as u8;
|
||||
quote!(#request)
|
||||
} else {
|
||||
quote!(())
|
||||
};
|
||||
|
||||
g.extend(quote! {
|
||||
dma_trait_impl!(#tr, #peri, #channel, #request);
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// ========
|
||||
// Write generated.rs
|
||||
|
||||
|
@ -482,15 +482,6 @@ crate::pac::interrupts! {
|
||||
|
||||
dma_trait!(FrameDma, Instance);
|
||||
|
||||
crate::pac::peripheral_dma_channels! {
|
||||
($peri:ident, dcmi, $kind:ident, PSSI, $channel:tt, $request:expr) => {
|
||||
dma_trait_impl!(FrameDma, $peri, $channel, $request);
|
||||
};
|
||||
($peri:ident, dcmi, $kind:ident, DCMI, $channel:tt, $request:expr) => {
|
||||
dma_trait_impl!(FrameDma, $peri, $channel, $request);
|
||||
};
|
||||
}
|
||||
|
||||
crate::pac::peripheral_pins!(
|
||||
($inst:ident, dcmi, DCMI, $pin:ident, D0, $af:expr) => {
|
||||
pin_trait_impl!(D0Pin, $inst, $pin, $af);
|
||||
|
@ -91,12 +91,3 @@ crate::pac::peripheral_pins!(
|
||||
pin_trait_impl!(SdaPin, $inst, $pin, 0);
|
||||
};
|
||||
);
|
||||
|
||||
crate::pac::peripheral_dma_channels! {
|
||||
($peri:ident, i2c, $kind:ident, RX, $channel:tt, $request:expr) => {
|
||||
dma_trait_impl!(RxDma, $peri, $channel, $request);
|
||||
};
|
||||
($peri:ident, i2c, $kind:ident, TX, $channel:tt, $request:expr) => {
|
||||
dma_trait_impl!(TxDma, $peri, $channel, $request);
|
||||
};
|
||||
}
|
||||
|
@ -911,12 +911,3 @@ crate::pac::peripheral_pins!(
|
||||
pin_trait_impl!(MisoPin, $inst, $pin, 0);
|
||||
};
|
||||
);
|
||||
|
||||
crate::pac::peripheral_dma_channels! {
|
||||
($peri:ident, spi, $kind:ident, RX, $channel:tt, $request:expr) => {
|
||||
dma_trait_impl!(RxDma, $peri, $channel, $request);
|
||||
};
|
||||
($peri:ident, spi, $kind:ident, TX, $channel:tt, $request:expr) => {
|
||||
dma_trait_impl!(TxDma, $peri, $channel, $request);
|
||||
};
|
||||
}
|
||||
|
@ -31,8 +31,8 @@ macro_rules! dma_trait {
|
||||
#[allow(unused)]
|
||||
macro_rules! dma_trait_impl {
|
||||
// DMAMUX
|
||||
($signal:ident, $instance:ident, {dmamux: $dmamux:ident}, $request:expr) => {
|
||||
impl<T> $signal<crate::peripherals::$instance> for T
|
||||
(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>,
|
||||
{
|
||||
@ -43,8 +43,8 @@ macro_rules! dma_trait_impl {
|
||||
};
|
||||
|
||||
// No DMAMUX
|
||||
($signal:ident, $instance:ident, {channel: $channel:ident}, $request:expr) => {
|
||||
impl $signal<crate::peripherals::$instance> for crate::peripherals::$channel {
|
||||
(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
|
||||
}
|
||||
|
@ -712,18 +712,3 @@ crate::pac::peripheral_pins!(
|
||||
pin_trait_impl!(CkPin, $inst, $pin, 0);
|
||||
};
|
||||
);
|
||||
|
||||
crate::pac::peripheral_dma_channels! {
|
||||
($peri:ident, usart, $kind:ident, RX, $channel:tt, $request:expr) => {
|
||||
dma_trait_impl!(RxDma, $peri, $channel, $request);
|
||||
};
|
||||
($peri:ident, usart, $kind:ident, TX, $channel:tt, $request:expr) => {
|
||||
dma_trait_impl!(TxDma, $peri, $channel, $request);
|
||||
};
|
||||
($peri:ident, uart, $kind:ident, RX, $channel:tt, $request:expr) => {
|
||||
dma_trait_impl!(RxDma, $peri, $channel, $request);
|
||||
};
|
||||
($peri:ident, uart, $kind:ident, TX, $channel:tt, $request:expr) => {
|
||||
dma_trait_impl!(TxDma, $peri, $channel, $request);
|
||||
};
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user