Skip to content

Commit 31fd8cf

Browse files
committed
feat: chips, peripheral_versions cfgs generate
1 parent 989cce9 commit 31fd8cf

File tree

1 file changed

+49
-60
lines changed

1 file changed

+49
-60
lines changed

build.rs

Lines changed: 49 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use quote::{format_ident, quote};
1010
use py32_metapac::metadata::ir::BitOffset;
1111
use py32_metapac::metadata::{
1212
MemoryRegionKind, PeripheralRccKernelClock, PeripheralRccRegister, PeripheralRegisters, /*StopMode,*/
13-
// ALL_CHIPS, ALL_PERIPHERAL_VERSIONS,
13+
ALL_CHIPS, ALL_PERIPHERAL_VERSIONS,
1414
METADATA,
1515
};
1616

@@ -43,12 +43,12 @@ fn main() {
4343
}
4444
}
4545

46-
// for &(kind, versions) in ALL_PERIPHERAL_VERSIONS.iter() {
47-
// cfgs.declare(kind);
48-
// for &version in versions.iter() {
49-
// cfgs.declare(format!("{}_{}", kind, version));
50-
// }
51-
// }
46+
for &(kind, versions) in ALL_PERIPHERAL_VERSIONS.iter() {
47+
cfgs.declare(kind);
48+
for &version in versions.iter() {
49+
cfgs.declare(format!("{}_{}", kind, version));
50+
}
51+
}
5252

5353
// ========
5454
// Generate singletons
@@ -561,7 +561,7 @@ fn main() {
561561
.unwrap()
562562
.byte_offset;
563563
let reg_offset: u8 = (reg_offset / 4).try_into().unwrap();
564-
564+
565565
let bit_offset = &rcc_registers
566566
.ir
567567
.fieldsets
@@ -1635,64 +1635,53 @@ fn main() {
16351635
// ========
16361636
// Configs for multicore and for targeting groups of chips
16371637

1638-
// fn get_chip_cfgs(chip_name: &str) -> Vec<String> {
1639-
// let mut cfgs = Vec::new();
1638+
fn get_chip_cfgs(chip_name: &str) -> Vec<String> {
1639+
let mut cfgs = Vec::new();
16401640

1641-
// // Multicore
1641+
// Multicore
16421642

1643-
// let mut s = chip_name.split('_');
1644-
// let mut chip_name: String = s.next().unwrap().to_string();
1645-
// let core_name = if let Some(c) = s.next() {
1646-
// if !c.starts_with("CM") {
1647-
// chip_name.push('_');
1648-
// chip_name.push_str(c);
1649-
// None
1650-
// } else {
1651-
// Some(c)
1652-
// }
1653-
// } else {
1654-
// None
1655-
// };
1656-
1657-
// if let Some(core) = core_name {
1658-
// cfgs.push(format!("{}_{}", &chip_name[..chip_name.len() - 2], core));
1659-
// }
1643+
let mut s = chip_name.split('_');
1644+
let mut chip_name: String = s.next().unwrap().to_string();
1645+
let core_name = if let Some(c) = s.next() {
1646+
if !c.starts_with("CM") {
1647+
chip_name.push('_');
1648+
chip_name.push_str(c);
1649+
None
1650+
} else {
1651+
Some(c)
1652+
}
1653+
} else {
1654+
None
1655+
};
16601656

1661-
// // Configs for targeting groups of chips
1662-
// if &chip_name[..8] == "stm32wba" {
1663-
// cfgs.push(chip_name[..8].to_owned()); // stm32wba
1664-
// cfgs.push(chip_name[..10].to_owned()); // stm32wba52
1665-
// cfgs.push(format!("package_{}", &chip_name[10..11]));
1666-
// cfgs.push(format!("flashsize_{}", &chip_name[11..12]));
1667-
// } else {
1668-
// if &chip_name[..8] == "stm32h7r" || &chip_name[..8] == "stm32h7s" {
1669-
// cfgs.push("stm32h7rs".to_owned());
1670-
// } else {
1671-
// cfgs.push(chip_name[..7].to_owned()); // stm32f4
1672-
// }
1673-
// cfgs.push(chip_name[..9].to_owned()); // stm32f429
1674-
// cfgs.push(format!("{}x", &chip_name[..8])); // stm32f42x
1675-
// cfgs.push(format!("{}x{}", &chip_name[..7], &chip_name[8..9])); // stm32f4x9
1676-
// cfgs.push(format!("package_{}", &chip_name[9..10]));
1677-
// cfgs.push(format!("flashsize_{}", &chip_name[10..11]));
1678-
// }
1657+
if let Some(core) = core_name {
1658+
cfgs.push(format!("{}_{}", &chip_name[..chip_name.len() - 2], core));
1659+
}
16791660

1680-
// // Mark the L4+ chips as they have many differences to regular L4.
1681-
// if &chip_name[..7] == "stm32l4" {
1682-
// if "pqrs".contains(&chip_name[7..8]) {
1683-
// cfgs.push("stm32l4_plus".to_owned());
1684-
// } else {
1685-
// cfgs.push("stm32l4_nonplus".to_owned());
1686-
// }
1687-
// }
1661+
// Configs for targeting groups of chips
1662+
if &chip_name[..9] == "py32f002a" || &chip_name[..9] == "py32f002b" {
1663+
cfgs.push(chip_name[..6].to_owned()); // py32f0
1664+
cfgs.push(chip_name[..9].to_owned()); // py32f002a
1665+
// TODO
1666+
}
1667+
else {
1668+
cfgs.push(chip_name[..6].to_owned()); // py32f0
1669+
cfgs.push(chip_name[..8].to_owned()); // py32f030
1670+
cfgs.push(format!("package_{}", &chip_name[8..10]));
1671+
cfgs.push(format!("flashsize_{}", &chip_name[10..11]));
1672+
}
1673+
1674+
// cfgs.push(format!("{}x", &chip_name[..8])); // stm32f42x
1675+
// cfgs.push(format!("{}x{}", &chip_name[..7], &chip_name[8..9])); // stm32f4x9
1676+
16881677

1689-
// cfgs
1690-
// }
1678+
cfgs
1679+
}
16911680

1692-
// cfgs.enable_all(&get_chip_cfgs(&chip_name));
1693-
// for &chip_name in ALL_CHIPS.iter() {
1694-
// cfgs.declare_all(&get_chip_cfgs(&chip_name.to_ascii_lowercase()));
1695-
// }
1681+
cfgs.enable_all(&get_chip_cfgs(&chip_name));
1682+
for &chip_name in ALL_CHIPS.iter() {
1683+
cfgs.declare_all(&get_chip_cfgs(&chip_name.to_ascii_lowercase()));
1684+
}
16961685

16971686
println!("cargo:rerun-if-changed=build.rs");
16981687
}

0 commit comments

Comments
 (0)