From 20c35d5e14a6a14bcb763d5bf5c373729b4ea2bc Mon Sep 17 00:00:00 2001 From: Nic0w Date: Sun, 25 Apr 2021 19:45:45 +0200 Subject: [PATCH] Fix type conversion issue --- rp2040-hal/src/pll.rs | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/rp2040-hal/src/pll.rs b/rp2040-hal/src/pll.rs index 5071658..05940c3 100644 --- a/rp2040-hal/src/pll.rs +++ b/rp2040-hal/src/pll.rs @@ -131,7 +131,6 @@ pub mod common_configs { post_div1: 5, post_div2: 2 }; - } impl PhaseLockedLoop { @@ -145,13 +144,17 @@ impl PhaseLockedLoop { } /// Configures and starts the PLL : it switches to Locking state. - pub fn initialize(self, xosc_frequency: Generic, config: PLLConfig) -> Result, Error> where R: Into { + pub fn initialize(self, xosc_frequency: Generic, config: PLLConfig) -> Result, Error> where R: Into>{ const VCO_FREQ_RANGE: RangeInclusive> = Hertz(400_000_000)..=Hertz(1600_000_000); const POSTDIV_RANGE: Range = 1..7; const FBDIV_RANGE: Range = 16..320; - let vco_freq: Hertz = config.vco_freq.try_into().map_err(|_| Error::BadArgument)?; + //First we convert our rate to Hertz as all other rates can be converted to that. + let vco_freq: Hertz = config.vco_freq.into(); + + //Then we try to downscale to u32. + let vco_freq: Hertz = vco_freq.try_into().map_err(|_| Error::BadArgument)?; if !VCO_FREQ_RANGE.contains(&vco_freq) { return Err(Error::VCOFreqOutOfRange)