Skip to content

Commit 2f9470f

Browse files
authored
Merge pull request #4 from dbrgn/features-pac-dependencies
MCU Features: Add PAC dependencies
2 parents 4f788e0 + 272f8d2 commit 2f9470f

File tree

1 file changed

+52
-6
lines changed

1 file changed

+52
-6
lines changed

src/main.rs

Lines changed: 52 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -95,18 +95,36 @@ fn main() -> Result<(), String> {
9595
}
9696

9797
match generate {
98-
GenerateTarget::Features => generate_features(&mcu_gpio_map)?,
98+
GenerateTarget::Features => generate_features(&mcu_gpio_map, &mcu_family)?,
9999
GenerateTarget::PinMappings => generate_pin_mappings(&mcu_gpio_map, &db_dir)?,
100100
};
101101

102102
Ok(())
103103
}
104104

105+
lazy_static! {
106+
static ref FEATURE_DEPENDENCIES: HashMap<&'static str, HashMap<&'static str, &'static str>> = {
107+
let mut m = HashMap::new();
108+
109+
// STM32L0
110+
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");
114+
m.insert("STM32L0", l0);
115+
116+
m
117+
};
118+
}
119+
105120
/// Print the IO features, followed by MCU features that act purely as aliases
106121
/// for the IO features.
107122
///
108123
/// Both lists are sorted alphanumerically.
109-
fn generate_features(mcu_gpio_map: &HashMap<String, Vec<String>>) -> Result<(), String> {
124+
fn generate_features(
125+
mcu_gpio_map: &HashMap<String, Vec<String>>,
126+
mcu_family: &str,
127+
) -> Result<(), String> {
110128
let mut main_features = mcu_gpio_map
111129
.keys()
112130
.map(|gpio| gpio_version_to_feature(gpio))
@@ -117,18 +135,46 @@ fn generate_features(mcu_gpio_map: &HashMap<String, Vec<String>>) -> Result<(),
117135
for (gpio, mcu_list) in mcu_gpio_map {
118136
let gpio_version_feature = gpio_version_to_feature(gpio).unwrap();
119137
for mcu in mcu_list {
138+
let mut dependencies = vec![];
139+
140+
// PAC feature
141+
if let Some(family) = FEATURE_DEPENDENCIES.get(mcu_family) {
142+
for (pattern, feature) in family {
143+
if Regex::new(pattern).unwrap().is_match(&mcu) {
144+
dependencies.push(feature.to_string());
145+
break;
146+
}
147+
}
148+
}
149+
150+
// GPIO version feature
151+
dependencies.push(gpio_version_feature.clone());
152+
120153
let mcu_feature = format!("mcu-{}", mcu);
121-
mcu_aliases.push(format!("{} = [\"{}\"]", mcu_feature, gpio_version_feature));
154+
mcu_aliases.push(format!(
155+
"{} = [{}]",
156+
mcu_feature,
157+
&dependencies.iter().map(|val| format!("\"{}\"", val)).fold(
158+
String::new(),
159+
|mut acc, x| {
160+
if !acc.is_empty() {
161+
acc.push_str(", ");
162+
}
163+
acc.push_str(&x);
164+
acc
165+
}
166+
)
167+
));
122168
}
123169
}
124170
mcu_aliases.sort();
125171

126-
println!("// Features based on the GPIO peripheral version.");
127-
println!("// This determines the pin function mapping of the MCU.");
172+
println!("# Features based on the GPIO peripheral version.");
173+
println!("# This determines the pin function mapping of the MCU.");
128174
for feature in main_features {
129175
println!("{} = []", feature);
130176
}
131-
println!("\n// Per-MCU aliases for the GPIO peripheral version.");
177+
println!("\n# Per-MCU aliases for the GPIO peripheral version.");
132178
for alias in mcu_aliases {
133179
println!("{}", alias);
134180
}

0 commit comments

Comments
 (0)