Struct rp2040_hal::adc::Adc

source ·
pub struct Adc { /* private fields */ }
Expand description

Analog to Digital Convertor (ADC).

Represents an ADC within the RP2040. Each ADC has multiple channels, and each channel is either associated with a specific GPIO pin or attached to the internal temperature sensor. You should put the relevant pin into ADC mode by creating an AdcPin object with it, or you can put the ADC into Temperature Sensing Mode by calling Adc::take_temp_sensor(). Either way, the resulting objects can be passed to the OneShot::read() trait method to actually do the read.

Implementations§

source§

impl Adc

source

pub fn new(device: ADC, resets: &mut RESETS) -> Self

Create new adc struct and bring up adc

source

pub fn free(self) -> ADC

Free underlying register block

source

pub fn read_single(&self) -> u16

Read the most recently sampled ADC value

This function does not wait for the current conversion to finish. If a conversion is still in progress, it returns the result of the previous one.

It also doesn’t trigger a new conversion.

source

pub fn enable_temp_sensor(&mut self) -> TempSense

👎Deprecated since 0.9.0: This method may panic, use take_temp_sensor() instead.

Enable temperature sensor, returns a channel to use.

This can only be done once before calling Adc::disable_temp_sensor(). If the sensor has already been enabled, this method will panic.

source

pub fn take_temp_sensor(&mut self) -> Option<TempSense>

Enable temperature sensor, returns a channel to use

If the sensor has already been enabled, this method returns None.

source

pub fn disable_temp_sensor(&mut self, _: TempSense)

Disable temperature sensor, consumes channel

source

pub fn build_fifo(&mut self) -> AdcFifoBuilder<'_, u16>

Start configuring free-running mode, and set up the FIFO

The AdcFifoBuilder returned by this method can be used to configure capture options, like sample rate, channels to capture from etc.

Capturing is started by calling AdcFifoBuilder::start, which returns an AdcFifo to read from.

source

pub fn free_running(&mut self, pin: &dyn AdcChannel)

Enable free-running mode by setting the start_many flag.

source

pub fn stop(&mut self)

Disable free-running mode by unsetting the start_many flag.

source

pub fn wait_ready(&self)

Wait for the ADC to become ready.

Also returns immediately if start_many is set, to avoid indefinite blocking.

source

pub fn is_ready(&self) -> bool

Returns true if the ADC is ready for the next conversion.

This implies that any previous conversion has finished.

Trait Implementations§

source§

impl<F: Function, M: PullType> Channel<Adc> for AdcPin<Pin<DynPinId, F, M>>

§

type ID = ()

Channel ID type Read more
source§

fn channel()

Get the specific ID that identifies this channel, for example 0_u8 for the first ADC channel, if Self::ID is u8.
source§

impl<F: Function, M: PullType> Channel<Adc> for AdcPin<Pin<Gpio26, F, M>>

§

type ID = u8

Channel ID type Read more
source§

fn channel() -> u8

Get the specific ID that identifies this channel, for example 0_u8 for the first ADC channel, if Self::ID is u8.
source§

impl<F: Function, M: PullType> Channel<Adc> for AdcPin<Pin<Gpio27, F, M>>

§

type ID = u8

Channel ID type Read more
source§

fn channel() -> u8

Get the specific ID that identifies this channel, for example 0_u8 for the first ADC channel, if Self::ID is u8.
source§

impl<F: Function, M: PullType> Channel<Adc> for AdcPin<Pin<Gpio28, F, M>>

§

type ID = u8

Channel ID type Read more
source§

fn channel() -> u8

Get the specific ID that identifies this channel, for example 0_u8 for the first ADC channel, if Self::ID is u8.
source§

impl<F: Function, M: PullType> Channel<Adc> for AdcPin<Pin<Gpio29, F, M>>

§

type ID = u8

Channel ID type Read more
source§

fn channel() -> u8

Get the specific ID that identifies this channel, for example 0_u8 for the first ADC channel, if Self::ID is u8.
source§

impl Channel<Adc> for TempSense

§

type ID = u8

Channel ID type Read more
source§

fn channel() -> u8

Get the specific ID that identifies this channel, for example 0_u8 for the first ADC channel, if Self::ID is u8.
source§

impl<WORD, F, M> OneShot<Adc, WORD, AdcPin<Pin<DynPinId, F, M>>> for Adc
where WORD: From<u16>, F: Function, M: PullType, DynPinId: ValidFunction<F>, AdcPin<Pin<DynPinId, F, M>>: Channel<Adc, ID = ()>,

§

type Error = Infallible

Error type returned by ADC methods
source§

fn read( &mut self, pin: &mut AdcPin<Pin<DynPinId, F, M>> ) -> Result<WORD, Self::Error>

Request that the ADC begin a conversion on the specified pin Read more
source§

impl<WORD, SRC> OneShot<Adc, WORD, SRC> for Adc
where WORD: From<u16>, SRC: Channel<Adc, ID = u8>,

§

type Error = Infallible

Error type returned by ADC methods
source§

fn read(&mut self, _pin: &mut SRC) -> Result<WORD, Self::Error>

Request that the ADC begin a conversion on the specified pin Read more

Auto Trait Implementations§

§

impl Freeze for Adc

§

impl RefUnwindSafe for Adc

§

impl Send for Adc

§

impl !Sync for Adc

§

impl Unpin for Adc

§

impl UnwindSafe for Adc

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.