Struct rp2040_hal::adc::AdcFifo
source · pub struct AdcFifo<'a, Word> { /* private fields */ }
Expand description
Represents the ADC fifo
Constructed by AdcFifoBuilder::start
, which is accessible through Adc::build_fifo
.
Implementations§
source§impl<'a, Word> AdcFifo<'a, Word>
impl<'a, Word> AdcFifo<'a, Word>
sourcepub fn is_over(&mut self) -> bool
pub fn is_over(&mut self) -> bool
Check if there was a fifo overrun
An overrun happens when the fifo is filled up faster than read
is called to consume it.
This function also clears the over
bit if it was set.
sourcepub fn is_under(&mut self) -> bool
pub fn is_under(&mut self) -> bool
Check if there was a fifo underrun
An underrun happens when read
is called on an empty fifo (len() == 0
).
This function also clears the under
bit if it was set.
sourcepub fn read_single(&mut self) -> u16
pub fn read_single(&mut self) -> u16
Read the most recently sampled ADC value
Returns the most recently sampled value, bypassing the FIFO.
This can be used if you want to read samples occasionally, but don’t want to incur the 96 cycle delay of a one-off read.
Example:
// start continuously sampling values:
let mut fifo = adc.build_fifo().set_channel(&mut adc_pin).start();
loop {
do_something_timing_critical();
// read the most recent value:
if fifo.read_single() > THRESHOLD {
led.set_high().unwrap();
} else {
led.set_low().unwrap();
}
}
// stop sampling, when it's no longer needed
fifo.stop();
Note that when round-robin sampling is used, there is no way to tell from which channel this sample came.
sourcepub fn is_paused(&mut self) -> bool
pub fn is_paused(&mut self) -> bool
Returns true
if conversion is currently paused.
While paused, no samples will be added to the FIFO.
There may be existing samples in the FIFO though, or a conversion may still be in progress.
sourcepub fn pause(&mut self)
pub fn pause(&mut self)
Temporarily pause conversion
This method stops ADC conversion, but leaves everything else configured.
No new samples are captured until AdcFifo::resume
is called.
Note that existing samples can still be read from the FIFO, and can possibly cause interrupts and DMA transfer progress until the FIFO is emptied.
sourcepub fn resume(&mut self)
pub fn resume(&mut self)
Resume conversion after it was paused
There are two situations when it makes sense to use this method:
- After having called
AdcFifo::pause
on an AdcFifo - If the FIFO was initialized using
AdcFifoBuilder::prepare
.
Calling this method when conversion is already running has no effect.
sourcepub fn clear(&mut self)
pub fn clear(&mut self)
Clears the FIFO, removing all values
Reads and discards values from the FIFO until it is empty.
This only makes sense to use while the FIFO is paused (see AdcFifo::pause
).
sourcepub fn stop(self) -> &'a mut Adc
pub fn stop(self) -> &'a mut Adc
Stop capturing in free running mode.
Resets all capture options that can be set via AdcFifoBuilder
to
their defaults.
Returns the underlying Adc
, to be reused.
sourcepub fn wait_for_interrupt(&mut self)
pub fn wait_for_interrupt(&mut self)
Block until a ADC_IRQ_FIFO interrupt occurs
Interrupts must be enabled (AdcFifoBuilder::enable_interrupt
), or else this methods blocks forever.
sourcepub fn dma_read_target(&self) -> DmaReadTarget<Word>
pub fn dma_read_target(&self) -> DmaReadTarget<Word>
Returns a read-target for initiating DMA transfers
The DmaReadTarget
returned by this function can be used to initiate DMA transfers
reading from the ADC.
sourcepub fn trigger(&mut self)
pub fn trigger(&mut self)
Trigger a single conversion
Ignored when in Adc::free_running
mode.
sourcepub fn is_ready(&self) -> bool
pub fn is_ready(&self) -> bool
Check if ADC is ready for the next conversion trigger
Not useful when in Adc::free_running
mode.
Auto Trait Implementations§
impl<'a, Word> Freeze for AdcFifo<'a, Word>
impl<'a, Word> RefUnwindSafe for AdcFifo<'a, Word>where
Word: RefUnwindSafe,
impl<'a, Word> Send for AdcFifo<'a, Word>where
Word: Send,
impl<'a, Word> !Sync for AdcFifo<'a, Word>
impl<'a, Word> Unpin for AdcFifo<'a, Word>where
Word: Unpin,
impl<'a, Word> !UnwindSafe for AdcFifo<'a, Word>
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<Choices> CoproductSubsetter<CNil, HNil> for Choices
impl<Choices> CoproductSubsetter<CNil, HNil> for Choices
source§impl<T> IntoEither for T
impl<T> IntoEither for T
source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moresource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more