stm32f4: Use unwrap! where possible
This commit is contained in:
parent
f4950c4449
commit
e44acd0d56
2 changed files with 14 additions and 18 deletions
|
@ -63,7 +63,7 @@ impl<'d> Rcc<'d> {
|
||||||
}
|
}
|
||||||
|
|
||||||
let sysclk = if sysclk_on_pll {
|
let sysclk = if sysclk_on_pll {
|
||||||
plls.pllsysclk.unwrap()
|
unwrap!(plls.pllsysclk)
|
||||||
} else {
|
} else {
|
||||||
sysclk
|
sysclk
|
||||||
};
|
};
|
||||||
|
@ -245,13 +245,11 @@ impl<'d> Rcc<'d> {
|
||||||
|
|
||||||
// Find the lowest pllm value that minimize the difference between
|
// Find the lowest pllm value that minimize the difference between
|
||||||
// target frequency and the real vco_out frequency.
|
// target frequency and the real vco_out frequency.
|
||||||
let pllm = (pllm_min..=pllm_max)
|
let pllm = unwrap!((pllm_min..=pllm_max).min_by_key(|pllm| {
|
||||||
.min_by_key(|pllm| {
|
|
||||||
let vco_in = pllsrcclk / pllm;
|
let vco_in = pllsrcclk / pllm;
|
||||||
let plln = target_freq / vco_in;
|
let plln = target_freq / vco_in;
|
||||||
target_freq - vco_in * plln
|
target_freq - vco_in * plln
|
||||||
})
|
}));
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
let vco_in = pllsrcclk / pllm;
|
let vco_in = pllsrcclk / pllm;
|
||||||
assert!((1_000_000..=2_000_000).contains(&vco_in));
|
assert!((1_000_000..=2_000_000).contains(&vco_in));
|
||||||
|
@ -261,14 +259,12 @@ impl<'d> Rcc<'d> {
|
||||||
let plln = if pll48clk {
|
let plln = if pll48clk {
|
||||||
// try the different valid pllq according to the valid
|
// try the different valid pllq according to the valid
|
||||||
// main scaller values, and take the best
|
// main scaller values, and take the best
|
||||||
let pllq = (4..=9)
|
let pllq = unwrap!((4..=9).min_by_key(|pllq| {
|
||||||
.min_by_key(|pllq| {
|
|
||||||
let plln = 48_000_000 * pllq / vco_in;
|
let plln = 48_000_000 * pllq / vco_in;
|
||||||
let pll48_diff = 48_000_000 - vco_in * plln / pllq;
|
let pll48_diff = 48_000_000 - vco_in * plln / pllq;
|
||||||
let sysclk_diff = (sysclk as i32 - (vco_in * plln / sysclk_div) as i32).abs();
|
let sysclk_diff = (sysclk as i32 - (vco_in * plln / sysclk_div) as i32).abs();
|
||||||
(pll48_diff, sysclk_diff)
|
(pll48_diff, sysclk_diff)
|
||||||
})
|
}));
|
||||||
.unwrap();
|
|
||||||
48_000_000 * pllq / vco_in
|
48_000_000 * pllq / vco_in
|
||||||
} else {
|
} else {
|
||||||
sysclk * sysclk_div / vco_in
|
sysclk * sysclk_div / vco_in
|
||||||
|
|
|
@ -31,7 +31,7 @@ fn main() -> ! {
|
||||||
|
|
||||||
let mut buf = [0u8; 1];
|
let mut buf = [0u8; 1];
|
||||||
loop {
|
loop {
|
||||||
unwrap!(usart.read_blocking(&mut buf).unwbrap());
|
unwrap!(usart.read_blocking(&mut buf));
|
||||||
unwrap!(usart.bwrite_all(&buf).unwrap());
|
unwrap!(usart.bwrite_all(&buf));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue