Pulling the integer out of the frequency first.

This commit is contained in:
Nic0w 2021-05-04 19:54:15 +02:00
parent d9b1b2b1ec
commit ac2af7582e

View file

@ -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),