mirror of
https://github.com/embassy-rs/embassy.git
synced 2024-11-22 23:02:30 +00:00
Changing the casts (code review request)
This commit is contained in:
parent
bce909ec1e
commit
ce361abb1b
@ -28,7 +28,6 @@ stm32-metapac = { version = "0.1.0", path = "../stm32-metapac", features = ["rt"
|
|||||||
vcell = { version = "0.1.3", optional = true }
|
vcell = { version = "0.1.3", optional = true }
|
||||||
bxcan = "0.5.1"
|
bxcan = "0.5.1"
|
||||||
seq-macro = "0.2.2"
|
seq-macro = "0.2.2"
|
||||||
cast = { version = "0.2.2", default-features = false }
|
|
||||||
|
|
||||||
cfg-if = "1.0.0"
|
cfg-if = "1.0.0"
|
||||||
|
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
use core::convert::TryFrom;
|
||||||
use core::marker::PhantomData;
|
use core::marker::PhantomData;
|
||||||
|
|
||||||
use embassy::util::Unborrow;
|
use embassy::util::Unborrow;
|
||||||
@ -7,8 +8,6 @@ use crate::pac::{FLASH, RCC};
|
|||||||
use crate::peripherals;
|
use crate::peripherals;
|
||||||
use crate::time::Hertz;
|
use crate::time::Hertz;
|
||||||
|
|
||||||
use cast::u32;
|
|
||||||
|
|
||||||
use super::{set_freqs, Clocks};
|
use super::{set_freqs, Clocks};
|
||||||
|
|
||||||
const HSI: u32 = 8_000_000;
|
const HSI: u32 = 8_000_000;
|
||||||
@ -94,8 +93,8 @@ impl<'d> Rcc<'d> {
|
|||||||
})
|
})
|
||||||
.unwrap_or(0b011);
|
.unwrap_or(0b011);
|
||||||
|
|
||||||
let ppre1: i32 = 1 << (ppre1_bits - 0b011);
|
let ppre1 = 1 << (ppre1_bits - 0b011);
|
||||||
let pclk1 = hclk / u32(ppre1).unwrap();
|
let pclk1 = hclk / u32::try_from(ppre1).unwrap();
|
||||||
let timer_mul1 = if ppre1 == 1 { 1 } else { 2 };
|
let timer_mul1 = if ppre1 == 1 { 1 } else { 2 };
|
||||||
|
|
||||||
assert!(pclk1 <= 36_000_000);
|
assert!(pclk1 <= 36_000_000);
|
||||||
@ -113,8 +112,8 @@ impl<'d> Rcc<'d> {
|
|||||||
})
|
})
|
||||||
.unwrap_or(0b011);
|
.unwrap_or(0b011);
|
||||||
|
|
||||||
let ppre2: i32 = 1 << (ppre2_bits - 0b011);
|
let ppre2 = 1 << (ppre2_bits - 0b011);
|
||||||
let pclk2 = hclk / u32(ppre2).unwrap();
|
let pclk2 = hclk / u32::try_from(ppre2).unwrap();
|
||||||
let timer_mul2 = if ppre2 == 1 { 1 } else { 2 };
|
let timer_mul2 = if ppre2 == 1 { 1 } else { 2 };
|
||||||
|
|
||||||
assert!(pclk2 <= 72_000_000);
|
assert!(pclk2 <= 72_000_000);
|
||||||
@ -154,7 +153,7 @@ impl<'d> Rcc<'d> {
|
|||||||
.unwrap_or(0b11);
|
.unwrap_or(0b11);
|
||||||
|
|
||||||
let apre = (apre_bits + 1) << 1;
|
let apre = (apre_bits + 1) << 1;
|
||||||
let adcclk = pclk2 / u32(apre);
|
let adcclk = pclk2 / unwrap!(u32::try_from(apre));
|
||||||
|
|
||||||
assert!(adcclk <= 14_000_000);
|
assert!(adcclk <= 14_000_000);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user