448: Dummy pin implementation for Saadc internal vdd sampling r=Dirbaio a=jacobrosenthal

For instance, for reading the battery input voltage on the nrf
Api ends up looking like
`let channel_config = saadc::ChannelConfig::single_ended(saadc::VddInput::default());`

I ~haven't confirmed a sane reading yet~, but this compiles so is ready for bikeshedding
Update: It looks like Ive got sane readings

Co-authored-by: Jacob Rosenthal <jacobrosenthal@gmail.com>
This commit is contained in:
bors[bot] 2021-10-25 00:56:44 +00:00 committed by GitHub
commit 9b59eb3dbe
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -78,6 +78,29 @@ pub struct ChannelConfig<'d> {
phantom: PhantomData<&'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> { impl<'d> ChannelConfig<'d> {
/// Default configuration for single ended channel sampling. /// Default configuration for single ended channel sampling.
pub fn single_ended(input: impl Unborrow<Target = impl Input> + 'd) -> Self { pub fn single_ended(input: impl Unborrow<Target = impl Input> + 'd) -> Self {