From 39e82b76a48da6e051af16aa34575aba0d1b8aa6 Mon Sep 17 00:00:00 2001 From: xoviat Date: Thu, 19 Oct 2023 21:01:17 -0500 Subject: [PATCH] rcc: solve data mutability --- stm32-data-gen/src/rcc.rs | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/stm32-data-gen/src/rcc.rs b/stm32-data-gen/src/rcc.rs index 749f5cb..845316a 100644 --- a/stm32-data-gen/src/rcc.rs +++ b/stm32-data-gen/src/rcc.rs @@ -1,3 +1,4 @@ +use std::collections::hash_map::Entry; use std::collections::{HashMap, HashSet}; use anyhow::{anyhow, Ok}; @@ -256,7 +257,24 @@ impl PeripheralToClock { mux, }; - family_clocks.insert(peri.to_string(), res); + match family_clocks.entry(peri.to_string()) { + Entry::Vacant(e) => { + e.insert(res); + } + Entry::Occupied(mut e) => { + if (e.get().clock != "pclk1" || e.get().clock != "hclk1") + && (res.clock == "pclk1" || res.clock == "hclk1") + { + e.insert(res); + } else if !(e.get().clock == "pclk1" || e.get().clock == "hclk1") { + return Err(anyhow!( + "rcc: duplicate entry for peri {} for rcc_{}", + peri.to_string(), + rcc_name + )); + } + } + } } } }