Merge pull request #414 from embassy-rs/nrf-saadc-remove-trait

nrf/saadc: remove Sample trait.
This commit is contained in:
Dario Nieuwenhuis 2021-10-07 02:15:19 +02:00 committed by GitHub
commit 009b77c1b9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 3 additions and 21 deletions

View File

@ -1,4 +1,3 @@
use core::future::Future;
use core::marker::PhantomData; use core::marker::PhantomData;
use core::sync::atomic::{compiler_fence, Ordering}; use core::sync::atomic::{compiler_fence, Ordering};
use core::task::Poll; use core::task::Poll;
@ -129,11 +128,11 @@ impl<'d> OneShot<'d> {
unsafe { &*SAADC::ptr() } unsafe { &*SAADC::ptr() }
} }
async fn sample_inner(&mut self, pin: PositiveChannel) -> i16 { pub async fn sample(&mut self, pin: &mut impl PositivePin) -> i16 {
let r = Self::regs(); let r = Self::regs();
// Set positive channel // Set positive channel
r.ch[0].pselp.write(|w| w.pselp().variant(pin)); r.ch[0].pselp.write(|w| w.pselp().variant(pin.channel()));
// Set up the DMA // Set up the DMA
let mut val: i16 = 0; let mut val: i16 = 0;
@ -180,23 +179,6 @@ impl<'d> Drop for OneShot<'d> {
} }
} }
pub trait Sample {
type SampleFuture<'a>: Future<Output = i16> + 'a
where
Self: 'a;
fn sample<'a, T: PositivePin>(&'a mut self, pin: &mut T) -> Self::SampleFuture<'a>;
}
impl<'d> Sample for OneShot<'d> {
#[rustfmt::skip]
type SampleFuture<'a> where Self: 'a = impl Future<Output = i16> + 'a;
fn sample<'a, T: PositivePin>(&'a mut self, pin: &mut T) -> Self::SampleFuture<'a> {
self.sample_inner(pin.channel())
}
}
/// A pin that can be used as the positive end of a ADC differential in the SAADC periperhal. /// A pin that can be used as the positive end of a ADC differential in the SAADC periperhal.
/// ///
/// Currently negative is always shorted to ground (0V). /// Currently negative is always shorted to ground (0V).

View File

@ -7,7 +7,7 @@ mod example_common;
use defmt::panic; use defmt::panic;
use embassy::executor::Spawner; use embassy::executor::Spawner;
use embassy::time::{Duration, Timer}; use embassy::time::{Duration, Timer};
use embassy_nrf::saadc::{Config, OneShot, Sample}; use embassy_nrf::saadc::{Config, OneShot};
use embassy_nrf::{interrupt, Peripherals}; use embassy_nrf::{interrupt, Peripherals};
use example_common::*; use example_common::*;