APM:Libraries
Classes | Macros | Typedefs | Functions | Variables
adc.h File Reference

Analog-to-Digital Conversion (ADC) header. More...

#include "stm32.h"
#include "hal_types.h"
Include dependency graph for adc.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  adc_dev
 

Macros

#define ADC_Channel_0   ((uint8_t)0x00)
 
#define ADC_Channel_1   ((uint8_t)0x01)
 
#define ADC_Channel_2   ((uint8_t)0x02)
 
#define ADC_Channel_3   ((uint8_t)0x03)
 
#define ADC_Channel_4   ((uint8_t)0x04)
 
#define ADC_Channel_5   ((uint8_t)0x05)
 
#define ADC_Channel_6   ((uint8_t)0x06)
 
#define ADC_Channel_7   ((uint8_t)0x07)
 
#define ADC_Channel_8   ((uint8_t)0x08)
 
#define ADC_Channel_9   ((uint8_t)0x09)
 
#define ADC_Channel_10   ((uint8_t)0x0A)
 
#define ADC_Channel_11   ((uint8_t)0x0B)
 
#define ADC_Channel_12   ((uint8_t)0x0C)
 
#define ADC_Channel_13   ((uint8_t)0x0D)
 
#define ADC_Channel_14   ((uint8_t)0x0E)
 
#define ADC_Channel_15   ((uint8_t)0x0F)
 
#define ADC_Channel_16   ((uint8_t)0x10)
 
#define ADC_Channel_17   ((uint8_t)0x11)
 
#define ADC_Channel_18   ((uint8_t)0x12)
 
#define ADC_Channel_TempSensor   ((uint8_t)ADC_Channel_16)
 
#define ADC_Channel_Vrefint   ((uint8_t)ADC_Channel_17)
 
#define ADC_Channel_Vbat   ((uint8_t)ADC_Channel_18)
 
#define ADC_SampleTime_3Cycles   ((uint8_t)0x00)
 
#define ADC_SampleTime_15Cycles   ((uint8_t)0x01)
 
#define ADC_SampleTime_28Cycles   ((uint8_t)0x02)
 
#define ADC_SampleTime_56Cycles   ((uint8_t)0x03)
 
#define ADC_SampleTime_84Cycles   ((uint8_t)0x04)
 
#define ADC_SampleTime_112Cycles   ((uint8_t)0x05)
 
#define ADC_SampleTime_144Cycles   ((uint8_t)0x06)
 
#define ADC_SampleTime_480Cycles   ((uint8_t)0x07)
 
#define SMPR_SMP_SET   ((uint32_t)0x00000007)
 
#define SQR_SQ_SET   ((uint32_t)0x0000001F)
 
#define SQR1_L_RESET   ((uint32_t)0xFE0FFFFF)
 

Typedefs

typedef struct adc_dev adc_dev
 

Functions

void adc_init (const adc_dev *dev)
 Initialize an ADC peripheral. More...
 
void adc_foreach (void(*fn)(const adc_dev *))
 Call a function on all ADC devices. More...
 
uint16_t adc_read (const adc_dev *dev, uint8_t channel)
 
uint16_t vref_read (void)
 
uint16_t temp_read (void)
 
static void adc_set_reg_seqlen (const adc_dev *dev, uint8_t length)
 Set the regular channel sequence length. More...
 
static void adc_channel_config (const adc_dev *dev, uint8_t channel, uint8_t rank, uint8_t sampleTime)
 
static void adc_enable (const adc_dev *dev)
 Enable an adc peripheral. More...
 
static void adc_disable (const adc_dev *dev)
 Disable an ADC peripheral. More...
 
static void adc_disable_all (void)
 Disable all ADC peripherals. More...
 
static void adc_start_conv (const adc_dev *dev)
 
static void adc_vref_enable ()
 
static void adc_vref_disable ()
 

Variables

const adc_dev *const _ADC1
 
const adc_dev *const _ADC2
 
const adc_dev *const _ADC3
 
const adc_dev _adc1
 
const adc_dev _adc2
 
const adc_dev _adc3
 

Detailed Description

Analog-to-Digital Conversion (ADC) header.

Definition in file adc.h.

Macro Definition Documentation

◆ ADC_Channel_0

#define ADC_Channel_0   ((uint8_t)0x00)

Definition at line 30 of file adc.h.

◆ ADC_Channel_1

#define ADC_Channel_1   ((uint8_t)0x01)

Definition at line 31 of file adc.h.

◆ ADC_Channel_10

#define ADC_Channel_10   ((uint8_t)0x0A)

Definition at line 40 of file adc.h.

◆ ADC_Channel_11

#define ADC_Channel_11   ((uint8_t)0x0B)

Definition at line 41 of file adc.h.

◆ ADC_Channel_12

#define ADC_Channel_12   ((uint8_t)0x0C)

Definition at line 42 of file adc.h.

◆ ADC_Channel_13

#define ADC_Channel_13   ((uint8_t)0x0D)

Definition at line 43 of file adc.h.

◆ ADC_Channel_14

#define ADC_Channel_14   ((uint8_t)0x0E)

Definition at line 44 of file adc.h.

◆ ADC_Channel_15

#define ADC_Channel_15   ((uint8_t)0x0F)

Definition at line 45 of file adc.h.

◆ ADC_Channel_16

#define ADC_Channel_16   ((uint8_t)0x10)

Definition at line 46 of file adc.h.

Referenced by adc_init().

◆ ADC_Channel_17

#define ADC_Channel_17   ((uint8_t)0x11)

Definition at line 47 of file adc.h.

Referenced by adc_init(), and F4Light::AnalogSource::setup_read().

◆ ADC_Channel_18

#define ADC_Channel_18   ((uint8_t)0x12)

Definition at line 48 of file adc.h.

◆ ADC_Channel_2

#define ADC_Channel_2   ((uint8_t)0x02)

Definition at line 32 of file adc.h.

◆ ADC_Channel_3

#define ADC_Channel_3   ((uint8_t)0x03)

Definition at line 33 of file adc.h.

◆ ADC_Channel_4

#define ADC_Channel_4   ((uint8_t)0x04)

Definition at line 34 of file adc.h.

◆ ADC_Channel_5

#define ADC_Channel_5   ((uint8_t)0x05)

Definition at line 35 of file adc.h.

◆ ADC_Channel_6

#define ADC_Channel_6   ((uint8_t)0x06)

Definition at line 36 of file adc.h.

◆ ADC_Channel_7

#define ADC_Channel_7   ((uint8_t)0x07)

Definition at line 37 of file adc.h.

◆ ADC_Channel_8

#define ADC_Channel_8   ((uint8_t)0x08)

Definition at line 38 of file adc.h.

◆ ADC_Channel_9

#define ADC_Channel_9   ((uint8_t)0x09)

Definition at line 39 of file adc.h.

Referenced by adc_channel_config().

◆ ADC_Channel_TempSensor

#define ADC_Channel_TempSensor   ((uint8_t)ADC_Channel_16)

Definition at line 50 of file adc.h.

◆ ADC_Channel_Vbat

#define ADC_Channel_Vbat   ((uint8_t)ADC_Channel_18)

Definition at line 52 of file adc.h.

◆ ADC_Channel_Vrefint

#define ADC_Channel_Vrefint   ((uint8_t)ADC_Channel_17)

Definition at line 51 of file adc.h.

◆ ADC_SampleTime_112Cycles

#define ADC_SampleTime_112Cycles   ((uint8_t)0x05)

Definition at line 59 of file adc.h.

◆ ADC_SampleTime_144Cycles

#define ADC_SampleTime_144Cycles   ((uint8_t)0x06)

Definition at line 60 of file adc.h.

◆ ADC_SampleTime_15Cycles

#define ADC_SampleTime_15Cycles   ((uint8_t)0x01)

Definition at line 55 of file adc.h.

◆ ADC_SampleTime_28Cycles

#define ADC_SampleTime_28Cycles   ((uint8_t)0x02)

Definition at line 56 of file adc.h.

◆ ADC_SampleTime_3Cycles

#define ADC_SampleTime_3Cycles   ((uint8_t)0x00)

Definition at line 54 of file adc.h.

◆ ADC_SampleTime_480Cycles

#define ADC_SampleTime_480Cycles   ((uint8_t)0x07)

Definition at line 61 of file adc.h.

◆ ADC_SampleTime_56Cycles

#define ADC_SampleTime_56Cycles   ((uint8_t)0x03)

Definition at line 57 of file adc.h.

Referenced by adc_init().

◆ ADC_SampleTime_84Cycles

#define ADC_SampleTime_84Cycles   ((uint8_t)0x04)

Definition at line 58 of file adc.h.

Referenced by adc_init(), and F4Light::AnalogSource::setup_read().

◆ SMPR_SMP_SET

#define SMPR_SMP_SET   ((uint32_t)0x00000007)

Definition at line 63 of file adc.h.

Referenced by adc_channel_config().

◆ SQR1_L_RESET

#define SQR1_L_RESET   ((uint32_t)0xFE0FFFFF)

Definition at line 65 of file adc.h.

Referenced by adc_set_reg_seqlen().

◆ SQR_SQ_SET

#define SQR_SQ_SET   ((uint32_t)0x0000001F)

Definition at line 64 of file adc.h.

Referenced by adc_channel_config().

Typedef Documentation

◆ adc_dev

typedef struct adc_dev adc_dev

ADC device type.

Function Documentation

◆ adc_channel_config()

static void adc_channel_config ( const adc_dev dev,
uint8_t  channel,
uint8_t  rank,
uint8_t  sampleTime 
)
inlinestatic

Definition at line 104 of file adc.h.

Referenced by adc_init(), and F4Light::AnalogSource::setup_read().

Here is the caller graph for this function:

◆ adc_disable()

static void adc_disable ( const adc_dev dev)
inlinestatic

Disable an ADC peripheral.

Parameters
devADC device to disable

Definition at line 141 of file adc.h.

Referenced by adc_disable_all(), adc_init(), and F4Light::AnalogSource::stop_read().

Here is the caller graph for this function:

◆ adc_disable_all()

static void adc_disable_all ( void  )
inlinestatic

Disable all ADC peripherals.

Definition at line 148 of file adc.h.

Here is the call graph for this function:

◆ adc_enable()

static void adc_enable ( const adc_dev dev)
inlinestatic

Enable an adc peripheral.

Parameters
devADC device to enable

Definition at line 131 of file adc.h.

Referenced by adc_init(), F4Light::AnalogSource::set_pin(), and F4Light::AnalogSource::setup_read().

Here is the caller graph for this function:

◆ adc_foreach()

void adc_foreach ( void(*)(const adc_dev *)  fn)

Call a function on all ADC devices.

Parameters
fnFunction to call on each ADC device.

Definition at line 41 of file adc.c.

Referenced by adc_disable_all().

Here is the caller graph for this function:

◆ adc_init()

void adc_init ( const adc_dev dev)

Initialize an ADC peripheral.

Initializes the RCC clock line for the given peripheral. Resets ADC device registers.

Parameters
devADC peripheral to initialize

Definition at line 56 of file adc.c.

Referenced by F4Light::AnalogSource::set_pin().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ adc_read()

uint16_t adc_read ( const adc_dev dev,
uint8_t  channel 
)

Referenced by adc_init().

Here is the caller graph for this function:

◆ adc_set_reg_seqlen()

static void adc_set_reg_seqlen ( const adc_dev dev,
uint8_t  length 
)
inlinestatic

Set the regular channel sequence length.

Defines the total number of conversions in the regular channel conversion sequence.

Parameters
devADC device.
lengthRegular channel sequence length, from 1 to 16.

Definition at line 86 of file adc.h.

Referenced by adc_init(), and F4Light::AnalogSource::setup_read().

Here is the caller graph for this function:

◆ adc_start_conv()

static void adc_start_conv ( const adc_dev dev)
inlinestatic

Definition at line 152 of file adc.h.

Referenced by F4Light::AnalogIn::_timer_event().

Here is the caller graph for this function:

◆ adc_vref_disable()

static void adc_vref_disable ( )
inlinestatic

Definition at line 163 of file adc.h.

Referenced by F4Light::AnalogSource::stop_read().

Here is the caller graph for this function:

◆ adc_vref_enable()

static void adc_vref_enable ( )
inlinestatic

Definition at line 158 of file adc.h.

Referenced by F4Light::AnalogSource::setup_read().

Here is the caller graph for this function:

◆ temp_read()

uint16_t temp_read ( void  )

Referenced by adc_init().

Here is the caller graph for this function:

◆ vref_read()

uint16_t vref_read ( void  )

Referenced by adc_init().

Here is the caller graph for this function:

Variable Documentation

◆ _ADC1

const adc_dev* const _ADC1

ADC1 device.

Definition at line 20 of file adc.c.

Referenced by F4Light::AnalogSource::_find_device().

◆ _adc1

const adc_dev _adc1

Definition at line 16 of file adc.c.

◆ _ADC2

const adc_dev* const _ADC2

ADC2 device.

Definition at line 26 of file adc.c.

◆ _adc2

const adc_dev _adc2

Definition at line 22 of file adc.c.

◆ _ADC3

const adc_dev* const _ADC3

ADC3 device.

Definition at line 32 of file adc.c.

◆ _adc3

const adc_dev _adc3

Definition at line 28 of file adc.c.