From 0d709fa5c8c517a29594c29323f1dcfc845f38cd Mon Sep 17 00:00:00 2001
From: Dario Nieuwenhuis <dirbaio@dirbaio.net>
Date: Wed, 13 Oct 2021 21:58:43 +0200
Subject: [PATCH 1/3] nrf/saadc: require unborrow for Input.

This allows using borrowed pins in ChannelConfig.
---
 embassy-nrf/src/saadc.rs | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/embassy-nrf/src/saadc.rs b/embassy-nrf/src/saadc.rs
index 2ce7ef16d..7f81d255f 100644
--- a/embassy-nrf/src/saadc.rs
+++ b/embassy-nrf/src/saadc.rs
@@ -229,7 +229,7 @@ impl<'d, const N: usize> Drop for OneShot<'d, N> {
 }
 
 /// An input that can be used as either or negative end of a ADC differential in the SAADC periperhal.
-pub trait Input {
+pub trait Input: Unborrow<Target = Self> {
     fn channel(&self) -> InputChannel;
 }
 

From d8c3365d6a78f272a28ee9c2740d4e7543dde474 Mon Sep 17 00:00:00 2001
From: Dario Nieuwenhuis <dirbaio@dirbaio.net>
Date: Wed, 13 Oct 2021 22:01:39 +0200
Subject: [PATCH 2/3] nrf/saadc: make Input trait sealed.

---
 embassy-nrf/src/saadc.rs | 15 +++++++++++----
 1 file changed, 11 insertions(+), 4 deletions(-)

diff --git a/embassy-nrf/src/saadc.rs b/embassy-nrf/src/saadc.rs
index 7f81d255f..c2787e02b 100644
--- a/embassy-nrf/src/saadc.rs
+++ b/embassy-nrf/src/saadc.rs
@@ -228,17 +228,24 @@ impl<'d, const N: usize> Drop for OneShot<'d, N> {
     }
 }
 
-/// An input that can be used as either or negative end of a ADC differential in the SAADC periperhal.
-pub trait Input: Unborrow<Target = Self> {
-    fn channel(&self) -> InputChannel;
+pub(crate) mod sealed {
+    use super::*;
+
+    pub trait Input {
+        fn channel(&self) -> InputChannel;
+    }
 }
 
+/// An input that can be used as either or negative end of a ADC differential in the SAADC periperhal.
+pub trait Input: sealed::Input + Unborrow<Target = Self> {}
+
 macro_rules! impl_saadc_input {
     ($pin:ident, $ch:ident) => {
-        impl crate::saadc::Input for crate::peripherals::$pin {
+        impl crate::saadc::sealed::Input for crate::peripherals::$pin {
             fn channel(&self) -> crate::saadc::InputChannel {
                 crate::saadc::InputChannel::$ch
             }
         }
+        impl crate::saadc::Input for crate::peripherals::$pin {}
     };
 }

From c675fb1036c18cbbfc714734888eececc0f7beb1 Mon Sep 17 00:00:00 2001
From: Dario Nieuwenhuis <dirbaio@dirbaio.net>
Date: Wed, 13 Oct 2021 22:01:49 +0200
Subject: [PATCH 3/3] nrf/saadc: make InputChannel private.

---
 embassy-nrf/src/saadc.rs | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/embassy-nrf/src/saadc.rs b/embassy-nrf/src/saadc.rs
index c2787e02b..94744c444 100644
--- a/embassy-nrf/src/saadc.rs
+++ b/embassy-nrf/src/saadc.rs
@@ -14,11 +14,11 @@ use crate::{pac, peripherals};
 
 use pac::{saadc, SAADC};
 
+// We treat the positive and negative channels with the same enum values to keep our type tidy and given they are the same
+pub(crate) use saadc::ch::pselp::PSELP_A as InputChannel;
+
 pub use saadc::{
-    ch::{
-        config::{GAIN_A as Gain, REFSEL_A as Reference, RESP_A as Resistor, TACQ_A as Time},
-        pselp::PSELP_A as InputChannel, // We treat the positive and negative channels with the same enum values to keep our type tidy and given they are the same
-    },
+    ch::config::{GAIN_A as Gain, REFSEL_A as Reference, RESP_A as Resistor, TACQ_A as Time},
     oversample::OVERSAMPLE_A as Oversample,
     resolution::VAL_A as Resolution,
 };