From 32850bba79cbf5fcb06f8068cfd46919020b19be Mon Sep 17 00:00:00 2001 From: Jacob Rosenthal Date: Sat, 23 Oct 2021 15:53:31 -0700 Subject: [PATCH] nrf: saadc dummy pin for vdd sampling --- embassy-nrf/src/saadc.rs | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/embassy-nrf/src/saadc.rs b/embassy-nrf/src/saadc.rs index 215f968a7..efcdfb2b1 100644 --- a/embassy-nrf/src/saadc.rs +++ b/embassy-nrf/src/saadc.rs @@ -78,6 +78,29 @@ pub struct ChannelConfig<'d> { phantom: PhantomData<&'d ()>, } +/// A dummy `Input` pin implementation for SAADC peripheral sampling from the +/// internal voltage. +pub struct VddInput; + +unsafe impl Unborrow for VddInput { + type Target = VddInput; + unsafe fn unborrow(self) -> Self::Target { + self + } +} + +impl sealed::Input for VddInput { + #[cfg(not(feature = "nrf9160"))] + fn channel(&self) -> InputChannel { + InputChannel::VDD + } + #[cfg(feature = "nrf9160")] + fn channel(&self) -> InputChannel { + InputChannel::VDDGPIO + } +} +impl Input for VddInput {} + impl<'d> ChannelConfig<'d> { /// Default configuration for single ended channel sampling. pub fn single_ended(input: impl Unborrow + 'd) -> Self {