diff options
| author | Siarhei B <[email protected]> | 2025-08-04 10:15:37 +0200 |
|---|---|---|
| committer | Siarhei B <[email protected]> | 2025-08-04 10:19:14 +0200 |
| commit | 3b7b343863ac347bf86f4d2a79cb43788b5fcdc0 (patch) | |
| tree | a5b490ad2fc08ef9de6d9bfee5d67967104e6fcc /embassy-mspm0/src | |
| parent | 8091155a2f0eaa64f3ca7c9da4c835c956e860e8 (diff) | |
mspm0-I2C: remove type time:Herz usage
Diffstat (limited to 'embassy-mspm0/src')
| -rw-r--r-- | embassy-mspm0/src/i2c.rs | 29 | ||||
| -rw-r--r-- | embassy-mspm0/src/lib.rs | 1 | ||||
| -rw-r--r-- | embassy-mspm0/src/time.rs | 102 |
3 files changed, 14 insertions, 118 deletions
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}; | |||
| 16 | use crate::mode::{Async, Blocking, Mode}; | 16 | use crate::mode::{Async, Blocking, Mode}; |
| 17 | use crate::pac::i2c::{vals, I2c as Regs}; | 17 | use crate::pac::i2c::{vals, I2c as Regs}; |
| 18 | use crate::pac::{self}; | 18 | use crate::pac::{self}; |
| 19 | use crate::time::Hertz; | ||
| 20 | use crate::Peri; | 19 | use crate::Peri; |
| 21 | 20 | ||
| 22 | /// The clock source for the I2C. | 21 | /// The clock source for the I2C. |
| @@ -106,15 +105,15 @@ pub enum BusSpeed { | |||
| 106 | /// Custom mode. | 105 | /// Custom mode. |
| 107 | /// | 106 | /// |
| 108 | /// The custom mode frequency (in Hz) can be set manually. | 107 | /// The custom mode frequency (in Hz) can be set manually. |
| 109 | Custom(Hertz), | 108 | Custom(u32), |
| 110 | } | 109 | } |
| 111 | 110 | ||
| 112 | impl BusSpeed { | 111 | impl BusSpeed { |
| 113 | fn hertz(self) -> Hertz { | 112 | fn hertz(self) -> u32 { |
| 114 | match self { | 113 | match self { |
| 115 | Self::Standard => Hertz::khz(100), | 114 | Self::Standard => 100_000, |
| 116 | Self::FastMode => Hertz::khz(400), | 115 | Self::FastMode => 400_000, |
| 117 | Self::FastModePlus => Hertz::mhz(1), | 116 | Self::FastModePlus => 1_000_000, |
| 118 | Self::Custom(s) => s, | 117 | Self::Custom(s) => s, |
| 119 | } | 118 | } |
| 120 | } | 119 | } |
| @@ -197,12 +196,12 @@ impl Config { | |||
| 197 | } | 196 | } |
| 198 | 197 | ||
| 199 | #[cfg(any(mspm0c110x))] | 198 | #[cfg(any(mspm0c110x))] |
| 200 | fn calculate_clock_source(&self) -> Hertz { | 199 | fn calculate_clock_source(&self) -> u32 { |
| 201 | // Assume that BusClk has default value. | 200 | // Assume that BusClk has default value. |
| 202 | // TODO: calculate BusClk more precisely. | 201 | // TODO: calculate BusClk more precisely. |
| 203 | match self.clock_source { | 202 | match self.clock_source { |
| 204 | ClockSel::MfClk => Hertz::mhz(4), | 203 | ClockSel::MfClk => 4_000_000, |
| 205 | ClockSel::BusClk => Hertz::mhz(24), | 204 | ClockSel::BusClk => 24_000_000, |
| 206 | } | 205 | } |
| 207 | } | 206 | } |
| 208 | 207 | ||
| @@ -210,18 +209,18 @@ impl Config { | |||
| 210 | mspm0g110x, mspm0g150x, mspm0g151x, mspm0g310x, mspm0g350x, mspm0g351x, mspm0l110x, mspm0l122x, mspm0l130x, | 209 | mspm0g110x, mspm0g150x, mspm0g151x, mspm0g310x, mspm0g350x, mspm0g351x, mspm0l110x, mspm0l122x, mspm0l130x, |
| 211 | mspm0l134x, mspm0l222x | 210 | mspm0l134x, mspm0l222x |
| 212 | ))] | 211 | ))] |
| 213 | fn calculate_clock_source(&self) -> Hertz { | 212 | fn calculate_clock_source(&self) -> u32 { |
| 214 | // Assume that BusClk has default value. | 213 | // Assume that BusClk has default value. |
| 215 | // TODO: calculate BusClk more precisely. | 214 | // TODO: calculate BusClk more precisely. |
| 216 | match self.clock_source { | 215 | match self.clock_source { |
| 217 | ClockSel::MfClk => Hertz::mhz(4), | 216 | ClockSel::MfClk => 4_000_000, |
| 218 | ClockSel::BusClk => Hertz::mhz(32), | 217 | ClockSel::BusClk => 24_000_000, |
| 219 | } | 218 | } |
| 220 | } | 219 | } |
| 221 | 220 | ||
| 222 | fn check_clock_i2c(&self) -> bool { | 221 | fn check_clock_i2c(&self) -> bool { |
| 223 | // make sure source clock is ~20 faster than i2c clock | 222 | // make sure source clock is ~20 faster than i2c clock |
| 224 | let clk_ratio = 20u8; | 223 | let clk_ratio = 20; |
| 225 | 224 | ||
| 226 | let i2c_clk = self.bus_speed.hertz() / self.clock_div.divider(); | 225 | let i2c_clk = self.bus_speed.hertz() / self.clock_div.divider(); |
| 227 | let src_clk = self.calculate_clock_source(); | 226 | let src_clk = self.calculate_clock_source(); |
| @@ -233,7 +232,7 @@ impl Config { | |||
| 233 | fn define_clock_source(&mut self) -> bool { | 232 | fn define_clock_source(&mut self) -> bool { |
| 234 | // decide which clock source to choose based on i2c clock. | 233 | // decide which clock source to choose based on i2c clock. |
| 235 | // If i2c speed <= 200kHz, use MfClk, otherwise use BusClk | 234 | // If i2c speed <= 200kHz, use MfClk, otherwise use BusClk |
| 236 | if self.bus_speed.hertz() / self.clock_div.divider() > Hertz::khz(200) { | 235 | if self.bus_speed.hertz() / self.clock_div.divider() > 200_000 { |
| 237 | // TODO: check if BUSCLK enabled | 236 | // TODO: check if BUSCLK enabled |
| 238 | self.clock_source = ClockSel::BusClk; | 237 | self.clock_source = ClockSel::BusClk; |
| 239 | } else { | 238 | } else { |
| @@ -419,7 +418,7 @@ impl<'d, M: Mode> I2c<'d, M> { | |||
| 419 | 418 | ||
| 420 | self.state | 419 | self.state |
| 421 | .clock | 420 | .clock |
| 422 | .store(config.calculate_clock_source().0, Ordering::Relaxed); | 421 | .store(config.calculate_clock_source(), Ordering::Relaxed); |
| 423 | 422 | ||
| 424 | self.info | 423 | self.info |
| 425 | .regs | 424 | .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; | |||
| 16 | pub mod dma; | 16 | pub mod dma; |
| 17 | pub mod gpio; | 17 | pub mod gpio; |
| 18 | pub mod i2c; | 18 | pub mod i2c; |
| 19 | pub mod time; | ||
| 20 | pub mod timer; | 19 | pub mod timer; |
| 21 | pub mod uart; | 20 | pub mod uart; |
| 22 | 21 | ||
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 @@ | |||
| 1 | //! Time units | ||
| 2 | |||
| 3 | use core::fmt::Display; | ||
| 4 | use core::ops::{Div, Mul}; | ||
| 5 | |||
| 6 | /// Hertz | ||
| 7 | #[derive(Eq, PartialEq, Ord, PartialOrd, Clone, Copy, Debug)] | ||
| 8 | pub struct Hertz(pub u32); | ||
| 9 | |||
| 10 | impl Display for Hertz { | ||
| 11 | fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { | ||
| 12 | write!(f, "{} Hz", self.0) | ||
| 13 | } | ||
| 14 | } | ||
| 15 | |||
| 16 | #[cfg(feature = "defmt")] | ||
| 17 | impl defmt::Format for Hertz { | ||
| 18 | fn format(&self, f: defmt::Formatter) { | ||
| 19 | defmt::write!(f, "{=u32} Hz", self.0) | ||
| 20 | } | ||
| 21 | } | ||
| 22 | |||
| 23 | impl Hertz { | ||
| 24 | /// Create a `Hertz` from the given hertz. | ||
| 25 | pub const fn hz(hertz: u32) -> Self { | ||
| 26 | Self(hertz) | ||
| 27 | } | ||
| 28 | |||
| 29 | /// Create a `Hertz` from the given kilohertz. | ||
| 30 | pub const fn khz(kilohertz: u32) -> Self { | ||
| 31 | Self(kilohertz * 1_000) | ||
| 32 | } | ||
| 33 | |||
| 34 | /// Create a `Hertz` from the given megahertz. | ||
| 35 | pub const fn mhz(megahertz: u32) -> Self { | ||
| 36 | Self(megahertz * 1_000_000) | ||
| 37 | } | ||
| 38 | } | ||
| 39 | |||
| 40 | /// This is a convenience shortcut for [`Hertz::hz`] | ||
| 41 | pub const fn hz(hertz: u32) -> Hertz { | ||
| 42 | Hertz::hz(hertz) | ||
| 43 | } | ||
| 44 | |||
| 45 | /// This is a convenience shortcut for [`Hertz::khz`] | ||
| 46 | pub const fn khz(kilohertz: u32) -> Hertz { | ||
| 47 | Hertz::khz(kilohertz) | ||
| 48 | } | ||
| 49 | |||
| 50 | /// This is a convenience shortcut for [`Hertz::mhz`] | ||
| 51 | pub const fn mhz(megahertz: u32) -> Hertz { | ||
| 52 | Hertz::mhz(megahertz) | ||
| 53 | } | ||
| 54 | |||
| 55 | impl Mul<u32> for Hertz { | ||
| 56 | type Output = Hertz; | ||
| 57 | fn mul(self, rhs: u32) -> Self::Output { | ||
| 58 | Hertz(self.0 * rhs) | ||
| 59 | } | ||
| 60 | } | ||
| 61 | |||
| 62 | impl Div<u32> for Hertz { | ||
| 63 | type Output = Hertz; | ||
| 64 | fn div(self, rhs: u32) -> Self::Output { | ||
| 65 | Hertz(self.0 / rhs) | ||
| 66 | } | ||
| 67 | } | ||
| 68 | |||
| 69 | impl Mul<u16> for Hertz { | ||
| 70 | type Output = Hertz; | ||
| 71 | fn mul(self, rhs: u16) -> Self::Output { | ||
| 72 | self * (rhs as u32) | ||
| 73 | } | ||
| 74 | } | ||
| 75 | |||
| 76 | impl Div<u16> for Hertz { | ||
| 77 | type Output = Hertz; | ||
| 78 | fn div(self, rhs: u16) -> Self::Output { | ||
| 79 | self / (rhs as u32) | ||
| 80 | } | ||
| 81 | } | ||
| 82 | |||
| 83 | impl Mul<u8> for Hertz { | ||
| 84 | type Output = Hertz; | ||
| 85 | fn mul(self, rhs: u8) -> Self::Output { | ||
| 86 | self * (rhs as u32) | ||
| 87 | } | ||
| 88 | } | ||
| 89 | |||
| 90 | impl Div<u8> for Hertz { | ||
| 91 | type Output = Hertz; | ||
| 92 | fn div(self, rhs: u8) -> Self::Output { | ||
| 93 | self / (rhs as u32) | ||
| 94 | } | ||
| 95 | } | ||
| 96 | |||
| 97 | impl Div<Hertz> for Hertz { | ||
| 98 | type Output = u32; | ||
| 99 | fn div(self, rhs: Hertz) -> Self::Output { | ||
| 100 | self.0 / rhs.0 | ||
| 101 | } | ||
| 102 | } | ||
