Skip to content

Commit 7c369c6

Browse files
committed
generate_features: Add support for package features
1 parent 2f9470f commit 7c369c6

File tree

2 files changed

+42
-12
lines changed

2 files changed

+42
-12
lines changed

src/family.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ pub struct SubFamily {
6161
#[serde(rename_all = "PascalCase")]
6262
pub struct Mcu {
6363
pub name: String,
64-
package_name: String,
64+
pub package_name: String,
6565
pub ref_name: String,
6666
}
6767

src/main.rs

Lines changed: 41 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -77,25 +77,38 @@ fn main() -> Result<(), String> {
7777
.find(|v| v.name == mcu_family)
7878
.ok_or_else(|| format!("Could not find family {}", mcu_family))?;
7979

80-
// Build MCU map
80+
// MCU map
8181
//
8282
// The keys of this map are GPIO peripheral version strings (e.g.
8383
// "STM32L051_gpio_v1_0"), while the value is a Vec of MCU ref names.
8484
let mut mcu_gpio_map: HashMap<String, Vec<String>> = HashMap::new();
85+
86+
// Package map
87+
//
88+
// The keys of this map are MCU ref names, the values are package names
89+
// (e.g. ).
90+
let mut mcu_package_map: HashMap<String, String> = HashMap::new();
91+
8592
for sf in family {
8693
for mcu in sf {
8794
let mcu_dat = mcu::Mcu::load(&db_dir, &mcu.name)
8895
.map_err(|e| format!("Could not load MCU data: {}", e))?;
96+
8997
let gpio_version = mcu_dat.get_ip("GPIO").unwrap().get_version().to_string();
9098
mcu_gpio_map
9199
.entry(gpio_version)
92100
.or_insert(vec![])
93101
.push(mcu.ref_name.clone());
102+
103+
if mcu_family == "STM32L0" {
104+
// The stm32l0xx-hal has package based features
105+
mcu_package_map.insert(mcu.ref_name.clone(), mcu.package_name.clone());
106+
}
94107
}
95108
}
96109

97110
match generate {
98-
GenerateTarget::Features => generate_features(&mcu_gpio_map, &mcu_family)?,
111+
GenerateTarget::Features => generate_features(&mcu_gpio_map, &mcu_package_map, &mcu_family)?,
99112
GenerateTarget::PinMappings => generate_pin_mappings(&mcu_gpio_map, &db_dir)?,
100113
};
101114

@@ -108,9 +121,9 @@ lazy_static! {
108121

109122
// STM32L0
110123
let mut l0 = HashMap::new();
111-
l0.insert("^STM32L0.1", "stm32l0/stm32l0x1");
112-
l0.insert("^STM32L0.2", "stm32l0/stm32l0x2");
113-
l0.insert("^STM32L0.3", "stm32l0/stm32l0x3");
124+
l0.insert("^STM32L0.1", "stm32l0x1");
125+
l0.insert("^STM32L0.2", "stm32l0x2");
126+
l0.insert("^STM32L0.3", "stm32l0x3");
114127
m.insert("STM32L0", l0);
115128

116129
m
@@ -123,6 +136,7 @@ lazy_static! {
123136
/// Both lists are sorted alphanumerically.
124137
fn generate_features(
125138
mcu_gpio_map: &HashMap<String, Vec<String>>,
139+
mcu_package_map: &HashMap<String, String>,
126140
mcu_family: &str,
127141
) -> Result<(), String> {
128142
let mut main_features = mcu_gpio_map
@@ -137,7 +151,10 @@ fn generate_features(
137151
for mcu in mcu_list {
138152
let mut dependencies = vec![];
139153

140-
// PAC feature
154+
// GPIO version feature
155+
dependencies.push(gpio_version_feature.clone());
156+
157+
// Additional dependencies
141158
if let Some(family) = FEATURE_DEPENDENCIES.get(mcu_family) {
142159
for (pattern, feature) in family {
143160
if Regex::new(pattern).unwrap().is_match(&mcu) {
@@ -147,8 +164,10 @@ fn generate_features(
147164
}
148165
}
149166

150-
// GPIO version feature
151-
dependencies.push(gpio_version_feature.clone());
167+
// Package based feature
168+
if let Some(package) = mcu_package_map.get(mcu) {
169+
dependencies.push(package.to_lowercase());
170+
}
152171

153172
let mcu_feature = format!("mcu-{}", mcu);
154173
mcu_aliases.push(format!(
@@ -169,12 +188,23 @@ fn generate_features(
169188
}
170189
mcu_aliases.sort();
171190

172-
println!("# Features based on the GPIO peripheral version.");
173-
println!("# This determines the pin function mapping of the MCU.");
191+
println!("# Features based on the GPIO peripheral version");
192+
println!("# This determines the pin function mapping of the MCU");
174193
for feature in main_features {
175194
println!("{} = []", feature);
176195
}
177-
println!("\n# Per-MCU aliases for the GPIO peripheral version.");
196+
println!();
197+
if !mcu_package_map.is_empty() {
198+
println!("# Physical packages");
199+
let mut packages = mcu_package_map.values().map(|v| v.to_lowercase()).collect::<Vec<_>>();
200+
packages.sort_by(|a, b| compare_str(a, b));
201+
packages.dedup();
202+
for pkg in packages {
203+
println!("{} = []", pkg);
204+
}
205+
println!();
206+
}
207+
println!("# MCUs");
178208
for alias in mcu_aliases {
179209
println!("{}", alias);
180210
}

0 commit comments

Comments
 (0)