Struct Adc

Source
pub struct Adc<'a> { /* private fields */ }
Expand description

ADC driver code for the SAM4L.

Implementations§

Source§

impl Adc<'_>

Functions for initializing the ADC.

Source

pub fn new(rx_dma_peripheral: DMAPeripheral, pm: &'static PowerManager) -> Self

Create a new ADC driver.

  • rx_dma_peripheral: type used for DMA transactions
Source

pub fn set_dma(&self, rx_dma: &'static DMAChannel)

Sets the DMA channel for this driver.

  • rx_dma: reference to the DMA channel the ADC should use
Source

pub fn handle_interrupt(&self)

Interrupt handler for the ADC.

Trait Implementations§

Source§

impl<'a> Adc<'a> for Adc<'a>

Implements an ADC capable reading ADC samples on any channel.

Source§

fn sample(&self, channel: &Self::Channel) -> Result<(), ErrorCode>

Capture a single analog sample, calling the client when complete. Returns an error if the ADC is already sampling.

  • channel: the ADC channel to sample
Source§

fn sample_continuous( &self, channel: &Self::Channel, frequency: u32, ) -> Result<(), ErrorCode>

Request repeated analog samples on a particular channel, calling after each sample. In order to not unacceptably slow down the system collecting samples, this interface is limited to one sample every 100 microseconds (10000 samples per second). To sample faster, use the sample_highspeed function.

  • channel: the ADC channel to sample
  • frequency: the number of samples per second to collect
Source§

fn stop_sampling(&self) -> Result<(), ErrorCode>

Stop continuously sampling the ADC. This is expected to be called to stop continuous sampling operations, but can be called to abort any currently running operation. The buffer, if any, will be returned via the samples_ready callback.

Source§

fn get_resolution_bits(&self) -> usize

Resolution of the reading.

Source§

fn get_voltage_reference_mv(&self) -> Option<usize>

Voltage reference is VCC/2, we assume VCC is 3.3 V, and we use a gain of 0.5.

Source§

fn set_client(&self, client: &'a dyn Client)

Sets the client for this driver.

  • client: reference to capsule which handles responses
Source§

type Channel = AdcChannel

The chip-dependent type of an ADC channel.
Source§

impl<'a> AdcHighSpeed<'a> for Adc<'a>

Implements an ADC capable of continuous sampling

Source§

fn sample_highspeed( &self, channel: &Self::Channel, frequency: u32, buffer1: &'static mut [u16], length1: usize, buffer2: &'static mut [u16], length2: usize, ) -> Result<(), (ErrorCode, &'static mut [u16], &'static mut [u16])>

Capture buffered samples from the ADC continuously at a given frequency, calling the client whenever a buffer fills up. The client is then expected to either stop sampling or provide an additional buffer to sample into. Note that due to hardware constraints the maximum frequency range of the ADC is from 187 kHz to 23 Hz (although its precision is limited at higher frequencies due to aliasing).

  • channel: the ADC channel to sample
  • frequency: frequency to sample at
  • buffer1: first buffer to fill with samples
  • length1: number of samples to collect (up to buffer length)
  • buffer2: second buffer to fill once the first is full
  • length2: number of samples to collect (up to buffer length)
Source§

fn provide_buffer( &self, buf: &'static mut [u16], length: usize, ) -> Result<(), (ErrorCode, &'static mut [u16])>

Provide a new buffer to send on-going buffered continuous samples to. This is expected to be called after the samples_ready callback.

  • buf: buffer to fill with samples
  • length: number of samples to collect (up to buffer length)
Source§

fn retrieve_buffers( &self, ) -> Result<(Option<&'static mut [u16]>, Option<&'static mut [u16]>), ErrorCode>

Reclaim buffers after the ADC is stopped. This is expected to be called after stop_sampling.

Source§

fn set_highspeed_client(&self, client: &'a dyn HighSpeedClient)

Source§

impl DMAClient for Adc<'_>

Implements a client of a DMA.

Source§

fn transfer_done(&self, pid: DMAPeripheral)

Handler for DMA transfer completion.

  • pid: the DMA peripheral that is complete

Auto Trait Implementations§

§

impl<'a> !Freeze for Adc<'a>

§

impl<'a> !RefUnwindSafe for Adc<'a>

§

impl<'a> !Send for Adc<'a>

§

impl<'a> !Sync for Adc<'a>

§

impl<'a> Unpin for Adc<'a>

§

impl<'a> !UnwindSafe for Adc<'a>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.