diff options
| -rw-r--r-- | embassy-stm32/Cargo.toml | 4 | ||||
| -rw-r--r-- | embassy-stm32/src/opamp.rs | 49 |
2 files changed, 20 insertions, 33 deletions
diff --git a/embassy-stm32/Cargo.toml b/embassy-stm32/Cargo.toml index 82bc76883..a1dc75dba 100644 --- a/embassy-stm32/Cargo.toml +++ b/embassy-stm32/Cargo.toml | |||
| @@ -73,7 +73,7 @@ rand_core = "0.6.3" | |||
| 73 | sdio-host = "0.9.0" | 73 | sdio-host = "0.9.0" |
| 74 | critical-section = "1.1" | 74 | critical-section = "1.1" |
| 75 | #stm32-metapac = { version = "16" } | 75 | #stm32-metapac = { version = "16" } |
| 76 | stm32-metapac = { git = "https://github.com/embassy-rs/stm32-data-generated", tag = "stm32-data-380f03cb71f43a242adc45e83607a380ffe0447b" } | 76 | stm32-metapac = { git = "https://github.com/embassy-rs/stm32-data-generated", tag = "stm32-data-9385c0824aff194913a2eab3c957791d0de06771" } |
| 77 | 77 | ||
| 78 | vcell = "0.1.3" | 78 | vcell = "0.1.3" |
| 79 | nb = "1.0.0" | 79 | nb = "1.0.0" |
| @@ -102,7 +102,7 @@ proc-macro2 = "1.0.36" | |||
| 102 | quote = "1.0.15" | 102 | quote = "1.0.15" |
| 103 | 103 | ||
| 104 | #stm32-metapac = { version = "16", default-features = false, features = ["metadata"]} | 104 | #stm32-metapac = { version = "16", default-features = false, features = ["metadata"]} |
| 105 | stm32-metapac = { git = "https://github.com/embassy-rs/stm32-data-generated", tag = "stm32-data-380f03cb71f43a242adc45e83607a380ffe0447b", default-features = false, features = ["metadata"] } | 105 | stm32-metapac = { git = "https://github.com/embassy-rs/stm32-data-generated", tag = "stm32-data-9385c0824aff194913a2eab3c957791d0de06771", default-features = false, features = ["metadata"] } |
| 106 | 106 | ||
| 107 | [features] | 107 | [features] |
| 108 | default = ["rt"] | 108 | default = ["rt"] |
diff --git a/embassy-stm32/src/opamp.rs b/embassy-stm32/src/opamp.rs index 82de4a89b..a76389495 100644 --- a/embassy-stm32/src/opamp.rs +++ b/embassy-stm32/src/opamp.rs | |||
| @@ -37,22 +37,12 @@ enum OpAmpDifferentialPair { | |||
| 37 | 37 | ||
| 38 | /// Speed | 38 | /// Speed |
| 39 | #[allow(missing_docs)] | 39 | #[allow(missing_docs)] |
| 40 | #[derive(Clone, Copy)] | 40 | #[derive(Clone, Copy, PartialEq)] |
| 41 | pub enum OpAmpSpeed { | 41 | pub enum OpAmpSpeed { |
| 42 | Normal, | 42 | Normal, |
| 43 | HighSpeed, | 43 | HighSpeed, |
| 44 | } | 44 | } |
| 45 | 45 | ||
| 46 | #[cfg(opamp_g4)] | ||
| 47 | impl From<OpAmpSpeed> for crate::pac::opamp::vals::Opahsm { | ||
| 48 | fn from(v: OpAmpSpeed) -> Self { | ||
| 49 | match v { | ||
| 50 | OpAmpSpeed::Normal => crate::pac::opamp::vals::Opahsm::NORMAL, | ||
| 51 | OpAmpSpeed::HighSpeed => crate::pac::opamp::vals::Opahsm::HIGH_SPEED, | ||
| 52 | } | ||
| 53 | } | ||
| 54 | } | ||
| 55 | |||
| 56 | /// OpAmp external outputs, wired to a GPIO pad. | 46 | /// OpAmp external outputs, wired to a GPIO pad. |
| 57 | /// | 47 | /// |
| 58 | /// This struct can also be used as an ADC input. | 48 | /// This struct can also be used as an ADC input. |
| @@ -80,7 +70,7 @@ impl<'d, T: Instance> OpAmp<'d, T> { | |||
| 80 | pub fn new(opamp: Peri<'d, T>, #[cfg(opamp_g4)] speed: OpAmpSpeed) -> Self { | 70 | pub fn new(opamp: Peri<'d, T>, #[cfg(opamp_g4)] speed: OpAmpSpeed) -> Self { |
| 81 | #[cfg(opamp_g4)] | 71 | #[cfg(opamp_g4)] |
| 82 | T::regs().csr().modify(|w| { | 72 | T::regs().csr().modify(|w| { |
| 83 | w.set_opahsm(speed.into()); | 73 | w.set_opahsm(speed == OpAmpSpeed::HighSpeed); |
| 84 | }); | 74 | }); |
| 85 | 75 | ||
| 86 | Self { _inner: opamp } | 76 | Self { _inner: opamp } |
| @@ -113,7 +103,7 @@ impl<'d, T: Instance> OpAmp<'d, T> { | |||
| 113 | w.set_vp_sel(VpSel::from_bits(in_pin.channel())); | 103 | w.set_vp_sel(VpSel::from_bits(in_pin.channel())); |
| 114 | w.set_vm_sel(vm_sel); | 104 | w.set_vm_sel(vm_sel); |
| 115 | #[cfg(opamp_g4)] | 105 | #[cfg(opamp_g4)] |
| 116 | w.set_opaintoen(Opaintoen::OUTPUT_PIN); | 106 | w.set_opaintoen(false); |
| 117 | w.set_opampen(true); | 107 | w.set_opampen(true); |
| 118 | }); | 108 | }); |
| 119 | 109 | ||
| @@ -166,7 +156,7 @@ impl<'d, T: Instance> OpAmp<'d, T> { | |||
| 166 | w.set_vm_sel(vm_sel); | 156 | w.set_vm_sel(vm_sel); |
| 167 | w.set_pga_gain(pga_gain); | 157 | w.set_pga_gain(pga_gain); |
| 168 | #[cfg(opamp_g4)] | 158 | #[cfg(opamp_g4)] |
| 169 | w.set_opaintoen(Opaintoen::OUTPUT_PIN); | 159 | w.set_opaintoen(false); |
| 170 | w.set_opampen(true); | 160 | w.set_opampen(true); |
| 171 | }); | 161 | }); |
| 172 | 162 | ||
| @@ -189,7 +179,7 @@ impl<'d, T: Instance> OpAmp<'d, T> { | |||
| 189 | 179 | ||
| 190 | w.set_vm_sel(VmSel::OUTPUT); | 180 | w.set_vm_sel(VmSel::OUTPUT); |
| 191 | w.set_vp_sel(VpSel::DAC3_CH1); | 181 | w.set_vp_sel(VpSel::DAC3_CH1); |
| 192 | w.set_opaintoen(Opaintoen::OUTPUT_PIN); | 182 | w.set_opaintoen(false); |
| 193 | w.set_opampen(true); | 183 | w.set_opampen(true); |
| 194 | }); | 184 | }); |
| 195 | 185 | ||
| @@ -215,7 +205,7 @@ impl<'d, T: Instance> OpAmp<'d, T> { | |||
| 215 | w.set_vp_sel(VpSel::from_bits(pin.channel())); | 205 | w.set_vp_sel(VpSel::from_bits(pin.channel())); |
| 216 | w.set_vm_sel(VmSel::OUTPUT); | 206 | w.set_vm_sel(VmSel::OUTPUT); |
| 217 | #[cfg(opamp_g4)] | 207 | #[cfg(opamp_g4)] |
| 218 | w.set_opaintoen(Opaintoen::ADCCHANNEL); | 208 | w.set_opaintoen(true); |
| 219 | w.set_opampen(true); | 209 | w.set_opampen(true); |
| 220 | }); | 210 | }); |
| 221 | 211 | ||
| @@ -251,7 +241,7 @@ impl<'d, T: Instance> OpAmp<'d, T> { | |||
| 251 | w.set_vp_sel(VpSel::from_bits(pin.channel())); | 241 | w.set_vp_sel(VpSel::from_bits(pin.channel())); |
| 252 | w.set_vm_sel(VmSel::OUTPUT); | 242 | w.set_vm_sel(VmSel::OUTPUT); |
| 253 | w.set_pga_gain(pga_gain); | 243 | w.set_pga_gain(pga_gain); |
| 254 | w.set_opaintoen(Opaintoen::ADCCHANNEL); | 244 | w.set_opaintoen(true); |
| 255 | w.set_opampen(true); | 245 | w.set_opampen(true); |
| 256 | }); | 246 | }); |
| 257 | 247 | ||
| @@ -278,7 +268,7 @@ impl<'d, T: Instance> OpAmp<'d, T> { | |||
| 278 | use crate::pac::opamp::vals::*; | 268 | use crate::pac::opamp::vals::*; |
| 279 | w.set_vp_sel(VpSel::DAC3_CH1); // Actually DAC3_CHx | 269 | w.set_vp_sel(VpSel::DAC3_CH1); // Actually DAC3_CHx |
| 280 | w.set_vm_sel(VmSel::from_bits(m_pin.channel())); | 270 | w.set_vm_sel(VmSel::from_bits(m_pin.channel())); |
| 281 | w.set_opaintoen(Opaintoen::ADCCHANNEL); | 271 | w.set_opaintoen(true); |
| 282 | w.set_opampen(true); | 272 | w.set_opampen(true); |
| 283 | }); | 273 | }); |
| 284 | 274 | ||
| @@ -308,7 +298,7 @@ impl<'d, T: Instance> OpAmp<'d, T> { | |||
| 308 | use crate::pac::opamp::vals::*; | 298 | use crate::pac::opamp::vals::*; |
| 309 | w.set_vp_sel(VpSel::DAC3_CH1); // Actually DAC3_CHx | 299 | w.set_vp_sel(VpSel::DAC3_CH1); // Actually DAC3_CHx |
| 310 | w.set_vm_sel(VmSel::from_bits(m_pin.channel())); | 300 | w.set_vm_sel(VmSel::from_bits(m_pin.channel())); |
| 311 | w.set_opaintoen(Opaintoen::OUTPUT_PIN); | 301 | w.set_opaintoen(false); |
| 312 | w.set_opampen(true); | 302 | w.set_opampen(true); |
| 313 | }); | 303 | }); |
| 314 | 304 | ||
| @@ -340,7 +330,7 @@ impl<'d, T: Instance> OpAmp<'d, T> { | |||
| 340 | use crate::pac::opamp::vals::*; | 330 | use crate::pac::opamp::vals::*; |
| 341 | w.set_vp_sel(VpSel::from_bits(p_pin.channel())); | 331 | w.set_vp_sel(VpSel::from_bits(p_pin.channel())); |
| 342 | w.set_vm_sel(VmSel::from_bits(m_pin.channel())); | 332 | w.set_vm_sel(VmSel::from_bits(m_pin.channel())); |
| 343 | w.set_opaintoen(Opaintoen::OUTPUT_PIN); | 333 | w.set_opaintoen(false); |
| 344 | w.set_opampen(true); | 334 | w.set_opampen(true); |
| 345 | }); | 335 | }); |
| 346 | 336 | ||
| @@ -369,7 +359,7 @@ impl<'d, T: Instance> OpAmp<'d, T> { | |||
| 369 | use crate::pac::opamp::vals::*; | 359 | use crate::pac::opamp::vals::*; |
| 370 | w.set_vp_sel(VpSel::from_bits(p_pin.channel())); | 360 | w.set_vp_sel(VpSel::from_bits(p_pin.channel())); |
| 371 | w.set_vm_sel(VmSel::from_bits(m_pin.channel())); | 361 | w.set_vm_sel(VmSel::from_bits(m_pin.channel())); |
| 372 | w.set_opaintoen(Opaintoen::ADCCHANNEL); | 362 | w.set_opaintoen(true); |
| 373 | w.set_opampen(true); | 363 | w.set_opampen(true); |
| 374 | }); | 364 | }); |
| 375 | 365 | ||
| @@ -389,17 +379,14 @@ impl<'d, T: Instance> OpAmp<'d, T> { | |||
| 389 | T::regs().csr().modify(|w| { | 379 | T::regs().csr().modify(|w| { |
| 390 | w.set_opampen(true); | 380 | w.set_opampen(true); |
| 391 | w.set_calon(true); | 381 | w.set_calon(true); |
| 392 | w.set_usertrim(Usertrim::USER); | 382 | w.set_usertrim(true); |
| 393 | }); | 383 | }); |
| 394 | 384 | ||
| 395 | match T::regs().csr().read().opahsm() { | 385 | if T::regs().csr().read().opahsm() { |
| 396 | Opahsm::NORMAL => { | 386 | self.calibrate_differential_pair(OpAmpDifferentialPair::P); |
| 397 | self.calibrate_differential_pair(OpAmpDifferentialPair::P); | 387 | } else { |
| 398 | self.calibrate_differential_pair(OpAmpDifferentialPair::N); | 388 | self.calibrate_differential_pair(OpAmpDifferentialPair::P); |
| 399 | } | 389 | self.calibrate_differential_pair(OpAmpDifferentialPair::N); |
| 400 | Opahsm::HIGH_SPEED => { | ||
| 401 | self.calibrate_differential_pair(OpAmpDifferentialPair::P); | ||
| 402 | } | ||
| 403 | } | 390 | } |
| 404 | 391 | ||
| 405 | T::regs().csr().modify(|w| { | 392 | T::regs().csr().modify(|w| { |
| @@ -448,7 +435,7 @@ impl<'d, T: Instance> OpAmp<'d, T> { | |||
| 448 | // (with a maximum stabilization time remaining below 2 ms in any case) -- RM0440 25.3.7 | 435 | // (with a maximum stabilization time remaining below 2 ms in any case) -- RM0440 25.3.7 |
| 449 | blocking_delay_ms(2); | 436 | blocking_delay_ms(2); |
| 450 | 437 | ||
| 451 | if T::regs().csr().read().outcal() == Outcal::LOW { | 438 | if !T::regs().csr().read().calout() { |
| 452 | if mid == 0 { | 439 | if mid == 0 { |
| 453 | break; | 440 | break; |
| 454 | } | 441 | } |
