Microchip® Advanced Software Framework

ac.h File Reference

SAM Analog Comparator Driver.

Copyright (c) 2012-2020 Microchip Technology Inc. and its subsidiaries.

#include <compiler.h>
#include <clock.h>

Data Structures

struct  ac_chan_config
 Analog Comparator Comparator channel configuration structure. More...
 
struct  ac_config
 Analog Comparator module configuration structure. More...
 
struct  ac_events
 AC event enable/disable structure. More...
 
struct  ac_module
 AC software device instance structure. More...
 
struct  ac_win_config
 Analog Comparator Window configuration structure. More...
 

Macros

Driver Feature Definition

Define AC driver feature set according to different device family.

#define FEATURE_AC_HYSTERESIS_LEVEL
 Setting of hysteresis level. More...
 
#define FEATURE_AC_SYNCBUSY_SCHEME_VERSION_2
 SYNCBUSY scheme version 2. More...
 
#define FEATURE_AC_RUN_IN_STANDY_EACH_COMPARATOR
 Run in standby feature for each comparator. More...
 
AC Window Channel Status Flags

AC window channel status flags, returned by ac_win_get_status().

#define AC_WIN_STATUS_UNKNOWN   (1UL << 0)
 Unknown output state; the comparator window channel was not ready. More...
 
#define AC_WIN_STATUS_ABOVE   (1UL << 1)
 Window Comparator's input voltage is above the window. More...
 
#define AC_WIN_STATUS_INSIDE   (1UL << 2)
 Window Comparator's input voltage is inside the window. More...
 
#define AC_WIN_STATUS_BELOW   (1UL << 3)
 Window Comparator's input voltage is below the window. More...
 
#define AC_WIN_STATUS_INTERRUPT_SET   (1UL << 4)
 This state reflects the window interrupt flag. More...
 
AC Channel Status Flags

AC channel status flags, returned by ac_chan_get_status().

#define AC_CHAN_STATUS_UNKNOWN   (1UL << 0)
 Unknown output state; the comparator channel was not ready. More...
 
#define AC_CHAN_STATUS_NEG_ABOVE_POS   (1UL << 1)
 Comparator's negative input pin is higher in voltage than the positive input pin. More...
 
#define AC_CHAN_STATUS_POS_ABOVE_NEG   (1UL << 2)
 Comparator's positive input pin is higher in voltage than the negative input pin. More...
 
#define AC_CHAN_STATUS_INTERRUPT_SET   (1UL << 3)
 This state reflects the channel interrupt flag. More...
 

Typedefs

typedef void(* ac_callback_t )(struct ac_module *const module_inst)
 Type definition for a AC module callback function. More...
 

Enumerations

enum  ac_callback {
  AC_CALLBACK_COMPARATOR_0 = 0,
  AC_CALLBACK_COMPARATOR_1 = 1,
  AC_CALLBACK_WINDOW_0 = 4
}
 Enum for possible callback types for the AC module. More...
 
enum  ac_chan_channel {
  AC_CHAN_CHANNEL_0 = 0,
  AC_CHAN_CHANNEL_1 = 1,
  AC_CHAN_CHANNEL_2 = 2,
  AC_CHAN_CHANNEL_3 = 3
}
 AC comparator channel selection enum. More...
 
enum  ac_chan_filter {
  AC_CHAN_FILTER_NONE = AC_COMPCTRL_FLEN_OFF,
  AC_CHAN_FILTER_MAJORITY_3 = AC_COMPCTRL_FLEN_MAJ3,
  AC_CHAN_FILTER_MAJORITY_5 = AC_COMPCTRL_FLEN_MAJ5
}
 AC channel output filtering configuration enum. More...
 
enum  ac_chan_interrupt_selection {
  AC_CHAN_INTERRUPT_SELECTION_TOGGLE = AC_COMPCTRL_INTSEL_TOGGLE,
  AC_CHAN_INTERRUPT_SELECTION_RISING = AC_COMPCTRL_INTSEL_RISING,
  AC_CHAN_INTERRUPT_SELECTION_FALLING = AC_COMPCTRL_INTSEL_FALLING,
  AC_CHAN_INTERRUPT_SELECTION_END_OF_COMPARE = AC_COMPCTRL_INTSEL_EOC
}
 Channel interrupt selection enum. More...
 
enum  ac_chan_neg_mux {
  AC_CHAN_NEG_MUX_PIN0 = AC_COMPCTRL_MUXNEG_PIN0,
  AC_CHAN_NEG_MUX_PIN1 = AC_COMPCTRL_MUXNEG_PIN1,
  AC_CHAN_NEG_MUX_PIN2 = AC_COMPCTRL_MUXNEG_PIN2,
  AC_CHAN_NEG_MUX_PIN3 = AC_COMPCTRL_MUXNEG_PIN3,
  AC_CHAN_NEG_MUX_GND = AC_COMPCTRL_MUXNEG_GND,
  AC_CHAN_NEG_MUX_SCALED_VCC = AC_COMPCTRL_MUXNEG_VSCALE,
  AC_CHAN_NEG_MUX_BANDGAP = AC_COMPCTRL_MUXNEG_BANDGAP,
  AC_CHAN_NEG_MUX_DAC0 = AC_COMPCTRL_MUXNEG_DAC
}
 AC channel negative comparator pin input configuration enum. More...
 
enum  ac_chan_output {
  AC_CHAN_OUTPUT_INTERNAL = AC_COMPCTRL_OUT_OFF,
  AC_CHAN_OUTPUT_ASYNCRONOUS = AC_COMPCTRL_OUT_ASYNC,
  AC_CHAN_OUTPUT_SYNCHRONOUS = AC_COMPCTRL_OUT_SYNC
}
 AC channel GPIO output routing configuration enum. More...
 
enum  ac_chan_pos_mux {
  AC_CHAN_POS_MUX_PIN0 = AC_COMPCTRL_MUXPOS_PIN0,
  AC_CHAN_POS_MUX_PIN1 = AC_COMPCTRL_MUXPOS_PIN1,
  AC_CHAN_POS_MUX_PIN2 = AC_COMPCTRL_MUXPOS_PIN2,
  AC_CHAN_POS_MUX_PIN3 = AC_COMPCTRL_MUXPOS_PIN3
}
 AC channel positive comparator pin input configuration enum. More...
 
enum  ac_chan_sample_mode {
  AC_CHAN_MODE_CONTINUOUS = 0,
  AC_CHAN_MODE_SINGLE_SHOT = AC_COMPCTRL_SINGLE
}
 AC channel input sampling mode configuration enum. More...
 
enum  ac_hysteresis_level {
  AC_HYSTERESIS_LEVEL_50 = 0,
  AC_HYSTERESIS_LEVEL_70,
  AC_HYSTERESIS_LEVEL_90,
  AC_HYSTERESIS_LEVEL_110
}
 Enum for possible hysteresis level types for AC module. More...
 
enum  ac_win_channel {
  AC_WIN_CHANNEL_0 = 0,
  AC_WIN_CHANNEL_1 = 1
}
 AC window channel selection enum. More...
 
enum  ac_win_interrupt_selection {
  AC_WIN_INTERRUPT_SELECTION_ABOVE = AC_WINCTRL_WINTSEL0_ABOVE,
  AC_WIN_INTERRUPT_SELECTION_INSIDE = AC_WINCTRL_WINTSEL0_INSIDE,
  AC_WIN_INTERRUPT_SELECTION_BELOW = AC_WINCTRL_WINTSEL0_BELOW,
  AC_WIN_INTERRUPT_SELECTION_OUTSIDE = AC_WINCTRL_WINTSEL0_OUTSIDE
}
 Window interrupt selection enum. More...
 

Functions

Configuration and Initialization
enum status_code ac_reset (struct ac_module *const module_inst)
 Resets and disables the Analog Comparator driver. More...
 
enum status_code ac_init (struct ac_module *const module_inst, Ac *const hw, struct ac_config *const config)
 Initializes and configures the Analog Comparator driver. More...
 
static bool ac_is_syncing (struct ac_module *const module_inst)
 Determines if the hardware module(s) are currently synchronizing to the bus. More...
 
static void ac_get_config_defaults (struct ac_config *const config)
 Initializes all members of an Analog Comparator configuration structure to safe defaults. More...
 
static void ac_enable (struct ac_module *const module_inst)
 Enables an Analog Comparator that was previously configured. More...
 
static void ac_disable (struct ac_module *const module_inst)
 Disables an Analog Comparator that was previously enabled. More...
 
static void ac_enable_events (struct ac_module *const module_inst, struct ac_events *const events)
 Enables an Analog Comparator event input or output. More...
 
static void ac_disable_events (struct ac_module *const module_inst, struct ac_events *const events)
 Disables an Analog Comparator event input or output. More...
 
Channel Configuration and Initialization
static void ac_chan_get_config_defaults (struct ac_chan_config *const config)
 Initializes all members of an Analog Comparator channel configuration structure to safe defaults. More...
 
enum status_code ac_chan_set_config (struct ac_module *const module_inst, const enum ac_chan_channel channel, struct ac_chan_config *const config)
 Writes an Analog Comparator channel configuration to the hardware module. More...
 
static void ac_chan_enable (struct ac_module *const module_inst, const enum ac_chan_channel channel)
 Enables an Analog Comparator channel that was previously configured. More...
 
static void ac_chan_disable (struct ac_module *const module_inst, const enum ac_chan_channel channel)
 Disables an Analog Comparator channel that was previously enabled. More...
 
Channel Control
static void ac_chan_trigger_single_shot (struct ac_module *const module_inst, const enum ac_chan_channel channel)
 Triggers a comparison on a comparator that is configured in single shot mode. More...
 
static bool ac_chan_is_ready (struct ac_module *const module_inst, const enum ac_chan_channel channel)
 Determines if a given comparator channel is ready for comparisons. More...
 
static uint8_t ac_chan_get_status (struct ac_module *const module_inst, const enum ac_chan_channel channel)
 Determines the output state of a comparator channel. More...
 
static void ac_chan_clear_status (struct ac_module *const module_inst, const enum ac_chan_channel channel)
 Clears an interrupt status flag. More...
 
Window Mode Configuration and Initialization
static void ac_win_get_config_defaults (struct ac_win_config *const config)
 Initializes an Analog Comparator window configuration structure to defaults. More...
 
enum status_code ac_win_set_config (struct ac_module *const module_inst, enum ac_win_channel const win_channel, struct ac_win_config *const config)
 Function used to setup interrupt selection of a window. More...
 
enum status_code ac_win_enable (struct ac_module *const module_inst, const enum ac_win_channel win_channel)
 Enables an Analog Comparator window channel that was previously configured. More...
 
void ac_win_disable (struct ac_module *const module_inst, const enum ac_win_channel win_channel)
 Disables an Analog Comparator window channel that was previously enabled. More...
 
Window Mode Control
static bool ac_win_is_ready (struct ac_module *const module_inst, const enum ac_win_channel win_channel)
 Determines if a given Window Comparator is ready for comparisons. More...
 
uint8_t ac_win_get_status (struct ac_module *const module_inst, const enum ac_win_channel win_channel)
 Determines the state of a specified Window Comparator. More...
 
static void ac_win_clear_status (struct ac_module *const module_inst, const enum ac_win_channel win_channel)
 Clears an interrupt status flag. More...