Trait nrf52840_hal::prelude::_embedded_hal_adc_OneShot[][src]

pub trait _embedded_hal_adc_OneShot<ADC, Word, Pin> where
    Pin: Channel<ADC>, 
{ type Error; fn read(&mut self, pin: &mut Pin) -> Result<Word, Error<Self::Error>>; }
Expand description

ADCs that sample on single channels per request, and do so at the time of the request.

This trait is the interface to an ADC that is configured to read a specific channel at the time of the request (in contrast to continuous asynchronous sampling).

use embedded_hal::adc::{Channel, OneShot};

struct MyAdc; // 10-bit ADC, with 5 channels

impl<WORD, PIN> OneShot<MyAdc, WORD, PIN> for MyAdc
where
   WORD: From<u16>,
   PIN: Channel<MyAdc, ID=u8>,
{
   type Error = ();

   fn read(&mut self, _pin: &mut PIN) -> nb::Result<WORD, Self::Error> {
       let chan = 1 << PIN::channel();
       self.power_up();
       let result = self.do_conversion(chan);
       self.power_down();
       Ok(result.into())
   }
}

Associated Types

type Error[src]

Error type returned by ADC methods

Required methods

fn read(&mut self, pin: &mut Pin) -> Result<Word, Error<Self::Error>>[src]

Request that the ADC begin a conversion on the specified pin

This method takes a Pin reference, as it is expected that the ADC will be able to sample whatever channel underlies the pin.

Implementors

impl<PIN> OneShot<Saadc, i16, PIN> for Saadc where
    PIN: Channel<Saadc, ID = u8>, 
[src]

pub fn read(
    &mut self,
    _pin: &mut PIN
) -> Result<i16, Error<<Saadc as OneShot<Saadc, i16, PIN>>::Error>>
[src]

Sample channel PIN for the configured ADC acquisition time in differential input mode. Note that this is a blocking operation.

type Error = ()