From d614717d719a66e20e1ce691e1ee5998a625186b Mon Sep 17 00:00:00 2001 From: Albin Hedman Date: Fri, 20 Dec 2024 20:28:26 +0100 Subject: [PATCH 1/2] Fix some clippy warnings --- src/rcc.rs | 4 ++-- src/rcc/mco.rs | 2 +- src/rcc/pll.rs | 5 ++--- 3 files changed, 5 insertions(+), 6 deletions(-) diff --git a/src/rcc.rs b/src/rcc.rs index c7c552e..4af33e9 100644 --- a/src/rcc.rs +++ b/src/rcc.rs @@ -413,7 +413,7 @@ macro_rules! ppre_calculate { .unwrap_or($hclk); // Calculate suitable divider - let ($bits, $ppre) = match ($hclk + $pclk - 1) / $pclk + let ($bits, $ppre) = match $hclk.div_ceil($pclk) { 0 => unreachable!(), 1 => (PPRE::Div1, 1 as u8), @@ -618,7 +618,7 @@ impl Rcc { // Estimate divisor let (hpre_bits, hpre_div) = - match (sys_ck.raw() + rcc_hclk - 1) / rcc_hclk { + match sys_ck.raw().div_ceil(rcc_hclk) { 0 => unreachable!(), 1 => (HPRE::Div1, 1), 2 => (HPRE::Div2, 2), diff --git a/src/rcc/mco.rs b/src/rcc/mco.rs index ba7545a..35aece3 100644 --- a/src/rcc/mco.rs +++ b/src/rcc/mco.rs @@ -44,7 +44,7 @@ macro_rules! calculate_prescaler { // Running? if let Some(freq) = self.frequency { // Calculate prescaler - let prescaler = match (in_ck + freq - 1) / freq { + let prescaler = match in_ck.div_ceil(freq) { 0 => unreachable!(), x @ 1..=15 => x, _ => { diff --git a/src/rcc/pll.rs b/src/rcc/pll.rs index 7b67d3e..6ecc12d 100644 --- a/src/rcc/pll.rs +++ b/src/rcc/pll.rs @@ -129,8 +129,7 @@ fn vco_output_divider_setup( let vco_out_target = max_output * min_div; let vco_out_target = if (vco_out_target / min_output) > PLL_OUT_DIV_MAX { - let f = ((vco_out_target / min_output) + PLL_OUT_DIV_MAX - 1) - / PLL_OUT_DIV_MAX; + let f = (vco_out_target / min_output).div_ceil(PLL_OUT_DIV_MAX); vco_out_target / f } else { vco_out_target @@ -153,7 +152,7 @@ fn vco_output_divider_setup( // Input divisor, resulting in a reference clock in the // range 2 to 16 MHz. let pll_x_m_min = - (pllsrc + range.input_range.end() - 1) / range.input_range.end(); + pllsrc.div_ceil(*range.input_range.end()); let pll_x_m_max = (pllsrc / range.input_range.start()).min(PLL_M_MAX); // Iterative search for the lowest m value that minimizes From 929ed66f2fccfae922f37184a5c188d698da8059 Mon Sep 17 00:00:00 2001 From: Albin Hedman Date: Fri, 20 Dec 2024 20:30:24 +0100 Subject: [PATCH 2/2] fmt --- src/rcc.rs | 25 ++++++++++++------------- src/rcc/pll.rs | 3 +-- 2 files changed, 13 insertions(+), 15 deletions(-) diff --git a/src/rcc.rs b/src/rcc.rs index 4af33e9..60f79d1 100644 --- a/src/rcc.rs +++ b/src/rcc.rs @@ -617,19 +617,18 @@ impl Rcc { let rcc_hclk = self.config.rcc_hclk.unwrap_or(sys_ck.raw()); // Estimate divisor - let (hpre_bits, hpre_div) = - match sys_ck.raw().div_ceil(rcc_hclk) { - 0 => unreachable!(), - 1 => (HPRE::Div1, 1), - 2 => (HPRE::Div2, 2), - 3..=5 => (HPRE::Div4, 4), - 6..=11 => (HPRE::Div8, 8), - 12..=39 => (HPRE::Div16, 16), - 40..=95 => (HPRE::Div64, 64), - 96..=191 => (HPRE::Div128, 128), - 192..=383 => (HPRE::Div256, 256), - _ => (HPRE::Div512, 512), - }; + let (hpre_bits, hpre_div) = match sys_ck.raw().div_ceil(rcc_hclk) { + 0 => unreachable!(), + 1 => (HPRE::Div1, 1), + 2 => (HPRE::Div2, 2), + 3..=5 => (HPRE::Div4, 4), + 6..=11 => (HPRE::Div8, 8), + 12..=39 => (HPRE::Div16, 16), + 40..=95 => (HPRE::Div64, 64), + 96..=191 => (HPRE::Div128, 128), + 192..=383 => (HPRE::Div256, 256), + _ => (HPRE::Div512, 512), + }; // Calculate real AHB clock let rcc_hclk = sys_ck.raw() / hpre_div; diff --git a/src/rcc/pll.rs b/src/rcc/pll.rs index 6ecc12d..2037839 100644 --- a/src/rcc/pll.rs +++ b/src/rcc/pll.rs @@ -151,8 +151,7 @@ fn vco_output_divider_setup( // Input divisor, resulting in a reference clock in the // range 2 to 16 MHz. - let pll_x_m_min = - pllsrc.div_ceil(*range.input_range.end()); + let pll_x_m_min = pllsrc.div_ceil(*range.input_range.end()); let pll_x_m_max = (pllsrc / range.input_range.start()).min(PLL_M_MAX); // Iterative search for the lowest m value that minimizes