Microchip® Advanced Software Framework

sdadc.h File Reference

SAM Sigma-Delta Analog-to-Digital Converter (SDADC) Driver.

Copyright (c) 2015-2018 Microchip Technology Inc. and its subsidiaries.

#include <compiler.h>
#include <system.h>
#include <system_interrupt.h>

Data Structures

struct  sdadc_config
 SDADC configuration structure. More...
 
struct  sdadc_correction_config
 SDADC correction configuration structure. More...
 
struct  sdadc_events
 SDADC event enable/disable structure. More...
 
struct  sdadc_module
 SDADC software device instance structure. More...
 
struct  sdadc_reference
 Reference configuration structure. More...
 
struct  sdadc_window_config
 Window monitor configuration structure. More...
 

Macros

Module Status Flags

SDADC status flags, returned by sdadc_get_status() and cleared by sdadc_clear_status().

#define SDADC_STATUS_RESULT_READY   (1UL << 0)
 SDADC result ready. More...
 
#define SDADC_STATUS_OVERRUN   (1UL << 1)
 SDADC result overwritten before read. More...
 
#define SDADC_STATUS_WINDOW   (1UL << 2)
 Window monitor match. More...
 

Typedefs

typedef void(* sdadc_callback_t )(const struct sdadc_module *const module)
 Type of the callback functions. More...
 

Enumerations

enum  sdadc_callback {
  SDADC_CALLBACK_READ_BUFFER,
  SDADC_CALLBACK_WINDOW,
  SDADC_CALLBACK_ERROR
}
 SDADC Callback enum. More...
 
enum  sdadc_event_action {
  SDADC_EVENT_ACTION_DISABLED = 0,
  SDADC_EVENT_ACTION_FLUSH_START_CONV = SDADC_EVCTRL_FLUSHEI,
  SDADC_EVENT_ACTION_START_CONV = SDADC_EVCTRL_STARTEI
}
 SDADC event action enum. More...
 
enum  sdadc_interrupt_flag {
  SDADC_INTERRUPT_RESULT_READY = SDADC_INTFLAG_RESRDY,
  SDADC_INTERRUPT_OVERRUN = SDADC_INTFLAG_OVERRUN,
  SDADC_INTERRUPT_WINDOW = SDADC_INTFLAG_WINMON
}
 Enum for the possible SDADC interrupt flags. More...
 
enum  sdadc_mux_input {
  SDADC_MUX_INPUT_AIN0 = SDADC_INPUTCTRL_MUXSEL_AIN0,
  SDADC_MUX_INPUT_AIN1 = SDADC_INPUTCTRL_MUXSEL_AIN1,
  SDADC_MUX_INPUT_AIN2 = SDADC_INPUTCTRL_MUXSEL_AIN2
}
 SDADC MUX input selection enum. More...
 
enum  sdadc_over_sampling_ratio {
  SDADC_OVER_SAMPLING_RATIO64 = SDADC_CTRLB_OSR(0),
  SDADC_OVER_SAMPLING_RATIO128 = SDADC_CTRLB_OSR(1),
  SDADC_OVER_SAMPLING_RATIO256 = SDADC_CTRLB_OSR(2),
  SDADC_OVER_SAMPLING_RATIO512 = SDADC_CTRLB_OSR(3),
  SDADC_OVER_SAMPLING_RATIO1024 = SDADC_CTRLB_OSR(4)
}
 SDADC over sampling ratio enum. More...
 
enum  sdadc_reference_range {
  SDADC_REFRANGE_0 = SDADC_REFCTRL_REFRANGE(0),
  SDADC_REFRANGE_1 = SDADC_REFCTRL_REFRANGE(1),
  SDADC_REFRANGE_2 = SDADC_REFCTRL_REFRANGE(2),
  SDADC_REFRANGE_3 = SDADC_REFCTRL_REFRANGE(3)
}
 SDADC reference range enum. More...
 
enum  sdadc_reference_select {
  SDADC_REFERENCE_INTREF = SDADC_REFCTRL_REFSEL(0),
  SDADC_REFERENCE_AREFB = SDADC_REFCTRL_REFSEL(1),
  SDADC_REFERENCE_DACOUT = SDADC_REFCTRL_REFSEL(2),
  SDADC_REFERENCE_INTVCC = SDADC_REFCTRL_REFSEL(3)
}
 SDADC reference voltage enum. More...
 
enum  sdadc_window_mode {
  SDADC_WINDOW_MODE_DISABLE = SDADC_WINCTRL_WINMODE(0),
  SDADC_WINDOW_MODE_ABOVE = SDADC_WINCTRL_WINMODE(1),
  SDADC_WINDOW_MODE_BELOW = SDADC_WINCTRL_WINMODE(2),
  SDADC_WINDOW_MODE_INSIDE = SDADC_WINCTRL_WINMODE(3),
  SDADC_WINDOW_MODE_OUTSIDE = SDADC_WINCTRL_WINMODE(4)
}
 SDADC window monitor mode enum. More...
 

Functions

Driver Initialization and Configuration
enum status_code sdadc_init (struct sdadc_module *const module_inst, Sdadc *hw, struct sdadc_config *config)
 Initializes the SDADC. More...
 
static void sdadc_get_config_defaults (struct sdadc_config *const config)
 Initializes an SDADC configuration structure to defaults. More...
 
Status Management
static uint32_t sdadc_get_status (struct sdadc_module *const module_inst)
 Retrieves the current module status. More...
 
static void sdadc_clear_status (struct sdadc_module *const module_inst, const uint32_t status_flags)
 Clears a module status flag. More...
 
static bool sdadc_get_sequence_status (struct sdadc_module *const module_inst, uint8_t *seq_state)
 Get a module sequence flag. More...
 
Enable, Disable, and Reset SDADC Module, Start Conversion and Read Result
static bool sdadc_is_syncing (struct sdadc_module *const module_inst)
 Determines if the hardware module(s) are currently synchronizing to the bus. More...
 
static enum status_code sdadc_enable (struct sdadc_module *const module_inst)
 Enables the SDADC module. More...
 
static enum status_code sdadc_disable (struct sdadc_module *const module_inst)
 Disables the SDADC module. More...
 
static enum status_code sdadc_reset (struct sdadc_module *const module_inst)
 Resets the SDADC module. More...
 
static void sdadc_enable_events (struct sdadc_module *const module_inst, struct sdadc_events *const events)
 Enables an SDADC event input or output. More...
 
static void sdadc_disable_events (struct sdadc_module *const module_inst, struct sdadc_events *const events)
 Disables an SDADC event input or output. More...
 
static void sdadc_start_conversion (struct sdadc_module *const module_inst)
 Starts an SDADC conversion. More...
 
static enum status_code sdadc_read (struct sdadc_module *const module_inst, int32_t *result)
 Reads the SDADC result. More...
 
Runtime Changes of SDADC Module
static void sdadc_flush (struct sdadc_module *const module_inst)
 Flushes the SDADC pipeline. More...
 
static void sdadc_set_window_mode (struct sdadc_module *const module_inst, const enum sdadc_window_mode window_mode, const int16_t window_lower_value, const int16_t window_upper_value)
 Sets the SDADC window mode. More...
 
static void sdadc_set_mux_input (struct sdadc_module *const module_inst, const enum sdadc_mux_input mux_input)
 Sets MUX SDADC input pin. More...
 
Enable and Disable Interrupts
static void sdadc_enable_interrupt (struct sdadc_module *const module_inst, enum sdadc_interrupt_flag interrupt)
 Enable interrupt. More...
 
static void sdadc_disable_interrupt (struct sdadc_module *const module_inst, enum sdadc_interrupt_flag interrupt)
 Disable interrupt. More...