From 5f5470a320c47f0cda207e515aaf36e4f63ac043 Mon Sep 17 00:00:00 2001 From: huntc Date: Mon, 11 Oct 2021 08:52:45 +1100 Subject: [PATCH] Need to borrow the pins for the lifetime of the config, and subsequently the one shot. --- embassy-nrf/src/saadc.rs | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/embassy-nrf/src/saadc.rs b/embassy-nrf/src/saadc.rs index 12c302d5..d7ccd2fc 100644 --- a/embassy-nrf/src/saadc.rs +++ b/embassy-nrf/src/saadc.rs @@ -60,7 +60,7 @@ impl Default for Config { /// /// See the `Default` impl for suitable default values. #[non_exhaustive] -pub struct ChannelConfig { +pub struct ChannelConfig<'d> { /// Reference voltage of the SAADC input. pub reference: Reference, /// Gain used to control the effective input range of the SAADC. @@ -73,11 +73,13 @@ pub struct ChannelConfig { p_channel: PositiveChannel, /// An optional negative channel to sample n_channel: Option, + + phantom: PhantomData<&'d ()>, } -impl ChannelConfig { +impl<'d> ChannelConfig<'d> { /// Default configuration for single ended channel sampling. - pub fn single_ended(pin: impl Unborrow) -> Self { + pub fn single_ended(pin: impl Unborrow + 'd) -> Self { unborrow!(pin); Self { reference: Reference::INTERNAL, @@ -86,12 +88,13 @@ impl ChannelConfig { time: Time::_10US, p_channel: pin.channel(), n_channel: None, + phantom: PhantomData, } } /// Default configuration for differential channel sampling. pub fn differential( - ppin: impl Unborrow, - npin: impl Unborrow, + ppin: impl Unborrow + 'd, + npin: impl Unborrow + 'd, ) -> Self { unborrow!(ppin, npin); Self { @@ -101,6 +104,7 @@ impl ChannelConfig { time: Time::_10US, p_channel: ppin.channel(), n_channel: Some(npin.channel()), + phantom: PhantomData, } } }