Struct stm32_hal2::adc::Adc

source ·
pub struct Adc<R> {
    pub regs: R,
    pub cfg: AdcConfig,
    pub vdda_calibrated: f32,
    /* private fields */
}
Expand description

Represents an Analog to Digital Converter (ADC) peripheral.

Fields§

§regs: R

ADC Register

§cfg: AdcConfig§vdda_calibrated: f32

This field is managed internally, and is set up on init.

Implementations§

source§

impl Adc<ADC1>

source

pub fn new_adc1( regs: ADC1, device: AdcDevice, cfg: AdcConfig, ahb_freq: u32 ) -> Self

Initialize an ADC peripheral, including configuration register writes, enabling and resetting its RCC peripheral clock, and calibrtation.

If used with ADC1, this also performs VDDA measurement, used for converting raw output to voltage. If using an ADC other than ADC1, this measurement is skipped, and 3.3V is assumed. In this case, it’s recommended to setup ADC1, read it’s VDDA value (vdda_calibrated field), and update the ADC in question with it.

source

pub fn set_sequence_len(&mut self, len: u8)

Set the ADC conversion sequence length, between 1 and 16.

source

pub fn set_align(&self, align: Align)

Set the alignment mode.

source

pub fn enable(&mut self)

Enable the ADC. ADEN=1 enables the ADC. The flag ADRDY will be set once the ADC is ready for operation.

source

pub fn disable(&mut self)

Disable the ADC. ADDIS=1 disables the ADC. ADEN and ADDIS are then automatically cleared by hardware as soon as the analog ADC is effectively disabled

source

pub fn stop_conversions(&mut self)

If any conversions are in progress, stop them. This is a step listed in the RMs for disable, and calibration procedures. See L4 RM: 16.4.17. When the ADSTP bit is set by software, any ongoing regular conversion is aborted with partial result discarded (ADC_DR register is not updated with the current conversion). When the JADSTP bit is set by software, any ongoing injected conversion is aborted with partial result discarded (ADC_JDRy register is not updated with the current conversion). The scan sequence is also aborted and reset (meaning that relaunching the ADC would restart a new sequence).

source

pub fn is_enabled(&self) -> bool

Check if the ADC is enabled.

source

pub fn is_advregen_enabled(&self) -> bool

Check if the ADC voltage regulator is enabled.

source

pub fn advregen_enable(&mut self, ahb_freq: u32)

Enable the ADC voltage regulator, and exit deep sleep mode (some MCUs)

source

pub fn advregen_disable(&mut self)

Disable power, eg to save power in low power modes. Inferred from RM, we should run this before entering STOP mode, in conjunction with with disabling the ADC.

source

pub fn calibrate(&mut self, input_type: InputType, ahb_freq: u32)

Calibrate. See L4 RM, 16.5.8, or F404 RM, section 15.3.8. Stores calibration values, which can be re-inserted later, eg after entering ADC deep sleep mode, or MCU STANDBY or VBAT.

source

pub fn inject_calibration(&mut self)

Insert a previously-saved calibration value into the ADC. Se L4 RM, 16.4.8.

source

pub fn set_input_type(&mut self, channel: u8, input_type: InputType)

Select single-ended, or differential conversions for a given channel.

source

pub fn set_sequence(&mut self, chan: u8, position: u8)

Select a sequence to sample, by inputting a single channel and position.

source

pub fn set_sample_time(&mut self, chan: u8, smp: SampleTime)

Select the sample time for a given channel.

source

pub fn reading_to_voltage(&self, reading: u16) -> f32

Convert a raw measurement into a voltage in Volts, using the calibrated VDDA. See RM0394, section 16.4.34

source

pub fn start_conversion(&mut self, sequence: &[u8])

Start a conversion: Either a single measurement, or continuous conversions. Blocks until the conversion is complete. See L4 RM 16.4.15 for details.

source

pub fn read_result(&mut self) -> u16

Read data from a conversion. In OneShot mode, this will generally be run right after start_conversion.

source

pub fn read(&mut self, channel: u8) -> u16

Take a single reading; return a raw integer value.

source

pub fn read_voltage(&mut self, channel: u8) -> f32

Take a single reading; return a voltage.

source

pub fn set_trigger(&mut self, trigger: Trigger, edge: TriggerEdge)

Select and activate a trigger. See G4 RM, section 21.4.18: Conversion on external trigger and trigger polarit

source

pub unsafe fn read_dma( &mut self, buf: &mut [u16], adc_channels: &[u8], dma_channel: DmaChannel, channel_cfg: ChannelCfg, dma_periph: DmaPeriph )

Take a reading, using DMA. Sets conversion sequence; no need to set it directly. Note that the channel argument is unused on F3 and L4, since it is hard-coded, and can’t be configured using the DMAMUX peripheral. (dma::mux() fn).

source

pub fn enable_interrupt(&mut self, interrupt: AdcInterrupt)

Enable a specific type of ADC interrupt.

source

pub fn clear_interrupt(&mut self, interrupt: AdcInterrupt)

Clear an interrupt flag of the specified type. Consider running this in the corresponding ISR.

source

pub fn read_status(&self) -> u32

Print the (raw) contents of the status register.

source§

impl Adc<ADC2>

source

pub fn new_adc2( regs: ADC2, device: AdcDevice, cfg: AdcConfig, ahb_freq: u32 ) -> Self

Initialize an ADC peripheral, including configuration register writes, enabling and resetting its RCC peripheral clock, and calibrtation.

If used with ADC1, this also performs VDDA measurement, used for converting raw output to voltage. If using an ADC other than ADC1, this measurement is skipped, and 3.3V is assumed. In this case, it’s recommended to setup ADC1, read it’s VDDA value (vdda_calibrated field), and update the ADC in question with it.

source

pub fn set_sequence_len(&mut self, len: u8)

Set the ADC conversion sequence length, between 1 and 16.

source

pub fn set_align(&self, align: Align)

Set the alignment mode.

source

pub fn enable(&mut self)

Enable the ADC. ADEN=1 enables the ADC. The flag ADRDY will be set once the ADC is ready for operation.

source

pub fn disable(&mut self)

Disable the ADC. ADDIS=1 disables the ADC. ADEN and ADDIS are then automatically cleared by hardware as soon as the analog ADC is effectively disabled

source

pub fn stop_conversions(&mut self)

If any conversions are in progress, stop them. This is a step listed in the RMs for disable, and calibration procedures. See L4 RM: 16.4.17. When the ADSTP bit is set by software, any ongoing regular conversion is aborted with partial result discarded (ADC_DR register is not updated with the current conversion). When the JADSTP bit is set by software, any ongoing injected conversion is aborted with partial result discarded (ADC_JDRy register is not updated with the current conversion). The scan sequence is also aborted and reset (meaning that relaunching the ADC would restart a new sequence).

source

pub fn is_enabled(&self) -> bool

Check if the ADC is enabled.

source

pub fn is_advregen_enabled(&self) -> bool

Check if the ADC voltage regulator is enabled.

source

pub fn advregen_enable(&mut self, ahb_freq: u32)

Enable the ADC voltage regulator, and exit deep sleep mode (some MCUs)

source

pub fn advregen_disable(&mut self)

Disable power, eg to save power in low power modes. Inferred from RM, we should run this before entering STOP mode, in conjunction with with disabling the ADC.

source

pub fn calibrate(&mut self, input_type: InputType, ahb_freq: u32)

Calibrate. See L4 RM, 16.5.8, or F404 RM, section 15.3.8. Stores calibration values, which can be re-inserted later, eg after entering ADC deep sleep mode, or MCU STANDBY or VBAT.

source

pub fn inject_calibration(&mut self)

Insert a previously-saved calibration value into the ADC. Se L4 RM, 16.4.8.

source

pub fn set_input_type(&mut self, channel: u8, input_type: InputType)

Select single-ended, or differential conversions for a given channel.

source

pub fn set_sequence(&mut self, chan: u8, position: u8)

Select a sequence to sample, by inputting a single channel and position.

source

pub fn set_sample_time(&mut self, chan: u8, smp: SampleTime)

Select the sample time for a given channel.

source

pub fn reading_to_voltage(&self, reading: u16) -> f32

Convert a raw measurement into a voltage in Volts, using the calibrated VDDA. See RM0394, section 16.4.34

source

pub fn start_conversion(&mut self, sequence: &[u8])

Start a conversion: Either a single measurement, or continuous conversions. Blocks until the conversion is complete. See L4 RM 16.4.15 for details.

source

pub fn read_result(&mut self) -> u16

Read data from a conversion. In OneShot mode, this will generally be run right after start_conversion.

source

pub fn read(&mut self, channel: u8) -> u16

Take a single reading; return a raw integer value.

source

pub fn read_voltage(&mut self, channel: u8) -> f32

Take a single reading; return a voltage.

source

pub fn set_trigger(&mut self, trigger: Trigger, edge: TriggerEdge)

Select and activate a trigger. See G4 RM, section 21.4.18: Conversion on external trigger and trigger polarit

source

pub unsafe fn read_dma( &mut self, buf: &mut [u16], adc_channels: &[u8], dma_channel: DmaChannel, channel_cfg: ChannelCfg, dma_periph: DmaPeriph )

Take a reading, using DMA. Sets conversion sequence; no need to set it directly. Note that the channel argument is unused on F3 and L4, since it is hard-coded, and can’t be configured using the DMAMUX peripheral. (dma::mux() fn).

source

pub fn enable_interrupt(&mut self, interrupt: AdcInterrupt)

Enable a specific type of ADC interrupt.

source

pub fn clear_interrupt(&mut self, interrupt: AdcInterrupt)

Clear an interrupt flag of the specified type. Consider running this in the corresponding ISR.

source

pub fn read_status(&self) -> u32

Print the (raw) contents of the status register.

source§

impl Adc<ADC3>

source

pub fn new_adc3( regs: ADC3, device: AdcDevice, cfg: AdcConfig, ahb_freq: u32 ) -> Self

Initialize an ADC peripheral, including configuration register writes, enabling and resetting its RCC peripheral clock, and calibrtation.

If used with ADC1, this also performs VDDA measurement, used for converting raw output to voltage. If using an ADC other than ADC1, this measurement is skipped, and 3.3V is assumed. In this case, it’s recommended to setup ADC1, read it’s VDDA value (vdda_calibrated field), and update the ADC in question with it.

source

pub fn set_sequence_len(&mut self, len: u8)

Set the ADC conversion sequence length, between 1 and 16.

source

pub fn set_align(&self, align: Align)

Set the alignment mode.

source

pub fn enable(&mut self)

Enable the ADC. ADEN=1 enables the ADC. The flag ADRDY will be set once the ADC is ready for operation.

source

pub fn disable(&mut self)

Disable the ADC. ADDIS=1 disables the ADC. ADEN and ADDIS are then automatically cleared by hardware as soon as the analog ADC is effectively disabled

source

pub fn stop_conversions(&mut self)

If any conversions are in progress, stop them. This is a step listed in the RMs for disable, and calibration procedures. See L4 RM: 16.4.17. When the ADSTP bit is set by software, any ongoing regular conversion is aborted with partial result discarded (ADC_DR register is not updated with the current conversion). When the JADSTP bit is set by software, any ongoing injected conversion is aborted with partial result discarded (ADC_JDRy register is not updated with the current conversion). The scan sequence is also aborted and reset (meaning that relaunching the ADC would restart a new sequence).

source

pub fn is_enabled(&self) -> bool

Check if the ADC is enabled.

source

pub fn is_advregen_enabled(&self) -> bool

Check if the ADC voltage regulator is enabled.

source

pub fn advregen_enable(&mut self, ahb_freq: u32)

Enable the ADC voltage regulator, and exit deep sleep mode (some MCUs)

source

pub fn advregen_disable(&mut self)

Disable power, eg to save power in low power modes. Inferred from RM, we should run this before entering STOP mode, in conjunction with with disabling the ADC.

source

pub fn calibrate(&mut self, input_type: InputType, ahb_freq: u32)

Calibrate. See L4 RM, 16.5.8, or F404 RM, section 15.3.8. Stores calibration values, which can be re-inserted later, eg after entering ADC deep sleep mode, or MCU STANDBY or VBAT.

source

pub fn inject_calibration(&mut self)

Insert a previously-saved calibration value into the ADC. Se L4 RM, 16.4.8.

source

pub fn set_input_type(&mut self, channel: u8, input_type: InputType)

Select single-ended, or differential conversions for a given channel.

source

pub fn set_sequence(&mut self, chan: u8, position: u8)

Select a sequence to sample, by inputting a single channel and position.

source

pub fn set_sample_time(&mut self, chan: u8, smp: SampleTime)

Select the sample time for a given channel.

source

pub fn reading_to_voltage(&self, reading: u16) -> f32

Convert a raw measurement into a voltage in Volts, using the calibrated VDDA. See RM0394, section 16.4.34

source

pub fn start_conversion(&mut self, sequence: &[u8])

Start a conversion: Either a single measurement, or continuous conversions. Blocks until the conversion is complete. See L4 RM 16.4.15 for details.

source

pub fn read_result(&mut self) -> u16

Read data from a conversion. In OneShot mode, this will generally be run right after start_conversion.

source

pub fn read(&mut self, channel: u8) -> u16

Take a single reading; return a raw integer value.

source

pub fn read_voltage(&mut self, channel: u8) -> f32

Take a single reading; return a voltage.

source

pub fn set_trigger(&mut self, trigger: Trigger, edge: TriggerEdge)

Select and activate a trigger. See G4 RM, section 21.4.18: Conversion on external trigger and trigger polarit

source

pub unsafe fn read_dma( &mut self, buf: &mut [u16], adc_channels: &[u8], dma_channel: DmaChannel, channel_cfg: ChannelCfg, dma_periph: DmaPeriph )

Take a reading, using DMA. Sets conversion sequence; no need to set it directly. Note that the channel argument is unused on F3 and L4, since it is hard-coded, and can’t be configured using the DMAMUX peripheral. (dma::mux() fn).

source

pub fn enable_interrupt(&mut self, interrupt: AdcInterrupt)

Enable a specific type of ADC interrupt.

source

pub fn clear_interrupt(&mut self, interrupt: AdcInterrupt)

Clear an interrupt flag of the specified type. Consider running this in the corresponding ISR.

source

pub fn read_status(&self) -> u32

Print the (raw) contents of the status register.

Auto Trait Implementations§

§

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

§

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

§

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

§

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

§

impl<R> UnwindSafe for Adc<R>
where R: 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>,

§

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.