diff options
| -rw-r--r-- | embassy-nrf/src/saadc.rs | 23 |
1 files changed, 15 insertions, 8 deletions
diff --git a/embassy-nrf/src/saadc.rs b/embassy-nrf/src/saadc.rs index 2ce7ef16d..94744c444 100644 --- a/embassy-nrf/src/saadc.rs +++ b/embassy-nrf/src/saadc.rs | |||
| @@ -14,11 +14,11 @@ use crate::{pac, peripherals}; | |||
| 14 | 14 | ||
| 15 | use pac::{saadc, SAADC}; | 15 | use pac::{saadc, SAADC}; |
| 16 | 16 | ||
| 17 | // We treat the positive and negative channels with the same enum values to keep our type tidy and given they are the same | ||
| 18 | pub(crate) use saadc::ch::pselp::PSELP_A as InputChannel; | ||
| 19 | |||
| 17 | pub use saadc::{ | 20 | pub use saadc::{ |
| 18 | ch::{ | 21 | ch::config::{GAIN_A as Gain, REFSEL_A as Reference, RESP_A as Resistor, TACQ_A as Time}, |
| 19 | config::{GAIN_A as Gain, REFSEL_A as Reference, RESP_A as Resistor, TACQ_A as Time}, | ||
| 20 | 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 | ||
| 21 | }, | ||
| 22 | oversample::OVERSAMPLE_A as Oversample, | 22 | oversample::OVERSAMPLE_A as Oversample, |
| 23 | resolution::VAL_A as Resolution, | 23 | resolution::VAL_A as Resolution, |
| 24 | }; | 24 | }; |
| @@ -228,17 +228,24 @@ impl<'d, const N: usize> Drop for OneShot<'d, N> { | |||
| 228 | } | 228 | } |
| 229 | } | 229 | } |
| 230 | 230 | ||
| 231 | /// An input that can be used as either or negative end of a ADC differential in the SAADC periperhal. | 231 | pub(crate) mod sealed { |
| 232 | pub trait Input { | 232 | use super::*; |
| 233 | fn channel(&self) -> InputChannel; | 233 | |
| 234 | pub trait Input { | ||
| 235 | fn channel(&self) -> InputChannel; | ||
| 236 | } | ||
| 234 | } | 237 | } |
| 235 | 238 | ||
| 239 | /// An input that can be used as either or negative end of a ADC differential in the SAADC periperhal. | ||
| 240 | pub trait Input: sealed::Input + Unborrow<Target = Self> {} | ||
| 241 | |||
| 236 | macro_rules! impl_saadc_input { | 242 | macro_rules! impl_saadc_input { |
| 237 | ($pin:ident, $ch:ident) => { | 243 | ($pin:ident, $ch:ident) => { |
| 238 | impl crate::saadc::Input for crate::peripherals::$pin { | 244 | impl crate::saadc::sealed::Input for crate::peripherals::$pin { |
| 239 | fn channel(&self) -> crate::saadc::InputChannel { | 245 | fn channel(&self) -> crate::saadc::InputChannel { |
| 240 | crate::saadc::InputChannel::$ch | 246 | crate::saadc::InputChannel::$ch |
| 241 | } | 247 | } |
| 242 | } | 248 | } |
| 249 | impl crate::saadc::Input for crate::peripherals::$pin {} | ||
| 243 | }; | 250 | }; |
| 244 | } | 251 | } |
