From 6ef9e564cad088c246af97f408c5b34dc47301b5 Mon Sep 17 00:00:00 2001 From: Dion Dokter Date: Thu, 25 Jul 2024 12:22:55 +0200 Subject: [PATCH 1/2] Add extra lifetime to opamp-using structs --- embassy-stm32/src/opamp.rs | 40 +++++++++++++++++++------------------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/embassy-stm32/src/opamp.rs b/embassy-stm32/src/opamp.rs index ca94a573d..f3f8368f8 100644 --- a/embassy-stm32/src/opamp.rs +++ b/embassy-stm32/src/opamp.rs @@ -38,15 +38,15 @@ impl From for crate::pac::opamp::vals::Opahsm { /// OpAmp external outputs, wired to a GPIO pad. /// /// This struct can also be used as an ADC input. -pub struct OpAmpOutput<'d, T: Instance> { - _inner: &'d OpAmp<'d, T>, +pub struct OpAmpOutput<'a, 'd: 'a, T: Instance> { + _inner: &'a OpAmp<'d, T>, } /// OpAmp internal outputs, wired directly to ADC inputs. /// /// This struct can be used as an ADC input. -pub struct OpAmpInternalOutput<'d, T: Instance> { - _inner: &'d OpAmp<'d, T>, +pub struct OpAmpInternalOutput<'a, 'd: 'a, T: Instance> { + _inner: &'a OpAmp<'d, T>, } /// OpAmp driver. @@ -80,11 +80,11 @@ impl<'d, T: Instance> OpAmp<'d, T> { /// directly used as an ADC input. The opamp will be disabled when the /// [`OpAmpOutput`] is dropped. pub fn buffer_ext( - &'d mut self, + &mut self, in_pin: impl Peripheral

+ crate::gpio::Pin>, out_pin: impl Peripheral

+ crate::gpio::Pin> + 'd, gain: OpAmpGain, - ) -> OpAmpOutput<'d, T> { + ) -> OpAmpOutput<'_, 'd, T> { into_ref!(in_pin); into_ref!(out_pin); in_pin.set_as_analog(); @@ -119,9 +119,9 @@ impl<'d, T: Instance> OpAmp<'d, T> { /// [`OpAmpOutput`] is dropped. #[cfg(opamp_g4)] pub fn buffer_dac( - &'d mut self, + &mut self, out_pin: impl Peripheral

+ crate::gpio::Pin> + 'd, - ) -> OpAmpOutput<'d, T> { + ) -> OpAmpOutput<'_, 'd, T> { into_ref!(out_pin); out_pin.set_as_analog(); @@ -147,10 +147,10 @@ impl<'d, T: Instance> OpAmp<'d, T> { /// The opamp output will be disabled when it is dropped. #[cfg(opamp_g4)] pub fn buffer_int( - &'d mut self, + &mut self, pin: impl Peripheral

+ crate::gpio::Pin>, gain: OpAmpGain, - ) -> OpAmpInternalOutput<'d, T> { + ) -> OpAmpInternalOutput<'_, 'd, T> { into_ref!(pin); pin.set_as_analog(); @@ -176,7 +176,7 @@ impl<'d, T: Instance> OpAmp<'d, T> { } } -impl<'d, T: Instance> Drop for OpAmpOutput<'d, T> { +impl<'a, 'd: 'a, T: Instance> Drop for OpAmpOutput<'a, 'd, T> { fn drop(&mut self) { T::regs().csr().modify(|w| { w.set_opampen(false); @@ -184,7 +184,7 @@ impl<'d, T: Instance> Drop for OpAmpOutput<'d, T> { } } -impl<'d, T: Instance> Drop for OpAmpInternalOutput<'d, T> { +impl<'a, 'd: 'a, T: Instance> Drop for OpAmpInternalOutput<'a, 'd, T> { fn drop(&mut self) { T::regs().csr().modify(|w| { w.set_opampen(false); @@ -224,16 +224,16 @@ macro_rules! impl_opamp_external_output { ($inst:ident, $adc:ident, $ch:expr) => { foreach_adc!( ($adc, $common_inst:ident, $adc_clock:ident) => { - impl<'d> crate::adc::SealedAdcChannel - for OpAmpOutput<'d, crate::peripherals::$inst> + impl<'a, 'd: 'a> crate::adc::SealedAdcChannel + for OpAmpOutput<'a, 'd, crate::peripherals::$inst> { fn channel(&self) -> u8 { $ch } } - impl<'d> crate::adc::AdcChannel - for OpAmpOutput<'d, crate::peripherals::$inst> + impl<'a, 'd: 'a> crate::adc::AdcChannel + for OpAmpOutput<'a, 'd, crate::peripherals::$inst> { } }; @@ -270,16 +270,16 @@ macro_rules! impl_opamp_internal_output { ($inst:ident, $adc:ident, $ch:expr) => { foreach_adc!( ($adc, $common_inst:ident, $adc_clock:ident) => { - impl<'d> crate::adc::SealedAdcChannel - for OpAmpInternalOutput<'d, crate::peripherals::$inst> + impl<'a, 'd: 'a> crate::adc::SealedAdcChannel + for OpAmpInternalOutput<'a, 'd, crate::peripherals::$inst> { fn channel(&self) -> u8 { $ch } } - impl<'d> crate::adc::AdcChannel - for OpAmpInternalOutput<'d, crate::peripherals::$inst> + impl<'a, 'd: 'a> crate::adc::AdcChannel + for OpAmpInternalOutput<'a, 'd, crate::peripherals::$inst> { } }; From 4a8abe802806c5d193a43ec81450636a86a34f0a Mon Sep 17 00:00:00 2001 From: Dion Dokter Date: Thu, 25 Jul 2024 16:01:27 +0200 Subject: [PATCH 2/2] Relax lifetimes again --- embassy-stm32/src/opamp.rs | 38 +++++++++++++++++++------------------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/embassy-stm32/src/opamp.rs b/embassy-stm32/src/opamp.rs index f3f8368f8..36b9cb9cc 100644 --- a/embassy-stm32/src/opamp.rs +++ b/embassy-stm32/src/opamp.rs @@ -38,15 +38,15 @@ impl From for crate::pac::opamp::vals::Opahsm { /// OpAmp external outputs, wired to a GPIO pad. /// /// This struct can also be used as an ADC input. -pub struct OpAmpOutput<'a, 'd: 'a, T: Instance> { - _inner: &'a OpAmp<'d, T>, +pub struct OpAmpOutput<'d, T: Instance> { + _inner: &'d OpAmp<'d, T>, } /// OpAmp internal outputs, wired directly to ADC inputs. /// /// This struct can be used as an ADC input. -pub struct OpAmpInternalOutput<'a, 'd: 'a, T: Instance> { - _inner: &'a OpAmp<'d, T>, +pub struct OpAmpInternalOutput<'d, T: Instance> { + _inner: &'d OpAmp<'d, T>, } /// OpAmp driver. @@ -82,9 +82,9 @@ impl<'d, T: Instance> OpAmp<'d, T> { pub fn buffer_ext( &mut self, in_pin: impl Peripheral

+ crate::gpio::Pin>, - out_pin: impl Peripheral

+ crate::gpio::Pin> + 'd, + out_pin: impl Peripheral

+ crate::gpio::Pin>, gain: OpAmpGain, - ) -> OpAmpOutput<'_, 'd, T> { + ) -> OpAmpOutput<'_, T> { into_ref!(in_pin); into_ref!(out_pin); in_pin.set_as_analog(); @@ -120,8 +120,8 @@ impl<'d, T: Instance> OpAmp<'d, T> { #[cfg(opamp_g4)] pub fn buffer_dac( &mut self, - out_pin: impl Peripheral

+ crate::gpio::Pin> + 'd, - ) -> OpAmpOutput<'_, 'd, T> { + out_pin: impl Peripheral

+ crate::gpio::Pin>, + ) -> OpAmpOutput<'_, T> { into_ref!(out_pin); out_pin.set_as_analog(); @@ -150,7 +150,7 @@ impl<'d, T: Instance> OpAmp<'d, T> { &mut self, pin: impl Peripheral

+ crate::gpio::Pin>, gain: OpAmpGain, - ) -> OpAmpInternalOutput<'_, 'd, T> { + ) -> OpAmpInternalOutput<'_, T> { into_ref!(pin); pin.set_as_analog(); @@ -176,7 +176,7 @@ impl<'d, T: Instance> OpAmp<'d, T> { } } -impl<'a, 'd: 'a, T: Instance> Drop for OpAmpOutput<'a, 'd, T> { +impl<'d, T: Instance> Drop for OpAmpOutput<'d, T> { fn drop(&mut self) { T::regs().csr().modify(|w| { w.set_opampen(false); @@ -184,7 +184,7 @@ impl<'a, 'd: 'a, T: Instance> Drop for OpAmpOutput<'a, 'd, T> { } } -impl<'a, 'd: 'a, T: Instance> Drop for OpAmpInternalOutput<'a, 'd, T> { +impl<'d, T: Instance> Drop for OpAmpInternalOutput<'d, T> { fn drop(&mut self) { T::regs().csr().modify(|w| { w.set_opampen(false); @@ -224,16 +224,16 @@ macro_rules! impl_opamp_external_output { ($inst:ident, $adc:ident, $ch:expr) => { foreach_adc!( ($adc, $common_inst:ident, $adc_clock:ident) => { - impl<'a, 'd: 'a> crate::adc::SealedAdcChannel - for OpAmpOutput<'a, 'd, crate::peripherals::$inst> + impl<'d> crate::adc::SealedAdcChannel + for OpAmpOutput<'d, crate::peripherals::$inst> { fn channel(&self) -> u8 { $ch } } - impl<'a, 'd: 'a> crate::adc::AdcChannel - for OpAmpOutput<'a, 'd, crate::peripherals::$inst> + impl<'d> crate::adc::AdcChannel + for OpAmpOutput<'d, crate::peripherals::$inst> { } }; @@ -270,16 +270,16 @@ macro_rules! impl_opamp_internal_output { ($inst:ident, $adc:ident, $ch:expr) => { foreach_adc!( ($adc, $common_inst:ident, $adc_clock:ident) => { - impl<'a, 'd: 'a> crate::adc::SealedAdcChannel - for OpAmpInternalOutput<'a, 'd, crate::peripherals::$inst> + impl<'d> crate::adc::SealedAdcChannel + for OpAmpInternalOutput<'d, crate::peripherals::$inst> { fn channel(&self) -> u8 { $ch } } - impl<'a, 'd: 'a> crate::adc::AdcChannel - for OpAmpInternalOutput<'a, 'd, crate::peripherals::$inst> + impl<'d> crate::adc::AdcChannel + for OpAmpInternalOutput<'d, crate::peripherals::$inst> { } };