diff options
| -rw-r--r-- | embassy-stm32/src/opamp.rs | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/embassy-stm32/src/opamp.rs b/embassy-stm32/src/opamp.rs index 487902959..ca94a573d 100644 --- a/embassy-stm32/src/opamp.rs +++ b/embassy-stm32/src/opamp.rs | |||
| @@ -110,6 +110,32 @@ impl<'d, T: Instance> OpAmp<'d, T> { | |||
| 110 | 110 | ||
| 111 | OpAmpOutput { _inner: self } | 111 | OpAmpOutput { _inner: self } |
| 112 | } | 112 | } |
| 113 | /// Configure the OpAmp as a buffer for the DAC it is connected to, | ||
| 114 | /// outputting to the provided output pin, and enable the opamp. | ||
| 115 | /// | ||
| 116 | /// The output pin is held within the returned [`OpAmpOutput`] struct, | ||
| 117 | /// preventing it being used elsewhere. The `OpAmpOutput` can then be | ||
| 118 | /// directly used as an ADC input. The opamp will be disabled when the | ||
| 119 | /// [`OpAmpOutput`] is dropped. | ||
| 120 | #[cfg(opamp_g4)] | ||
| 121 | pub fn buffer_dac( | ||
| 122 | &'d mut self, | ||
| 123 | out_pin: impl Peripheral<P = impl OutputPin<T> + crate::gpio::Pin> + 'd, | ||
| 124 | ) -> OpAmpOutput<'d, T> { | ||
| 125 | into_ref!(out_pin); | ||
| 126 | out_pin.set_as_analog(); | ||
| 127 | |||
| 128 | T::regs().csr().modify(|w| { | ||
| 129 | use crate::pac::opamp::vals::*; | ||
| 130 | |||
| 131 | w.set_vm_sel(VmSel::OUTPUT); | ||
| 132 | w.set_vp_sel(VpSel::DAC3_CH1); | ||
| 133 | w.set_opaintoen(Opaintoen::OUTPUTPIN); | ||
| 134 | w.set_opampen(true); | ||
| 135 | }); | ||
| 136 | |||
| 137 | OpAmpOutput { _inner: self } | ||
| 138 | } | ||
| 113 | 139 | ||
| 114 | /// Configure the OpAmp as a buffer for the provided input pin, | 140 | /// Configure the OpAmp as a buffer for the provided input pin, |
| 115 | /// with the output only used internally, and enable the opamp. | 141 | /// with the output only used internally, and enable the opamp. |
