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>

source

pub fn len(&mut self) -> u8

Returns the number of elements currently in the fifo

source

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.

source

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.

source

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.

source

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.

source

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.

source

pub fn resume(&mut self)

Resume conversion after it was paused

There are two situations when it makes sense to use this method:

Calling this method when conversion is already running has no effect.

source

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).

source

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.

source

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.

source

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.

source

pub fn trigger(&mut self)

Trigger a single conversion

Ignored when in Adc::free_running mode.

source

pub fn is_ready(&self) -> bool

Check if ADC is ready for the next conversion trigger

Not useful when in Adc::free_running mode.

source§

impl<'a> AdcFifo<'a, u16>

source

pub fn read(&mut self) -> u16

Read a single value from the fifo (u16 version, not shifted)

source§

impl<'a> AdcFifo<'a, u8>

source

pub fn read(&mut self) -> u8

Read a single value from the fifo (u8 version, shifted)

Also see AdcFifoBuilder::shift_8bit.

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> 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<Choices> CoproductSubsetter<CNil, HNil> for Choices

§

type Remainder = Choices

source§

fn subset( self ) -> Result<CNil, <Choices as CoproductSubsetter<CNil, HNil>>::Remainder>

Extract a subset of the possible types in a coproduct (or get the remaining possibilities) 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> IntoEither for T

source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
source§

impl<T, U, I> LiftInto<U, I> for T
where U: LiftFrom<T, I>,

source§

fn lift_into(self) -> U

Performs the indexed conversion.
source§

impl<Source> Sculptor<HNil, HNil> for Source

§

type Remainder = Source

source§

fn sculpt(self) -> (HNil, <Source as Sculptor<HNil, HNil>>::Remainder)

Consumes the current HList and returns an HList with the requested shape. Read more
source§

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

§

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>,

§

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.