Need to borrow the pins for the lifetime of the config, and subsequently the one shot.

This commit is contained in:
huntc 2021-10-11 08:52:45 +11:00
parent cef6158c31
commit 5f5470a320

View File

@ -60,7 +60,7 @@ impl Default for Config {
/// ///
/// See the `Default` impl for suitable default values. /// See the `Default` impl for suitable default values.
#[non_exhaustive] #[non_exhaustive]
pub struct ChannelConfig { pub struct ChannelConfig<'d> {
/// Reference voltage of the SAADC input. /// Reference voltage of the SAADC input.
pub reference: Reference, pub reference: Reference,
/// Gain used to control the effective input range of the SAADC. /// Gain used to control the effective input range of the SAADC.
@ -73,11 +73,13 @@ pub struct ChannelConfig {
p_channel: PositiveChannel, p_channel: PositiveChannel,
/// An optional negative channel to sample /// An optional negative channel to sample
n_channel: Option<NegativeChannel>, n_channel: Option<NegativeChannel>,
phantom: PhantomData<&'d ()>,
} }
impl ChannelConfig { impl<'d> ChannelConfig<'d> {
/// Default configuration for single ended channel sampling. /// Default configuration for single ended channel sampling.
pub fn single_ended(pin: impl Unborrow<Target = impl PositivePin>) -> Self { pub fn single_ended(pin: impl Unborrow<Target = impl PositivePin> + 'd) -> Self {
unborrow!(pin); unborrow!(pin);
Self { Self {
reference: Reference::INTERNAL, reference: Reference::INTERNAL,
@ -86,12 +88,13 @@ impl ChannelConfig {
time: Time::_10US, time: Time::_10US,
p_channel: pin.channel(), p_channel: pin.channel(),
n_channel: None, n_channel: None,
phantom: PhantomData,
} }
} }
/// Default configuration for differential channel sampling. /// Default configuration for differential channel sampling.
pub fn differential( pub fn differential(
ppin: impl Unborrow<Target = impl PositivePin>, ppin: impl Unborrow<Target = impl PositivePin> + 'd,
npin: impl Unborrow<Target = impl NegativePin>, npin: impl Unborrow<Target = impl NegativePin> + 'd,
) -> Self { ) -> Self {
unborrow!(ppin, npin); unborrow!(ppin, npin);
Self { Self {
@ -101,6 +104,7 @@ impl ChannelConfig {
time: Time::_10US, time: Time::_10US,
p_channel: ppin.channel(), p_channel: ppin.channel(),
n_channel: Some(npin.channel()), n_channel: Some(npin.channel()),
phantom: PhantomData,
} }
} }
} }