diff options
| author | xoviat <[email protected]> | 2023-10-04 16:15:08 -0500 |
|---|---|---|
| committer | xoviat <[email protected]> | 2023-10-04 16:15:08 -0500 |
| commit | e1a0635ca302b0a4009e305f170c906bb0d56949 (patch) | |
| tree | f5ced84d8633ba58096fa243539380a507cce9de | |
| parent | 59f706ee2f93252d1c040cea149dfd744f4d8c16 (diff) | |
stm32: update metapac and fix opamp ch
| -rw-r--r-- | embassy-stm32/Cargo.toml | 4 | ||||
| -rw-r--r-- | embassy-stm32/src/opamp.rs | 32 | ||||
| -rw-r--r-- | examples/stm32f334/src/bin/opamp.rs | 4 |
3 files changed, 33 insertions, 7 deletions
diff --git a/embassy-stm32/Cargo.toml b/embassy-stm32/Cargo.toml index d43252ada..1b688eca9 100644 --- a/embassy-stm32/Cargo.toml +++ b/embassy-stm32/Cargo.toml | |||
| @@ -59,7 +59,7 @@ sdio-host = "0.5.0" | |||
| 59 | embedded-sdmmc = { git = "https://github.com/embassy-rs/embedded-sdmmc-rs", rev = "a4f293d3a6f72158385f79c98634cb8a14d0d2fc", optional = true } | 59 | embedded-sdmmc = { git = "https://github.com/embassy-rs/embedded-sdmmc-rs", rev = "a4f293d3a6f72158385f79c98634cb8a14d0d2fc", optional = true } |
| 60 | critical-section = "1.1" | 60 | critical-section = "1.1" |
| 61 | atomic-polyfill = "1.0.1" | 61 | atomic-polyfill = "1.0.1" |
| 62 | stm32-metapac = { git = "https://github.com/embassy-rs/stm32-data-generated", tag = "stm32-data-06d13dfd245cc9bf86fd88c35b401bdb84c079c4" } | 62 | stm32-metapac = { git = "https://github.com/embassy-rs/stm32-data-generated", tag = "stm32-data-172c5ea18824d7cd38decb210e4af441fa3816cb" } |
| 63 | vcell = "0.1.3" | 63 | vcell = "0.1.3" |
| 64 | bxcan = "0.7.0" | 64 | bxcan = "0.7.0" |
| 65 | nb = "1.0.0" | 65 | nb = "1.0.0" |
| @@ -78,7 +78,7 @@ critical-section = { version = "1.1", features = ["std"] } | |||
| 78 | [build-dependencies] | 78 | [build-dependencies] |
| 79 | proc-macro2 = "1.0.36" | 79 | proc-macro2 = "1.0.36" |
| 80 | quote = "1.0.15" | 80 | quote = "1.0.15" |
| 81 | stm32-metapac = { git = "https://github.com/embassy-rs/stm32-data-generated", tag = "stm32-data-06d13dfd245cc9bf86fd88c35b401bdb84c079c4", default-features = false, features = ["metadata"]} | 81 | stm32-metapac = { git = "https://github.com/embassy-rs/stm32-data-generated", tag = "stm32-data-172c5ea18824d7cd38decb210e4af441fa3816cb", default-features = false, features = ["metadata"]} |
| 82 | 82 | ||
| 83 | 83 | ||
| 84 | [features] | 84 | [features] |
diff --git a/embassy-stm32/src/opamp.rs b/embassy-stm32/src/opamp.rs index 7b388aefe..e0fad26eb 100644 --- a/embassy-stm32/src/opamp.rs +++ b/embassy-stm32/src/opamp.rs | |||
| @@ -4,7 +4,15 @@ use embassy_hal_internal::{into_ref, PeripheralRef}; | |||
| 4 | 4 | ||
| 5 | use crate::Peripheral; | 5 | use crate::Peripheral; |
| 6 | 6 | ||
| 7 | #[cfg(opamp_f3)] | 7 | #[derive(Clone, Copy)] |
| 8 | pub enum OpAmpGain { | ||
| 9 | Mul1, | ||
| 10 | Mul2, | ||
| 11 | Mul4, | ||
| 12 | Mul8, | ||
| 13 | Mul16, | ||
| 14 | } | ||
| 15 | |||
| 8 | pub struct OpAmpOutput<'d, 'p, T: Instance, P: NonInvertingPin<T>> { | 16 | pub struct OpAmpOutput<'d, 'p, T: Instance, P: NonInvertingPin<T>> { |
| 9 | _inner: &'d OpAmp<'d, T>, | 17 | _inner: &'d OpAmp<'d, T>, |
| 10 | _input: &'p mut P, | 18 | _input: &'p mut P, |
| @@ -35,14 +43,32 @@ impl<'d, T: Instance> OpAmp<'d, T> { | |||
| 35 | Self { _inner: opamp } | 43 | Self { _inner: opamp } |
| 36 | } | 44 | } |
| 37 | 45 | ||
| 38 | #[cfg(opamp_f3)] | 46 | pub fn buffer_for<'a, 'b, P>(&'a mut self, pin: &'b mut P, gain: OpAmpGain) -> OpAmpOutput<'a, 'b, T, P> |
| 39 | pub fn buffer_for<'a, 'b, P>(&'a mut self, pin: &'b mut P) -> OpAmpOutput<'a, 'b, T, P> | ||
| 40 | where | 47 | where |
| 41 | P: NonInvertingPin<T>, | 48 | P: NonInvertingPin<T>, |
| 42 | { | 49 | { |
| 50 | let (vm_sel, pga_gain) = match gain { | ||
| 51 | OpAmpGain::Mul1 => (0b11, 0b00), | ||
| 52 | OpAmpGain::Mul2 => (0b10, 0b00), | ||
| 53 | OpAmpGain::Mul4 => (0b10, 0b01), | ||
| 54 | OpAmpGain::Mul8 => (0b10, 0b10), | ||
| 55 | OpAmpGain::Mul16 => (0b10, 0b11), | ||
| 56 | }; | ||
| 57 | |||
| 43 | #[cfg(opamp_f3)] | 58 | #[cfg(opamp_f3)] |
| 44 | T::regs().opampcsr().modify(|w| { | 59 | T::regs().opampcsr().modify(|w| { |
| 45 | w.set_vp_sel(pin.channel()); | 60 | w.set_vp_sel(pin.channel()); |
| 61 | w.set_vm_sel(vm_sel); | ||
| 62 | w.set_pga_gain(pga_gain); | ||
| 63 | }); | ||
| 64 | |||
| 65 | #[cfg(opamp_g4)] | ||
| 66 | T::regs().opamp_csr().modify(|w| { | ||
| 67 | use crate::pac::opamp::vals::*; | ||
| 68 | |||
| 69 | w.set_vp_sel(OpampCsrVpSel::from_bits(pin.channel())); | ||
| 70 | w.set_vm_sel(OpampCsrVmSel::from_bits(vm_sel)); | ||
| 71 | w.set_pga_gain(OpampCsrPgaGain::from_bits(pga_gain)); | ||
| 46 | }); | 72 | }); |
| 47 | 73 | ||
| 48 | OpAmpOutput { | 74 | OpAmpOutput { |
diff --git a/examples/stm32f334/src/bin/opamp.rs b/examples/stm32f334/src/bin/opamp.rs index 72263bab8..3fffcfb1f 100644 --- a/examples/stm32f334/src/bin/opamp.rs +++ b/examples/stm32f334/src/bin/opamp.rs | |||
| @@ -5,7 +5,7 @@ | |||
| 5 | use defmt::info; | 5 | use defmt::info; |
| 6 | use embassy_executor::Spawner; | 6 | use embassy_executor::Spawner; |
| 7 | use embassy_stm32::adc::{Adc, SampleTime}; | 7 | use embassy_stm32::adc::{Adc, SampleTime}; |
| 8 | use embassy_stm32::opamp::OpAmp; | 8 | use embassy_stm32::opamp::{OpAmp, OpAmpGain}; |
| 9 | use embassy_stm32::peripherals::ADC2; | 9 | use embassy_stm32::peripherals::ADC2; |
| 10 | use embassy_stm32::rcc::AdcClockSource; | 10 | use embassy_stm32::rcc::AdcClockSource; |
| 11 | use embassy_stm32::time::mhz; | 11 | use embassy_stm32::time::mhz; |
| @@ -39,7 +39,7 @@ async fn main(_spawner: Spawner) -> ! { | |||
| 39 | 39 | ||
| 40 | let mut vrefint = adc.enable_vref(&mut Delay); | 40 | let mut vrefint = adc.enable_vref(&mut Delay); |
| 41 | let mut temperature = adc.enable_temperature(); | 41 | let mut temperature = adc.enable_temperature(); |
| 42 | let mut buffer = opamp.buffer_for(&mut p.PA7); | 42 | let mut buffer = opamp.buffer_for(&mut p.PA7, OpAmpGain::Mul1); |
| 43 | 43 | ||
| 44 | loop { | 44 | loop { |
| 45 | let vref = adc.read(&mut vrefint).await; | 45 | let vref = adc.read(&mut vrefint).await; |
