Struct Adc

Source
pub struct Adc { /* private fields */ }
Expand description

Analog to Digital converter interface

Implementations§

Source§

impl Adc

Source

pub fn new(adc: ADC, rcc: &mut Rcc) -> Self

Source

pub fn set_clock_source(&mut self, clock_source: ClockSource)

Sets ADC source

Source

pub fn calibrate(&mut self)

Runs the calibration routine on the ADC

Wait for tADCVREG_SETUP (20us on STM32G071x8) after calling Self::new() before calibrating, to wait for the ADC voltage regulator to stabilize.

Do not call if an ADC reading is ongoing.

Source

pub fn get_calibration(&self) -> CalibrationFactor

Returns the calibration factors used by the ADC

The ADC does not have a factory-stored calibration, Self::calibrate() must be run before calling this for the returned value to be useful.

The ADC loses its calibration factors when Standby or Vbat mode is entered. Saving and restoring the calibration factors can be used to recalibrate the ADC after waking up from sleep more quickly than re-running calibraiton. Note that VDDA changes and to a lesser extent temperature changes affect the ADC operating conditions and calibration should be run again for the best accuracy.

Source

pub fn set_calibration(&mut self, calfact: CalibrationFactor)

Writes the calibration factors used by the ADC

See Self::get_calibration().

Do not call if an ADC reading is ongoing.

Source

pub fn set_sample_time(&mut self, t_samp: SampleTime)

Set the Adc sampling time

Source

pub fn set_align(&mut self, align: Align)

Set the Adc result alignment

Source

pub fn set_precision(&mut self, precision: Precision)

Set the Adc precision

Source

pub fn set_oversampling_shift(&mut self, nrbits: u8)

The nuber of bits, the oversampling result is shifted in bits at the end of oversampling

Source

pub fn set_oversampling_ratio(&mut self, ratio: OversamplingRatio)

Oversampling of adc according to datasheet of stm32g0, when oversampling is enabled

Source

pub fn oversampling_enable(&mut self, enable: bool)

Source

pub fn start_injected(&mut self)

Source

pub fn stop_injected(&mut self)

Source

pub fn read_vref(&mut self) -> Result<u16, ()>

Read actual VREF voltage using the internal reference

If oversampling is enabled, the return value is scaled down accordingly. The product of the return value and any ADC reading always gives correct voltage in 4096ths of mV regardless of oversampling and shift settings provided that these settings remain the same.

Source

pub fn get_vref_cached(&mut self) -> Result<u16, ()>

Get VREF value using cached value if possible

See read_vref for more details.

Source

pub fn read_voltage<PIN: Channel<Adc, ID = u8>>( &mut self, pin: &mut PIN, ) -> Result<u16, ()>

Source

pub fn read_temperature(&mut self) -> Result<i16, ()>

Source

pub fn release(self) -> ADC

Trait Implementations§

Source§

impl Channel<Adc> for PA0<Analog>

Source§

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 PA1<Analog>

Source§

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 PA2<Analog>

Source§

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 PA3<Analog>

Source§

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 PA4<Analog>

Source§

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 PA5<Analog>

Source§

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 PA6<Analog>

Source§

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 PA7<Analog>

Source§

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 PB0<Analog>

Source§

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 PB1<Analog>

Source§

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 PB10<Analog>

Source§

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 PB11<Analog>

Source§

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 PB12<Analog>

Source§

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 PB2<Analog>

Source§

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 PC4<Analog>

Source§

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 PC5<Analog>

Source§

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 VBat

Source§

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 VRef

Source§

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 VTemp

Source§

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 DmaMode<Adc> for Adc

Source§

type Error = ()

Error type returned by ADC methods
Source§

fn dma_enable(&mut self, enable: bool)

Source§

fn dma_circualr_mode(&mut self, enable: bool)

Source§

impl<PIN> InjectMode<Adc, PIN> for Adc
where PIN: Channel<Adc, ID = u8>,

Source§

type Error = ()

Error type returned by ADC methods
Source§

fn prepare_injected(&mut self, _pin: &mut PIN, triger_source: InjTrigSource)

Source§

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

Source§

type Error = ()

Error type returned by ADC methods
Source§

fn read(&mut self, _pin: &mut PIN) -> 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<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, U> TryFrom<U> for T
where U: Into<T>,

Source§

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

Source§

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.