From f4e0487ae54d03572f58a3b4cf3d79cab695c7f5 Mon Sep 17 00:00:00 2001 From: Don Reilly Date: Tue, 8 Aug 2023 15:15:36 -0500 Subject: [PATCH] map all (most?) edge cases of ADC --- stm32-data-gen/src/rcc.rs | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/stm32-data-gen/src/rcc.rs b/stm32-data-gen/src/rcc.rs index d4e17c6..a6052f9 100644 --- a/stm32-data-gen/src/rcc.rs +++ b/stm32-data-gen/src/rcc.rs @@ -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, + 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 + } }