From 3b7b343863ac347bf86f4d2a79cb43788b5fcdc0 Mon Sep 17 00:00:00 2001 From: Siarhei B Date: Mon, 4 Aug 2025 10:15:37 +0200 Subject: mspm0-I2C: remove type time:Herz usage --- embassy-mspm0/src/i2c.rs | 29 +++++++------ embassy-mspm0/src/lib.rs | 1 - embassy-mspm0/src/time.rs | 102 ---------------------------------------------- 3 files changed, 14 insertions(+), 118 deletions(-) delete mode 100644 embassy-mspm0/src/time.rs diff --git a/embassy-mspm0/src/i2c.rs b/embassy-mspm0/src/i2c.rs index 7581f131e..d1b260114 100644 --- a/embassy-mspm0/src/i2c.rs +++ b/embassy-mspm0/src/i2c.rs @@ -16,7 +16,6 @@ use crate::interrupt::{Interrupt, InterruptExt}; use crate::mode::{Async, Blocking, Mode}; use crate::pac::i2c::{vals, I2c as Regs}; use crate::pac::{self}; -use crate::time::Hertz; use crate::Peri; /// The clock source for the I2C. @@ -106,15 +105,15 @@ pub enum BusSpeed { /// Custom mode. /// /// The custom mode frequency (in Hz) can be set manually. - Custom(Hertz), + Custom(u32), } impl BusSpeed { - fn hertz(self) -> Hertz { + fn hertz(self) -> u32 { match self { - Self::Standard => Hertz::khz(100), - Self::FastMode => Hertz::khz(400), - Self::FastModePlus => Hertz::mhz(1), + Self::Standard => 100_000, + Self::FastMode => 400_000, + Self::FastModePlus => 1_000_000, Self::Custom(s) => s, } } @@ -197,12 +196,12 @@ impl Config { } #[cfg(any(mspm0c110x))] - fn calculate_clock_source(&self) -> Hertz { + fn calculate_clock_source(&self) -> u32 { // Assume that BusClk has default value. // TODO: calculate BusClk more precisely. match self.clock_source { - ClockSel::MfClk => Hertz::mhz(4), - ClockSel::BusClk => Hertz::mhz(24), + ClockSel::MfClk => 4_000_000, + ClockSel::BusClk => 24_000_000, } } @@ -210,18 +209,18 @@ impl Config { mspm0g110x, mspm0g150x, mspm0g151x, mspm0g310x, mspm0g350x, mspm0g351x, mspm0l110x, mspm0l122x, mspm0l130x, mspm0l134x, mspm0l222x ))] - fn calculate_clock_source(&self) -> Hertz { + fn calculate_clock_source(&self) -> u32 { // Assume that BusClk has default value. // TODO: calculate BusClk more precisely. match self.clock_source { - ClockSel::MfClk => Hertz::mhz(4), - ClockSel::BusClk => Hertz::mhz(32), + ClockSel::MfClk => 4_000_000, + ClockSel::BusClk => 24_000_000, } } fn check_clock_i2c(&self) -> bool { // make sure source clock is ~20 faster than i2c clock - let clk_ratio = 20u8; + let clk_ratio = 20; let i2c_clk = self.bus_speed.hertz() / self.clock_div.divider(); let src_clk = self.calculate_clock_source(); @@ -233,7 +232,7 @@ impl Config { fn define_clock_source(&mut self) -> bool { // decide which clock source to choose based on i2c clock. // If i2c speed <= 200kHz, use MfClk, otherwise use BusClk - if self.bus_speed.hertz() / self.clock_div.divider() > Hertz::khz(200) { + if self.bus_speed.hertz() / self.clock_div.divider() > 200_000 { // TODO: check if BUSCLK enabled self.clock_source = ClockSel::BusClk; } else { @@ -419,7 +418,7 @@ impl<'d, M: Mode> I2c<'d, M> { self.state .clock - .store(config.calculate_clock_source().0, Ordering::Relaxed); + .store(config.calculate_clock_source(), Ordering::Relaxed); self.info .regs diff --git a/embassy-mspm0/src/lib.rs b/embassy-mspm0/src/lib.rs index 55aef79b1..c7cf40e0c 100644 --- a/embassy-mspm0/src/lib.rs +++ b/embassy-mspm0/src/lib.rs @@ -16,7 +16,6 @@ mod macros; pub mod dma; pub mod gpio; pub mod i2c; -pub mod time; pub mod timer; pub mod uart; diff --git a/embassy-mspm0/src/time.rs b/embassy-mspm0/src/time.rs deleted file mode 100644 index 1353a909a..000000000 --- a/embassy-mspm0/src/time.rs +++ /dev/null @@ -1,102 +0,0 @@ -//! Time units - -use core::fmt::Display; -use core::ops::{Div, Mul}; - -/// Hertz -#[derive(Eq, PartialEq, Ord, PartialOrd, Clone, Copy, Debug)] -pub struct Hertz(pub u32); - -impl Display for Hertz { - fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { - write!(f, "{} Hz", self.0) - } -} - -#[cfg(feature = "defmt")] -impl defmt::Format for Hertz { - fn format(&self, f: defmt::Formatter) { - defmt::write!(f, "{=u32} Hz", self.0) - } -} - -impl Hertz { - /// Create a `Hertz` from the given hertz. - pub const fn hz(hertz: u32) -> Self { - Self(hertz) - } - - /// Create a `Hertz` from the given kilohertz. - pub const fn khz(kilohertz: u32) -> Self { - Self(kilohertz * 1_000) - } - - /// Create a `Hertz` from the given megahertz. - pub const fn mhz(megahertz: u32) -> Self { - Self(megahertz * 1_000_000) - } -} - -/// This is a convenience shortcut for [`Hertz::hz`] -pub const fn hz(hertz: u32) -> Hertz { - Hertz::hz(hertz) -} - -/// This is a convenience shortcut for [`Hertz::khz`] -pub const fn khz(kilohertz: u32) -> Hertz { - Hertz::khz(kilohertz) -} - -/// This is a convenience shortcut for [`Hertz::mhz`] -pub const fn mhz(megahertz: u32) -> Hertz { - Hertz::mhz(megahertz) -} - -impl Mul for Hertz { - type Output = Hertz; - fn mul(self, rhs: u32) -> Self::Output { - Hertz(self.0 * rhs) - } -} - -impl Div for Hertz { - type Output = Hertz; - fn div(self, rhs: u32) -> Self::Output { - Hertz(self.0 / rhs) - } -} - -impl Mul for Hertz { - type Output = Hertz; - fn mul(self, rhs: u16) -> Self::Output { - self * (rhs as u32) - } -} - -impl Div for Hertz { - type Output = Hertz; - fn div(self, rhs: u16) -> Self::Output { - self / (rhs as u32) - } -} - -impl Mul for Hertz { - type Output = Hertz; - fn mul(self, rhs: u8) -> Self::Output { - self * (rhs as u32) - } -} - -impl Div for Hertz { - type Output = Hertz; - fn div(self, rhs: u8) -> Self::Output { - self / (rhs as u32) - } -} - -impl Div for Hertz { - type Output = u32; - fn div(self, rhs: Hertz) -> Self::Output { - self.0 / rhs.0 - } -} -- cgit