Skip to content

Commit 890414a

Browse files
committed
Use match instead of nested if let
This is much more readable.
1 parent b0aaa37 commit 890414a

File tree

1 file changed

+14
-23
lines changed

1 file changed

+14
-23
lines changed

src/rcc.rs

Lines changed: 14 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -438,32 +438,23 @@ impl CFGR {
438438
fn get_sysclk(&self) -> (u32, cfgr::SW_A, Option<PllConfig>) {
439439
// If a sysclk is given, check if the PLL has to be used,
440440
// else select the system clock source, which is either HSI or HSE.
441-
if let Some(sysclk) = self.sysclk {
442-
if let Some(hseclk) = self.hse {
443-
if sysclk == hseclk {
444-
// No need to use the PLL
445-
// PLL is needed for USB, but we can make this assumption, to not use PLL here,
446-
// because the two valid USB clocks, 72 Mhz and 48 Mhz, can't be generated
447-
// directly from neither the internal rc (8 Mhz) nor the external
448-
// Oscillator (max 32 Mhz), without using the PLL.
449-
(hseclk, cfgr::SW_A::HSE, None)
450-
} else {
451-
let clock_with_pll = self.calc_pll(sysclk);
452-
(clock_with_pll.0, cfgr::SW_A::PLL, Some(clock_with_pll.1))
453-
}
454-
} else if sysclk == HSI {
455-
// No need to use the PLL
456-
(HSI, cfgr::SW_A::HSE, None)
457-
} else {
458-
let clock_with_pll = self.calc_pll(sysclk);
459-
(clock_with_pll.0, cfgr::SW_A::PLL, Some(clock_with_pll.1))
441+
match (self.sysclk, self.hse) {
442+
// No need to use the PLL
443+
// PLL is needed for USB, but we can make this assumption, to not use PLL here,
444+
// because the two valid USB clocks, 72 Mhz and 48 Mhz, can't be generated
445+
// directly from neither the internal rc (8 Mhz) nor the external
446+
// Oscillator (max 32 Mhz), without using the PLL.
447+
(Some(sysclk), Some(hse)) if sysclk == hse => (hse, cfgr::SW_A::HSE, None),
448+
// No need to use the PLL
449+
(Some(sysclk), None) if sysclk == HSI => (HSI, cfgr::SW_A::HSI, None),
450+
(Some(sysclk), _) => {
451+
let (sysclk, pll_config) = self.calc_pll(sysclk);
452+
(sysclk, cfgr::SW_A::PLL, Some(pll_config))
460453
}
461-
} else if let Some(hseclk) = self.hse {
462454
// Use HSE as system clock
463-
(hseclk, cfgr::SW_A::HSE, None)
464-
} else {
455+
(None, Some(hse)) => (hse, cfgr::SW_A::HSE, None),
465456
// Use HSI as system clock
466-
(HSI, cfgr::SW_A::HSI, None)
457+
(None, None) => (HSI, cfgr::SW_A::HSI, None),
467458
}
468459
}
469460

0 commit comments

Comments
 (0)