Skip to content

Commit 8e5d235

Browse files
committed
Simplify mcu_gpio_map creation code
1 parent cc6c4b1 commit 8e5d235

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

src/main.rs

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -104,27 +104,29 @@ fn main() -> Result<(), String> {
104104
_ => unreachable!(),
105105
};
106106

107+
// Load families
107108
let families = family::Families::load(&db_dir)
108109
.map_err(|e| format!("Could not load families XML: {}", e))?;
109110

111+
// Find target family
110112
let family = (&families)
111113
.into_iter()
112114
.find(|v| v.name == mcu_family)
113115
.ok_or_else(|| format!("Could not find family {}", mcu_family))?;
114116

115-
let mut mcu_gpio_map = HashMap::new();
116-
117+
// Build MCU map
118+
//
119+
// The keys of this map are GPIO peripheral version strings (e.g.
120+
// "STM32L051_gpio_v1_0"), while the value is a Vec of MCU ref names.
121+
let mut mcu_gpio_map: HashMap<String, Vec<String>> = HashMap::new();
117122
for sf in family {
118123
for mcu in sf {
119124
let mcu_dat = mcu::Mcu::load(&db_dir, &mcu.name)
120125
.map_err(|e| format!("Could not load MCU data: {}", e))?;
121126
let gpio_version = mcu_dat.get_ip("GPIO").unwrap().get_version().to_string();
122-
if !mcu_gpio_map.contains_key(&gpio_version) {
123-
mcu_gpio_map.insert(gpio_version.clone(), Vec::new());
124-
}
125127
mcu_gpio_map
126-
.get_mut(&gpio_version)
127-
.unwrap()
128+
.entry(gpio_version)
129+
.or_insert(vec![])
128130
.push(mcu.name.clone());
129131
}
130132
}

0 commit comments

Comments
 (0)