pub struct Adc<'d, ADC, Dm: DriverMode> { /* private fields */ }unstable only.Expand description
Analog-to-Digital Converter peripheral driver.
Implementations§
Source§impl<'d, ADCX> Adc<'d, ADCX, Blocking>where
ADCX: RegisterAccess + 'd,
impl<'d, ADCX> Adc<'d, ADCX, Blocking>where
ADCX: RegisterAccess + 'd,
Sourcepub fn new(adc_instance: ADCX, config: AdcConfig<ADCX>) -> Result<Self, Error>
pub fn new(adc_instance: ADCX, config: AdcConfig<ADCX>) -> Result<Self, Error>
Creates a new ADC instance with the given configuration.
The ESP32-S31 SAR ADC has a single attenuation setting, so the attenuation given per pin has no effect.
Sourcepub fn into_async(self) -> Adc<'d, ADCX, Async>
pub fn into_async(self) -> Adc<'d, ADCX, Async>
Reconfigures the ADC driver to operate in asynchronous mode.
Sourcepub fn read_blocking<PIN, CS>(
&mut self,
pin: &mut AdcPin<PIN, ADCX, CS>,
) -> Result<u16, Error>where
PIN: AdcChannel,
CS: AdcCalScheme<ADCX>,
pub fn read_blocking<PIN, CS>(
&mut self,
pin: &mut AdcPin<PIN, ADCX, CS>,
) -> Result<u16, Error>where
PIN: AdcChannel,
CS: AdcCalScheme<ADCX>,
Starts and waits for a conversion on the specified pin and returns the result.
The result is in the range 0..=FULL_SCALE, and an input tied to
ground reads about ZERO_DIFF_CODE.
§Errors
Returns Error::ChannelNotConfigured if the channel was not configured in
AdcConfig.
Sourcepub fn read_oneshot<PIN, CS>(
&mut self,
pin: &mut AdcPin<PIN, ADCX, CS>,
) -> Result<u16, Error>where
PIN: AdcChannel,
CS: AdcCalScheme<ADCX>,
pub fn read_oneshot<PIN, CS>(
&mut self,
pin: &mut AdcPin<PIN, ADCX, CS>,
) -> Result<u16, Error>where
PIN: AdcChannel,
CS: AdcCalScheme<ADCX>,
Requests that the ADC begin a conversion on the specified pin.
Takes an AdcPin reference, as it is
expected that the ADC will be able to sample whatever channel
underlies the pin.
The result is in the range 0..=FULL_SCALE, and an input tied to
ground reads about ZERO_DIFF_CODE.
§Errors
Returns Error::ChannelNotConfigured if the channel was not configured in
AdcConfig.
Source§impl<'d, ADCX> Adc<'d, ADCX, Async>where
ADCX: RegisterAccess + 'd,
impl<'d, ADCX> Adc<'d, ADCX, Async>where
ADCX: RegisterAccess + 'd,
Sourcepub fn into_blocking(self) -> Adc<'d, ADCX, Blocking>
pub fn into_blocking(self) -> Adc<'d, ADCX, Blocking>
Reconfigures the ADC driver to operate in Blocking mode.
Sourcepub async fn read_oneshot<PIN, CS>(
&mut self,
pin: &mut AdcPin<PIN, ADCX, CS>,
) -> Result<u16, Error>
pub async fn read_oneshot<PIN, CS>( &mut self, pin: &mut AdcPin<PIN, ADCX, CS>, ) -> Result<u16, Error>
Starts a conversion on the specified pin and waits for the result.
Takes an AdcPin reference, as it is
expected that the ADC will be able to sample whatever channel
underlies the pin.
The result is in the range 0..=FULL_SCALE, and an input tied to
ground reads about ZERO_DIFF_CODE.
§Errors
Returns Error::ChannelNotConfigured if the channel was not configured in
AdcConfig.