diff options
| -rw-r--r-- | embassy-nrf/src/saadc.rs | 27 |
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"))] |
| 120 | impl Input for VddhDiv5Input {} | 120 | impl Input for VddhDiv5Input {} |
| 121 | 121 | ||
| 122 | pub struct AnyInput { | ||
| 123 | channel: InputChannel, | ||
| 124 | } | ||
| 125 | |||
| 126 | unsafe impl Unborrow for AnyInput { | ||
| 127 | type Target = AnyInput; | ||
| 128 | unsafe fn unborrow(self) -> Self::Target { | ||
| 129 | self | ||
| 130 | } | ||
| 131 | } | ||
| 132 | |||
| 133 | impl sealed::Input for AnyInput { | ||
| 134 | fn channel(&self) -> InputChannel { | ||
| 135 | self.channel | ||
| 136 | } | ||
| 137 | } | ||
| 138 | |||
| 139 | impl Input for AnyInput {} | ||
| 140 | |||
| 122 | impl<'d> ChannelConfig<'d> { | 141 | impl<'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. |
| 673 | pub trait Input: sealed::Input + Unborrow<Target = Self> {} | 692 | pub 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 | ||
| 675 | macro_rules! impl_saadc_input { | 700 | macro_rules! impl_saadc_input { |
| 676 | ($pin:ident, $ch:ident) => { | 701 | ($pin:ident, $ch:ident) => { |
