mirror of
https://github.com/italicsjenga/rp-hal-boards.git
synced 2025-01-11 21:11:31 +11:00
Pulling the integer out of the frequency first.
This commit is contained in:
parent
d9b1b2b1ec
commit
ac2af7582e
|
@ -360,13 +360,11 @@ fn calculate_baudrate_dividers(
|
||||||
frequency: &Hertz,
|
frequency: &Hertz,
|
||||||
) -> Result<(u16, u16), Error> {
|
) -> Result<(u16, u16), Error> {
|
||||||
// baudrate_div = frequency * 8 / wanted_baudrate
|
// baudrate_div = frequency * 8 / wanted_baudrate
|
||||||
let baudrate_div = frequency
|
let baudrate_div = frequency.integer()
|
||||||
.checked_mul(&8)
|
.checked_mul(8)
|
||||||
.and_then(|r| r.checked_div(wanted_baudrate.integer()))
|
.and_then(|r| r.checked_div(*wanted_baudrate.integer()))
|
||||||
.ok_or(Error::BadArgument)?;
|
.ok_or(Error::BadArgument)?;
|
||||||
|
|
||||||
let baudrate_div: u32 = *baudrate_div.integer();
|
|
||||||
|
|
||||||
Ok(match (baudrate_div >> 7, ((baudrate_div & 0x7F) + 1) / 2) {
|
Ok(match (baudrate_div >> 7, ((baudrate_div & 0x7F) + 1) / 2) {
|
||||||
(0, _) => (1, 0),
|
(0, _) => (1, 0),
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue