stm32: remove last use of python at build time

This commit is contained in:
Dario Nieuwenhuis
2021-08-19 23:15:11 +02:00
parent 9f51f9a170
commit 446d6c275c
2 changed files with 65 additions and 98 deletions

View File

@ -1,6 +1,6 @@
use std::env;
use std::fs;
use std::path::PathBuf;
use std::process::Command;
fn main() {
let chip_name = env::vars_os()
@ -11,17 +11,72 @@ fn main() {
.unwrap()
.to_ascii_lowercase();
struct Peripheral {
kind: String,
name: String,
}
let mut peripherals: Vec<Peripheral> = Vec::new();
stm32_metapac::peripherals!(
($kind:ident, $name:ident) => {
peripherals.push(Peripheral{
kind: stringify!($kind).to_string(),
name: stringify!($name).to_string(),
});
};
);
let mut singletons: Vec<String> = Vec::new();
for p in peripherals {
match p.kind.as_str() {
// Generate singletons per pin, not per port
"gpio" => {
println!("{}", p.name);
let port_letter = p.name.strip_prefix("GPIO").unwrap();
for pin_num in 0..16 {
singletons.push(format!("P{}{}", port_letter, pin_num));
}
}
// No singleton for these, the HAL handles them specially.
"exti" => {}
// We *shouldn't* have singletons for these, but the HAL currently requires
// singletons, for using with RccPeripheral to enable/disable clocks to them.
//"rcc" => {}
//"dbgmcu" => {}
//"syscfg" => {}
//"dma" => {}
//"bdma" => {}
//"dmamux" => {}
// For other peripherals, one singleton per peri
_ => singletons.push(p.name.clone()),
}
}
// One singleton per EXTI line
for pin_num in 0..16 {
singletons.push(format!("EXTI{}", pin_num));
}
// One singleton per DMA channel
stm32_metapac::dma_channels! {
($channel_peri:ident, $dma_peri:ident, $version:ident, $channel_num:expr, $ignore:tt) => {
singletons.push(stringify!($channel_peri).to_string());
};
}
let out_dir = &PathBuf::from(env::var_os("OUT_DIR").unwrap());
let out_file = out_dir.join("generated.rs").to_string_lossy().to_string();
let exit_code = Command::new("python3")
.args(&["gen.py", &chip_name, &out_file])
.status()
.expect("failed to execute gen.py");
if !exit_code.success() {
panic!("gen.py exited with {:?}", exit_code)
}
fs::write(
out_file,
format!(
"embassy_hal_common::peripherals!({});",
singletons.join(",")
),
)
.unwrap();
stm32_metapac::peripheral_versions!(
($peri:ident, $version:ident) => {