AVR XMEGA Analog to Digital Converter driver.
Copyright (c) 2010-2018 Microchip Technology Inc. and its subsidiaries.
#include <compiler.h>
#include <conf_adc.h>
#include <nvm.h>
#include <parts.h>
#include <sleepmgr.h>
#include <sysclk.h>
Data Structures | |
struct | adc_channel_config |
ADC channel configuration. More... | |
struct | adc_config |
ADC configuration. More... | |
Macros | |
#define | ADC_CH_GAIN_DIV2_gc (0x07 << 2) |
#define | ADC_CH_OFFSET_gp 4 /* Positive MUX setting offset group position. */ |
#define | ADC_CURRLIMIT_gm 0x60 /* Current limit group mask. */ |
#define | ADC_CURRLIMIT_HIGH_gc (0x03 << 5) |
#define | ADC_CURRLIMIT_LOW_gc (0x01 << 5) |
#define | ADC_CURRLIMIT_MED_gc (0x02 << 5) |
#define | ADC_CURRLIMIT_NO_gc (0x00 << 5) |
#define | ADC_EVACT_SYNCSWEEP_gc (0x06 << 0) |
#define | ADC_NR_OF_CHANNELS 4 |
Number of channels per ADC. More... | |
#define | ADC_REFSEL_INTVCC_gc (0x01 << 4) |
#define | ADC_REFSEL_VCCDIV2_gc (0x04 << 4) |
#define | CONFIG_ADC_INTLVL ADC_CH_INTLVL_LO_gc |
Default ADC channel interrupt level. More... | |
Calibration data addresses | |
| |
#define | ADCACAL0 offsetof(NVM_PROD_SIGNATURES_t, ADCACAL0) |
ADC A, calibration byte 0. More... | |
#define | ADCACAL1 offsetof(NVM_PROD_SIGNATURES_t, ADCACAL1) |
ADC A, calibration byte 1. More... | |
#define | ADCBCAL0 offsetof(NVM_PROD_SIGNATURES_t, ADCBCAL0) |
ADC B, calibration byte 0. More... | |
#define | ADCBCAL1 offsetof(NVM_PROD_SIGNATURES_t, ADCBCAL1) |
ADC B, calibration byte 1. More... | |
#define | TEMPSENSE0 offsetof(NVM_PROD_SIGNATURES_t, TEMPSENSE0) |
Temperature sensor calibration byte 0. More... | |
#define | TEMPSENSE1 offsetof(NVM_PROD_SIGNATURES_t, TEMPSENSE1) |
Temperature sensor calibration byte 1. More... | |
#define | HOTTEMP offsetof(NVM_PROD_SIGNATURES_t, HOTTEMP) |
Temperature at which TEMPSENSE1/TEMPSENSE0 is measured. More... | |
#define | ROOMTEMP offsetof(NVM_PROD_SIGNATURES_t, ROOMTEMP) |
Temperature at which TEMPSENSE3/TEMPSENSE2 is measured. More... | |
#define | TEMPSENSE2 offsetof(NVM_PROD_SIGNATURES_t, TEMPSENSE2) |
Temperature sensor calibration byte 2. More... | |
#define | TEMPSENSE3 offsetof(NVM_PROD_SIGNATURES_t, TEMPSENSE3) |
Temperature sensor calibration byte 3. More... | |
ADC channel masks | |
#define | ADC_CH0 (1U << 0) |
ADC channel 0. More... | |
#define | ADC_CH1 (1U << 1) |
ADC channel 1. More... | |
#define | ADC_CH2 (1U << 2) |
ADC channel 2. More... | |
#define | ADC_CH3 (1U << 3) |
ADC channel 3. More... | |
Internal ADC input masks | |
#define | ADC_INT_TEMPSENSE ADC_TEMPREF_bm |
Temperature sensor. More... | |
#define | ADC_INT_BANDGAP ADC_BANDGAP_bm |
Bandgap reference. More... | |
Functions | |
Internal functions for driver | |
static __always_inline ADC_CH_t * | adc_get_channel (ADC_t *adc, uint8_t ch_mask) |
Get ADC channel pointer from channel mask. More... | |
ADC interrupt callback function | |
#define | CONFIG_ADC_CALLBACK_ENABLE |
Configuration symbol to enable callback on ADC interrupts. More... | |
#define | CONFIG_ADC_CALLBACK_TYPE uint16_t |
Configuration symbol for datatype of result parameter for callback. More... | |
typedef CONFIG_ADC_CALLBACK_TYPE | adc_result_t |
Datatype of ADC conversion result parameter for callback. More... | |
typedef void(* | adc_callback_t )(ADC_t *adc, uint8_t ch_mask, adc_result_t res) |
ADC interrupt callback function pointer. More... | |
void | adc_set_callback (ADC_t *adc, adc_callback_t callback) |
Set ADC interrupt callback function. More... | |
ADC module management | |
#define | adc_get_result(adc, ch_mask) (adc_get_channel(adc, ch_mask)->RES) |
Get result from ADC channel. More... | |
#define | adc_set_compare_value(adc, val) |
Set compare value directly to ADC. More... | |
#define | adc_get_compare_value(adc) ((adc)->CMP) |
Get compare value directly from ADC. More... | |
void | adc_enable (ADC_t *adc) |
Enable ADC. More... | |
void | adc_disable (ADC_t *adc) |
Disable ADC. More... | |
bool | adc_is_enabled (ADC_t *adc) |
Check if the ADC is enabled. More... | |
static void | adc_start_conversion (ADC_t *adc, uint8_t ch_mask) |
Start one-shot conversion on ADC channel(s) More... | |
static int16_t | adc_get_signed_result (ADC_t *adc, uint8_t ch_mask) |
Get signed result from ADC channel. More... | |
static uint16_t | adc_get_unsigned_result (ADC_t *adc, uint8_t ch_mask) |
Get unsigned result from ADC channel. More... | |
static uint8_t | adc_get_interrupt_flag (ADC_t *adc, uint8_t ch_mask) |
Get interrupt flag of ADC channel(s) More... | |
static void | adc_clear_interrupt_flag (ADC_t *adc, uint8_t ch_mask) |
Clear interrupt flag of ADC channel(s) More... | |
static void | adc_wait_for_interrupt_flag (ADC_t *adc, uint8_t ch_mask) |
Wait for interrupt flag of ADC channel(s) More... | |
static void | adc_flush (ADC_t *adc) |
Flush the ADC. More... | |
static int16_t | adc_get_signed_compare_value (ADC_t *adc) |
Get signed compare value directly from ADC. More... | |
static uint16_t | adc_get_unsigned_compare_value (ADC_t *adc) |
Get unsigned compare value directly from ADC. More... | |
static uint16_t | adc_get_calibration_data (enum adc_calibration_data cal) |
Get calibration data. More... | |
ADC module configuration | |
#define | adc_set_config_compare_value(conf, val) |
Set ADC compare value in configuration. More... | |
#define | adc_get_config_compare_value(conf) (conf->cmp) |
Get ADC compare value from configuration. More... | |
enum | adc_gainstage_impmode { ADC_GAIN_HIGHIMPEDANCE, ADC_GAIN_LOWIMPEDANCE } |
ADC gain stage impedance settings. More... | |
enum | adc_current_limit { ADC_CURRENT_LIMIT_NO, ADC_CURRENT_LIMIT_LOW, ADC_CURRENT_LIMIT_MED, ADC_CURRENT_LIMIT_HIGH } |
ADC current limit settings. More... | |
void | adc_write_configuration (ADC_t *adc, const struct adc_config *conf) |
Write configuration to ADC module. More... | |
void | adc_read_configuration (ADC_t *adc, struct adc_config *conf) |
Read configuration from ADC module. More... | |
static void | adc_set_clock_rate (struct adc_config *conf, uint32_t clk_adc) |
Set ADC prescaler to get desired clock rate. More... | |
static void | adc_set_conversion_parameters (struct adc_config *conf, enum adc_sign sign, enum adc_resolution res, enum adc_reference ref) |
Set ADC conversion parameters. More... | |
static void | adc_set_conversion_trigger (struct adc_config *conf, enum adc_trigger trig, uint8_t nr_of_ch, uint8_t base_ev_ch) |
Set ADC conversion trigger. More... | |
static void | adc_set_dma_request_group (struct adc_config *conf, uint8_t nr_of_ch) |
Set DMA request group. More... | |
static void | adc_enable_internal_input (struct adc_config *conf, uint8_t int_inp) |
Enable internal ADC input. More... | |
static void | adc_disable_internal_input (struct adc_config *conf, uint8_t int_inp) |
Disable internal ADC input. More... | |
static void | adc_set_gain_impedance_mode (struct adc_config *conf, enum adc_gainstage_impmode impmode) |
Set ADC gain stage impedance mode. More... | |
static void | adc_set_current_limit (struct adc_config *conf, enum adc_current_limit currlimit) |
Set ADC current limit. More... | |
ADC channel configuration | |
#define | ADCCH_FORCE_1X_GAINSTAGE 0xff |
Force enabling of gainstage with unity gain. More... | |
void | adcch_write_configuration (ADC_t *adc, uint8_t ch_mask, const struct adc_channel_config *ch_conf) |
Write configuration to ADC channel. More... | |
void | adcch_read_configuration (ADC_t *adc, uint8_t ch_mask, struct adc_channel_config *ch_conf) |
Read configuration from ADC channel. More... | |
static uint8_t | adcch_get_gain_setting (uint8_t gain) |
Get ADC channel setting for specified gain. More... | |
static void | adcch_set_input (struct adc_channel_config *ch_conf, enum adcch_positive_input pos, enum adcch_negative_input neg, uint8_t gain) |
Set ADC channel input mode, multiplexing and gain. More... | |
static void | adcch_set_pin_scan (struct adc_channel_config *ch_conf, uint8_t start_offset, uint8_t max_offset) |
Set ADC channel 0 pin scan. More... | |
static void | adcch_set_interrupt_mode (struct adc_channel_config *ch_conf, enum adcch_mode mode) |
Set ADC channel interrupt mode. More... | |
static void | adcch_enable_interrupt (struct adc_channel_config *ch_conf) |
Enable interrupts on ADC channel. More... | |
static void | adcch_disable_interrupt (struct adc_channel_config *ch_conf) |
Disable interrupts on ADC channel. More... | |
#define ADC_CH_GAIN_DIV2_gc (0x07 << 2) |
Referenced by adcch_get_gain_setting().
#define ADC_CH_OFFSET_gp 4 /* Positive MUX setting offset group position. */ |
Referenced by adcch_set_pin_scan().
#define ADC_CURRLIMIT_gm 0x60 /* Current limit group mask. */ |
Referenced by adc_set_current_limit().
#define ADC_CURRLIMIT_HIGH_gc (0x03 << 5) |
Referenced by adc_set_current_limit().
#define ADC_CURRLIMIT_LOW_gc (0x01 << 5) |
Referenced by adc_set_current_limit().
#define ADC_CURRLIMIT_MED_gc (0x02 << 5) |
Referenced by adc_set_current_limit().
#define ADC_CURRLIMIT_NO_gc (0x00 << 5) |
Referenced by adc_set_current_limit().
#define ADC_EVACT_SYNCSWEEP_gc (0x06 << 0) |
Referenced by adc_set_conversion_trigger().
#define ADC_REFSEL_INTVCC_gc (0x01 << 4) |
#define ADC_REFSEL_VCCDIV2_gc (0x04 << 4) |