pub struct Adc<'a> { /* private fields */ }
Expand description
ADC driver code for the SAM4L.
Implementations§
Source§impl Adc<'_>
Functions for initializing the ADC.
impl Adc<'_>
Functions for initializing the ADC.
Sourcepub fn new(rx_dma_peripheral: DMAPeripheral, pm: &'static PowerManager) -> Self
pub fn new(rx_dma_peripheral: DMAPeripheral, pm: &'static PowerManager) -> Self
Create a new ADC driver.
rx_dma_peripheral
: type used for DMA transactions
Sourcepub fn set_dma(&self, rx_dma: &'static DMAChannel)
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
Sourcepub fn handle_interrupt(&self)
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.
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>
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>
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 samplefrequency
: the number of samples per second to collect
Source§fn stop_sampling(&self) -> Result<(), ErrorCode>
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
fn get_resolution_bits(&self) -> usize
Resolution of the reading.
Source§fn get_voltage_reference_mv(&self) -> Option<usize>
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)
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
type Channel = AdcChannel
Source§impl<'a> AdcHighSpeed<'a> for Adc<'a>
Implements an ADC capable of continuous sampling
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])>
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 samplefrequency
: frequency to sample atbuffer1
: first buffer to fill with sampleslength1
: number of samples to collect (up to buffer length)buffer2
: second buffer to fill once the first is fulllength2
: 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])>
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 sampleslength
: number of samples to collect (up to buffer length)
Source§fn retrieve_buffers(
&self,
) -> Result<(Option<&'static mut [u16]>, Option<&'static mut [u16]>), ErrorCode>
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
.
fn set_highspeed_client(&self, client: &'a dyn HighSpeedClient)
Source§impl DMAClient for Adc<'_>
Implements a client of a DMA.
impl DMAClient for Adc<'_>
Implements a client of a DMA.
Source§fn transfer_done(&self, pid: DMAPeripheral)
fn transfer_done(&self, pid: DMAPeripheral)
Handler for DMA transfer completion.
pid
: the DMA peripheral that is complete