aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorhuntc <[email protected]>2021-10-11 08:52:45 +1100
committerhuntc <[email protected]>2021-10-11 08:52:45 +1100
commit5f5470a320c47f0cda207e515aaf36e4f63ac043 (patch)
treeb1724353ada3cc462700cb734bc2fc5d18f275a9
parentcef6158c31794795f16099e3df4c9049b976dae6 (diff)
Need to borrow the pins for the lifetime of the config, and subsequently the one shot.
-rw-r--r--embassy-nrf/src/saadc.rs14
1 files changed, 9 insertions, 5 deletions
diff --git a/embassy-nrf/src/saadc.rs b/embassy-nrf/src/saadc.rs
index 12c302d58..d7ccd2fc3 100644
--- a/embassy-nrf/src/saadc.rs
+++ b/embassy-nrf/src/saadc.rs
@@ -60,7 +60,7 @@ impl Default for Config {
60/// 60///
61/// See the `Default` impl for suitable default values. 61/// See the `Default` impl for suitable default values.
62#[non_exhaustive] 62#[non_exhaustive]
63pub struct ChannelConfig { 63pub struct ChannelConfig<'d> {
64 /// Reference voltage of the SAADC input. 64 /// Reference voltage of the SAADC input.
65 pub reference: Reference, 65 pub reference: Reference,
66 /// Gain used to control the effective input range of the SAADC. 66 /// Gain used to control the effective input range of the SAADC.
@@ -73,11 +73,13 @@ pub struct ChannelConfig {
73 p_channel: PositiveChannel, 73 p_channel: PositiveChannel,
74 /// An optional negative channel to sample 74 /// An optional negative channel to sample
75 n_channel: Option<NegativeChannel>, 75 n_channel: Option<NegativeChannel>,
76
77 phantom: PhantomData<&'d ()>,
76} 78}
77 79
78impl ChannelConfig { 80impl<'d> ChannelConfig<'d> {
79 /// Default configuration for single ended channel sampling. 81 /// Default configuration for single ended channel sampling.
80 pub fn single_ended(pin: impl Unborrow<Target = impl PositivePin>) -> Self { 82 pub fn single_ended(pin: impl Unborrow<Target = impl PositivePin> + 'd) -> Self {
81 unborrow!(pin); 83 unborrow!(pin);
82 Self { 84 Self {
83 reference: Reference::INTERNAL, 85 reference: Reference::INTERNAL,
@@ -86,12 +88,13 @@ impl ChannelConfig {
86 time: Time::_10US, 88 time: Time::_10US,
87 p_channel: pin.channel(), 89 p_channel: pin.channel(),
88 n_channel: None, 90 n_channel: None,
91 phantom: PhantomData,
89 } 92 }
90 } 93 }
91 /// Default configuration for differential channel sampling. 94 /// Default configuration for differential channel sampling.
92 pub fn differential( 95 pub fn differential(
93 ppin: impl Unborrow<Target = impl PositivePin>, 96 ppin: impl Unborrow<Target = impl PositivePin> + 'd,
94 npin: impl Unborrow<Target = impl NegativePin>, 97 npin: impl Unborrow<Target = impl NegativePin> + 'd,
95 ) -> Self { 98 ) -> Self {
96 unborrow!(ppin, npin); 99 unborrow!(ppin, npin);
97 Self { 100 Self {
@@ -101,6 +104,7 @@ impl ChannelConfig {
101 time: Time::_10US, 104 time: Time::_10US,
102 p_channel: ppin.channel(), 105 p_channel: ppin.channel(),
103 n_channel: Some(npin.channel()), 106 n_channel: Some(npin.channel()),
107 phantom: PhantomData,
104 } 108 }
105 } 109 }
106} 110}