aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDario Nieuwenhuis <[email protected]>2022-07-21 16:42:46 +0200
committerDario Nieuwenhuis <[email protected]>2022-07-21 16:42:46 +0200
commit424f6ffadbcb7c1f7df995ab98bcafebc941afc2 (patch)
tree9e8944f2ef7bb7e1f659ad3c7a2d9d5ed380be64
parent26fdfdb00a1819f4a21c8d0fe1220c079983eecc (diff)
nrf/saadc: add type-erased AnyInput.
-rw-r--r--embassy-nrf/src/saadc.rs27
1 files changed, 26 insertions, 1 deletions
diff --git a/embassy-nrf/src/saadc.rs b/embassy-nrf/src/saadc.rs
index 7d39e33f8..af1aa8812 100644
--- a/embassy-nrf/src/saadc.rs
+++ b/embassy-nrf/src/saadc.rs
@@ -119,6 +119,25 @@ impl sealed::Input for VddhDiv5Input {
119#[cfg(any(feature = "_nrf5340-app", feature = "nrf52833", feature = "nrf52840"))] 119#[cfg(any(feature = "_nrf5340-app", feature = "nrf52833", feature = "nrf52840"))]
120impl Input for VddhDiv5Input {} 120impl Input for VddhDiv5Input {}
121 121
122pub struct AnyInput {
123 channel: InputChannel,
124}
125
126unsafe impl Unborrow for AnyInput {
127 type Target = AnyInput;
128 unsafe fn unborrow(self) -> Self::Target {
129 self
130 }
131}
132
133impl sealed::Input for AnyInput {
134 fn channel(&self) -> InputChannel {
135 self.channel
136 }
137}
138
139impl Input for AnyInput {}
140
122impl<'d> ChannelConfig<'d> { 141impl<'d> ChannelConfig<'d> {
123 /// Default configuration for single ended channel sampling. 142 /// Default configuration for single ended channel sampling.
124 pub fn single_ended(input: impl Unborrow<Target = impl Input> + 'd) -> Self { 143 pub fn single_ended(input: impl Unborrow<Target = impl Input> + 'd) -> Self {
@@ -670,7 +689,13 @@ pub(crate) mod sealed {
670} 689}
671 690
672/// An input that can be used as either or negative end of a ADC differential in the SAADC periperhal. 691/// An input that can be used as either or negative end of a ADC differential in the SAADC periperhal.
673pub trait Input: sealed::Input + Unborrow<Target = Self> {} 692pub trait Input: sealed::Input + Unborrow<Target = Self> + Sized {
693 fn degrade_saadc(self) -> AnyInput {
694 AnyInput {
695 channel: self.channel(),
696 }
697 }
698}
674 699
675macro_rules! impl_saadc_input { 700macro_rules! impl_saadc_input {
676 ($pin:ident, $ch:ident) => { 701 ($pin:ident, $ch:ident) => {