diff options
| author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2021-10-25 00:56:44 +0000 |
|---|---|---|
| committer | GitHub <[email protected]> | 2021-10-25 00:56:44 +0000 |
| commit | 9b59eb3dbecb1c1b79f2be55e4f68747b0698953 (patch) | |
| tree | 00ebd4a1aed263c35850122aa63036150bfba972 | |
| parent | f3f3858328ed4f13efb3790e32ee4fba772b57a2 (diff) | |
| parent | 32850bba79cbf5fcb06f8068cfd46919020b19be (diff) | |
Merge #448
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 <[email protected]>
| -rw-r--r-- | embassy-nrf/src/saadc.rs | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/embassy-nrf/src/saadc.rs b/embassy-nrf/src/saadc.rs index 215f968a7..efcdfb2b1 100644 --- a/embassy-nrf/src/saadc.rs +++ b/embassy-nrf/src/saadc.rs | |||
| @@ -78,6 +78,29 @@ pub struct ChannelConfig<'d> { | |||
| 78 | phantom: PhantomData<&'d ()>, | 78 | phantom: PhantomData<&'d ()>, |
| 79 | } | 79 | } |
| 80 | 80 | ||
| 81 | /// A dummy `Input` pin implementation for SAADC peripheral sampling from the | ||
| 82 | /// internal voltage. | ||
| 83 | pub struct VddInput; | ||
| 84 | |||
| 85 | unsafe impl Unborrow for VddInput { | ||
| 86 | type Target = VddInput; | ||
| 87 | unsafe fn unborrow(self) -> Self::Target { | ||
| 88 | self | ||
| 89 | } | ||
| 90 | } | ||
| 91 | |||
| 92 | impl sealed::Input for VddInput { | ||
| 93 | #[cfg(not(feature = "nrf9160"))] | ||
| 94 | fn channel(&self) -> InputChannel { | ||
| 95 | InputChannel::VDD | ||
| 96 | } | ||
| 97 | #[cfg(feature = "nrf9160")] | ||
| 98 | fn channel(&self) -> InputChannel { | ||
| 99 | InputChannel::VDDGPIO | ||
| 100 | } | ||
| 101 | } | ||
| 102 | impl Input for VddInput {} | ||
| 103 | |||
| 81 | impl<'d> ChannelConfig<'d> { | 104 | impl<'d> ChannelConfig<'d> { |
| 82 | /// Default configuration for single ended channel sampling. | 105 | /// Default configuration for single ended channel sampling. |
| 83 | pub fn single_ended(input: impl Unborrow<Target = impl Input> + 'd) -> Self { | 106 | pub fn single_ended(input: impl Unborrow<Target = impl Input> + 'd) -> Self { |
