[][src]Module stm32l0x1_hal::adc

Analog-digital conversion

This is a (partial) implementation of the ADC for the STM32L0x1 family.

The ADC has three basic run modes: Single, Continuous, and Discontinuous. For a discussion of these modes, see 13.3.9 for Single, 13.3.10 for Continuous, and 13.4.1 for Disconinuous modes. Only the OneShot trait is implemented, which greatly underutilizes the hardware.

use stm32l0x1_hal;

let d = stm32l0x1_hal::stm32l0x1::Peripherals::take().unwrap();
let adc = d.ADC;
let mut flash = d.FLASH.constrain();
let mut pwr = d.PWR.constrain();
let mut rcc = d.RCC.constrain().freeze(&mut flash, &mut pwr);

// Configure the ADC
let mut adc: adc::Adc<adc::Res12Bit, adc::Single> = adc::Adc::new(
    adc,
    Duration::new(0, 0),
    adc::AdcClkSrc::Hsi16,
    &pwr,
    &rcc.cfgr.context().unwrap(),
    &mut rcc.apb2,
    );

// Set up a pin that supports being used as an ADC input
let gpioa = gpio::A::new(d.GPIOA, &mut self.rcc.iop);
let mut light_sense = gpioa
    .PA7
    .into_input::<Floating>(&mut gpioa.moder, &mut gpioa.pupdr)
    .into_analog(&mut gpioa.moder, &mut gpioa.pupdr);

let lvl = block!(adc.read_channel(&mut light_sense)).unwrap();

Structs

Adc

The constrained ADC peripheral

Continuous

Continuous (type state) conversion mode

Discontinuous

Discontinuous (type state) mode

Res6Bit

6-bit resolution (type state)

Res8Bit

8-bit resolution (type state)

Res10Bit

10-bit resolution (type state)

Res12Bit

12-bit resolution (type state)

ScanDown

Scan from the highest-numbered channel to 0 (varies based on chip) (type state)

ScanUp

Scan from channel 0 to the highest-numbered channel (varies based on chip) (type state)

Single

Single (type state) conversion mode

Enums

AdcClkSrc

ADC clock input selection

Error

ADC-related errors

Events

ADC interrupt sources