diff options
| author | Dario Nieuwenhuis <[email protected]> | 2024-02-26 02:16:41 +0000 |
|---|---|---|
| committer | GitHub <[email protected]> | 2024-02-26 02:16:41 +0000 |
| commit | 1ad28581c78c10d34d01f203006791cda18e19ff (patch) | |
| tree | d3a6180bdfacfa096308d94a7b38c5f900353ee1 | |
| parent | fd5058875ad5bda90de9603abe28a1b6134b5a51 (diff) | |
| parent | c83ab20526c0812d738853db015e201120ecce44 (diff) | |
Merge pull request #2625 from OroArmor/add-pll1_p_mul_2-clock
Add `PLL1_P_MUL_2` clock.
28 files changed, 246 insertions, 377 deletions
diff --git a/embassy-stm32/Cargo.toml b/embassy-stm32/Cargo.toml index d585d2cd6..7d21383c3 100644 --- a/embassy-stm32/Cargo.toml +++ b/embassy-stm32/Cargo.toml | |||
| @@ -70,7 +70,7 @@ rand_core = "0.6.3" | |||
| 70 | sdio-host = "0.5.0" | 70 | sdio-host = "0.5.0" |
| 71 | critical-section = "1.1" | 71 | critical-section = "1.1" |
| 72 | #stm32-metapac = { version = "15" } | 72 | #stm32-metapac = { version = "15" } |
| 73 | stm32-metapac = { git = "https://github.com/embassy-rs/stm32-data-generated", tag = "stm32-data-6097928f720646c73d6483a3245f922bd5faee2f" } | 73 | stm32-metapac = { git = "https://github.com/embassy-rs/stm32-data-generated", tag = "stm32-data-7c8b53413499acc3273b706318777a60f932d77a" } |
| 74 | vcell = "0.1.3" | 74 | vcell = "0.1.3" |
| 75 | bxcan = "0.7.0" | 75 | bxcan = "0.7.0" |
| 76 | nb = "1.0.0" | 76 | nb = "1.0.0" |
| @@ -94,7 +94,7 @@ critical-section = { version = "1.1", features = ["std"] } | |||
| 94 | proc-macro2 = "1.0.36" | 94 | proc-macro2 = "1.0.36" |
| 95 | quote = "1.0.15" | 95 | quote = "1.0.15" |
| 96 | #stm32-metapac = { version = "15", default-features = false, features = ["metadata"]} | 96 | #stm32-metapac = { version = "15", default-features = false, features = ["metadata"]} |
| 97 | stm32-metapac = { git = "https://github.com/embassy-rs/stm32-data-generated", tag = "stm32-data-6097928f720646c73d6483a3245f922bd5faee2f", default-features = false, features = ["metadata"]} | 97 | stm32-metapac = { git = "https://github.com/embassy-rs/stm32-data-generated", tag = "stm32-data-7c8b53413499acc3273b706318777a60f932d77a", default-features = false, features = ["metadata"]} |
| 98 | 98 | ||
| 99 | 99 | ||
| 100 | [features] | 100 | [features] |
diff --git a/embassy-stm32/src/adc/f1.rs b/embassy-stm32/src/adc/f1.rs index c896d8e3a..b27b99827 100644 --- a/embassy-stm32/src/adc/f1.rs +++ b/embassy-stm32/src/adc/f1.rs | |||
| @@ -74,7 +74,7 @@ impl<'d, T: Instance> Adc<'d, T> { | |||
| 74 | 74 | ||
| 75 | Self { | 75 | Self { |
| 76 | adc, | 76 | adc, |
| 77 | sample_time: Default::default(), | 77 | sample_time: SampleTime::from_bits(0), |
| 78 | } | 78 | } |
| 79 | } | 79 | } |
| 80 | 80 | ||
| @@ -84,14 +84,14 @@ impl<'d, T: Instance> Adc<'d, T> { | |||
| 84 | 84 | ||
| 85 | pub fn sample_time_for_us(&self, us: u32) -> SampleTime { | 85 | pub fn sample_time_for_us(&self, us: u32) -> SampleTime { |
| 86 | match us * Self::freq().0 / 1_000_000 { | 86 | match us * Self::freq().0 / 1_000_000 { |
| 87 | 0..=1 => SampleTime::Cycles1_5, | 87 | 0..=1 => SampleTime::CYCLES1_5, |
| 88 | 2..=7 => SampleTime::Cycles7_5, | 88 | 2..=7 => SampleTime::CYCLES7_5, |
| 89 | 8..=13 => SampleTime::Cycles13_5, | 89 | 8..=13 => SampleTime::CYCLES13_5, |
| 90 | 14..=28 => SampleTime::Cycles28_5, | 90 | 14..=28 => SampleTime::CYCLES28_5, |
| 91 | 29..=41 => SampleTime::Cycles41_5, | 91 | 29..=41 => SampleTime::CYCLES41_5, |
| 92 | 42..=55 => SampleTime::Cycles55_5, | 92 | 42..=55 => SampleTime::CYCLES55_5, |
| 93 | 56..=71 => SampleTime::Cycles71_5, | 93 | 56..=71 => SampleTime::CYCLES71_5, |
| 94 | _ => SampleTime::Cycles239_5, | 94 | _ => SampleTime::CYCLES239_5, |
| 95 | } | 95 | } |
| 96 | } | 96 | } |
| 97 | 97 | ||
diff --git a/embassy-stm32/src/adc/f3.rs b/embassy-stm32/src/adc/f3.rs index 6606a2b9c..efade1f64 100644 --- a/embassy-stm32/src/adc/f3.rs +++ b/embassy-stm32/src/adc/f3.rs | |||
| @@ -97,7 +97,7 @@ impl<'d, T: Instance> Adc<'d, T> { | |||
| 97 | 97 | ||
| 98 | Self { | 98 | Self { |
| 99 | adc, | 99 | adc, |
| 100 | sample_time: Default::default(), | 100 | sample_time: SampleTime::from_bits(0), |
| 101 | } | 101 | } |
| 102 | } | 102 | } |
| 103 | 103 | ||
| @@ -107,13 +107,13 @@ impl<'d, T: Instance> Adc<'d, T> { | |||
| 107 | 107 | ||
| 108 | pub fn sample_time_for_us(&self, us: u32) -> SampleTime { | 108 | pub fn sample_time_for_us(&self, us: u32) -> SampleTime { |
| 109 | match us * Self::freq().0 / 1_000_000 { | 109 | match us * Self::freq().0 / 1_000_000 { |
| 110 | 0..=1 => SampleTime::Cycles1_5, | 110 | 0..=1 => SampleTime::CYCLES1_5, |
| 111 | 2..=4 => SampleTime::Cycles4_5, | 111 | 2..=4 => SampleTime::CYCLES4_5, |
| 112 | 5..=7 => SampleTime::Cycles7_5, | 112 | 5..=7 => SampleTime::CYCLES7_5, |
| 113 | 8..=19 => SampleTime::Cycles19_5, | 113 | 8..=19 => SampleTime::CYCLES19_5, |
| 114 | 20..=61 => SampleTime::Cycles61_5, | 114 | 20..=61 => SampleTime::CYCLES61_5, |
| 115 | 62..=181 => SampleTime::Cycles181_5, | 115 | 62..=181 => SampleTime::CYCLES181_5, |
| 116 | _ => SampleTime::Cycles601_5, | 116 | _ => SampleTime::CYCLES601_5, |
| 117 | } | 117 | } |
| 118 | } | 118 | } |
| 119 | 119 | ||
diff --git a/embassy-stm32/src/adc/f3_v1_1.rs b/embassy-stm32/src/adc/f3_v1_1.rs index 6915a8f1c..f842893fa 100644 --- a/embassy-stm32/src/adc/f3_v1_1.rs +++ b/embassy-stm32/src/adc/f3_v1_1.rs | |||
| @@ -107,12 +107,12 @@ impl Calibration { | |||
| 107 | 107 | ||
| 108 | /// Returns a calibrated voltage value as in microvolts (uV) | 108 | /// Returns a calibrated voltage value as in microvolts (uV) |
| 109 | pub fn cal_uv(&self, raw: u16, resolution: super::Resolution) -> u32 { | 109 | pub fn cal_uv(&self, raw: u16, resolution: super::Resolution) -> u32 { |
| 110 | (self.vdda_uv() / resolution.to_max_count()) * raw as u32 | 110 | (self.vdda_uv() / super::resolution_to_max_count(resolution)) * raw as u32 |
| 111 | } | 111 | } |
| 112 | 112 | ||
| 113 | /// Returns a calibrated voltage value as an f32 | 113 | /// Returns a calibrated voltage value as an f32 |
| 114 | pub fn cal_f32(&self, raw: u16, resolution: super::Resolution) -> f32 { | 114 | pub fn cal_f32(&self, raw: u16, resolution: super::Resolution) -> f32 { |
| 115 | raw as f32 * self.vdda_f32() / resolution.to_max_count() as f32 | 115 | raw as f32 * self.vdda_f32() / super::resolution_to_max_count(resolution) as f32 |
| 116 | } | 116 | } |
| 117 | } | 117 | } |
| 118 | 118 | ||
| @@ -175,12 +175,7 @@ impl<'d, T: Instance> Adc<'d, T> { | |||
| 175 | } | 175 | } |
| 176 | 176 | ||
| 177 | pub fn resolution(&self) -> Resolution { | 177 | pub fn resolution(&self) -> Resolution { |
| 178 | match T::regs().cr1().read().res() { | 178 | T::regs().cr1().read().res() |
| 179 | crate::pac::adc::vals::Res::TWELVEBIT => Resolution::TwelveBit, | ||
| 180 | crate::pac::adc::vals::Res::TENBIT => Resolution::TenBit, | ||
| 181 | crate::pac::adc::vals::Res::EIGHTBIT => Resolution::EightBit, | ||
| 182 | crate::pac::adc::vals::Res::SIXBIT => Resolution::SixBit, | ||
| 183 | } | ||
| 184 | } | 179 | } |
| 185 | 180 | ||
| 186 | pub fn enable_vref(&self) -> Vref<T> { | 181 | pub fn enable_vref(&self) -> Vref<T> { |
| @@ -359,23 +354,23 @@ impl<'d, T: Instance> Adc<'d, T> { | |||
| 359 | 354 | ||
| 360 | fn get_res_clks(res: Resolution) -> u32 { | 355 | fn get_res_clks(res: Resolution) -> u32 { |
| 361 | match res { | 356 | match res { |
| 362 | Resolution::TwelveBit => 12, | 357 | Resolution::BITS12 => 12, |
| 363 | Resolution::TenBit => 11, | 358 | Resolution::BITS10 => 11, |
| 364 | Resolution::EightBit => 9, | 359 | Resolution::BITS8 => 9, |
| 365 | Resolution::SixBit => 7, | 360 | Resolution::BITS6 => 7, |
| 366 | } | 361 | } |
| 367 | } | 362 | } |
| 368 | 363 | ||
| 369 | fn get_sample_time_clks(sample_time: SampleTime) -> u32 { | 364 | fn get_sample_time_clks(sample_time: SampleTime) -> u32 { |
| 370 | match sample_time { | 365 | match sample_time { |
| 371 | SampleTime::Cycles4 => 4, | 366 | SampleTime::CYCLES4 => 4, |
| 372 | SampleTime::Cycles9 => 9, | 367 | SampleTime::CYCLES9 => 9, |
| 373 | SampleTime::Cycles16 => 16, | 368 | SampleTime::CYCLES16 => 16, |
| 374 | SampleTime::Cycles24 => 24, | 369 | SampleTime::CYCLES24 => 24, |
| 375 | SampleTime::Cycles48 => 48, | 370 | SampleTime::CYCLES48 => 48, |
| 376 | SampleTime::Cycles96 => 96, | 371 | SampleTime::CYCLES96 => 96, |
| 377 | SampleTime::Cycles192 => 192, | 372 | SampleTime::CYCLES192 => 192, |
| 378 | SampleTime::Cycles384 => 384, | 373 | SampleTime::CYCLES384 => 384, |
| 379 | } | 374 | } |
| 380 | } | 375 | } |
| 381 | 376 | ||
| @@ -384,14 +379,14 @@ impl<'d, T: Instance> Adc<'d, T> { | |||
| 384 | let us_clks = us * Self::freq().0 / 1_000_000; | 379 | let us_clks = us * Self::freq().0 / 1_000_000; |
| 385 | let clks = us_clks.saturating_sub(res_clks); | 380 | let clks = us_clks.saturating_sub(res_clks); |
| 386 | match clks { | 381 | match clks { |
| 387 | 0..=4 => SampleTime::Cycles4, | 382 | 0..=4 => SampleTime::CYCLES4, |
| 388 | 5..=9 => SampleTime::Cycles9, | 383 | 5..=9 => SampleTime::CYCLES9, |
| 389 | 10..=16 => SampleTime::Cycles16, | 384 | 10..=16 => SampleTime::CYCLES16, |
| 390 | 17..=24 => SampleTime::Cycles24, | 385 | 17..=24 => SampleTime::CYCLES24, |
| 391 | 25..=48 => SampleTime::Cycles48, | 386 | 25..=48 => SampleTime::CYCLES48, |
| 392 | 49..=96 => SampleTime::Cycles96, | 387 | 49..=96 => SampleTime::CYCLES96, |
| 393 | 97..=192 => SampleTime::Cycles192, | 388 | 97..=192 => SampleTime::CYCLES192, |
| 394 | 193.. => SampleTime::Cycles384, | 389 | 193.. => SampleTime::CYCLES384, |
| 395 | } | 390 | } |
| 396 | } | 391 | } |
| 397 | 392 | ||
diff --git a/embassy-stm32/src/adc/mod.rs b/embassy-stm32/src/adc/mod.rs index 51b4b5fcc..0d0d40549 100644 --- a/embassy-stm32/src/adc/mod.rs +++ b/embassy-stm32/src/adc/mod.rs | |||
| @@ -10,22 +10,17 @@ | |||
| 10 | #[cfg_attr(adc_v1, path = "v1.rs")] | 10 | #[cfg_attr(adc_v1, path = "v1.rs")] |
| 11 | #[cfg_attr(adc_l0, path = "v1.rs")] | 11 | #[cfg_attr(adc_l0, path = "v1.rs")] |
| 12 | #[cfg_attr(adc_v2, path = "v2.rs")] | 12 | #[cfg_attr(adc_v2, path = "v2.rs")] |
| 13 | #[cfg_attr(any(adc_v3, adc_g0), path = "v3.rs")] | 13 | #[cfg_attr(any(adc_v3, adc_g0, adc_h5), path = "v3.rs")] |
| 14 | #[cfg_attr(adc_v4, path = "v4.rs")] | 14 | #[cfg_attr(adc_v4, path = "v4.rs")] |
| 15 | mod _version; | 15 | mod _version; |
| 16 | 16 | ||
| 17 | #[cfg(not(any(adc_f1, adc_f3_v2)))] | ||
| 18 | mod resolution; | ||
| 19 | mod sample_time; | ||
| 20 | |||
| 21 | #[allow(unused)] | 17 | #[allow(unused)] |
| 22 | #[cfg(not(adc_f3_v2))] | 18 | #[cfg(not(adc_f3_v2))] |
| 23 | pub use _version::*; | 19 | pub use _version::*; |
| 24 | #[cfg(not(any(adc_f1, adc_f3, adc_f3_v2)))] | ||
| 25 | pub use resolution::Resolution; | ||
| 26 | #[cfg(not(adc_f3_v2))] | ||
| 27 | pub use sample_time::SampleTime; | ||
| 28 | 20 | ||
| 21 | #[cfg(not(any(adc_f1, adc_f3_v2)))] | ||
| 22 | pub use crate::pac::adc::vals::Res as Resolution; | ||
| 23 | pub use crate::pac::adc::vals::SampleTime; | ||
| 29 | use crate::peripherals; | 24 | use crate::peripherals; |
| 30 | 25 | ||
| 31 | /// Analog to Digital driver. | 26 | /// Analog to Digital driver. |
| @@ -79,10 +74,10 @@ pub(crate) mod sealed { | |||
| 79 | } | 74 | } |
| 80 | 75 | ||
| 81 | /// ADC instance. | 76 | /// ADC instance. |
| 82 | #[cfg(not(any(adc_f1, adc_v1, adc_l0, adc_v2, adc_v3, adc_v4, adc_f3, adc_f3_v1_1, adc_g0)))] | 77 | #[cfg(not(any(adc_f1, adc_v1, adc_l0, adc_v2, adc_v3, adc_v4, adc_f3, adc_f3_v1_1, adc_g0, adc_h5)))] |
| 83 | pub trait Instance: sealed::Instance + crate::Peripheral<P = Self> {} | 78 | pub trait Instance: sealed::Instance + crate::Peripheral<P = Self> {} |
| 84 | /// ADC instance. | 79 | /// ADC instance. |
| 85 | #[cfg(any(adc_f1, adc_v1, adc_l0, adc_v2, adc_v3, adc_v4, adc_f3, adc_f3_v1_1, adc_g0))] | 80 | #[cfg(any(adc_f1, adc_v1, adc_l0, adc_v2, adc_v3, adc_v4, adc_f3, adc_f3_v1_1, adc_g0, adc_h5))] |
| 86 | pub trait Instance: sealed::Instance + crate::Peripheral<P = Self> + crate::rcc::RccPeripheral {} | 81 | pub trait Instance: sealed::Instance + crate::Peripheral<P = Self> + crate::rcc::RccPeripheral {} |
| 87 | 82 | ||
| 88 | /// ADC pin. | 83 | /// ADC pin. |
| @@ -137,3 +132,27 @@ macro_rules! impl_adc_pin { | |||
| 137 | } | 132 | } |
| 138 | }; | 133 | }; |
| 139 | } | 134 | } |
| 135 | |||
| 136 | /// Get the maximum reading value for this resolution. | ||
| 137 | /// | ||
| 138 | /// This is `2**n - 1`. | ||
| 139 | #[cfg(not(any(adc_f1, adc_f3_v2)))] | ||
| 140 | pub const fn resolution_to_max_count(res: Resolution) -> u32 { | ||
| 141 | match res { | ||
| 142 | #[cfg(adc_v4)] | ||
| 143 | Resolution::BITS16 => (1 << 16) - 1, | ||
| 144 | #[cfg(adc_v4)] | ||
| 145 | Resolution::BITS14 => (1 << 14) - 1, | ||
| 146 | #[cfg(adc_v4)] | ||
| 147 | Resolution::BITS14V => (1 << 14) - 1, | ||
| 148 | #[cfg(adc_v4)] | ||
| 149 | Resolution::BITS12V => (1 << 12) - 1, | ||
| 150 | Resolution::BITS12 => (1 << 12) - 1, | ||
| 151 | Resolution::BITS10 => (1 << 10) - 1, | ||
| 152 | Resolution::BITS8 => (1 << 8) - 1, | ||
| 153 | #[cfg(any(adc_v1, adc_v2, adc_v3, adc_l0, adc_g0, adc_f3, adc_f3_v1_1, adc_h5))] | ||
| 154 | Resolution::BITS6 => (1 << 6) - 1, | ||
| 155 | #[allow(unreachable_patterns)] | ||
| 156 | _ => core::unreachable!(), | ||
| 157 | } | ||
| 158 | } | ||
diff --git a/embassy-stm32/src/adc/resolution.rs b/embassy-stm32/src/adc/resolution.rs deleted file mode 100644 index 0e6c45c65..000000000 --- a/embassy-stm32/src/adc/resolution.rs +++ /dev/null | |||
| @@ -1,72 +0,0 @@ | |||
| 1 | /// ADC resolution | ||
| 2 | #[allow(missing_docs)] | ||
| 3 | #[cfg(any(adc_v1, adc_v2, adc_v3, adc_l0, adc_g0, adc_f3, adc_f3_v1_1))] | ||
| 4 | #[derive(Clone, Copy, Debug, Eq, PartialEq)] | ||
| 5 | #[cfg_attr(feature = "defmt", derive(defmt::Format))] | ||
| 6 | pub enum Resolution { | ||
| 7 | TwelveBit, | ||
| 8 | TenBit, | ||
| 9 | EightBit, | ||
| 10 | SixBit, | ||
| 11 | } | ||
| 12 | |||
| 13 | /// ADC resolution | ||
| 14 | #[allow(missing_docs)] | ||
| 15 | #[cfg(adc_v4)] | ||
| 16 | #[derive(Clone, Copy, Debug, Eq, PartialEq)] | ||
| 17 | #[cfg_attr(feature = "defmt", derive(defmt::Format))] | ||
| 18 | pub enum Resolution { | ||
| 19 | SixteenBit, | ||
| 20 | FourteenBit, | ||
| 21 | TwelveBit, | ||
| 22 | TenBit, | ||
| 23 | EightBit, | ||
| 24 | } | ||
| 25 | |||
| 26 | impl Default for Resolution { | ||
| 27 | fn default() -> Self { | ||
| 28 | #[cfg(any(adc_v1, adc_v2, adc_v3, adc_l0, adc_g0, adc_f3, adc_f3_v1_1))] | ||
| 29 | { | ||
| 30 | Self::TwelveBit | ||
| 31 | } | ||
| 32 | #[cfg(adc_v4)] | ||
| 33 | { | ||
| 34 | Self::SixteenBit | ||
| 35 | } | ||
| 36 | } | ||
| 37 | } | ||
| 38 | |||
| 39 | impl From<Resolution> for crate::pac::adc::vals::Res { | ||
| 40 | fn from(res: Resolution) -> crate::pac::adc::vals::Res { | ||
| 41 | match res { | ||
| 42 | #[cfg(adc_v4)] | ||
| 43 | Resolution::SixteenBit => crate::pac::adc::vals::Res::SIXTEENBIT, | ||
| 44 | #[cfg(adc_v4)] | ||
| 45 | Resolution::FourteenBit => crate::pac::adc::vals::Res::FOURTEENBITV, | ||
| 46 | Resolution::TwelveBit => crate::pac::adc::vals::Res::TWELVEBIT, | ||
| 47 | Resolution::TenBit => crate::pac::adc::vals::Res::TENBIT, | ||
| 48 | Resolution::EightBit => crate::pac::adc::vals::Res::EIGHTBIT, | ||
| 49 | #[cfg(any(adc_v1, adc_v2, adc_v3, adc_l0, adc_g0, adc_f3, adc_f3_v1_1))] | ||
| 50 | Resolution::SixBit => crate::pac::adc::vals::Res::SIXBIT, | ||
| 51 | } | ||
| 52 | } | ||
| 53 | } | ||
| 54 | |||
| 55 | impl Resolution { | ||
| 56 | /// Get the maximum reading value for this resolution. | ||
| 57 | /// | ||
| 58 | /// This is `2**n - 1`. | ||
| 59 | pub const fn to_max_count(&self) -> u32 { | ||
| 60 | match self { | ||
| 61 | #[cfg(adc_v4)] | ||
| 62 | Resolution::SixteenBit => (1 << 16) - 1, | ||
| 63 | #[cfg(adc_v4)] | ||
| 64 | Resolution::FourteenBit => (1 << 14) - 1, | ||
| 65 | Resolution::TwelveBit => (1 << 12) - 1, | ||
| 66 | Resolution::TenBit => (1 << 10) - 1, | ||
| 67 | Resolution::EightBit => (1 << 8) - 1, | ||
| 68 | #[cfg(any(adc_v1, adc_v2, adc_v3, adc_l0, adc_g0, adc_f3, adc_f3_v1_1))] | ||
| 69 | Resolution::SixBit => (1 << 6) - 1, | ||
| 70 | } | ||
| 71 | } | ||
| 72 | } | ||
diff --git a/embassy-stm32/src/adc/sample_time.rs b/embassy-stm32/src/adc/sample_time.rs deleted file mode 100644 index f4b22b462..000000000 --- a/embassy-stm32/src/adc/sample_time.rs +++ /dev/null | |||
| @@ -1,148 +0,0 @@ | |||
| 1 | #[cfg(not(adc_f3_v2))] | ||
| 2 | macro_rules! impl_sample_time { | ||
| 3 | ($default_doc:expr, $default:ident, ($(($doc:expr, $variant:ident, $pac_variant:ident)),*)) => { | ||
| 4 | #[doc = concat!("ADC sample time\n\nThe default setting is ", $default_doc, " ADC clock cycles.")] | ||
| 5 | #[derive(Clone, Copy, Debug, Eq, PartialEq, Ord, PartialOrd)] | ||
| 6 | #[cfg_attr(feature = "defmt", derive(defmt::Format))] | ||
| 7 | pub enum SampleTime { | ||
| 8 | $( | ||
| 9 | #[doc = concat!($doc, " ADC clock cycles.")] | ||
| 10 | $variant, | ||
| 11 | )* | ||
| 12 | } | ||
| 13 | |||
| 14 | impl From<SampleTime> for crate::pac::adc::vals::SampleTime { | ||
| 15 | fn from(sample_time: SampleTime) -> crate::pac::adc::vals::SampleTime { | ||
| 16 | match sample_time { | ||
| 17 | $(SampleTime::$variant => crate::pac::adc::vals::SampleTime::$pac_variant),* | ||
| 18 | } | ||
| 19 | } | ||
| 20 | } | ||
| 21 | |||
| 22 | impl From<crate::pac::adc::vals::SampleTime> for SampleTime { | ||
| 23 | fn from(sample_time: crate::pac::adc::vals::SampleTime) -> SampleTime { | ||
| 24 | match sample_time { | ||
| 25 | $(crate::pac::adc::vals::SampleTime::$pac_variant => SampleTime::$variant),* | ||
| 26 | } | ||
| 27 | } | ||
| 28 | } | ||
| 29 | |||
| 30 | impl Default for SampleTime { | ||
| 31 | fn default() -> Self { | ||
| 32 | Self::$default | ||
| 33 | } | ||
| 34 | } | ||
| 35 | }; | ||
| 36 | } | ||
| 37 | |||
| 38 | #[cfg(any(adc_f1, adc_v1))] | ||
| 39 | impl_sample_time!( | ||
| 40 | "1.5", | ||
| 41 | Cycles1_5, | ||
| 42 | ( | ||
| 43 | ("1.5", Cycles1_5, CYCLES1_5), | ||
| 44 | ("7.5", Cycles7_5, CYCLES7_5), | ||
| 45 | ("13.5", Cycles13_5, CYCLES13_5), | ||
| 46 | ("28.5", Cycles28_5, CYCLES28_5), | ||
| 47 | ("41.5", Cycles41_5, CYCLES41_5), | ||
| 48 | ("55.5", Cycles55_5, CYCLES55_5), | ||
| 49 | ("71.5", Cycles71_5, CYCLES71_5), | ||
| 50 | ("239.5", Cycles239_5, CYCLES239_5) | ||
| 51 | ) | ||
| 52 | ); | ||
| 53 | |||
| 54 | #[cfg(adc_v2)] | ||
| 55 | impl_sample_time!( | ||
| 56 | "3", | ||
| 57 | Cycles3, | ||
| 58 | ( | ||
| 59 | ("3", Cycles3, CYCLES3), | ||
| 60 | ("15", Cycles15, CYCLES15), | ||
| 61 | ("28", Cycles28, CYCLES28), | ||
| 62 | ("56", Cycles56, CYCLES56), | ||
| 63 | ("84", Cycles84, CYCLES84), | ||
| 64 | ("112", Cycles112, CYCLES112), | ||
| 65 | ("144", Cycles144, CYCLES144), | ||
| 66 | ("480", Cycles480, CYCLES480) | ||
| 67 | ) | ||
| 68 | ); | ||
| 69 | |||
| 70 | #[cfg(adc_v3)] | ||
| 71 | impl_sample_time!( | ||
| 72 | "2.5", | ||
| 73 | Cycles2_5, | ||
| 74 | ( | ||
| 75 | ("2.5", Cycles2_5, CYCLES2_5), | ||
| 76 | ("6.5", Cycles6_5, CYCLES6_5), | ||
| 77 | ("12.5", Cycles12_5, CYCLES12_5), | ||
| 78 | ("24.5", Cycles24_5, CYCLES24_5), | ||
| 79 | ("47.5", Cycles47_5, CYCLES47_5), | ||
| 80 | ("92.5", Cycles92_5, CYCLES92_5), | ||
| 81 | ("247.5", Cycles247_5, CYCLES247_5), | ||
| 82 | ("640.5", Cycles640_5, CYCLES640_5) | ||
| 83 | ) | ||
| 84 | ); | ||
| 85 | |||
| 86 | #[cfg(any(adc_l0, adc_g0))] | ||
| 87 | impl_sample_time!( | ||
| 88 | "1.5", | ||
| 89 | Cycles1_5, | ||
| 90 | ( | ||
| 91 | ("1.5", Cycles1_5, CYCLES1_5), | ||
| 92 | ("3.5", Cycles3_5, CYCLES3_5), | ||
| 93 | ("7.5", Cycles7_5, CYCLES7_5), | ||
| 94 | ("12.5", Cycles12_5, CYCLES12_5), | ||
| 95 | ("19.5", Cycles19_5, CYCLES19_5), | ||
| 96 | ("39.5", Cycles39_5, CYCLES39_5), | ||
| 97 | ("79.5", Cycles79_5, CYCLES79_5), | ||
| 98 | ("160.5", Cycles160_5, CYCLES160_5) | ||
| 99 | ) | ||
| 100 | ); | ||
| 101 | |||
| 102 | #[cfg(adc_v4)] | ||
| 103 | impl_sample_time!( | ||
| 104 | "1.5", | ||
| 105 | Cycles1_5, | ||
| 106 | ( | ||
| 107 | ("1.5", Cycles1_5, CYCLES1_5), | ||
| 108 | ("2.5", Cycles2_5, CYCLES2_5), | ||
| 109 | ("8.5", Cycles8_5, CYCLES8_5), | ||
| 110 | ("16.5", Cycles16_5, CYCLES16_5), | ||
| 111 | ("32.5", Cycles32_5, CYCLES32_5), | ||
| 112 | ("64.5", Cycles64_5, CYCLES64_5), | ||
| 113 | ("387.5", Cycles387_5, CYCLES387_5), | ||
| 114 | ("810.5", Cycles810_5, CYCLES810_5) | ||
| 115 | ) | ||
| 116 | ); | ||
| 117 | |||
| 118 | #[cfg(adc_f3)] | ||
| 119 | impl_sample_time!( | ||
| 120 | "1.5", | ||
| 121 | Cycles1_5, | ||
| 122 | ( | ||
| 123 | ("1.5", Cycles1_5, CYCLES1_5), | ||
| 124 | ("2.5", Cycles2_5, CYCLES2_5), | ||
| 125 | ("4.5", Cycles4_5, CYCLES4_5), | ||
| 126 | ("7.5", Cycles7_5, CYCLES7_5), | ||
| 127 | ("19.5", Cycles19_5, CYCLES19_5), | ||
| 128 | ("61.5", Cycles61_5, CYCLES61_5), | ||
| 129 | ("181.5", Cycles181_5, CYCLES181_5), | ||
| 130 | ("601.5", Cycles601_5, CYCLES601_5) | ||
| 131 | ) | ||
| 132 | ); | ||
| 133 | |||
| 134 | #[cfg(any(adc_f3_v1_1))] | ||
| 135 | impl_sample_time!( | ||
| 136 | "4", | ||
| 137 | Cycles4, | ||
| 138 | ( | ||
| 139 | ("4", Cycles4, CYCLES4), | ||
| 140 | ("9", Cycles9, CYCLES9), | ||
| 141 | ("16", Cycles16, CYCLES16), | ||
| 142 | ("24", Cycles24, CYCLES24), | ||
| 143 | ("48", Cycles48, CYCLES48), | ||
| 144 | ("96", Cycles96, CYCLES96), | ||
| 145 | ("192", Cycles192, CYCLES192), | ||
| 146 | ("384", Cycles384, CYCLES384) | ||
| 147 | ) | ||
| 148 | ); | ||
diff --git a/embassy-stm32/src/adc/v1.rs b/embassy-stm32/src/adc/v1.rs index 37115dfab..a8dc6ce98 100644 --- a/embassy-stm32/src/adc/v1.rs +++ b/embassy-stm32/src/adc/v1.rs | |||
| @@ -109,7 +109,7 @@ impl<'d, T: Instance> Adc<'d, T> { | |||
| 109 | 109 | ||
| 110 | Self { | 110 | Self { |
| 111 | adc, | 111 | adc, |
| 112 | sample_time: Default::default(), | 112 | sample_time: SampleTime::from_bits(0), |
| 113 | } | 113 | } |
| 114 | } | 114 | } |
| 115 | 115 | ||
diff --git a/embassy-stm32/src/adc/v2.rs b/embassy-stm32/src/adc/v2.rs index b37ac5a5d..f6f7dbfcc 100644 --- a/embassy-stm32/src/adc/v2.rs +++ b/embassy-stm32/src/adc/v2.rs | |||
| @@ -111,7 +111,7 @@ where | |||
| 111 | 111 | ||
| 112 | Self { | 112 | Self { |
| 113 | adc, | 113 | adc, |
| 114 | sample_time: Default::default(), | 114 | sample_time: SampleTime::from_bits(0), |
| 115 | } | 115 | } |
| 116 | } | 116 | } |
| 117 | 117 | ||
diff --git a/embassy-stm32/src/adc/v3.rs b/embassy-stm32/src/adc/v3.rs index 281a99f72..5f3512cad 100644 --- a/embassy-stm32/src/adc/v3.rs +++ b/embassy-stm32/src/adc/v3.rs | |||
| @@ -1,3 +1,4 @@ | |||
| 1 | use cfg_if::cfg_if; | ||
| 1 | use embassy_hal_internal::into_ref; | 2 | use embassy_hal_internal::into_ref; |
| 2 | use embedded_hal_02::blocking::delay::DelayUs; | 3 | use embedded_hal_02::blocking::delay::DelayUs; |
| 3 | 4 | ||
| @@ -13,10 +14,15 @@ pub struct VrefInt; | |||
| 13 | impl<T: Instance> AdcPin<T> for VrefInt {} | 14 | impl<T: Instance> AdcPin<T> for VrefInt {} |
| 14 | impl<T: Instance> super::sealed::AdcPin<T> for VrefInt { | 15 | impl<T: Instance> super::sealed::AdcPin<T> for VrefInt { |
| 15 | fn channel(&self) -> u8 { | 16 | fn channel(&self) -> u8 { |
| 16 | #[cfg(not(adc_g0))] | 17 | cfg_if! { |
| 17 | let val = 0; | 18 | if #[cfg(adc_g0)] { |
| 18 | #[cfg(adc_g0)] | 19 | let val = 13; |
| 19 | let val = 13; | 20 | } else if #[cfg(adc_h5)] { |
| 21 | let val = 17; | ||
| 22 | } else { | ||
| 23 | let val = 0; | ||
| 24 | } | ||
| 25 | } | ||
| 20 | val | 26 | val |
| 21 | } | 27 | } |
| 22 | } | 28 | } |
| @@ -25,10 +31,15 @@ pub struct Temperature; | |||
| 25 | impl<T: Instance> AdcPin<T> for Temperature {} | 31 | impl<T: Instance> AdcPin<T> for Temperature {} |
| 26 | impl<T: Instance> super::sealed::AdcPin<T> for Temperature { | 32 | impl<T: Instance> super::sealed::AdcPin<T> for Temperature { |
| 27 | fn channel(&self) -> u8 { | 33 | fn channel(&self) -> u8 { |
| 28 | #[cfg(not(adc_g0))] | 34 | cfg_if! { |
| 29 | let val = 17; | 35 | if #[cfg(adc_g0)] { |
| 30 | #[cfg(adc_g0)] | 36 | let val = 12; |
| 31 | let val = 12; | 37 | } else if #[cfg(adc_h5)] { |
| 38 | let val = 16; | ||
| 39 | } else { | ||
| 40 | let val = 17; | ||
| 41 | } | ||
| 42 | } | ||
| 32 | val | 43 | val |
| 33 | } | 44 | } |
| 34 | } | 45 | } |
| @@ -37,14 +48,31 @@ pub struct Vbat; | |||
| 37 | impl<T: Instance> AdcPin<T> for Vbat {} | 48 | impl<T: Instance> AdcPin<T> for Vbat {} |
| 38 | impl<T: Instance> super::sealed::AdcPin<T> for Vbat { | 49 | impl<T: Instance> super::sealed::AdcPin<T> for Vbat { |
| 39 | fn channel(&self) -> u8 { | 50 | fn channel(&self) -> u8 { |
| 40 | #[cfg(not(adc_g0))] | 51 | cfg_if! { |
| 41 | let val = 18; | 52 | if #[cfg(adc_g0)] { |
| 42 | #[cfg(adc_g0)] | 53 | let val = 14; |
| 43 | let val = 14; | 54 | } else if #[cfg(adc_h5)] { |
| 55 | let val = 2; | ||
| 56 | } else { | ||
| 57 | let val = 18; | ||
| 58 | } | ||
| 59 | } | ||
| 44 | val | 60 | val |
| 45 | } | 61 | } |
| 46 | } | 62 | } |
| 47 | 63 | ||
| 64 | cfg_if! { | ||
| 65 | if #[cfg(adc_h5)] { | ||
| 66 | pub struct VddCore; | ||
| 67 | impl<T: Instance> AdcPin<T> for VddCore {} | ||
| 68 | impl<T: Instance> super::sealed::AdcPin<T> for VddCore { | ||
| 69 | fn channel(&self) -> u8 { | ||
| 70 | 6 | ||
| 71 | } | ||
| 72 | } | ||
| 73 | } | ||
| 74 | } | ||
| 75 | |||
| 48 | impl<'d, T: Instance> Adc<'d, T> { | 76 | impl<'d, T: Instance> Adc<'d, T> { |
| 49 | pub fn new(adc: impl Peripheral<P = T> + 'd, delay: &mut impl DelayUs<u32>) -> Self { | 77 | pub fn new(adc: impl Peripheral<P = T> + 'd, delay: &mut impl DelayUs<u32>) -> Self { |
| 50 | into_ref!(adc); | 78 | into_ref!(adc); |
| @@ -74,7 +102,7 @@ impl<'d, T: Instance> Adc<'d, T> { | |||
| 74 | 102 | ||
| 75 | Self { | 103 | Self { |
| 76 | adc, | 104 | adc, |
| 77 | sample_time: Default::default(), | 105 | sample_time: SampleTime::from_bits(0), |
| 78 | } | 106 | } |
| 79 | } | 107 | } |
| 80 | 108 | ||
| @@ -98,27 +126,41 @@ impl<'d, T: Instance> Adc<'d, T> { | |||
| 98 | } | 126 | } |
| 99 | 127 | ||
| 100 | pub fn enable_temperature(&self) -> Temperature { | 128 | pub fn enable_temperature(&self) -> Temperature { |
| 101 | #[cfg(not(adc_g0))] | 129 | cfg_if! { |
| 102 | T::common_regs().ccr().modify(|reg| { | 130 | if #[cfg(adc_g0)] { |
| 103 | reg.set_ch17sel(true); | 131 | T::regs().ccr().modify(|reg| { |
| 104 | }); | 132 | reg.set_tsen(true); |
| 105 | #[cfg(adc_g0)] | 133 | }); |
| 106 | T::regs().ccr().modify(|reg| { | 134 | } else if #[cfg(adc_h5)] { |
| 107 | reg.set_tsen(true); | 135 | T::common_regs().ccr().modify(|reg| { |
| 108 | }); | 136 | reg.set_tsen(true); |
| 137 | }); | ||
| 138 | } else { | ||
| 139 | T::common_regs().ccr().modify(|reg| { | ||
| 140 | reg.set_ch17sel(true); | ||
| 141 | }); | ||
| 142 | } | ||
| 143 | } | ||
| 109 | 144 | ||
| 110 | Temperature {} | 145 | Temperature {} |
| 111 | } | 146 | } |
| 112 | 147 | ||
| 113 | pub fn enable_vbat(&self) -> Vbat { | 148 | pub fn enable_vbat(&self) -> Vbat { |
| 114 | #[cfg(not(adc_g0))] | 149 | cfg_if! { |
| 115 | T::common_regs().ccr().modify(|reg| { | 150 | if #[cfg(adc_g0)] { |
| 116 | reg.set_ch18sel(true); | 151 | T::regs().ccr().modify(|reg| { |
| 117 | }); | 152 | reg.set_vbaten(true); |
| 118 | #[cfg(adc_g0)] | 153 | }); |
| 119 | T::regs().ccr().modify(|reg| { | 154 | } else if #[cfg(adc_h5)] { |
| 120 | reg.set_vbaten(true); | 155 | T::common_regs().ccr().modify(|reg| { |
| 121 | }); | 156 | reg.set_vbaten(true); |
| 157 | }); | ||
| 158 | } else { | ||
| 159 | T::common_regs().ccr().modify(|reg| { | ||
| 160 | reg.set_ch18sel(true); | ||
| 161 | }); | ||
| 162 | } | ||
| 163 | } | ||
| 122 | 164 | ||
| 123 | Vbat {} | 165 | Vbat {} |
| 124 | } | 166 | } |
| @@ -205,16 +247,21 @@ impl<'d, T: Instance> Adc<'d, T> { | |||
| 205 | val | 247 | val |
| 206 | } | 248 | } |
| 207 | 249 | ||
| 208 | #[cfg(adc_g0)] | ||
| 209 | fn set_channel_sample_time(_ch: u8, sample_time: SampleTime) { | 250 | fn set_channel_sample_time(_ch: u8, sample_time: SampleTime) { |
| 210 | T::regs().smpr().modify(|reg| reg.set_smp1(sample_time.into())); | 251 | cfg_if! { |
| 211 | } | 252 | if #[cfg(adc_g0)] { |
| 212 | 253 | T::regs().smpr().modify(|reg| reg.set_smp1(sample_time.into())); | |
| 213 | #[cfg(not(adc_g0))] | 254 | } else if #[cfg(adc_h5)] { |
| 214 | fn set_channel_sample_time(ch: u8, sample_time: SampleTime) { | 255 | match _ch { |
| 215 | let sample_time = sample_time.into(); | 256 | 0..=9 => T::regs().smpr1().modify(|w| w.set_smp(_ch as usize % 10, sample_time.into())), |
| 216 | T::regs() | 257 | _ => T::regs().smpr2().modify(|w| w.set_smp(_ch as usize % 10, sample_time.into())), |
| 217 | .smpr(ch as usize / 10) | 258 | } |
| 218 | .modify(|reg| reg.set_smp(ch as usize % 10, sample_time)); | 259 | } else { |
| 260 | let sample_time = sample_time.into(); | ||
| 261 | T::regs() | ||
| 262 | .smpr(_ch as usize / 10) | ||
| 263 | .modify(|reg| reg.set_smp(_ch as usize % 10, sample_time)); | ||
| 264 | } | ||
| 265 | } | ||
| 219 | } | 266 | } |
| 220 | } | 267 | } |
diff --git a/embassy-stm32/src/adc/v4.rs b/embassy-stm32/src/adc/v4.rs index 048e73184..3fd047375 100644 --- a/embassy-stm32/src/adc/v4.rs +++ b/embassy-stm32/src/adc/v4.rs | |||
| @@ -159,7 +159,7 @@ impl<'d, T: Instance> Adc<'d, T> { | |||
| 159 | } | 159 | } |
| 160 | let mut s = Self { | 160 | let mut s = Self { |
| 161 | adc, | 161 | adc, |
| 162 | sample_time: Default::default(), | 162 | sample_time: SampleTime::from_bits(0), |
| 163 | }; | 163 | }; |
| 164 | s.power_up(delay); | 164 | s.power_up(delay); |
| 165 | s.configure_differential_inputs(); | 165 | s.configure_differential_inputs(); |
diff --git a/embassy-stm32/src/fmc.rs b/embassy-stm32/src/fmc.rs index 873c8a70c..9d731a512 100644 --- a/embassy-stm32/src/fmc.rs +++ b/embassy-stm32/src/fmc.rs | |||
| @@ -36,8 +36,10 @@ where | |||
| 36 | // fmc v1 and v2 does not have the fmcen bit | 36 | // fmc v1 and v2 does not have the fmcen bit |
| 37 | // fsmc v1, v2 and v3 does not have the fmcen bit | 37 | // fsmc v1, v2 and v3 does not have the fmcen bit |
| 38 | // This is a "not" because it is expected that all future versions have this bit | 38 | // This is a "not" because it is expected that all future versions have this bit |
| 39 | #[cfg(not(any(fmc_v1x3, fmc_v2x1, fsmc_v1x0, fsmc_v1x3, fsmc_v2x3, fsmc_v3x1)))] | 39 | #[cfg(not(any(fmc_v1x3, fmc_v2x1, fsmc_v1x0, fsmc_v1x3, fsmc_v2x3, fsmc_v3x1, fmc_v4)))] |
| 40 | T::REGS.bcr1().modify(|r| r.set_fmcen(true)); | 40 | T::REGS.bcr1().modify(|r| r.set_fmcen(true)); |
| 41 | #[cfg(any(fmc_v4))] | ||
| 42 | T::REGS.nor_psram().bcr1().modify(|r| r.set_fmcen(true)); | ||
| 41 | } | 43 | } |
| 42 | 44 | ||
| 43 | /// Get the kernel clock currently in use for this FMC instance. | 45 | /// Get the kernel clock currently in use for this FMC instance. |
| @@ -60,8 +62,10 @@ where | |||
| 60 | // fmc v1 and v2 does not have the fmcen bit | 62 | // fmc v1 and v2 does not have the fmcen bit |
| 61 | // fsmc v1, v2 and v3 does not have the fmcen bit | 63 | // fsmc v1, v2 and v3 does not have the fmcen bit |
| 62 | // This is a "not" because it is expected that all future versions have this bit | 64 | // This is a "not" because it is expected that all future versions have this bit |
| 63 | #[cfg(not(any(fmc_v1x3, fmc_v2x1, fsmc_v1x0, fsmc_v1x3, fsmc_v2x3, fsmc_v3x1)))] | 65 | #[cfg(not(any(fmc_v1x3, fmc_v2x1, fsmc_v1x0, fsmc_v1x3, fsmc_v2x3, fsmc_v3x1, fmc_v4)))] |
| 64 | T::REGS.bcr1().modify(|r| r.set_fmcen(true)); | 66 | T::REGS.bcr1().modify(|r| r.set_fmcen(true)); |
| 67 | #[cfg(any(fmc_v4))] | ||
| 68 | T::REGS.nor_psram().bcr1().modify(|r| r.set_fmcen(true)); | ||
| 65 | } | 69 | } |
| 66 | 70 | ||
| 67 | fn source_clock_hz(&self) -> u32 { | 71 | fn source_clock_hz(&self) -> u32 { |
diff --git a/embassy-stm32/src/i2s.rs b/embassy-stm32/src/i2s.rs index e9065dce6..fa9ec0532 100644 --- a/embassy-stm32/src/i2s.rs +++ b/embassy-stm32/src/i2s.rs | |||
| @@ -79,20 +79,20 @@ impl Format { | |||
| 79 | #[cfg(any(spi_v1, spi_f1))] | 79 | #[cfg(any(spi_v1, spi_f1))] |
| 80 | const fn datlen(&self) -> vals::Datlen { | 80 | const fn datlen(&self) -> vals::Datlen { |
| 81 | match self { | 81 | match self { |
| 82 | Format::Data16Channel16 => vals::Datlen::SIXTEENBIT, | 82 | Format::Data16Channel16 => vals::Datlen::BITS16, |
| 83 | Format::Data16Channel32 => vals::Datlen::SIXTEENBIT, | 83 | Format::Data16Channel32 => vals::Datlen::BITS16, |
| 84 | Format::Data24Channel32 => vals::Datlen::TWENTYFOURBIT, | 84 | Format::Data24Channel32 => vals::Datlen::BITS24, |
| 85 | Format::Data32Channel32 => vals::Datlen::THIRTYTWOBIT, | 85 | Format::Data32Channel32 => vals::Datlen::BITS32, |
| 86 | } | 86 | } |
| 87 | } | 87 | } |
| 88 | 88 | ||
| 89 | #[cfg(any(spi_v1, spi_f1))] | 89 | #[cfg(any(spi_v1, spi_f1))] |
| 90 | const fn chlen(&self) -> vals::Chlen { | 90 | const fn chlen(&self) -> vals::Chlen { |
| 91 | match self { | 91 | match self { |
| 92 | Format::Data16Channel16 => vals::Chlen::SIXTEENBIT, | 92 | Format::Data16Channel16 => vals::Chlen::BITS16, |
| 93 | Format::Data16Channel32 => vals::Chlen::THIRTYTWOBIT, | 93 | Format::Data16Channel32 => vals::Chlen::BITS32, |
| 94 | Format::Data24Channel32 => vals::Chlen::THIRTYTWOBIT, | 94 | Format::Data24Channel32 => vals::Chlen::BITS32, |
| 95 | Format::Data32Channel32 => vals::Chlen::THIRTYTWOBIT, | 95 | Format::Data32Channel32 => vals::Chlen::BITS32, |
| 96 | } | 96 | } |
| 97 | } | 97 | } |
| 98 | } | 98 | } |
diff --git a/embassy-stm32/src/lib.rs b/embassy-stm32/src/lib.rs index cd1ede0fa..15798e115 100644 --- a/embassy-stm32/src/lib.rs +++ b/embassy-stm32/src/lib.rs | |||
| @@ -216,6 +216,11 @@ pub fn init(config: Config) -> Peripherals { | |||
| 216 | 216 | ||
| 217 | #[cfg(dbgmcu)] | 217 | #[cfg(dbgmcu)] |
| 218 | crate::pac::DBGMCU.cr().modify(|cr| { | 218 | crate::pac::DBGMCU.cr().modify(|cr| { |
| 219 | #[cfg(any(dbgmcu_h5))] | ||
| 220 | { | ||
| 221 | cr.set_stop(config.enable_debug_during_sleep); | ||
| 222 | cr.set_standby(config.enable_debug_during_sleep); | ||
| 223 | } | ||
| 219 | #[cfg(any(dbgmcu_f0, dbgmcu_c0, dbgmcu_g0, dbgmcu_u5, dbgmcu_wba, dbgmcu_l5))] | 224 | #[cfg(any(dbgmcu_f0, dbgmcu_c0, dbgmcu_g0, dbgmcu_u5, dbgmcu_wba, dbgmcu_l5))] |
| 220 | { | 225 | { |
| 221 | cr.set_dbg_stop(config.enable_debug_during_sleep); | 226 | cr.set_dbg_stop(config.enable_debug_during_sleep); |
diff --git a/embassy-stm32/src/rcc/f013.rs b/embassy-stm32/src/rcc/f013.rs index de209272d..5046f0a3a 100644 --- a/embassy-stm32/src/rcc/f013.rs +++ b/embassy-stm32/src/rcc/f013.rs | |||
| @@ -209,6 +209,9 @@ pub(crate) unsafe fn init(config: Config) { | |||
| 209 | out_freq | 209 | out_freq |
| 210 | }); | 210 | }); |
| 211 | 211 | ||
| 212 | #[cfg(stm32f3)] | ||
| 213 | let pll_mul_2 = pll.map(|pll| pll * 2u32); | ||
| 214 | |||
| 212 | #[cfg(any(rcc_f1, rcc_f1cl, stm32f3))] | 215 | #[cfg(any(rcc_f1, rcc_f1cl, stm32f3))] |
| 213 | let usb = match pll { | 216 | let usb = match pll { |
| 214 | Some(Hertz(72_000_000)) => Some(crate::pac::rcc::vals::Usbpre::DIV1_5), | 217 | Some(Hertz(72_000_000)) => Some(crate::pac::rcc::vals::Usbpre::DIV1_5), |
| @@ -374,6 +377,9 @@ pub(crate) unsafe fn init(config: Config) { | |||
| 374 | hsi: hsi, | 377 | hsi: hsi, |
| 375 | hse: hse, | 378 | hse: hse, |
| 376 | pll1_p: pll, | 379 | pll1_p: pll, |
| 380 | #[cfg(stm32f3)] | ||
| 381 | pll1_p_mul_2: pll_mul_2, | ||
| 382 | hsi_div_244: hsi.map(|h| h / 244u32), | ||
| 377 | sys: Some(sys), | 383 | sys: Some(sys), |
| 378 | pclk1: Some(pclk1), | 384 | pclk1: Some(pclk1), |
| 379 | pclk2: Some(pclk2), | 385 | pclk2: Some(pclk2), |
diff --git a/embassy-stm32/src/rcc/f247.rs b/embassy-stm32/src/rcc/f247.rs index e306d478d..343d075cd 100644 --- a/embassy-stm32/src/rcc/f247.rs +++ b/embassy-stm32/src/rcc/f247.rs | |||
| @@ -288,6 +288,7 @@ pub(crate) unsafe fn init(config: Config) { | |||
| 288 | 288 | ||
| 289 | clk48: pll.q, | 289 | clk48: pll.q, |
| 290 | 290 | ||
| 291 | hsi_div488: hsi.map(|hsi| hsi/488u32), | ||
| 291 | hsi_hse: None, | 292 | hsi_hse: None, |
| 292 | afif: None, | 293 | afif: None, |
| 293 | ); | 294 | ); |
diff --git a/embassy-stm32/src/rcc/g0.rs b/embassy-stm32/src/rcc/g0.rs index 0b1f34a20..ae502dd9c 100644 --- a/embassy-stm32/src/rcc/g0.rs +++ b/embassy-stm32/src/rcc/g0.rs | |||
| @@ -365,5 +365,6 @@ pub(crate) unsafe fn init(config: Config) { | |||
| 365 | pll1_q: pll1_q_freq, | 365 | pll1_q: pll1_q_freq, |
| 366 | pll1_p: pll1_p_freq, | 366 | pll1_p: pll1_p_freq, |
| 367 | rtc: rtc, | 367 | rtc: rtc, |
| 368 | hsi_div_488: None, | ||
| 368 | ); | 369 | ); |
| 369 | } | 370 | } |
diff --git a/embassy-stm32/src/rcc/h.rs b/embassy-stm32/src/rcc/h.rs index c2a71eaf1..c6da79afb 100644 --- a/embassy-stm32/src/rcc/h.rs +++ b/embassy-stm32/src/rcc/h.rs | |||
| @@ -617,6 +617,7 @@ pub(crate) unsafe fn init(config: Config) { | |||
| 617 | hsi: hsi, | 617 | hsi: hsi, |
| 618 | hsi48: hsi48, | 618 | hsi48: hsi48, |
| 619 | csi: csi, | 619 | csi: csi, |
| 620 | csi_div_122: csi.map(|c| c / 122u32), | ||
| 620 | hse: hse, | 621 | hse: hse, |
| 621 | 622 | ||
| 622 | lse: None, | 623 | lse: None, |
diff --git a/embassy-stm32/src/rcc/u5.rs b/embassy-stm32/src/rcc/u5.rs index 43138f05c..c8814ed69 100644 --- a/embassy-stm32/src/rcc/u5.rs +++ b/embassy-stm32/src/rcc/u5.rs | |||
| @@ -290,6 +290,8 @@ pub(crate) unsafe fn init(config: Config) { | |||
| 290 | lsi: None, | 290 | lsi: None, |
| 291 | msik: None, | 291 | msik: None, |
| 292 | iclk: None, | 292 | iclk: None, |
| 293 | shsi: None, | ||
| 294 | shsi_div_2: None, | ||
| 293 | ); | 295 | ); |
| 294 | } | 296 | } |
| 295 | 297 | ||
diff --git a/embassy-stm32/src/sai/mod.rs b/embassy-stm32/src/sai/mod.rs index b6c3e4028..02f96f8a9 100644 --- a/embassy-stm32/src/sai/mod.rs +++ b/embassy-stm32/src/sai/mod.rs | |||
| @@ -1,5 +1,6 @@ | |||
| 1 | //! Serial Audio Interface (SAI) | 1 | //! Serial Audio Interface (SAI) |
| 2 | #![macro_use] | 2 | #![macro_use] |
| 3 | #![cfg_attr(gpdma, allow(unused))] | ||
| 3 | 4 | ||
| 4 | use core::marker::PhantomData; | 5 | use core::marker::PhantomData; |
| 5 | 6 | ||
| @@ -7,6 +8,7 @@ use embassy_hal_internal::{into_ref, PeripheralRef}; | |||
| 7 | 8 | ||
| 8 | use self::sealed::WhichSubBlock; | 9 | use self::sealed::WhichSubBlock; |
| 9 | pub use crate::dma::word; | 10 | pub use crate::dma::word; |
| 11 | #[cfg(not(gpdma))] | ||
| 10 | use crate::dma::{ringbuffer, Channel, ReadableRingBuffer, Request, TransferOptions, WritableRingBuffer}; | 12 | use crate::dma::{ringbuffer, Channel, ReadableRingBuffer, Request, TransferOptions, WritableRingBuffer}; |
| 11 | use crate::gpio::sealed::{AFType, Pin as _}; | 13 | use crate::gpio::sealed::{AFType, Pin as _}; |
| 12 | use crate::gpio::AnyPin; | 14 | use crate::gpio::AnyPin; |
| @@ -26,6 +28,7 @@ pub enum Error { | |||
| 26 | Overrun, | 28 | Overrun, |
| 27 | } | 29 | } |
| 28 | 30 | ||
| 31 | #[cfg(not(gpdma))] | ||
| 29 | impl From<ringbuffer::OverrunError> for Error { | 32 | impl From<ringbuffer::OverrunError> for Error { |
| 30 | fn from(_: ringbuffer::OverrunError) -> Self { | 33 | fn from(_: ringbuffer::OverrunError) -> Self { |
| 31 | Self::Overrun | 34 | Self::Overrun |
| @@ -41,7 +44,7 @@ pub enum Mode { | |||
| 41 | } | 44 | } |
| 42 | 45 | ||
| 43 | impl Mode { | 46 | impl Mode { |
| 44 | #[cfg(any(sai_v1, sai_v2, sai_v3, sai_v4))] | 47 | #[cfg(any(sai_v1, sai_v2, sai_v3_2pdm, sai_v3_4pdm, sai_v4_2pdm, sai_v4_4pdm))] |
| 45 | const fn mode(&self, tx_rx: TxRx) -> vals::Mode { | 48 | const fn mode(&self, tx_rx: TxRx) -> vals::Mode { |
| 46 | match tx_rx { | 49 | match tx_rx { |
| 47 | TxRx::Transmitter => match self { | 50 | TxRx::Transmitter => match self { |
| @@ -76,7 +79,7 @@ pub enum SlotSize { | |||
| 76 | } | 79 | } |
| 77 | 80 | ||
| 78 | impl SlotSize { | 81 | impl SlotSize { |
| 79 | #[cfg(any(sai_v1, sai_v2, sai_v3, sai_v4))] | 82 | #[cfg(any(sai_v1, sai_v2, sai_v3_2pdm, sai_v3_4pdm, sai_v4_2pdm, sai_v4_4pdm))] |
| 80 | const fn slotsz(&self) -> vals::Slotsz { | 83 | const fn slotsz(&self) -> vals::Slotsz { |
| 81 | match self { | 84 | match self { |
| 82 | SlotSize::DataSize => vals::Slotsz::DATASIZE, | 85 | SlotSize::DataSize => vals::Slotsz::DATASIZE, |
| @@ -99,7 +102,7 @@ pub enum DataSize { | |||
| 99 | } | 102 | } |
| 100 | 103 | ||
| 101 | impl DataSize { | 104 | impl DataSize { |
| 102 | #[cfg(any(sai_v1, sai_v2, sai_v3, sai_v4))] | 105 | #[cfg(any(sai_v1, sai_v2, sai_v3_2pdm, sai_v3_4pdm, sai_v4_2pdm, sai_v4_4pdm))] |
| 103 | const fn ds(&self) -> vals::Ds { | 106 | const fn ds(&self) -> vals::Ds { |
| 104 | match self { | 107 | match self { |
| 105 | DataSize::Data8 => vals::Ds::BIT8, | 108 | DataSize::Data8 => vals::Ds::BIT8, |
| @@ -124,7 +127,7 @@ pub enum FifoThreshold { | |||
| 124 | } | 127 | } |
| 125 | 128 | ||
| 126 | impl FifoThreshold { | 129 | impl FifoThreshold { |
| 127 | #[cfg(any(sai_v1, sai_v2, sai_v3, sai_v4))] | 130 | #[cfg(any(sai_v1, sai_v2, sai_v3_2pdm, sai_v3_4pdm, sai_v4_2pdm, sai_v4_4pdm))] |
| 128 | const fn fth(&self) -> vals::Fth { | 131 | const fn fth(&self) -> vals::Fth { |
| 129 | match self { | 132 | match self { |
| 130 | FifoThreshold::Empty => vals::Fth::EMPTY, | 133 | FifoThreshold::Empty => vals::Fth::EMPTY, |
| @@ -145,7 +148,7 @@ pub enum MuteValue { | |||
| 145 | } | 148 | } |
| 146 | 149 | ||
| 147 | impl MuteValue { | 150 | impl MuteValue { |
| 148 | #[cfg(any(sai_v1, sai_v2, sai_v3, sai_v4))] | 151 | #[cfg(any(sai_v1, sai_v2, sai_v3_2pdm, sai_v3_4pdm, sai_v4_2pdm, sai_v4_4pdm))] |
| 149 | const fn muteval(&self) -> vals::Muteval { | 152 | const fn muteval(&self) -> vals::Muteval { |
| 150 | match self { | 153 | match self { |
| 151 | MuteValue::Zero => vals::Muteval::SENDZERO, | 154 | MuteValue::Zero => vals::Muteval::SENDZERO, |
| @@ -164,7 +167,7 @@ pub enum Protocol { | |||
| 164 | } | 167 | } |
| 165 | 168 | ||
| 166 | impl Protocol { | 169 | impl Protocol { |
| 167 | #[cfg(any(sai_v1, sai_v2, sai_v3, sai_v4))] | 170 | #[cfg(any(sai_v1, sai_v2, sai_v3_2pdm, sai_v3_4pdm, sai_v4_2pdm, sai_v4_4pdm))] |
| 168 | const fn prtcfg(&self) -> vals::Prtcfg { | 171 | const fn prtcfg(&self) -> vals::Prtcfg { |
| 169 | match self { | 172 | match self { |
| 170 | Protocol::Free => vals::Prtcfg::FREE, | 173 | Protocol::Free => vals::Prtcfg::FREE, |
| @@ -183,7 +186,7 @@ pub enum SyncInput { | |||
| 183 | /// Syncs with the other A/B sub-block within the SAI unit | 186 | /// Syncs with the other A/B sub-block within the SAI unit |
| 184 | Internal, | 187 | Internal, |
| 185 | /// Syncs with a sub-block in the other SAI unit | 188 | /// Syncs with a sub-block in the other SAI unit |
| 186 | #[cfg(sai_v4)] | 189 | #[cfg(any(sai_v4_2pdm, sai_v4_4pdm))] |
| 187 | External(SyncInputInstance), | 190 | External(SyncInputInstance), |
| 188 | } | 191 | } |
| 189 | 192 | ||
| @@ -192,14 +195,14 @@ impl SyncInput { | |||
| 192 | match self { | 195 | match self { |
| 193 | SyncInput::None => vals::Syncen::ASYNCHRONOUS, | 196 | SyncInput::None => vals::Syncen::ASYNCHRONOUS, |
| 194 | SyncInput::Internal => vals::Syncen::INTERNAL, | 197 | SyncInput::Internal => vals::Syncen::INTERNAL, |
| 195 | #[cfg(any(sai_v4))] | 198 | #[cfg(any(sai_v4_2pdm, sai_v4_4pdm))] |
| 196 | SyncInput::External(_) => vals::Syncen::EXTERNAL, | 199 | SyncInput::External(_) => vals::Syncen::EXTERNAL, |
| 197 | } | 200 | } |
| 198 | } | 201 | } |
| 199 | } | 202 | } |
| 200 | 203 | ||
| 201 | /// SAI instance to sync from. | 204 | /// SAI instance to sync from. |
| 202 | #[cfg(sai_v4)] | 205 | #[cfg(any(sai_v4_2pdm, sai_v4_4pdm))] |
| 203 | #[derive(Copy, Clone, PartialEq)] | 206 | #[derive(Copy, Clone, PartialEq)] |
| 204 | #[allow(missing_docs)] | 207 | #[allow(missing_docs)] |
| 205 | pub enum SyncInputInstance { | 208 | pub enum SyncInputInstance { |
| @@ -222,7 +225,7 @@ pub enum StereoMono { | |||
| 222 | } | 225 | } |
| 223 | 226 | ||
| 224 | impl StereoMono { | 227 | impl StereoMono { |
| 225 | #[cfg(any(sai_v1, sai_v2, sai_v3, sai_v4))] | 228 | #[cfg(any(sai_v1, sai_v2, sai_v3_2pdm, sai_v3_4pdm, sai_v4_2pdm, sai_v4_4pdm))] |
| 226 | const fn mono(&self) -> vals::Mono { | 229 | const fn mono(&self) -> vals::Mono { |
| 227 | match self { | 230 | match self { |
| 228 | StereoMono::Stereo => vals::Mono::STEREO, | 231 | StereoMono::Stereo => vals::Mono::STEREO, |
| @@ -241,7 +244,7 @@ pub enum BitOrder { | |||
| 241 | } | 244 | } |
| 242 | 245 | ||
| 243 | impl BitOrder { | 246 | impl BitOrder { |
| 244 | #[cfg(any(sai_v1, sai_v2, sai_v3, sai_v4))] | 247 | #[cfg(any(sai_v1, sai_v2, sai_v3_2pdm, sai_v3_4pdm, sai_v4_2pdm, sai_v4_4pdm))] |
| 245 | const fn lsbfirst(&self) -> vals::Lsbfirst { | 248 | const fn lsbfirst(&self) -> vals::Lsbfirst { |
| 246 | match self { | 249 | match self { |
| 247 | BitOrder::LsbFirst => vals::Lsbfirst::LSBFIRST, | 250 | BitOrder::LsbFirst => vals::Lsbfirst::LSBFIRST, |
| @@ -260,7 +263,7 @@ pub enum FrameSyncOffset { | |||
| 260 | } | 263 | } |
| 261 | 264 | ||
| 262 | impl FrameSyncOffset { | 265 | impl FrameSyncOffset { |
| 263 | #[cfg(any(sai_v1, sai_v2, sai_v3, sai_v4))] | 266 | #[cfg(any(sai_v1, sai_v2, sai_v3_2pdm, sai_v3_4pdm, sai_v4_2pdm, sai_v4_4pdm))] |
| 264 | const fn fsoff(&self) -> vals::Fsoff { | 267 | const fn fsoff(&self) -> vals::Fsoff { |
| 265 | match self { | 268 | match self { |
| 266 | FrameSyncOffset::OnFirstBit => vals::Fsoff::ONFIRST, | 269 | FrameSyncOffset::OnFirstBit => vals::Fsoff::ONFIRST, |
| @@ -279,7 +282,7 @@ pub enum FrameSyncPolarity { | |||
| 279 | } | 282 | } |
| 280 | 283 | ||
| 281 | impl FrameSyncPolarity { | 284 | impl FrameSyncPolarity { |
| 282 | #[cfg(any(sai_v1, sai_v2, sai_v3, sai_v4))] | 285 | #[cfg(any(sai_v1, sai_v2, sai_v3_2pdm, sai_v3_4pdm, sai_v4_2pdm, sai_v4_4pdm))] |
| 283 | const fn fspol(&self) -> vals::Fspol { | 286 | const fn fspol(&self) -> vals::Fspol { |
| 284 | match self { | 287 | match self { |
| 285 | FrameSyncPolarity::ActiveLow => vals::Fspol::FALLINGEDGE, | 288 | FrameSyncPolarity::ActiveLow => vals::Fspol::FALLINGEDGE, |
| @@ -297,7 +300,7 @@ pub enum FrameSyncDefinition { | |||
| 297 | } | 300 | } |
| 298 | 301 | ||
| 299 | impl FrameSyncDefinition { | 302 | impl FrameSyncDefinition { |
| 300 | #[cfg(any(sai_v1, sai_v2, sai_v3, sai_v4))] | 303 | #[cfg(any(sai_v1, sai_v2, sai_v3_2pdm, sai_v3_4pdm, sai_v4_2pdm, sai_v4_4pdm))] |
| 301 | const fn fsdef(&self) -> bool { | 304 | const fn fsdef(&self) -> bool { |
| 302 | match self { | 305 | match self { |
| 303 | FrameSyncDefinition::StartOfFrame => false, | 306 | FrameSyncDefinition::StartOfFrame => false, |
| @@ -315,7 +318,7 @@ pub enum ClockStrobe { | |||
| 315 | } | 318 | } |
| 316 | 319 | ||
| 317 | impl ClockStrobe { | 320 | impl ClockStrobe { |
| 318 | #[cfg(any(sai_v1, sai_v2, sai_v3, sai_v4))] | 321 | #[cfg(any(sai_v1, sai_v2, sai_v3_2pdm, sai_v3_4pdm, sai_v4_2pdm, sai_v4_4pdm))] |
| 319 | const fn ckstr(&self) -> vals::Ckstr { | 322 | const fn ckstr(&self) -> vals::Ckstr { |
| 320 | match self { | 323 | match self { |
| 321 | ClockStrobe::Falling => vals::Ckstr::FALLINGEDGE, | 324 | ClockStrobe::Falling => vals::Ckstr::FALLINGEDGE, |
| @@ -333,7 +336,7 @@ pub enum ComplementFormat { | |||
| 333 | } | 336 | } |
| 334 | 337 | ||
| 335 | impl ComplementFormat { | 338 | impl ComplementFormat { |
| 336 | #[cfg(any(sai_v1, sai_v2, sai_v3, sai_v4))] | 339 | #[cfg(any(sai_v1, sai_v2, sai_v3_2pdm, sai_v3_4pdm, sai_v4_2pdm, sai_v4_4pdm))] |
| 337 | const fn cpl(&self) -> vals::Cpl { | 340 | const fn cpl(&self) -> vals::Cpl { |
| 338 | match self { | 341 | match self { |
| 339 | ComplementFormat::OnesComplement => vals::Cpl::ONESCOMPLEMENT, | 342 | ComplementFormat::OnesComplement => vals::Cpl::ONESCOMPLEMENT, |
| @@ -352,7 +355,7 @@ pub enum Companding { | |||
| 352 | } | 355 | } |
| 353 | 356 | ||
| 354 | impl Companding { | 357 | impl Companding { |
| 355 | #[cfg(any(sai_v1, sai_v2, sai_v3, sai_v4))] | 358 | #[cfg(any(sai_v1, sai_v2, sai_v3_2pdm, sai_v3_4pdm, sai_v4_2pdm, sai_v4_4pdm))] |
| 356 | const fn comp(&self) -> vals::Comp { | 359 | const fn comp(&self) -> vals::Comp { |
| 357 | match self { | 360 | match self { |
| 358 | Companding::None => vals::Comp::NOCOMPANDING, | 361 | Companding::None => vals::Comp::NOCOMPANDING, |
| @@ -371,7 +374,7 @@ pub enum OutputDrive { | |||
| 371 | } | 374 | } |
| 372 | 375 | ||
| 373 | impl OutputDrive { | 376 | impl OutputDrive { |
| 374 | #[cfg(any(sai_v1, sai_v2, sai_v3, sai_v4))] | 377 | #[cfg(any(sai_v1, sai_v2, sai_v3_2pdm, sai_v3_4pdm, sai_v4_2pdm, sai_v4_4pdm))] |
| 375 | const fn outdriv(&self) -> vals::Outdriv { | 378 | const fn outdriv(&self) -> vals::Outdriv { |
| 376 | match self { | 379 | match self { |
| 377 | OutputDrive::OnStart => vals::Outdriv::ONSTART, | 380 | OutputDrive::OnStart => vals::Outdriv::ONSTART, |
| @@ -404,7 +407,7 @@ pub enum MasterClockDivider { | |||
| 404 | } | 407 | } |
| 405 | 408 | ||
| 406 | impl MasterClockDivider { | 409 | impl MasterClockDivider { |
| 407 | #[cfg(any(sai_v1, sai_v2, sai_v3, sai_v4))] | 410 | #[cfg(any(sai_v1, sai_v2, sai_v3_2pdm, sai_v3_4pdm, sai_v4_2pdm, sai_v4_4pdm))] |
| 408 | const fn mckdiv(&self) -> u8 { | 411 | const fn mckdiv(&self) -> u8 { |
| 409 | match self { | 412 | match self { |
| 410 | MasterClockDivider::MasterClockDisabled => 0, | 413 | MasterClockDivider::MasterClockDisabled => 0, |
| @@ -501,12 +504,12 @@ impl Config { | |||
| 501 | } | 504 | } |
| 502 | } | 505 | } |
| 503 | 506 | ||
| 507 | #[cfg(not(gpdma))] | ||
| 504 | enum RingBuffer<'d, W: word::Word> { | 508 | enum RingBuffer<'d, W: word::Word> { |
| 505 | Writable(WritableRingBuffer<'d, W>), | 509 | Writable(WritableRingBuffer<'d, W>), |
| 506 | Readable(ReadableRingBuffer<'d, W>), | 510 | Readable(ReadableRingBuffer<'d, W>), |
| 507 | } | 511 | } |
| 508 | 512 | ||
| 509 | #[cfg(any(sai_v1, sai_v2, sai_v3, sai_v4))] | ||
| 510 | fn dr<W: word::Word>(w: crate::pac::sai::Sai, sub_block: WhichSubBlock) -> *mut W { | 513 | fn dr<W: word::Word>(w: crate::pac::sai::Sai, sub_block: WhichSubBlock) -> *mut W { |
| 511 | let ch = w.ch(sub_block as usize); | 514 | let ch = w.ch(sub_block as usize); |
| 512 | ch.dr().as_ptr() as _ | 515 | ch.dr().as_ptr() as _ |
| @@ -528,6 +531,7 @@ fn get_af_types(mode: Mode, tx_rx: TxRx) -> (AFType, AFType) { | |||
| 528 | ) | 531 | ) |
| 529 | } | 532 | } |
| 530 | 533 | ||
| 534 | #[cfg(not(gpdma))] | ||
| 531 | fn get_ring_buffer<'d, T: Instance, W: word::Word>( | 535 | fn get_ring_buffer<'d, T: Instance, W: word::Word>( |
| 532 | dma: impl Peripheral<P = impl Channel> + 'd, | 536 | dma: impl Peripheral<P = impl Channel> + 'd, |
| 533 | dma_buf: &'d mut [W], | 537 | dma_buf: &'d mut [W], |
| @@ -554,12 +558,12 @@ fn update_synchronous_config(config: &mut Config) { | |||
| 554 | config.mode = Mode::Slave; | 558 | config.mode = Mode::Slave; |
| 555 | config.sync_output = false; | 559 | config.sync_output = false; |
| 556 | 560 | ||
| 557 | #[cfg(any(sai_v1, sai_v2, sai_v3))] | 561 | #[cfg(any(sai_v1, sai_v2, sai_v3_2pdm, sai_v3_4pdm))] |
| 558 | { | 562 | { |
| 559 | config.sync_input = SyncInput::Internal; | 563 | config.sync_input = SyncInput::Internal; |
| 560 | } | 564 | } |
| 561 | 565 | ||
| 562 | #[cfg(any(sai_v4))] | 566 | #[cfg(any(sai_v4_2pdm, sai_v4_4pdm))] |
| 563 | { | 567 | { |
| 564 | //this must either be Internal or External | 568 | //this must either be Internal or External |
| 565 | //The asynchronous sub-block on the same SAI needs to enable sync_output | 569 | //The asynchronous sub-block on the same SAI needs to enable sync_output |
| @@ -599,10 +603,14 @@ pub struct Sai<'d, T: Instance, W: word::Word> { | |||
| 599 | fs: Option<PeripheralRef<'d, AnyPin>>, | 603 | fs: Option<PeripheralRef<'d, AnyPin>>, |
| 600 | sck: Option<PeripheralRef<'d, AnyPin>>, | 604 | sck: Option<PeripheralRef<'d, AnyPin>>, |
| 601 | mclk: Option<PeripheralRef<'d, AnyPin>>, | 605 | mclk: Option<PeripheralRef<'d, AnyPin>>, |
| 606 | #[cfg(gpdma)] | ||
| 607 | ring_buffer: PhantomData<W>, | ||
| 608 | #[cfg(not(gpdma))] | ||
| 602 | ring_buffer: RingBuffer<'d, W>, | 609 | ring_buffer: RingBuffer<'d, W>, |
| 603 | sub_block: WhichSubBlock, | 610 | sub_block: WhichSubBlock, |
| 604 | } | 611 | } |
| 605 | 612 | ||
| 613 | #[cfg(not(gpdma))] | ||
| 606 | impl<'d, T: Instance, W: word::Word> Sai<'d, T, W> { | 614 | impl<'d, T: Instance, W: word::Word> Sai<'d, T, W> { |
| 607 | /// Create a new SAI driver in asynchronous mode with MCLK. | 615 | /// Create a new SAI driver in asynchronous mode with MCLK. |
| 608 | /// | 616 | /// |
| @@ -715,13 +723,13 @@ impl<'d, T: Instance, W: word::Word> Sai<'d, T, W> { | |||
| 715 | ring_buffer: RingBuffer<'d, W>, | 723 | ring_buffer: RingBuffer<'d, W>, |
| 716 | config: Config, | 724 | config: Config, |
| 717 | ) -> Self { | 725 | ) -> Self { |
| 718 | #[cfg(any(sai_v1, sai_v2, sai_v3, sai_v4))] | 726 | #[cfg(any(sai_v1, sai_v2, sai_v3_2pdm, sai_v3_4pdm, sai_v4_2pdm, sai_v4_4pdm))] |
| 719 | { | 727 | { |
| 720 | let ch = T::REGS.ch(sub_block as usize); | 728 | let ch = T::REGS.ch(sub_block as usize); |
| 721 | ch.cr1().modify(|w| w.set_saien(false)); | 729 | ch.cr1().modify(|w| w.set_saien(false)); |
| 722 | } | 730 | } |
| 723 | 731 | ||
| 724 | #[cfg(any(sai_v4))] | 732 | #[cfg(any(sai_v4_2pdm, sai_v4_4pdm))] |
| 725 | { | 733 | { |
| 726 | if let SyncInput::External(i) = config.sync_input { | 734 | if let SyncInput::External(i) = config.sync_input { |
| 727 | T::REGS.gcr().modify(|w| { | 735 | T::REGS.gcr().modify(|w| { |
| @@ -740,7 +748,7 @@ impl<'d, T: Instance, W: word::Word> Sai<'d, T, W> { | |||
| 740 | } | 748 | } |
| 741 | } | 749 | } |
| 742 | 750 | ||
| 743 | #[cfg(any(sai_v1, sai_v2, sai_v3, sai_v4))] | 751 | #[cfg(any(sai_v1, sai_v2, sai_v3_2pdm, sai_v3_4pdm, sai_v4_2pdm, sai_v4_4pdm))] |
| 744 | { | 752 | { |
| 745 | let ch = T::REGS.ch(sub_block as usize); | 753 | let ch = T::REGS.ch(sub_block as usize); |
| 746 | ch.cr1().modify(|w| { | 754 | ch.cr1().modify(|w| { |
diff --git a/embassy-stm32/src/spi/mod.rs b/embassy-stm32/src/spi/mod.rs index 23f027e70..172bc8112 100644 --- a/embassy-stm32/src/spi/mod.rs +++ b/embassy-stm32/src/spi/mod.rs | |||
| @@ -1005,8 +1005,8 @@ mod word_impl { | |||
| 1005 | 1005 | ||
| 1006 | pub type Config = vals::Dff; | 1006 | pub type Config = vals::Dff; |
| 1007 | 1007 | ||
| 1008 | impl_word!(u8, vals::Dff::EIGHTBIT); | 1008 | impl_word!(u8, vals::Dff::BITS8); |
| 1009 | impl_word!(u16, vals::Dff::SIXTEENBIT); | 1009 | impl_word!(u16, vals::Dff::BITS16); |
| 1010 | } | 1010 | } |
| 1011 | 1011 | ||
| 1012 | #[cfg(spi_v2)] | 1012 | #[cfg(spi_v2)] |
| @@ -1015,19 +1015,19 @@ mod word_impl { | |||
| 1015 | 1015 | ||
| 1016 | pub type Config = (vals::Ds, vals::Frxth); | 1016 | pub type Config = (vals::Ds, vals::Frxth); |
| 1017 | 1017 | ||
| 1018 | impl_word!(word::U4, (vals::Ds::FOURBIT, vals::Frxth::QUARTER)); | 1018 | impl_word!(word::U4, (vals::Ds::BITS4, vals::Frxth::QUARTER)); |
| 1019 | impl_word!(word::U5, (vals::Ds::FIVEBIT, vals::Frxth::QUARTER)); | 1019 | impl_word!(word::U5, (vals::Ds::BITS5, vals::Frxth::QUARTER)); |
| 1020 | impl_word!(word::U6, (vals::Ds::SIXBIT, vals::Frxth::QUARTER)); | 1020 | impl_word!(word::U6, (vals::Ds::BITS6, vals::Frxth::QUARTER)); |
| 1021 | impl_word!(word::U7, (vals::Ds::SEVENBIT, vals::Frxth::QUARTER)); | 1021 | impl_word!(word::U7, (vals::Ds::BITS7, vals::Frxth::QUARTER)); |
| 1022 | impl_word!(u8, (vals::Ds::EIGHTBIT, vals::Frxth::QUARTER)); | 1022 | impl_word!(u8, (vals::Ds::BITS8, vals::Frxth::QUARTER)); |
| 1023 | impl_word!(word::U9, (vals::Ds::NINEBIT, vals::Frxth::HALF)); | 1023 | impl_word!(word::U9, (vals::Ds::BITS9, vals::Frxth::HALF)); |
| 1024 | impl_word!(word::U10, (vals::Ds::TENBIT, vals::Frxth::HALF)); | 1024 | impl_word!(word::U10, (vals::Ds::BITS10, vals::Frxth::HALF)); |
| 1025 | impl_word!(word::U11, (vals::Ds::ELEVENBIT, vals::Frxth::HALF)); | 1025 | impl_word!(word::U11, (vals::Ds::BITS11, vals::Frxth::HALF)); |
| 1026 | impl_word!(word::U12, (vals::Ds::TWELVEBIT, vals::Frxth::HALF)); | 1026 | impl_word!(word::U12, (vals::Ds::BITS12, vals::Frxth::HALF)); |
| 1027 | impl_word!(word::U13, (vals::Ds::THIRTEENBIT, vals::Frxth::HALF)); | 1027 | impl_word!(word::U13, (vals::Ds::BITS13, vals::Frxth::HALF)); |
| 1028 | impl_word!(word::U14, (vals::Ds::FOURTEENBIT, vals::Frxth::HALF)); | 1028 | impl_word!(word::U14, (vals::Ds::BITS14, vals::Frxth::HALF)); |
| 1029 | impl_word!(word::U15, (vals::Ds::FIFTEENBIT, vals::Frxth::HALF)); | 1029 | impl_word!(word::U15, (vals::Ds::BITS15, vals::Frxth::HALF)); |
| 1030 | impl_word!(u16, (vals::Ds::SIXTEENBIT, vals::Frxth::HALF)); | 1030 | impl_word!(u16, (vals::Ds::BITS16, vals::Frxth::HALF)); |
| 1031 | } | 1031 | } |
| 1032 | 1032 | ||
| 1033 | #[cfg(any(spi_v3, spi_v4, spi_v5))] | 1033 | #[cfg(any(spi_v3, spi_v4, spi_v5))] |
diff --git a/examples/stm32f0/src/bin/adc.rs b/examples/stm32f0/src/bin/adc.rs index 8fef062b3..c2fb143cd 100644 --- a/examples/stm32f0/src/bin/adc.rs +++ b/examples/stm32f0/src/bin/adc.rs | |||
| @@ -19,7 +19,7 @@ async fn main(_spawner: Spawner) { | |||
| 19 | info!("Hello World!"); | 19 | info!("Hello World!"); |
| 20 | 20 | ||
| 21 | let mut adc = Adc::new(p.ADC, Irqs, &mut Delay); | 21 | let mut adc = Adc::new(p.ADC, Irqs, &mut Delay); |
| 22 | adc.set_sample_time(SampleTime::Cycles71_5); | 22 | adc.set_sample_time(SampleTime::CYCLES71_5); |
| 23 | let mut pin = p.PA1; | 23 | let mut pin = p.PA1; |
| 24 | 24 | ||
| 25 | let mut vrefint = adc.enable_vref(&mut Delay); | 25 | let mut vrefint = adc.enable_vref(&mut Delay); |
diff --git a/examples/stm32f334/src/bin/adc.rs b/examples/stm32f334/src/bin/adc.rs index a9fb7f1a6..bd126ce68 100644 --- a/examples/stm32f334/src/bin/adc.rs +++ b/examples/stm32f334/src/bin/adc.rs | |||
| @@ -40,7 +40,7 @@ async fn main(_spawner: Spawner) -> ! { | |||
| 40 | 40 | ||
| 41 | let mut adc = Adc::new(p.ADC1, Irqs, &mut Delay); | 41 | let mut adc = Adc::new(p.ADC1, Irqs, &mut Delay); |
| 42 | 42 | ||
| 43 | adc.set_sample_time(SampleTime::Cycles601_5); | 43 | adc.set_sample_time(SampleTime::CYCLES601_5); |
| 44 | 44 | ||
| 45 | info!("enable vrefint..."); | 45 | info!("enable vrefint..."); |
| 46 | 46 | ||
diff --git a/examples/stm32f334/src/bin/opamp.rs b/examples/stm32f334/src/bin/opamp.rs index 6f25191be..a5c710aa2 100644 --- a/examples/stm32f334/src/bin/opamp.rs +++ b/examples/stm32f334/src/bin/opamp.rs | |||
| @@ -42,7 +42,7 @@ async fn main(_spawner: Spawner) -> ! { | |||
| 42 | let mut adc = Adc::new(p.ADC2, Irqs, &mut Delay); | 42 | let mut adc = Adc::new(p.ADC2, Irqs, &mut Delay); |
| 43 | let mut opamp = OpAmp::new(p.OPAMP2); | 43 | let mut opamp = OpAmp::new(p.OPAMP2); |
| 44 | 44 | ||
| 45 | adc.set_sample_time(SampleTime::Cycles601_5); | 45 | adc.set_sample_time(SampleTime::CYCLES601_5); |
| 46 | 46 | ||
| 47 | info!("enable vrefint..."); | 47 | info!("enable vrefint..."); |
| 48 | 48 | ||
diff --git a/examples/stm32g4/src/bin/adc.rs b/examples/stm32g4/src/bin/adc.rs index 99e3ef63b..6c6de1ffe 100644 --- a/examples/stm32g4/src/bin/adc.rs +++ b/examples/stm32g4/src/bin/adc.rs | |||
| @@ -30,7 +30,7 @@ async fn main(_spawner: Spawner) { | |||
| 30 | info!("Hello World!"); | 30 | info!("Hello World!"); |
| 31 | 31 | ||
| 32 | let mut adc = Adc::new(p.ADC2, &mut Delay); | 32 | let mut adc = Adc::new(p.ADC2, &mut Delay); |
| 33 | adc.set_sample_time(SampleTime::Cycles32_5); | 33 | adc.set_sample_time(SampleTime::CYCLES32_5); |
| 34 | 34 | ||
| 35 | loop { | 35 | loop { |
| 36 | let measured = adc.read(&mut p.PA7); | 36 | let measured = adc.read(&mut p.PA7); |
diff --git a/examples/stm32h7/src/bin/adc.rs b/examples/stm32h7/src/bin/adc.rs index fe6fe69a1..f0278239f 100644 --- a/examples/stm32h7/src/bin/adc.rs +++ b/examples/stm32h7/src/bin/adc.rs | |||
| @@ -46,7 +46,7 @@ async fn main(_spawner: Spawner) { | |||
| 46 | 46 | ||
| 47 | let mut adc = Adc::new(p.ADC3, &mut Delay); | 47 | let mut adc = Adc::new(p.ADC3, &mut Delay); |
| 48 | 48 | ||
| 49 | adc.set_sample_time(SampleTime::Cycles32_5); | 49 | adc.set_sample_time(SampleTime::CYCLES32_5); |
| 50 | 50 | ||
| 51 | let mut vrefint_channel = adc.enable_vrefint(); | 51 | let mut vrefint_channel = adc.enable_vrefint(); |
| 52 | 52 | ||
diff --git a/examples/stm32l0/src/bin/adc.rs b/examples/stm32l0/src/bin/adc.rs index adeaa208a..97d41ca4b 100644 --- a/examples/stm32l0/src/bin/adc.rs +++ b/examples/stm32l0/src/bin/adc.rs | |||
| @@ -19,7 +19,7 @@ async fn main(_spawner: Spawner) { | |||
| 19 | info!("Hello World!"); | 19 | info!("Hello World!"); |
| 20 | 20 | ||
| 21 | let mut adc = Adc::new(p.ADC, Irqs, &mut Delay); | 21 | let mut adc = Adc::new(p.ADC, Irqs, &mut Delay); |
| 22 | adc.set_sample_time(SampleTime::Cycles79_5); | 22 | adc.set_sample_time(SampleTime::CYCLES79_5); |
| 23 | let mut pin = p.PA1; | 23 | let mut pin = p.PA1; |
| 24 | 24 | ||
| 25 | let mut vrefint = adc.enable_vref(&mut Delay); | 25 | let mut vrefint = adc.enable_vref(&mut Delay); |
diff --git a/examples/stm32l4/src/bin/adc.rs b/examples/stm32l4/src/bin/adc.rs index d01e9f1b3..910944673 100644 --- a/examples/stm32l4/src/bin/adc.rs +++ b/examples/stm32l4/src/bin/adc.rs | |||
| @@ -20,7 +20,7 @@ fn main() -> ! { | |||
| 20 | 20 | ||
| 21 | let mut adc = Adc::new(p.ADC1, &mut Delay); | 21 | let mut adc = Adc::new(p.ADC1, &mut Delay); |
| 22 | //adc.enable_vref(); | 22 | //adc.enable_vref(); |
| 23 | adc.set_resolution(Resolution::EightBit); | 23 | adc.set_resolution(Resolution::BITS8); |
| 24 | let mut channel = p.PC0; | 24 | let mut channel = p.PC0; |
| 25 | 25 | ||
| 26 | loop { | 26 | loop { |
