Skip to content

Commit 64e2378

Browse files
authored
Fix some clippy warnings (#29)
There are still some warnings left for the devices other than the 503. Most of which, I believe, are from unfinished things.
1 parent a230b98 commit 64e2378

File tree

3 files changed

+16
-19
lines changed

3 files changed

+16
-19
lines changed

src/rcc.rs

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -413,7 +413,7 @@ macro_rules! ppre_calculate {
413413
.unwrap_or($hclk);
414414

415415
// Calculate suitable divider
416-
let ($bits, $ppre) = match ($hclk + $pclk - 1) / $pclk
416+
let ($bits, $ppre) = match $hclk.div_ceil($pclk)
417417
{
418418
0 => unreachable!(),
419419
1 => (PPRE::Div1, 1 as u8),
@@ -617,19 +617,18 @@ impl Rcc {
617617
let rcc_hclk = self.config.rcc_hclk.unwrap_or(sys_ck.raw());
618618

619619
// Estimate divisor
620-
let (hpre_bits, hpre_div) =
621-
match (sys_ck.raw() + rcc_hclk - 1) / rcc_hclk {
622-
0 => unreachable!(),
623-
1 => (HPRE::Div1, 1),
624-
2 => (HPRE::Div2, 2),
625-
3..=5 => (HPRE::Div4, 4),
626-
6..=11 => (HPRE::Div8, 8),
627-
12..=39 => (HPRE::Div16, 16),
628-
40..=95 => (HPRE::Div64, 64),
629-
96..=191 => (HPRE::Div128, 128),
630-
192..=383 => (HPRE::Div256, 256),
631-
_ => (HPRE::Div512, 512),
632-
};
620+
let (hpre_bits, hpre_div) = match sys_ck.raw().div_ceil(rcc_hclk) {
621+
0 => unreachable!(),
622+
1 => (HPRE::Div1, 1),
623+
2 => (HPRE::Div2, 2),
624+
3..=5 => (HPRE::Div4, 4),
625+
6..=11 => (HPRE::Div8, 8),
626+
12..=39 => (HPRE::Div16, 16),
627+
40..=95 => (HPRE::Div64, 64),
628+
96..=191 => (HPRE::Div128, 128),
629+
192..=383 => (HPRE::Div256, 256),
630+
_ => (HPRE::Div512, 512),
631+
};
633632

634633
// Calculate real AHB clock
635634
let rcc_hclk = sys_ck.raw() / hpre_div;

src/rcc/mco.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ macro_rules! calculate_prescaler {
4444
// Running?
4545
if let Some(freq) = self.frequency {
4646
// Calculate prescaler
47-
let prescaler = match (in_ck + freq - 1) / freq {
47+
let prescaler = match in_ck.div_ceil(freq) {
4848
0 => unreachable!(),
4949
x @ 1..=15 => x,
5050
_ => {

src/rcc/pll.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -129,8 +129,7 @@ fn vco_output_divider_setup(
129129
let vco_out_target = max_output * min_div;
130130

131131
let vco_out_target = if (vco_out_target / min_output) > PLL_OUT_DIV_MAX {
132-
let f = ((vco_out_target / min_output) + PLL_OUT_DIV_MAX - 1)
133-
/ PLL_OUT_DIV_MAX;
132+
let f = (vco_out_target / min_output).div_ceil(PLL_OUT_DIV_MAX);
134133
vco_out_target / f
135134
} else {
136135
vco_out_target
@@ -152,8 +151,7 @@ fn vco_output_divider_setup(
152151

153152
// Input divisor, resulting in a reference clock in the
154153
// range 2 to 16 MHz.
155-
let pll_x_m_min =
156-
(pllsrc + range.input_range.end() - 1) / range.input_range.end();
154+
let pll_x_m_min = pllsrc.div_ceil(*range.input_range.end());
157155
let pll_x_m_max = (pllsrc / range.input_range.start()).min(PLL_M_MAX);
158156

159157
// Iterative search for the lowest m value that minimizes

0 commit comments

Comments
 (0)