stm32/dma: update codegen+macrotables for new stm32-data
This commit is contained in:
parent
dff4b42a33
commit
54b5012c56
6 changed files with 42 additions and 111 deletions
|
@ -150,8 +150,8 @@ pub(crate) unsafe fn init() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pac::bdma_channels! {
|
pac::dma_channels! {
|
||||||
($channel_peri:ident, $dma_peri:ident, $channel_num:expr) => {
|
($channel_peri:ident, $dma_peri:ident, bdma, $channel_num:expr, $dmamux:tt) => {
|
||||||
impl crate::dma::sealed::Channel for crate::peripherals::$channel_peri {}
|
impl crate::dma::sealed::Channel for crate::peripherals::$channel_peri {}
|
||||||
impl Channel for crate::peripherals::$channel_peri
|
impl Channel for crate::peripherals::$channel_peri
|
||||||
{
|
{
|
||||||
|
|
|
@ -153,7 +153,7 @@ pub(crate) unsafe fn init() {
|
||||||
}
|
}
|
||||||
|
|
||||||
pac::dma_channels! {
|
pac::dma_channels! {
|
||||||
($channel_peri:ident, $dma_peri:ident, $channel_num:expr) => {
|
($channel_peri:ident, $dma_peri:ident, dma, $channel_num:expr, $dmamux:tt) => {
|
||||||
impl crate::dma::sealed::Channel for crate::peripherals::$channel_peri {}
|
impl crate::dma::sealed::Channel for crate::peripherals::$channel_peri {}
|
||||||
impl Channel for crate::peripherals::$channel_peri
|
impl Channel for crate::peripherals::$channel_peri
|
||||||
{
|
{
|
||||||
|
|
|
@ -24,40 +24,11 @@ pub(crate) trait MuxChannel {
|
||||||
const DMAMUX_REGS: pac::dmamux::Dmamux;
|
const DMAMUX_REGS: pac::dmamux::Dmamux;
|
||||||
}
|
}
|
||||||
|
|
||||||
macro_rules! dma_num {
|
|
||||||
(DMA1) => {
|
|
||||||
0
|
|
||||||
};
|
|
||||||
(DMA2) => {
|
|
||||||
1
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(not(rcc_h7))]
|
|
||||||
pac::bdma_channels! {
|
|
||||||
($channel_peri:ident, $dma_peri:ident, $channel_num:expr) => {
|
|
||||||
impl MuxChannel for peripherals::$channel_peri {
|
|
||||||
const DMAMUX_CH_NUM: u8 = (dma_num!($dma_peri) * 8) + $channel_num;
|
|
||||||
const DMAMUX_REGS: pac::dmamux::Dmamux = pac::DMAMUX1;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(rcc_h7)]
|
|
||||||
pac::dma_channels! {
|
pac::dma_channels! {
|
||||||
($channel_peri:ident, $dma_peri:ident, $channel_num:expr) => {
|
($channel_peri:ident, $dma_peri:ident, $version:ident, $channel_num:expr, {dmamux: $dmamux:ident, dmamux_channel: $dmamux_channel:expr}) => {
|
||||||
impl MuxChannel for peripherals::$channel_peri {
|
impl MuxChannel for peripherals::$channel_peri {
|
||||||
const DMAMUX_CH_NUM: u8 = (dma_num!($dma_peri) * 8) + $channel_num;
|
const DMAMUX_CH_NUM: u8 = $dmamux_channel;
|
||||||
const DMAMUX_REGS: pac::dmamux::Dmamux = pac::DMAMUX1;
|
const DMAMUX_REGS: pac::dmamux::Dmamux = pac::$dmamux;
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
#[cfg(rcc_h7)]
|
|
||||||
pac::bdma_channels! {
|
|
||||||
($channel_peri:ident, $dma_peri:ident, $channel_num:expr) => {
|
|
||||||
impl MuxChannel for peripherals::$channel_peri {
|
|
||||||
const DMAMUX_CH_NUM: u8 = $channel_num;
|
|
||||||
const DMAMUX_REGS: pac::dmamux::Dmamux = pac::DMAMUX2;
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
@ -171,7 +171,7 @@ crate::pac::peripheral_pins!(
|
||||||
);
|
);
|
||||||
|
|
||||||
macro_rules! impl_dma {
|
macro_rules! impl_dma {
|
||||||
($inst:ident, ALL, $signal:ident, $request:expr) => {
|
($inst:ident, {dmamux: $dmamux:ident}, $signal:ident, $request:expr) => {
|
||||||
impl<T: crate::dma::Channel> sealed::$signal<peripherals::$inst> for T {
|
impl<T: crate::dma::Channel> sealed::$signal<peripherals::$inst> for T {
|
||||||
fn request(&self) -> dma::Request {
|
fn request(&self) -> dma::Request {
|
||||||
$request
|
$request
|
||||||
|
@ -180,7 +180,7 @@ macro_rules! impl_dma {
|
||||||
|
|
||||||
impl<T: crate::dma::Channel> $signal<peripherals::$inst> for T {}
|
impl<T: crate::dma::Channel> $signal<peripherals::$inst> for T {}
|
||||||
};
|
};
|
||||||
($inst:ident, $channel:ident, $signal:ident, $request:expr) => {
|
($inst:ident, {channel: $channel:ident}, $signal:ident, $request:expr) => {
|
||||||
impl sealed::$signal<peripherals::$inst> for peripherals::$channel {
|
impl sealed::$signal<peripherals::$inst> for peripherals::$channel {
|
||||||
fn request(&self) -> dma::Request {
|
fn request(&self) -> dma::Request {
|
||||||
$request
|
$request
|
||||||
|
@ -192,30 +192,16 @@ macro_rules! impl_dma {
|
||||||
}
|
}
|
||||||
|
|
||||||
crate::pac::peripheral_dma_channels! {
|
crate::pac::peripheral_dma_channels! {
|
||||||
($peri:ident, usart, $kind:ident, RX, $channel:ident, $dma_peri:ident, $channel_num:expr, $request:expr) => {
|
($peri:ident, usart, $kind:ident, RX, $channel:tt, $request:expr) => {
|
||||||
impl_dma!($peri, $channel, RxDma, $request);
|
impl_dma!($peri, $channel, RxDma, $request);
|
||||||
};
|
};
|
||||||
($peri:ident, usart, $kind:ident, TX, $channel:ident, $dma_peri:ident, $channel_num:expr, $request:expr) => {
|
($peri:ident, usart, $kind:ident, TX, $channel:tt, $request:expr) => {
|
||||||
impl_dma!($peri, $channel, TxDma, $request);
|
impl_dma!($peri, $channel, TxDma, $request);
|
||||||
};
|
};
|
||||||
($peri:ident, uart, $kind:ident, RX, $channel:ident, $dma_peri:ident, $channel_num:expr, $request:expr) => {
|
($peri:ident, uart, $kind:ident, RX, $channel:tt, $request:expr) => {
|
||||||
impl_dma!($peri, $channel, RxDma, $request);
|
impl_dma!($peri, $channel, RxDma, $request);
|
||||||
};
|
};
|
||||||
($peri:ident, uart, $kind:ident, TX, $channel:ident, $dma_peri:ident, $channel_num:expr, $request:expr) => {
|
($peri:ident, uart, $kind:ident, TX, $channel:tt, $request:expr) => {
|
||||||
impl_dma!($peri, $channel, TxDma, $request);
|
impl_dma!($peri, $channel, TxDma, $request);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
crate::pac::dma_requests! {
|
|
||||||
(usart, $peri:ident, RX, $request:expr) => {
|
|
||||||
impl_dma!($peri, ALL, RxDma, $request);
|
|
||||||
};
|
|
||||||
(usart, $peri:ident, TX, $request:expr) => {
|
|
||||||
impl_dma!($peri, ALL, TxDma, $request);
|
|
||||||
};
|
|
||||||
(uart, $peri:ident, RX, $request:expr) => {
|
|
||||||
impl_dma!($peri, ALL, RxDma, $request);
|
|
||||||
};
|
|
||||||
(uart, $peri:ident, TX, $request:expr) => {
|
|
||||||
impl_dma!($peri, ALL, TxDma, $request);
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
Subproject commit d285fced6573703be875436409f8c83dd80ae183
|
Subproject commit 8702a3a3bb83a59515dab2cf9f75952fa6edae8a
|
|
@ -49,8 +49,6 @@ pub struct Peripheral {
|
||||||
pub pins: Vec<Pin>,
|
pub pins: Vec<Pin>,
|
||||||
#[serde(default)]
|
#[serde(default)]
|
||||||
pub dma_channels: HashMap<String, Vec<PeripheralDmaChannel>>,
|
pub dma_channels: HashMap<String, Vec<PeripheralDmaChannel>>,
|
||||||
#[serde(default)]
|
|
||||||
pub dma_requests: HashMap<String, PeripheralDmaRequest>,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Eq, PartialEq, Clone, Deserialize)]
|
#[derive(Debug, Eq, PartialEq, Clone, Deserialize)]
|
||||||
|
@ -64,20 +62,17 @@ pub struct Pin {
|
||||||
pub struct DmaChannel {
|
pub struct DmaChannel {
|
||||||
pub dma: String,
|
pub dma: String,
|
||||||
pub channel: u32,
|
pub channel: u32,
|
||||||
|
pub dmamux: Option<String>,
|
||||||
|
pub dmamux_channel: Option<u32>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Eq, PartialEq, Clone, Deserialize, Hash)]
|
#[derive(Debug, Eq, PartialEq, Clone, Deserialize, Hash)]
|
||||||
pub struct PeripheralDmaChannel {
|
pub struct PeripheralDmaChannel {
|
||||||
pub channel: String,
|
pub channel: Option<String>,
|
||||||
|
pub dmamux: Option<String>,
|
||||||
pub request: Option<u32>,
|
pub request: Option<u32>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Eq, PartialEq, Clone, Deserialize, Hash)]
|
|
||||||
pub struct PeripheralDmaRequest {
|
|
||||||
pub dmamux: String,
|
|
||||||
pub request: u32,
|
|
||||||
}
|
|
||||||
|
|
||||||
struct BlockInfo {
|
struct BlockInfo {
|
||||||
/// usart_v1/USART -> usart
|
/// usart_v1/USART -> usart
|
||||||
module: String,
|
module: String,
|
||||||
|
@ -272,19 +267,10 @@ pub fn gen(options: Options) {
|
||||||
let mut peripheral_pins_table: Vec<Vec<String>> = Vec::new();
|
let mut peripheral_pins_table: Vec<Vec<String>> = Vec::new();
|
||||||
let mut peripheral_rcc_table: Vec<Vec<String>> = Vec::new();
|
let mut peripheral_rcc_table: Vec<Vec<String>> = Vec::new();
|
||||||
let mut dma_channels_table: Vec<Vec<String>> = Vec::new();
|
let mut dma_channels_table: Vec<Vec<String>> = Vec::new();
|
||||||
let mut bdma_channels_table: Vec<Vec<String>> = Vec::new();
|
|
||||||
let mut dma_requests_table: Vec<Vec<String>> = Vec::new();
|
|
||||||
let mut peripheral_dma_channels_table: Vec<Vec<String>> = Vec::new();
|
let mut peripheral_dma_channels_table: Vec<Vec<String>> = Vec::new();
|
||||||
let mut peripheral_counts: HashMap<String, u8> = HashMap::new();
|
let mut peripheral_counts: HashMap<String, u8> = HashMap::new();
|
||||||
let mut dma_channel_counts: HashMap<String, u8> = HashMap::new();
|
let mut dma_channel_counts: HashMap<String, u8> = HashMap::new();
|
||||||
|
|
||||||
let dma_base = core
|
|
||||||
.peripherals
|
|
||||||
.get(&"DMA".to_string())
|
|
||||||
.unwrap_or_else(|| core.peripherals.get(&"DMA1".to_string()).unwrap())
|
|
||||||
.address;
|
|
||||||
let dma_stride = 0x400;
|
|
||||||
|
|
||||||
let gpio_base = core.peripherals.get(&"GPIOA".to_string()).unwrap().address;
|
let gpio_base = core.peripherals.get(&"GPIOA".to_string()).unwrap().address;
|
||||||
let gpio_stride = 0x400;
|
let gpio_stride = 0x400;
|
||||||
|
|
||||||
|
@ -336,26 +322,20 @@ pub fn gen(options: Options) {
|
||||||
peripheral_pins_table.push(row);
|
peripheral_pins_table.push(row);
|
||||||
}
|
}
|
||||||
|
|
||||||
for dma_request in &p.dma_requests {
|
for (request, dma_channels) in &p.dma_channels {
|
||||||
let mut row = Vec::new();
|
|
||||||
row.push(bi.module.clone());
|
|
||||||
row.push(name.clone());
|
|
||||||
row.push(dma_request.0.clone());
|
|
||||||
row.push(dma_request.1.request.to_string());
|
|
||||||
// TODO add the `dmamux` column
|
|
||||||
dma_requests_table.push(row);
|
|
||||||
}
|
|
||||||
|
|
||||||
for (event, dma_channels) in &p.dma_channels {
|
|
||||||
for channel in dma_channels.iter() {
|
for channel in dma_channels.iter() {
|
||||||
let mut row = Vec::new();
|
let mut row = Vec::new();
|
||||||
row.push(name.clone());
|
row.push(name.clone());
|
||||||
row.push(bi.module.clone());
|
row.push(bi.module.clone());
|
||||||
row.push(bi.block.clone());
|
row.push(bi.block.clone());
|
||||||
row.push(event.clone());
|
row.push(request.clone());
|
||||||
row.push(channel.channel.clone());
|
if let Some(channel) = &channel.channel {
|
||||||
row.push(core.dma_channels[&channel.channel].dma.clone());
|
row.push(format!("{{channel: {}}}", channel));
|
||||||
row.push(core.dma_channels[&channel.channel].channel.to_string());
|
} else if let Some(dmamux) = &channel.dmamux {
|
||||||
|
row.push(format!("{{dmamux: {}}}", dmamux));
|
||||||
|
} else {
|
||||||
|
unreachable!();
|
||||||
|
}
|
||||||
if let Some(request) = channel.request {
|
if let Some(request) = channel.request {
|
||||||
row.push(request.to_string());
|
row.push(request.to_string());
|
||||||
} else {
|
} else {
|
||||||
|
@ -399,15 +379,6 @@ pub fn gen(options: Options) {
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
"dma" => {
|
|
||||||
let dma_num = if name == "DMA" {
|
|
||||||
0
|
|
||||||
} else {
|
|
||||||
let dma_letter = name.chars().skip(3).next().unwrap();
|
|
||||||
dma_letter as u32 - '1' as u32
|
|
||||||
};
|
|
||||||
assert_eq!(p.address, dma_base + dma_stride * dma_num);
|
|
||||||
}
|
|
||||||
_ => {}
|
_ => {}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -507,21 +478,25 @@ pub fn gen(options: Options) {
|
||||||
|
|
||||||
for (id, channel_info) in &core.dma_channels {
|
for (id, channel_info) in &core.dma_channels {
|
||||||
let mut row = Vec::new();
|
let mut row = Vec::new();
|
||||||
let dma_peri = core.peripherals.get(&channel_info.dma);
|
let dma_peri = core.peripherals.get(&channel_info.dma).unwrap();
|
||||||
|
let bi = BlockInfo::parse(dma_peri.block.as_ref().unwrap());
|
||||||
|
|
||||||
row.push(id.clone());
|
row.push(id.clone());
|
||||||
row.push(channel_info.dma.clone());
|
row.push(channel_info.dma.clone());
|
||||||
|
row.push(bi.module.clone());
|
||||||
row.push(channel_info.channel.to_string());
|
row.push(channel_info.channel.to_string());
|
||||||
if let Some(dma_peri) = dma_peri {
|
if let Some(dmamux) = &channel_info.dmamux {
|
||||||
if let Some(ref block) = dma_peri.block {
|
let dmamux_channel = channel_info.dmamux_channel.unwrap();
|
||||||
let bi = BlockInfo::parse(block);
|
row.push(format!(
|
||||||
if bi.module == "bdma" {
|
"{{dmamux: {}, dmamux_channel: {}}}",
|
||||||
bdma_channels_table.push(row);
|
dmamux, dmamux_channel
|
||||||
} else {
|
));
|
||||||
dma_channels_table.push(row);
|
} else {
|
||||||
}
|
row.push("{}".to_string());
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
dma_channels_table.push(row);
|
||||||
|
|
||||||
let dma_peri_name = channel_info.dma.clone();
|
let dma_peri_name = channel_info.dma.clone();
|
||||||
dma_channel_counts.insert(
|
dma_channel_counts.insert(
|
||||||
dma_peri_name.clone(),
|
dma_peri_name.clone(),
|
||||||
|
@ -548,7 +523,8 @@ pub fn gen(options: Options) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if name.starts_with("BDMA_") || name.starts_with("BDMA1_") || name.starts_with("BDMA2_") {
|
if name.starts_with("BDMA_") || name.starts_with("BDMA1_") || name.starts_with("BDMA2_")
|
||||||
|
{
|
||||||
interrupt_table.push(vec!["BDMA".to_string(), name.clone()]);
|
interrupt_table.push(vec!["BDMA".to_string(), name.clone()]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -583,8 +559,6 @@ pub fn gen(options: Options) {
|
||||||
);
|
);
|
||||||
make_table(&mut extra, "peripheral_rcc", &peripheral_rcc_table);
|
make_table(&mut extra, "peripheral_rcc", &peripheral_rcc_table);
|
||||||
make_table(&mut extra, "dma_channels", &dma_channels_table);
|
make_table(&mut extra, "dma_channels", &dma_channels_table);
|
||||||
make_table(&mut extra, "bdma_channels", &bdma_channels_table);
|
|
||||||
make_table(&mut extra, "dma_requests", &dma_requests_table);
|
|
||||||
make_peripheral_counts(&mut extra, &peripheral_counts);
|
make_peripheral_counts(&mut extra, &peripheral_counts);
|
||||||
make_dma_channel_counts(&mut extra, &dma_channel_counts);
|
make_dma_channel_counts(&mut extra, &dma_channel_counts);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue