pub struct Adc<const N: u8> { /* private fields */ }
Expand description
The ADC driver.
The ADC starts out with a default configuration of 4 hardware samples, a conversion speed of medium, a resolution of 10 bits, and low power mode disabled. It’s also pre-calibrated using 32 averages and a slow conversion speed.
Implementations§
source§impl<const N: u8> Adc<N>
impl<const N: u8> Adc<N>
sourcepub fn new(
reg: Instance<N>,
clock: ClockSelect,
division: ClockDivision
) -> Self
pub fn new( reg: Instance<N>, clock: ClockSelect, division: ClockDivision ) -> Self
Constuct an ADC from a RAL ADC instance
sourcepub fn set_resolution(&mut self, bits: ResolutionBits)
pub fn set_resolution(&mut self, bits: ResolutionBits)
Sets the resolution that analog reads return, in bits
sourcepub fn set_averaging(&mut self, avg: AveragingCount)
pub fn set_averaging(&mut self, avg: AveragingCount)
Sets the number of hardware averages taken by the ADC
sourcepub fn set_conversion_speed(&mut self, conversion_speed: ConversionSpeed)
pub fn set_conversion_speed(&mut self, conversion_speed: ConversionSpeed)
Sets the conversion speed for this ADC, see ConversionSpeed for clock cycle counts.
sourcepub fn set_low_power_mode(&mut self, state: bool)
pub fn set_low_power_mode(&mut self, state: bool)
Enables or disables the low power configuration in the ADC. This does limit the ADACK clock frequency (<= 20MHz)
sourcepub fn read_blocking<P>(&mut self, _: &mut AnalogInput<P, N>) -> u16where
P: Pin<N>,
pub fn read_blocking<P>(&mut self, _: &mut AnalogInput<P, N>) -> u16where
P: Pin<N>,
Perform a blocking read for an ADC sample.
sourcepub fn read_blocking_channel(&mut self, channel: u32) -> u16
pub fn read_blocking_channel(&mut self, channel: u32) -> u16
Perform a blocking read using the specified ADC channel.
Unlike read_blocking()
, which ensures
that the pin is configured as an ADC input, you’re responsible
for configuring the pin as an ADC input before using this method.
Otherwise, this method may not produce a (correct) value.
Panics
Panics if the ADC channel is greater than 15.