microHAL
An abstraction layer for your future F4xx projects
Loading...
Searching...
No Matches
adc.h File Reference

Function prototypes for the ADC driver. More...

#include <stdint.h>
#include "stm32f4xx.h"
#include "defines.h"

Go to the source code of this file.

Data Structures

struct  ADCRegs
 Contains ADC registers. More...
 
struct  ADCCommonRegs
 Contains ADC common registers. More...
 
struct  ADCModes
 Contains ADC conversion modes. More...
 

Macros

#define ADC_(NUM)
 
#define ADC_COMMON   (struct ADCCommonRegs *)(ADC123_COMMON_BASE)
 

Typedefs

typedef enum adc_peripheral adc_peripheral_t
 Available ADC peripherals.
 
typedef enum adc_res adc_res_t
 Available ADC resolutions.
 
typedef enum adc_trigger adc_trigger_t
 Available ADC trigger modes.
 
typedef enum adc_samplerate adc_samplerate_t
 Available ADC samplerates (in cycles)
 
typedef enum adc_prescaler adc_prescaler_t
 Available ADC prescaler dividers.
 

Enumerations

enum  adc_peripheral { ADC_PERIPH_LEN }
 Available ADC peripherals.
 
enum  adc_res { ADC_RES_B12 = 0x00 , ADC_RES_B10 = 0x01 , ADC_RES_B08 = 0x02 , ADC_RES_B06 = 0x03 }
 Available ADC resolutions.
 
enum  adc_trigger { ADC_TRIGGER_NONE = 0x00 , ADC_TRIGGER_RISE = 0x01 , ADC_TRIGGER_FALL = 0x02 , ADC_TRIGGER_BOTH = 0x03 }
 Available ADC trigger modes.
 
enum  adc_samplerate {
  ADC_SAMPLERATE_C003 = 0x00 , ADC_SAMPLERATE_C015 = 0x01 , ADC_SAMPLERATE_C028 = 0x02 , ADC_SAMPLERATE_C056 = 0x03 ,
  ADC_SAMPLERATE_C084 = 0x04 , ADC_SAMPLERATE_C112 = 0x05 , ADC_SAMPLERATE_C144 = 0x06 , ADC_SAMPLERATE_C480 = 0x07
}
 Available ADC samplerates (in cycles)
 
enum  adc_prescaler { ADC_PRESCALER_DIV2 = 0x00 , ADC_PRESCALER_DIV4 = 0x01 , ADC_PRESCALER_DIV6 = 0x02 , ADC_PRESCALER_DIV8 = 0x03 }
 Available ADC prescaler dividers.
 

Functions

void adc_set_prescaler (const adc_prescaler_t value)
 Sets the ADC Prescaler divider to the specified value.
 
void adc_set_resolution (const adc_peripheral_t adc, const adc_res_t value)
 Sets the ADC resolution to the specified value.
 
void adc_set_samplerate (const adc_peripheral_t adc, const uint8_t channel, const adc_samplerate_t value)
 Sets the ADC sampling rate to the specified value.
 
void adc_set_modes (const adc_peripheral_t adc, const struct ADCModes config)
 Sets the ADC modes according to the configuration.
 
void adc_set_seq (const adc_peripheral_t adc, const uint8_t *seq, const uint8_t count)
 Sets the ADC conversion sequence to the specified order.
 
void adc_on (const adc_peripheral_t adc)
 Starts the ADC conversion.
 
void adc_off (const adc_peripheral_t adc)
 Stops the ADC conversion.
 
uint16_t adc_read (const adc_peripheral_t adc)
 Reads the last ADC conversion result.
 

Detailed Description

Function prototypes for the ADC driver.

This file contains all of the enums, macros, and function prototypes required for a functional ADC driver.

DISCLAIMER: Only for regular channels in single / continuous / discontinuous modes. Injected channels may be implemented later.

Author
Vasileios Ch. (BillisC)
Bug
None, yet.

Macro Definition Documentation

◆ ADC_

#define ADC_ ( NUM)
Value:
(struct ADCRegs *)(ADC1_BASE + (0x100UL * ((uint8_t)NUM)))
Contains ADC registers.
Definition adc.h:28

Function Documentation

◆ adc_off()

void adc_off ( const adc_peripheral_t adc)

Stops the ADC conversion.

The ADC will be powered off upon calling this command and instantly stop the conversion procedure.

Parameters
adcThe selected ADC
Returns
None

◆ adc_on()

void adc_on ( const adc_peripheral_t adc)

Starts the ADC conversion.

The ADC will be powered on upon calling this command and start the conversion procedure as configured. Dummy reads are included.

Parameters
adcThe selected ADC
Returns
None

◆ adc_read()

uint16_t adc_read ( const adc_peripheral_t adc)

Reads the last ADC conversion result.

Parameters
adcThe selected ADC
Returns
The conversion result

◆ adc_set_modes()

void adc_set_modes ( const adc_peripheral_t adc,
const struct ADCModes config )

Sets the ADC modes according to the configuration.

The configuration values are specified within the adc_config struct. Some modes may not work as expected yet.

Parameters
adcThe selected ADC
configThe ADC configuration
Returns
None

◆ adc_set_prescaler()

void adc_set_prescaler ( const adc_prescaler_t value)

Sets the ADC Prescaler divider to the specified value.

The available dividers for the ADC Prescaler are specified in the adc_prescaler_t enum. Any other value will be ignored.

Parameters
valueThe prescaler divider value
Returns
None

◆ adc_set_resolution()

void adc_set_resolution ( const adc_peripheral_t adc,
const adc_res_t value )

Sets the ADC resolution to the specified value.

The available resolutions for the ADC channel reads are specified in the adc_res_t enum. Any other value will be ignored.

Parameters
adcThe selected ADC
valueThe resolution of the ADC conversions
Returns
None

◆ adc_set_samplerate()

void adc_set_samplerate ( const adc_peripheral_t adc,
const uint8_t channel,
const adc_samplerate_t value )

Sets the ADC sampling rate to the specified value.

The available sampling rates for the ADC channel reads are specified in the adc_res_t enum (in clock cycles). Any other value will be ignored.

Parameters
adcThe selected ADC
channelThe selected channel (0..19)
valueThe clock cycles of the ADC conversions
Returns
None

◆ adc_set_seq()

void adc_set_seq ( const adc_peripheral_t adc,
const uint8_t * seq,
const uint8_t count )

Sets the ADC conversion sequence to the specified order.

The sequence consists of 16 5-bit elements. Bits 6..8 will be ignored.

Parameters
adcThe selected ADC
seqPointer to channel conversion sequence array
countThe total amount of conversions
Returns
None