nrf/saadc: remove Sample trait.

This commit is contained in:
Dario Nieuwenhuis 2021-10-07 02:10:22 +02:00
parent a816776cb5
commit 0e05ba688d
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::sync::atomic::{compiler_fence, Ordering};
use core::task::Poll;
@ -129,11 +128,11 @@ impl<'d> OneShot<'d> {
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();
// 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
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.
///
/// Currently negative is always shorted to ground (0V).

View file

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