Struct Adc

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

ADC configuration

Implementations§

Source§

impl Adc<ADC1>

Source

pub fn read_temp(&mut self) -> i32

Temperature sensor is connected to channel 16 on ADC1. This sensor can be used to measure ambient temperature of the device. However note that the returned value is not an absolute temperature value.

In particular, according to section 11.10 from Reference Manual RM0008 Rev 20: “The temperature sensor output voltage changes linearly with temperature. The offset of this line varies from chip to chip due to process variation (up to 45 °C from one chip to another). The internal temperature sensor is more suited to applications that detect temperature variations instead of absolute temperatures. If accurate temperature readings are needed, an external temperature sensor part should be used.”

Formula to calculate temperature value is also taken from the section 11.10.

Source

pub fn read_vref(&mut self) -> u16

Internal reference voltage Vrefint is connected to channel 17 on ADC1. According to section 5.3.4 “Embedded reference voltage” from STM32F1xx datasheets, typical value of this reference voltage is 1200 mV.

This value is useful when ADC readings need to be converted into voltages. For instance, reading from any ADC channel can be converted into voltage (mV) using the following formula: v_chan = adc.read(chan) * 1200 / adc.read_vref()

Source§

impl Adc<ADC1>

Source

pub fn adc1(adc: ADC1, clocks: Clocks) -> Self

Init a new Adc

Sets all configurable parameters to one-shot defaults, performs a boot-time calibration.

Source

pub fn save_cfg(&mut self) -> StoredConfig

Save current ADC config

Source

pub fn restore_cfg(&mut self, cfg: StoredConfig)

Restore saved ADC config

Source

pub fn default_cfg(&mut self) -> StoredConfig

Reset the ADC config to default, return existing config

Source

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

Set ADC sampling time

Options can be found in SampleTime.

Source

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

Set the Adc result alignment

Options can be found in Align.

Source

pub fn max_sample(&self) -> u16

Returns the largest possible sample value for the current settings

Source

pub fn set_external_trigger(&mut self, trigger: EXTSEL_A)

Source

pub fn release(self) -> ADC1

Powers down the ADC, disables the ADC clock and releases the ADC Peripheral

Source§

impl Adc<ADC2>

Source

pub fn adc2(adc: ADC2, clocks: Clocks) -> Self

Init a new Adc

Sets all configurable parameters to one-shot defaults, performs a boot-time calibration.

Source

pub fn save_cfg(&mut self) -> StoredConfig

Save current ADC config

Source

pub fn restore_cfg(&mut self, cfg: StoredConfig)

Restore saved ADC config

Source

pub fn default_cfg(&mut self) -> StoredConfig

Reset the ADC config to default, return existing config

Source

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

Set ADC sampling time

Options can be found in SampleTime.

Source

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

Set the Adc result alignment

Options can be found in Align.

Source

pub fn max_sample(&self) -> u16

Returns the largest possible sample value for the current settings

Source

pub fn set_external_trigger(&mut self, trigger: EXTSEL_A)

Source

pub fn release(self) -> ADC2

Powers down the ADC, disables the ADC clock and releases the ADC Peripheral

Source§

impl Adc<ADC3>

Source

pub fn adc3(adc: ADC3, clocks: Clocks) -> Self

Init a new Adc

Sets all configurable parameters to one-shot defaults, performs a boot-time calibration.

Source

pub fn save_cfg(&mut self) -> StoredConfig

Save current ADC config

Source

pub fn restore_cfg(&mut self, cfg: StoredConfig)

Restore saved ADC config

Source

pub fn default_cfg(&mut self) -> StoredConfig

Reset the ADC config to default, return existing config

Source

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

Set ADC sampling time

Options can be found in SampleTime.

Source

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

Set the Adc result alignment

Options can be found in Align.

Source

pub fn max_sample(&self) -> u16

Returns the largest possible sample value for the current settings

Source

pub fn set_external_trigger(&mut self, trigger: EXTSEL_A)

Source

pub fn release(self) -> ADC3

Powers down the ADC, disables the ADC clock and releases the ADC Peripheral

Source§

impl Adc<ADC1>

Source

pub fn with_dma<PIN>( self, pins: PIN, dma_ch: C1, ) -> AdcDma<ADC1, PIN, Continuous, C1>
where PIN: Channel<ADC1, ID = u8>,

Source

pub fn with_scan_dma<PINS>( self, pins: PINS, dma_ch: C1, ) -> AdcDma<ADC1, PINS, Scan, C1>
where Self: SetChannels<PINS>,

Source§

impl Adc<ADC3>

Source

pub fn with_dma<PIN>( self, pins: PIN, dma_ch: C5, ) -> AdcDma<ADC3, PIN, Continuous, C5>
where PIN: Channel<ADC3, ID = u8>,

Source

pub fn with_scan_dma<PINS>( self, pins: PINS, dma_ch: C5, ) -> AdcDma<ADC3, PINS, Scan, C5>
where Self: SetChannels<PINS>,

Trait Implementations§

Source§

impl ChannelTimeSequence for Adc<ADC1>

Source§

fn set_channel_sample_time(&mut self, chan: u8, sample_time: SampleTime)

Set ADC sampling time for particular channel
Source§

fn set_regular_sequence(&mut self, channels: &[u8])

ADC Set a Regular Channel Conversion Sequence Read more
Source§

fn set_continuous_mode(&mut self, continuous: bool)

Set ADC continuous conversion Read more
Source§

fn set_discontinuous_mode(&mut self, channels: Option<u8>)

Set ADC discontinuous mode Read more
Source§

impl ChannelTimeSequence for Adc<ADC2>

Source§

fn set_channel_sample_time(&mut self, chan: u8, sample_time: SampleTime)

Set ADC sampling time for particular channel
Source§

fn set_regular_sequence(&mut self, channels: &[u8])

ADC Set a Regular Channel Conversion Sequence Read more
Source§

fn set_continuous_mode(&mut self, continuous: bool)

Set ADC continuous conversion Read more
Source§

fn set_discontinuous_mode(&mut self, channels: Option<u8>)

Set ADC discontinuous mode Read more
Source§

impl ChannelTimeSequence for Adc<ADC3>

Source§

fn set_channel_sample_time(&mut self, chan: u8, sample_time: SampleTime)

Set ADC sampling time for particular channel
Source§

fn set_regular_sequence(&mut self, channels: &[u8])

ADC Set a Regular Channel Conversion Sequence Read more
Source§

fn set_continuous_mode(&mut self, continuous: bool)

Set ADC continuous conversion Read more
Source§

fn set_discontinuous_mode(&mut self, channels: Option<u8>)

Set ADC discontinuous mode Read more
Source§

impl<WORD, PIN> OneShot<ADC1, WORD, PIN> for Adc<ADC1>
where WORD: From<u16>, PIN: Channel<ADC1, 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
Source§

impl<WORD, PIN> OneShot<ADC2, WORD, PIN> for Adc<ADC2>
where WORD: From<u16>, PIN: Channel<ADC2, 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
Source§

impl<WORD, PIN> OneShot<ADC3, WORD, PIN> for Adc<ADC3>
where WORD: From<u16>, PIN: Channel<ADC3, 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<ADC> Freeze for Adc<ADC>
where ADC: Freeze,

§

impl<ADC> RefUnwindSafe for Adc<ADC>
where ADC: RefUnwindSafe,

§

impl<ADC> Send for Adc<ADC>
where ADC: Send,

§

impl<ADC> Sync for Adc<ADC>
where ADC: Sync,

§

impl<ADC> Unpin for Adc<ADC>
where ADC: Unpin,

§

impl<ADC> UnwindSafe for Adc<ADC>
where ADC: UnwindSafe,

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.