From ac2af7582ee4503d7db4b96996bfa1b16cc99919 Mon Sep 17 00:00:00 2001 From: Nic0w Date: Tue, 4 May 2021 19:54:15 +0200 Subject: [PATCH] Pulling the integer out of the frequency first. --- rp2040-hal/src/uart.rs | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/rp2040-hal/src/uart.rs b/rp2040-hal/src/uart.rs index b6dbee9..888cdb5 100644 --- a/rp2040-hal/src/uart.rs +++ b/rp2040-hal/src/uart.rs @@ -360,13 +360,11 @@ fn calculate_baudrate_dividers( frequency: &Hertz, ) -> Result<(u16, u16), Error> { // baudrate_div = frequency * 8 / wanted_baudrate - let baudrate_div = frequency - .checked_mul(&8) - .and_then(|r| r.checked_div(wanted_baudrate.integer())) + let baudrate_div = frequency.integer() + .checked_mul(8) + .and_then(|r| r.checked_div(*wanted_baudrate.integer())) .ok_or(Error::BadArgument)?; - let baudrate_div: u32 = *baudrate_div.integer(); - Ok(match (baudrate_div >> 7, ((baudrate_div & 0x7F) + 1) / 2) { (0, _) => (1, 0),