map all (most?) edge cases of ADC

This commit is contained in:
Don Reilly 2023-08-08 15:15:36 -05:00
parent dff9c321f3
commit f4e0487ae5

View File

@ -79,6 +79,9 @@ impl PeripheralToClock {
const PERI_OVERRIDE: &[(&str, &[&str])] = &[("DCMI", &["DCMI_PSSI"]), ("PSSI", &["DCMI_PSSI"])];
let clocks = self.0.get(rcc_block)?;
if peri_name.starts_with("ADC") {
return self.match_adc_peri_clock(clocks, peri_name);
}
if let Some(res) = clocks.get(peri_name) {
Some(res)
} else if let Some(peri_name) = peri_name.strip_suffix('1') {
@ -94,4 +97,32 @@ impl PeripheralToClock {
None
}
}
fn match_adc_peri_clock<'a>(
&'a self,
clocks: &'a HashMap<String, stm32_data_serde::chip::core::peripheral::Rcc>,
peri_name: &str,
) -> Option<&stm32_data_serde::chip::core::peripheral::Rcc> {
// Direct match
if clocks.contains_key(peri_name) {
return clocks.get(peri_name);
}
// Paired match based on odd/even
if let Some(digit_char) = peri_name.chars().last() {
if let Some(digit) = digit_char.to_digit(10) {
let paired = if digit % 2 == 1 {
format!("ADC{}{}", digit, digit + 1)
} else {
format!("ADC{}{}", digit - 1, digit)
};
if clocks.contains_key(paired.as_str()) {
return clocks.get(paired.as_str());
}
}
}
None
}
}