mbed library sources. Supersedes mbed-src.

Fork of mbed-dev by mbed official

Committer:
mbed_official
Date:
Mon Nov 09 13:30:11 2015 +0000
Revision:
18:da299f395b9e
Synchronized with git revision f605825f66bb2e462ff7dbc5fb4ed2dbe979d1c3

Full URL: https://github.com/mbedmicro/mbed/commit/f605825f66bb2e462ff7dbc5fb4ed2dbe979d1c3/

Added support for SAML21

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mbed_official 18:da299f395b9e 1 /**
mbed_official 18:da299f395b9e 2 * \file
mbed_official 18:da299f395b9e 3 *
mbed_official 18:da299f395b9e 4 * \brief SAM ADC functionality
mbed_official 18:da299f395b9e 5 *
mbed_official 18:da299f395b9e 6 * Copyright (C) 2014-2015 Atmel Corporation. All rights reserved.
mbed_official 18:da299f395b9e 7 *
mbed_official 18:da299f395b9e 8 * \asf_license_start
mbed_official 18:da299f395b9e 9 *
mbed_official 18:da299f395b9e 10 * \page License
mbed_official 18:da299f395b9e 11 *
mbed_official 18:da299f395b9e 12 * Redistribution and use in source and binary forms, with or without
mbed_official 18:da299f395b9e 13 * modification, are permitted provided that the following conditions are met:
mbed_official 18:da299f395b9e 14 *
mbed_official 18:da299f395b9e 15 * 1. Redistributions of source code must retain the above copyright notice,
mbed_official 18:da299f395b9e 16 * this list of conditions and the following disclaimer.
mbed_official 18:da299f395b9e 17 *
mbed_official 18:da299f395b9e 18 * 2. Redistributions in binary form must reproduce the above copyright notice,
mbed_official 18:da299f395b9e 19 * this list of conditions and the following disclaimer in the documentation
mbed_official 18:da299f395b9e 20 * and/or other materials provided with the distribution.
mbed_official 18:da299f395b9e 21 *
mbed_official 18:da299f395b9e 22 * 3. The name of Atmel may not be used to endorse or promote products derived
mbed_official 18:da299f395b9e 23 * from this software without specific prior written permission.
mbed_official 18:da299f395b9e 24 *
mbed_official 18:da299f395b9e 25 * 4. This software may only be redistributed and used in connection with an
mbed_official 18:da299f395b9e 26 * Atmel microcontroller product.
mbed_official 18:da299f395b9e 27 *
mbed_official 18:da299f395b9e 28 * THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR IMPLIED
mbed_official 18:da299f395b9e 29 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
mbed_official 18:da299f395b9e 30 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
mbed_official 18:da299f395b9e 31 * EXPRESSLY AND SPECIFICALLY DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR
mbed_official 18:da299f395b9e 32 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
mbed_official 18:da299f395b9e 33 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
mbed_official 18:da299f395b9e 34 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
mbed_official 18:da299f395b9e 35 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
mbed_official 18:da299f395b9e 36 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
mbed_official 18:da299f395b9e 37 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
mbed_official 18:da299f395b9e 38 * POSSIBILITY OF SUCH DAMAGE.
mbed_official 18:da299f395b9e 39 *
mbed_official 18:da299f395b9e 40 * \asf_license_stop
mbed_official 18:da299f395b9e 41 *
mbed_official 18:da299f395b9e 42 */
mbed_official 18:da299f395b9e 43 /*
mbed_official 18:da299f395b9e 44 * Support and FAQ: visit <a href="http://www.atmel.com/design-support/">Atmel Support</a>
mbed_official 18:da299f395b9e 45 */
mbed_official 18:da299f395b9e 46 #ifndef ADC_FEATURE_H_INCLUDED
mbed_official 18:da299f395b9e 47 #define ADC_FEATURE_H_INCLUDED
mbed_official 18:da299f395b9e 48
mbed_official 18:da299f395b9e 49 /**
mbed_official 18:da299f395b9e 50 * \addtogroup asfdoc_sam0_adc_group
mbed_official 18:da299f395b9e 51 * @{
mbed_official 18:da299f395b9e 52 */
mbed_official 18:da299f395b9e 53
mbed_official 18:da299f395b9e 54 #ifdef __cplusplus
mbed_official 18:da299f395b9e 55 extern "C" {
mbed_official 18:da299f395b9e 56 #endif
mbed_official 18:da299f395b9e 57
mbed_official 18:da299f395b9e 58 /*@{*/
mbed_official 18:da299f395b9e 59 #if (SAMC20) || (SAMC21) || defined(__DOXYGEN__)
mbed_official 18:da299f395b9e 60 /** Output Driver Strength Selection feature support. */
mbed_official 18:da299f395b9e 61 # define FEATURE_ADC_SUPPORT_MASTER_SLAVE
mbed_official 18:da299f395b9e 62 #endif
mbed_official 18:da299f395b9e 63 /*@}*/
mbed_official 18:da299f395b9e 64
mbed_official 18:da299f395b9e 65 #if ADC_CALLBACK_MODE == true
mbed_official 18:da299f395b9e 66 # include <system_interrupt.h>
mbed_official 18:da299f395b9e 67
mbed_official 18:da299f395b9e 68 #if !defined(__DOXYGEN__)
mbed_official 18:da299f395b9e 69 extern struct adc_module *_adc_instances[ADC_INST_NUM];
mbed_official 18:da299f395b9e 70 #endif
mbed_official 18:da299f395b9e 71
mbed_official 18:da299f395b9e 72 /** Forward definition of the device instance. */
mbed_official 18:da299f395b9e 73 struct adc_module;
mbed_official 18:da299f395b9e 74
mbed_official 18:da299f395b9e 75 /** Type of the callback functions. */
mbed_official 18:da299f395b9e 76 typedef void (*adc_callback_t)(struct adc_module *const module);
mbed_official 18:da299f395b9e 77
mbed_official 18:da299f395b9e 78 /**
mbed_official 18:da299f395b9e 79 * \brief ADC callback enum.
mbed_official 18:da299f395b9e 80 *
mbed_official 18:da299f395b9e 81 * Callback types for ADC callback driver.
mbed_official 18:da299f395b9e 82 *
mbed_official 18:da299f395b9e 83 */
mbed_official 18:da299f395b9e 84 enum adc_callback {
mbed_official 18:da299f395b9e 85 /** Callback for buffer received */
mbed_official 18:da299f395b9e 86 ADC_CALLBACK_READ_BUFFER,
mbed_official 18:da299f395b9e 87 /** Callback when window is hit */
mbed_official 18:da299f395b9e 88 ADC_CALLBACK_WINDOW,
mbed_official 18:da299f395b9e 89 /** Callback for error */
mbed_official 18:da299f395b9e 90 ADC_CALLBACK_ERROR,
mbed_official 18:da299f395b9e 91 # if !defined(__DOXYGEN__)
mbed_official 18:da299f395b9e 92 /** Number of available callbacks */
mbed_official 18:da299f395b9e 93 ADC_CALLBACK_N,
mbed_official 18:da299f395b9e 94 # endif
mbed_official 18:da299f395b9e 95 };
mbed_official 18:da299f395b9e 96
mbed_official 18:da299f395b9e 97 #endif
mbed_official 18:da299f395b9e 98
mbed_official 18:da299f395b9e 99 /**
mbed_official 18:da299f395b9e 100 * \brief ADC reference voltage enum.
mbed_official 18:da299f395b9e 101 *
mbed_official 18:da299f395b9e 102 * Enum for the possible reference voltages for the ADC.
mbed_official 18:da299f395b9e 103 *
mbed_official 18:da299f395b9e 104 */
mbed_official 18:da299f395b9e 105 enum adc_reference {
mbed_official 18:da299f395b9e 106 /** Internal Bandgap Reference */
mbed_official 18:da299f395b9e 107 ADC_REFERENCE_INTREF = ADC_REFCTRL_REFSEL_INTREF,
mbed_official 18:da299f395b9e 108 /** 1/1.48V<SUB>CC</SUB> reference */
mbed_official 18:da299f395b9e 109 ADC_REFERENCE_INTVCC0 = ADC_REFCTRL_REFSEL_INTVCC0,
mbed_official 18:da299f395b9e 110 /** 1/2V<SUB>CC</SUB> (only for internal V<SUB>CC</SUB> > 2.1V) */
mbed_official 18:da299f395b9e 111 ADC_REFERENCE_INTVCC1 = ADC_REFCTRL_REFSEL_INTVCC1,
mbed_official 18:da299f395b9e 112 /** External reference A */
mbed_official 18:da299f395b9e 113 ADC_REFERENCE_AREFA = ADC_REFCTRL_REFSEL_AREFA,
mbed_official 18:da299f395b9e 114 #if (SAML21)
mbed_official 18:da299f395b9e 115 /** External reference B. */
mbed_official 18:da299f395b9e 116 ADC_REFERENCE_AREFB = ADC_REFCTRL_REFSEL_AREFB,
mbed_official 18:da299f395b9e 117 #endif
mbed_official 18:da299f395b9e 118 #if (SAMC20) || (SAMC21)
mbed_official 18:da299f395b9e 119 /** DAC. */
mbed_official 18:da299f395b9e 120 ADC_REFERENCE_DAC = ADC_REFCTRL_REFSEL_DAC,
mbed_official 18:da299f395b9e 121 #endif
mbed_official 18:da299f395b9e 122 /** VDDANA. */
mbed_official 18:da299f395b9e 123 ADC_REFERENCE_INTVCC2 = ADC_REFCTRL_REFSEL_INTVCC2,
mbed_official 18:da299f395b9e 124 };
mbed_official 18:da299f395b9e 125
mbed_official 18:da299f395b9e 126 /**
mbed_official 18:da299f395b9e 127 * \brief ADC clock prescaler enum.
mbed_official 18:da299f395b9e 128 *
mbed_official 18:da299f395b9e 129 * Enum for the possible clock prescaler values for the ADC.
mbed_official 18:da299f395b9e 130 *
mbed_official 18:da299f395b9e 131 */
mbed_official 18:da299f395b9e 132 enum adc_clock_prescaler {
mbed_official 18:da299f395b9e 133 /** ADC clock division factor 2 */
mbed_official 18:da299f395b9e 134 ADC_CLOCK_PRESCALER_DIV2 = ADC_CTRLB_PRESCALER_DIV2,
mbed_official 18:da299f395b9e 135 /** ADC clock division factor 4 */
mbed_official 18:da299f395b9e 136 ADC_CLOCK_PRESCALER_DIV4 = ADC_CTRLB_PRESCALER_DIV4,
mbed_official 18:da299f395b9e 137 /** ADC clock division factor 8 */
mbed_official 18:da299f395b9e 138 ADC_CLOCK_PRESCALER_DIV8 = ADC_CTRLB_PRESCALER_DIV8,
mbed_official 18:da299f395b9e 139 /** ADC clock division factor 16 */
mbed_official 18:da299f395b9e 140 ADC_CLOCK_PRESCALER_DIV16 = ADC_CTRLB_PRESCALER_DIV16,
mbed_official 18:da299f395b9e 141 /** ADC clock division factor 32 */
mbed_official 18:da299f395b9e 142 ADC_CLOCK_PRESCALER_DIV32 = ADC_CTRLB_PRESCALER_DIV32,
mbed_official 18:da299f395b9e 143 /** ADC clock division factor 64 */
mbed_official 18:da299f395b9e 144 ADC_CLOCK_PRESCALER_DIV64 = ADC_CTRLB_PRESCALER_DIV64,
mbed_official 18:da299f395b9e 145 /** ADC clock division factor 128 */
mbed_official 18:da299f395b9e 146 ADC_CLOCK_PRESCALER_DIV128 = ADC_CTRLB_PRESCALER_DIV128,
mbed_official 18:da299f395b9e 147 /** ADC clock division factor 256 */
mbed_official 18:da299f395b9e 148 ADC_CLOCK_PRESCALER_DIV256 = ADC_CTRLB_PRESCALER_DIV256,
mbed_official 18:da299f395b9e 149 };
mbed_official 18:da299f395b9e 150
mbed_official 18:da299f395b9e 151 /**
mbed_official 18:da299f395b9e 152 * \brief ADC resolution enum.
mbed_official 18:da299f395b9e 153 *
mbed_official 18:da299f395b9e 154 * Enum for the possible resolution values for the ADC.
mbed_official 18:da299f395b9e 155 *
mbed_official 18:da299f395b9e 156 */
mbed_official 18:da299f395b9e 157 enum adc_resolution {
mbed_official 18:da299f395b9e 158 /** ADC 12-bit resolution */
mbed_official 18:da299f395b9e 159 ADC_RESOLUTION_12BIT = ADC_CTRLC_RESSEL_12BIT,
mbed_official 18:da299f395b9e 160 /** ADC 16-bit resolution using oversampling and decimation */
mbed_official 18:da299f395b9e 161 ADC_RESOLUTION_16BIT = ADC_CTRLC_RESSEL_16BIT,
mbed_official 18:da299f395b9e 162 /** ADC 10-bit resolution */
mbed_official 18:da299f395b9e 163 ADC_RESOLUTION_10BIT = ADC_CTRLC_RESSEL_10BIT,
mbed_official 18:da299f395b9e 164 /** ADC 8-bit resolution */
mbed_official 18:da299f395b9e 165 ADC_RESOLUTION_8BIT = ADC_CTRLC_RESSEL_8BIT,
mbed_official 18:da299f395b9e 166 /** ADC 13-bit resolution using oversampling and decimation */
mbed_official 18:da299f395b9e 167 ADC_RESOLUTION_13BIT,
mbed_official 18:da299f395b9e 168 /** ADC 14-bit resolution using oversampling and decimation */
mbed_official 18:da299f395b9e 169 ADC_RESOLUTION_14BIT,
mbed_official 18:da299f395b9e 170 /** ADC 15-bit resolution using oversampling and decimation */
mbed_official 18:da299f395b9e 171 ADC_RESOLUTION_15BIT,
mbed_official 18:da299f395b9e 172 /** ADC 16-bit result register for use with averaging. When using this mode
mbed_official 18:da299f395b9e 173 * the ADC result register will be set to 16-bit wide, and the number of
mbed_official 18:da299f395b9e 174 * samples to accumulate and the division factor is configured by the
mbed_official 18:da299f395b9e 175 * \ref adc_config.accumulate_samples and \ref adc_config.divide_result
mbed_official 18:da299f395b9e 176 * members in the configuration struct.
mbed_official 18:da299f395b9e 177 */
mbed_official 18:da299f395b9e 178 ADC_RESOLUTION_CUSTOM,
mbed_official 18:da299f395b9e 179 };
mbed_official 18:da299f395b9e 180
mbed_official 18:da299f395b9e 181 /**
mbed_official 18:da299f395b9e 182 * \brief ADC window monitor mode enum.
mbed_official 18:da299f395b9e 183 *
mbed_official 18:da299f395b9e 184 * Enum for the possible window monitor modes for the ADC.
mbed_official 18:da299f395b9e 185 *
mbed_official 18:da299f395b9e 186 */
mbed_official 18:da299f395b9e 187 enum adc_window_mode {
mbed_official 18:da299f395b9e 188 /** No window mode */
mbed_official 18:da299f395b9e 189 ADC_WINDOW_MODE_DISABLE = ADC_CTRLC_WINMODE_DISABLE,
mbed_official 18:da299f395b9e 190 /** RESULT > WINLT */
mbed_official 18:da299f395b9e 191 ADC_WINDOW_MODE_ABOVE_LOWER = ADC_CTRLC_WINMODE_MODE1,
mbed_official 18:da299f395b9e 192 /** RESULT < WINUT */
mbed_official 18:da299f395b9e 193 ADC_WINDOW_MODE_BELOW_UPPER = ADC_CTRLC_WINMODE_MODE2,
mbed_official 18:da299f395b9e 194 /** WINLT < RESULT < WINUT */
mbed_official 18:da299f395b9e 195 ADC_WINDOW_MODE_BETWEEN = ADC_CTRLC_WINMODE_MODE3,
mbed_official 18:da299f395b9e 196 /** !(WINLT < RESULT < WINUT) */
mbed_official 18:da299f395b9e 197 ADC_WINDOW_MODE_BETWEEN_INVERTED = ADC_CTRLC_WINMODE_MODE4,
mbed_official 18:da299f395b9e 198 };
mbed_official 18:da299f395b9e 199
mbed_official 18:da299f395b9e 200 /**
mbed_official 18:da299f395b9e 201 * \brief ADC event action enum.
mbed_official 18:da299f395b9e 202 *
mbed_official 18:da299f395b9e 203 * Enum for the possible actions to take on an incoming event.
mbed_official 18:da299f395b9e 204 *
mbed_official 18:da299f395b9e 205 */
mbed_official 18:da299f395b9e 206 enum adc_event_action {
mbed_official 18:da299f395b9e 207 /** Event action disabled */
mbed_official 18:da299f395b9e 208 ADC_EVENT_ACTION_DISABLED = 0,
mbed_official 18:da299f395b9e 209 /** Flush ADC and start conversion */
mbed_official 18:da299f395b9e 210 ADC_EVENT_ACTION_FLUSH_START_CONV = ADC_EVCTRL_FLUSHEI,
mbed_official 18:da299f395b9e 211 /** Start conversion */
mbed_official 18:da299f395b9e 212 ADC_EVENT_ACTION_START_CONV = ADC_EVCTRL_STARTEI,
mbed_official 18:da299f395b9e 213 };
mbed_official 18:da299f395b9e 214
mbed_official 18:da299f395b9e 215 /**
mbed_official 18:da299f395b9e 216 * \brief ADC positive MUX input selection enum.
mbed_official 18:da299f395b9e 217 *
mbed_official 18:da299f395b9e 218 * Enum for the possible positive MUX input selections for the ADC.
mbed_official 18:da299f395b9e 219 *
mbed_official 18:da299f395b9e 220 */
mbed_official 18:da299f395b9e 221 enum adc_positive_input {
mbed_official 18:da299f395b9e 222 /** ADC0 pin */
mbed_official 18:da299f395b9e 223 ADC_POSITIVE_INPUT_PIN0 = ADC_INPUTCTRL_MUXPOS_AIN0,
mbed_official 18:da299f395b9e 224 /** ADC1 pin */
mbed_official 18:da299f395b9e 225 ADC_POSITIVE_INPUT_PIN1 = ADC_INPUTCTRL_MUXPOS_AIN1,
mbed_official 18:da299f395b9e 226 /** ADC2 pin */
mbed_official 18:da299f395b9e 227 ADC_POSITIVE_INPUT_PIN2 = ADC_INPUTCTRL_MUXPOS_AIN2,
mbed_official 18:da299f395b9e 228 /** ADC3 pin */
mbed_official 18:da299f395b9e 229 ADC_POSITIVE_INPUT_PIN3 = ADC_INPUTCTRL_MUXPOS_AIN3,
mbed_official 18:da299f395b9e 230 /** ADC4 pin */
mbed_official 18:da299f395b9e 231 ADC_POSITIVE_INPUT_PIN4 = ADC_INPUTCTRL_MUXPOS_AIN4,
mbed_official 18:da299f395b9e 232 /** ADC5 pin */
mbed_official 18:da299f395b9e 233 ADC_POSITIVE_INPUT_PIN5 = ADC_INPUTCTRL_MUXPOS_AIN5,
mbed_official 18:da299f395b9e 234 /** ADC6 pin */
mbed_official 18:da299f395b9e 235 ADC_POSITIVE_INPUT_PIN6 = ADC_INPUTCTRL_MUXPOS_AIN6,
mbed_official 18:da299f395b9e 236 /** ADC7 pin */
mbed_official 18:da299f395b9e 237 ADC_POSITIVE_INPUT_PIN7 = ADC_INPUTCTRL_MUXPOS_AIN7,
mbed_official 18:da299f395b9e 238 /** ADC8 pin */
mbed_official 18:da299f395b9e 239 ADC_POSITIVE_INPUT_PIN8 = ADC_INPUTCTRL_MUXPOS_AIN8,
mbed_official 18:da299f395b9e 240 /** ADC9 pin */
mbed_official 18:da299f395b9e 241 ADC_POSITIVE_INPUT_PIN9 = ADC_INPUTCTRL_MUXPOS_AIN9,
mbed_official 18:da299f395b9e 242 /** ADC10 pin */
mbed_official 18:da299f395b9e 243 ADC_POSITIVE_INPUT_PIN10 = ADC_INPUTCTRL_MUXPOS_AIN10,
mbed_official 18:da299f395b9e 244 /** ADC11 pin */
mbed_official 18:da299f395b9e 245 ADC_POSITIVE_INPUT_PIN11 = ADC_INPUTCTRL_MUXPOS_AIN11,
mbed_official 18:da299f395b9e 246 #if !(SAMC20) && !(SAMC21)
mbed_official 18:da299f395b9e 247 /** ADC12 pin. */
mbed_official 18:da299f395b9e 248 ADC_POSITIVE_INPUT_PIN12 = ADC_INPUTCTRL_MUXPOS_AIN12,
mbed_official 18:da299f395b9e 249 /** ADC13 pin */
mbed_official 18:da299f395b9e 250 ADC_POSITIVE_INPUT_PIN13 = ADC_INPUTCTRL_MUXPOS_AIN13,
mbed_official 18:da299f395b9e 251 /** ADC14 pin */
mbed_official 18:da299f395b9e 252 ADC_POSITIVE_INPUT_PIN14 = ADC_INPUTCTRL_MUXPOS_AIN14,
mbed_official 18:da299f395b9e 253 /** ADC15 pin */
mbed_official 18:da299f395b9e 254 ADC_POSITIVE_INPUT_PIN15 = ADC_INPUTCTRL_MUXPOS_AIN15,
mbed_official 18:da299f395b9e 255 /** ADC16 pin */
mbed_official 18:da299f395b9e 256 ADC_POSITIVE_INPUT_PIN16 = ADC_INPUTCTRL_MUXPOS_AIN16,
mbed_official 18:da299f395b9e 257 /** ADC17 pin */
mbed_official 18:da299f395b9e 258 ADC_POSITIVE_INPUT_PIN17 = ADC_INPUTCTRL_MUXPOS_AIN17,
mbed_official 18:da299f395b9e 259 /** ADC18 pin */
mbed_official 18:da299f395b9e 260 ADC_POSITIVE_INPUT_PIN18 = ADC_INPUTCTRL_MUXPOS_AIN18,
mbed_official 18:da299f395b9e 261 /** ADC19 pin */
mbed_official 18:da299f395b9e 262 ADC_POSITIVE_INPUT_PIN19 = ADC_INPUTCTRL_MUXPOS_AIN19,
mbed_official 18:da299f395b9e 263 /** ADC20 pin */
mbed_official 18:da299f395b9e 264 ADC_POSITIVE_INPUT_PIN20 = ADC_INPUTCTRL_MUXPOS_AIN20,
mbed_official 18:da299f395b9e 265 /** ADC21 pin */
mbed_official 18:da299f395b9e 266 ADC_POSITIVE_INPUT_PIN21 = ADC_INPUTCTRL_MUXPOS_AIN21,
mbed_official 18:da299f395b9e 267 /** ADC22 pin */
mbed_official 18:da299f395b9e 268 ADC_POSITIVE_INPUT_PIN22 = ADC_INPUTCTRL_MUXPOS_AIN22,
mbed_official 18:da299f395b9e 269 /** ADC23 pin */
mbed_official 18:da299f395b9e 270 ADC_POSITIVE_INPUT_PIN23 = ADC_INPUTCTRL_MUXPOS_AIN23,
mbed_official 18:da299f395b9e 271 /** Temperature reference */
mbed_official 18:da299f395b9e 272 ADC_POSITIVE_INPUT_TEMP = ADC_INPUTCTRL_MUXPOS_TEMP,
mbed_official 18:da299f395b9e 273 #endif
mbed_official 18:da299f395b9e 274 /** Bandgap voltage. */
mbed_official 18:da299f395b9e 275 ADC_POSITIVE_INPUT_BANDGAP = ADC_INPUTCTRL_MUXPOS_BANDGAP,
mbed_official 18:da299f395b9e 276 /** 1/4 scaled core supply */
mbed_official 18:da299f395b9e 277 ADC_POSITIVE_INPUT_SCALEDCOREVCC = ADC_INPUTCTRL_MUXPOS_SCALEDCOREVCC,
mbed_official 18:da299f395b9e 278 /** 1/4 scaled I/O supply */
mbed_official 18:da299f395b9e 279 ADC_POSITIVE_INPUT_SCALEDIOVCC = ADC_INPUTCTRL_MUXPOS_SCALEDIOVCC,
mbed_official 18:da299f395b9e 280 /** DAC input */
mbed_official 18:da299f395b9e 281 ADC_POSITIVE_INPUT_DAC = ADC_INPUTCTRL_MUXPOS_DAC,
mbed_official 18:da299f395b9e 282 #if !(SAMC20) && !(SAMC21)
mbed_official 18:da299f395b9e 283 /** SCALEDVBAT. */
mbed_official 18:da299f395b9e 284 ADC_POSITIVE_INPUT_SCALEDVBAT = ADC_INPUTCTRL_MUXPOS_SCALEDVBAT,
mbed_official 18:da299f395b9e 285 /** OPAMP01 */
mbed_official 18:da299f395b9e 286 ADC_POSITIVE_INPUT_OPAMP01 = ADC_INPUTCTRL_MUXPOS_OPAMP01,
mbed_official 18:da299f395b9e 287 /** OPAMP02 */
mbed_official 18:da299f395b9e 288 ADC_POSITIVE_INPUT_OPAMP2 = ADC_INPUTCTRL_MUXPOS_OPAMP2,
mbed_official 18:da299f395b9e 289 #endif
mbed_official 18:da299f395b9e 290 };
mbed_official 18:da299f395b9e 291
mbed_official 18:da299f395b9e 292 /**
mbed_official 18:da299f395b9e 293 * \brief ADC negative MUX input selection enum.
mbed_official 18:da299f395b9e 294 *
mbed_official 18:da299f395b9e 295 * Enum for the possible negative MUX input selections for the ADC.
mbed_official 18:da299f395b9e 296 *
mbed_official 18:da299f395b9e 297 */
mbed_official 18:da299f395b9e 298 enum adc_negative_input {
mbed_official 18:da299f395b9e 299 /** ADC0 pin */
mbed_official 18:da299f395b9e 300 ADC_NEGATIVE_INPUT_PIN0 = ADC_INPUTCTRL_MUXNEG_AIN0,
mbed_official 18:da299f395b9e 301 /** ADC1 pin */
mbed_official 18:da299f395b9e 302 ADC_NEGATIVE_INPUT_PIN1 = ADC_INPUTCTRL_MUXNEG_AIN1,
mbed_official 18:da299f395b9e 303 /** ADC2 pin */
mbed_official 18:da299f395b9e 304 ADC_NEGATIVE_INPUT_PIN2 = ADC_INPUTCTRL_MUXNEG_AIN2,
mbed_official 18:da299f395b9e 305 /** ADC3 pin */
mbed_official 18:da299f395b9e 306 ADC_NEGATIVE_INPUT_PIN3 = ADC_INPUTCTRL_MUXNEG_AIN3,
mbed_official 18:da299f395b9e 307 /** ADC4 pin */
mbed_official 18:da299f395b9e 308 ADC_NEGATIVE_INPUT_PIN4 = ADC_INPUTCTRL_MUXNEG_AIN4,
mbed_official 18:da299f395b9e 309 /** ADC5 pin */
mbed_official 18:da299f395b9e 310 ADC_NEGATIVE_INPUT_PIN5 = ADC_INPUTCTRL_MUXNEG_AIN5,
mbed_official 18:da299f395b9e 311 #if !(SAMC20) && !(SAMC21)
mbed_official 18:da299f395b9e 312 /** ADC6 pin. */
mbed_official 18:da299f395b9e 313 ADC_NEGATIVE_INPUT_PIN6 = ADC_INPUTCTRL_MUXNEG_AIN6,
mbed_official 18:da299f395b9e 314 /** ADC7 pin */
mbed_official 18:da299f395b9e 315 ADC_NEGATIVE_INPUT_PIN7 = ADC_INPUTCTRL_MUXNEG_AIN7,
mbed_official 18:da299f395b9e 316 #endif
mbed_official 18:da299f395b9e 317 /** Internal ground. */
mbed_official 18:da299f395b9e 318 ADC_NEGATIVE_INPUT_GND = ADC_INPUTCTRL_MUXNEG(0x18u),
mbed_official 18:da299f395b9e 319 };
mbed_official 18:da299f395b9e 320
mbed_official 18:da299f395b9e 321 /**
mbed_official 18:da299f395b9e 322 * \brief ADC number of accumulated samples enum.
mbed_official 18:da299f395b9e 323 *
mbed_official 18:da299f395b9e 324 * Enum for the possible numbers of ADC samples to accumulate.
mbed_official 18:da299f395b9e 325 * This setting is only used when the \ref ADC_RESOLUTION_CUSTOM
mbed_official 18:da299f395b9e 326 * resolution setting is used.
mbed_official 18:da299f395b9e 327 *
mbed_official 18:da299f395b9e 328 */
mbed_official 18:da299f395b9e 329 enum adc_accumulate_samples {
mbed_official 18:da299f395b9e 330 /** No averaging */
mbed_official 18:da299f395b9e 331 ADC_ACCUMULATE_DISABLE = ADC_AVGCTRL_SAMPLENUM_1,
mbed_official 18:da299f395b9e 332 /** Average 2 samples */
mbed_official 18:da299f395b9e 333 ADC_ACCUMULATE_SAMPLES_2 = ADC_AVGCTRL_SAMPLENUM_2,
mbed_official 18:da299f395b9e 334 /** Average 4 samples */
mbed_official 18:da299f395b9e 335 ADC_ACCUMULATE_SAMPLES_4 = ADC_AVGCTRL_SAMPLENUM_4,
mbed_official 18:da299f395b9e 336 /** Average 8 samples */
mbed_official 18:da299f395b9e 337 ADC_ACCUMULATE_SAMPLES_8 = ADC_AVGCTRL_SAMPLENUM_8,
mbed_official 18:da299f395b9e 338 /** Average 16 samples */
mbed_official 18:da299f395b9e 339 ADC_ACCUMULATE_SAMPLES_16 = ADC_AVGCTRL_SAMPLENUM_16,
mbed_official 18:da299f395b9e 340 /** Average 32 samples */
mbed_official 18:da299f395b9e 341 ADC_ACCUMULATE_SAMPLES_32 = ADC_AVGCTRL_SAMPLENUM_32,
mbed_official 18:da299f395b9e 342 /** Average 64 samples */
mbed_official 18:da299f395b9e 343 ADC_ACCUMULATE_SAMPLES_64 = ADC_AVGCTRL_SAMPLENUM_64,
mbed_official 18:da299f395b9e 344 /** Average 128 samples */
mbed_official 18:da299f395b9e 345 ADC_ACCUMULATE_SAMPLES_128 = ADC_AVGCTRL_SAMPLENUM_128,
mbed_official 18:da299f395b9e 346 /** Average 256 samples */
mbed_official 18:da299f395b9e 347 ADC_ACCUMULATE_SAMPLES_256 = ADC_AVGCTRL_SAMPLENUM_256,
mbed_official 18:da299f395b9e 348 /** Average 512 samples */
mbed_official 18:da299f395b9e 349 ADC_ACCUMULATE_SAMPLES_512 = ADC_AVGCTRL_SAMPLENUM_512,
mbed_official 18:da299f395b9e 350 /** Average 1024 samples */
mbed_official 18:da299f395b9e 351 ADC_ACCUMULATE_SAMPLES_1024 = ADC_AVGCTRL_SAMPLENUM_1024,
mbed_official 18:da299f395b9e 352 };
mbed_official 18:da299f395b9e 353
mbed_official 18:da299f395b9e 354 /**
mbed_official 18:da299f395b9e 355 * \brief ADC possible dividers for the result register.
mbed_official 18:da299f395b9e 356 *
mbed_official 18:da299f395b9e 357 * Enum for the possible division factors to use when accumulating
mbed_official 18:da299f395b9e 358 * multiple samples. To keep the same resolution for the averaged
mbed_official 18:da299f395b9e 359 * result and the actual input value, the division factor must
mbed_official 18:da299f395b9e 360 * be equal to the number of samples accumulated. This setting is only
mbed_official 18:da299f395b9e 361 * used when the \ref ADC_RESOLUTION_CUSTOM resolution setting is used.
mbed_official 18:da299f395b9e 362 */
mbed_official 18:da299f395b9e 363 enum adc_divide_result {
mbed_official 18:da299f395b9e 364 /** Don't divide result register after accumulation */
mbed_official 18:da299f395b9e 365 ADC_DIVIDE_RESULT_DISABLE = 0,
mbed_official 18:da299f395b9e 366 /** Divide result register by 2 after accumulation */
mbed_official 18:da299f395b9e 367 ADC_DIVIDE_RESULT_2 = 1,
mbed_official 18:da299f395b9e 368 /** Divide result register by 4 after accumulation */
mbed_official 18:da299f395b9e 369 ADC_DIVIDE_RESULT_4 = 2,
mbed_official 18:da299f395b9e 370 /** Divide result register by 8 after accumulation */
mbed_official 18:da299f395b9e 371 ADC_DIVIDE_RESULT_8 = 3,
mbed_official 18:da299f395b9e 372 /** Divide result register by 16 after accumulation */
mbed_official 18:da299f395b9e 373 ADC_DIVIDE_RESULT_16 = 4,
mbed_official 18:da299f395b9e 374 /** Divide result register by 32 after accumulation */
mbed_official 18:da299f395b9e 375 ADC_DIVIDE_RESULT_32 = 5,
mbed_official 18:da299f395b9e 376 /** Divide result register by 64 after accumulation */
mbed_official 18:da299f395b9e 377 ADC_DIVIDE_RESULT_64 = 6,
mbed_official 18:da299f395b9e 378 /** Divide result register by 128 after accumulation */
mbed_official 18:da299f395b9e 379 ADC_DIVIDE_RESULT_128 = 7,
mbed_official 18:da299f395b9e 380 };
mbed_official 18:da299f395b9e 381
mbed_official 18:da299f395b9e 382 #if ADC_CALLBACK_MODE == true
mbed_official 18:da299f395b9e 383 /**
mbed_official 18:da299f395b9e 384 * Enum for the possible ADC interrupt flags.
mbed_official 18:da299f395b9e 385 */
mbed_official 18:da299f395b9e 386 enum adc_interrupt_flag {
mbed_official 18:da299f395b9e 387 /** ADC result ready */
mbed_official 18:da299f395b9e 388 ADC_INTERRUPT_RESULT_READY = ADC_INTFLAG_RESRDY,
mbed_official 18:da299f395b9e 389 /** Window monitor match */
mbed_official 18:da299f395b9e 390 ADC_INTERRUPT_WINDOW = ADC_INTFLAG_WINMON,
mbed_official 18:da299f395b9e 391 /** ADC result overwritten before read */
mbed_official 18:da299f395b9e 392 ADC_INTERRUPT_OVERRUN = ADC_INTFLAG_OVERRUN,
mbed_official 18:da299f395b9e 393 };
mbed_official 18:da299f395b9e 394 #endif
mbed_official 18:da299f395b9e 395
mbed_official 18:da299f395b9e 396 /**
mbed_official 18:da299f395b9e 397 * \brief ADC oversampling and decimation enum.
mbed_official 18:da299f395b9e 398 *
mbed_official 18:da299f395b9e 399 * Enum for the possible numbers of bits resolution can be increased by when
mbed_official 18:da299f395b9e 400 * using oversampling and decimation.
mbed_official 18:da299f395b9e 401 *
mbed_official 18:da299f395b9e 402 */
mbed_official 18:da299f395b9e 403 enum adc_oversampling_and_decimation {
mbed_official 18:da299f395b9e 404 /** Don't use oversampling and decimation mode */
mbed_official 18:da299f395b9e 405 ADC_OVERSAMPLING_AND_DECIMATION_DISABLE = 0,
mbed_official 18:da299f395b9e 406 /** 1 bit resolution increase */
mbed_official 18:da299f395b9e 407 ADC_OVERSAMPLING_AND_DECIMATION_1BIT,
mbed_official 18:da299f395b9e 408 /** 2 bits resolution increase */
mbed_official 18:da299f395b9e 409 ADC_OVERSAMPLING_AND_DECIMATION_2BIT,
mbed_official 18:da299f395b9e 410 /** 3 bits resolution increase */
mbed_official 18:da299f395b9e 411 ADC_OVERSAMPLING_AND_DECIMATION_3BIT,
mbed_official 18:da299f395b9e 412 /** 4 bits resolution increase */
mbed_official 18:da299f395b9e 413 ADC_OVERSAMPLING_AND_DECIMATION_4BIT
mbed_official 18:da299f395b9e 414 };
mbed_official 18:da299f395b9e 415
mbed_official 18:da299f395b9e 416 #ifdef FEATURE_ADC_SUPPORT_MASTER_SLAVE
mbed_official 18:da299f395b9e 417 /**
mbed_official 18:da299f395b9e 418 * Enum for the trigger selection in dual mode.
mbed_official 18:da299f395b9e 419 */
mbed_official 18:da299f395b9e 420 enum adc_dual_mode_trigger_selection {
mbed_official 18:da299f395b9e 421 /** Start event or software trigger will start a conversion on both ADCs. */
mbed_official 18:da299f395b9e 422 ADC_DUAL_MODE_BOTH = ADC_CTRLC_DUALSEL_BOTH,
mbed_official 18:da299f395b9e 423 /** START event or software trigger will alternatingly start a conversion on ADC0 and ADC1. */
mbed_official 18:da299f395b9e 424 ADC_DUAL_MODE_INTERLEAVE = ADC_CTRLC_DUALSEL_INTERLEAVE,
mbed_official 18:da299f395b9e 425 };
mbed_official 18:da299f395b9e 426 #endif
mbed_official 18:da299f395b9e 427
mbed_official 18:da299f395b9e 428 /**
mbed_official 18:da299f395b9e 429 * \brief Window monitor configuration structure.
mbed_official 18:da299f395b9e 430 *
mbed_official 18:da299f395b9e 431 * Window monitor configuration structure.
mbed_official 18:da299f395b9e 432 */
mbed_official 18:da299f395b9e 433 struct adc_window_config {
mbed_official 18:da299f395b9e 434 /** Selected window mode */
mbed_official 18:da299f395b9e 435 enum adc_window_mode window_mode;
mbed_official 18:da299f395b9e 436 /** Lower window value */
mbed_official 18:da299f395b9e 437 int32_t window_lower_value;
mbed_official 18:da299f395b9e 438 /** Upper window value */
mbed_official 18:da299f395b9e 439 int32_t window_upper_value;
mbed_official 18:da299f395b9e 440 };
mbed_official 18:da299f395b9e 441
mbed_official 18:da299f395b9e 442 /**
mbed_official 18:da299f395b9e 443 * \brief ADC event enable/disable structure.
mbed_official 18:da299f395b9e 444 *
mbed_official 18:da299f395b9e 445 * Event flags for the ADC module. This is used to enable and
mbed_official 18:da299f395b9e 446 * disable events via \ref adc_enable_events() and \ref adc_disable_events().
mbed_official 18:da299f395b9e 447 */
mbed_official 18:da299f395b9e 448 struct adc_events {
mbed_official 18:da299f395b9e 449 /** Enable event generation on conversion done */
mbed_official 18:da299f395b9e 450 bool generate_event_on_conversion_done;
mbed_official 18:da299f395b9e 451 /** Enable event generation on window monitor */
mbed_official 18:da299f395b9e 452 bool generate_event_on_window_monitor;
mbed_official 18:da299f395b9e 453 };
mbed_official 18:da299f395b9e 454
mbed_official 18:da299f395b9e 455 /**
mbed_official 18:da299f395b9e 456 * \brief Gain and offset correction configuration structure.
mbed_official 18:da299f395b9e 457 *
mbed_official 18:da299f395b9e 458 * Gain and offset correction configuration structure.
mbed_official 18:da299f395b9e 459 * Part of the \ref adc_config struct and will be initialized by
mbed_official 18:da299f395b9e 460 * \ref adc_get_config_defaults.
mbed_official 18:da299f395b9e 461 */
mbed_official 18:da299f395b9e 462 struct adc_correction_config {
mbed_official 18:da299f395b9e 463 /**
mbed_official 18:da299f395b9e 464 * Enables correction for gain and offset based on values of gain_correction and
mbed_official 18:da299f395b9e 465 * offset_correction if set to true
mbed_official 18:da299f395b9e 466 */
mbed_official 18:da299f395b9e 467 bool correction_enable;
mbed_official 18:da299f395b9e 468 /**
mbed_official 18:da299f395b9e 469 * This value defines how the ADC conversion result is compensated for gain
mbed_official 18:da299f395b9e 470 * error before written to the result register. This is a fractional value,
mbed_official 18:da299f395b9e 471 * 1-bit integer plus an 11-bit fraction, therefore
mbed_official 18:da299f395b9e 472 * 1/2 ¡Ü gain_correction < 2. Valid \c gain_correction values ranges from
mbed_official 18:da299f395b9e 473 * \c 0b010000000000 to \c 0b111111111111.
mbed_official 18:da299f395b9e 474 */
mbed_official 18:da299f395b9e 475 uint16_t gain_correction;
mbed_official 18:da299f395b9e 476 /**
mbed_official 18:da299f395b9e 477 * This value defines how the ADC conversion result is compensated for
mbed_official 18:da299f395b9e 478 * offset error before written to the result register. This is a 12-bit
mbed_official 18:da299f395b9e 479 * value in two's complement format.
mbed_official 18:da299f395b9e 480 */
mbed_official 18:da299f395b9e 481 int16_t offset_correction;
mbed_official 18:da299f395b9e 482 };
mbed_official 18:da299f395b9e 483
mbed_official 18:da299f395b9e 484 /**
mbed_official 18:da299f395b9e 485 * \brief ADC configuration structure.
mbed_official 18:da299f395b9e 486 *
mbed_official 18:da299f395b9e 487 * Configuration structure for an ADC instance. This structure should be
mbed_official 18:da299f395b9e 488 * initialized by the \ref adc_get_config_defaults()
mbed_official 18:da299f395b9e 489 * function before being modified by the user application.
mbed_official 18:da299f395b9e 490 */
mbed_official 18:da299f395b9e 491 struct adc_config {
mbed_official 18:da299f395b9e 492 /** GCLK generator used to clock the peripheral */
mbed_official 18:da299f395b9e 493 enum gclk_generator clock_source;
mbed_official 18:da299f395b9e 494 /** Voltage reference */
mbed_official 18:da299f395b9e 495 enum adc_reference reference;
mbed_official 18:da299f395b9e 496 /** Clock prescaler */
mbed_official 18:da299f395b9e 497 enum adc_clock_prescaler clock_prescaler;
mbed_official 18:da299f395b9e 498 /** Result resolution */
mbed_official 18:da299f395b9e 499 enum adc_resolution resolution;
mbed_official 18:da299f395b9e 500 /** Positive MUX input */
mbed_official 18:da299f395b9e 501 enum adc_positive_input positive_input;
mbed_official 18:da299f395b9e 502 /** Negative MUX input */
mbed_official 18:da299f395b9e 503 enum adc_negative_input negative_input;
mbed_official 18:da299f395b9e 504 /** Number of ADC samples to accumulate when using the
mbed_official 18:da299f395b9e 505 * \c ADC_RESOLUTION_CUSTOM mode
mbed_official 18:da299f395b9e 506 */
mbed_official 18:da299f395b9e 507 enum adc_accumulate_samples accumulate_samples;
mbed_official 18:da299f395b9e 508 /** Division ration when using the ADC_RESOLUTION_CUSTOM mode */
mbed_official 18:da299f395b9e 509 enum adc_divide_result divide_result;
mbed_official 18:da299f395b9e 510 /** Left adjusted result */
mbed_official 18:da299f395b9e 511 bool left_adjust;
mbed_official 18:da299f395b9e 512 /** Enables differential mode if true */
mbed_official 18:da299f395b9e 513 bool differential_mode;
mbed_official 18:da299f395b9e 514 /** Enables free running mode if true */
mbed_official 18:da299f395b9e 515 bool freerunning;
mbed_official 18:da299f395b9e 516 /** ADC run in standby control */
mbed_official 18:da299f395b9e 517 bool run_in_standby;
mbed_official 18:da299f395b9e 518 /** ADC On demand control */
mbed_official 18:da299f395b9e 519 bool on_demand;
mbed_official 18:da299f395b9e 520 /**
mbed_official 18:da299f395b9e 521 * Enables sampling period offset compensation if true
mbed_official 18:da299f395b9e 522 */
mbed_official 18:da299f395b9e 523 bool sampling_time_compensation_enable;
mbed_official 18:da299f395b9e 524 /**
mbed_official 18:da299f395b9e 525 * Positive input enabled mask for conversion sequence.
mbed_official 18:da299f395b9e 526 * The sequence start from the lowest input, and go to the next enabled input
mbed_official 18:da299f395b9e 527 * automatically when the conversion is done. If no bits are set the
mbed_official 18:da299f395b9e 528 * sequence is disabled.
mbed_official 18:da299f395b9e 529 */
mbed_official 18:da299f395b9e 530 uint32_t positive_input_sequence_mask_enable;
mbed_official 18:da299f395b9e 531 /**
mbed_official 18:da299f395b9e 532 * Enables reference buffer offset compensation if true.
mbed_official 18:da299f395b9e 533 * This will increase the accuracy of the gain stage, but decreases the input
mbed_official 18:da299f395b9e 534 * impedance; therefore the startup time of the reference must be increased.
mbed_official 18:da299f395b9e 535 */
mbed_official 18:da299f395b9e 536 bool reference_compensation_enable;
mbed_official 18:da299f395b9e 537 /**
mbed_official 18:da299f395b9e 538 * This value (0-63) control the ADC sampling time in number of half ADC
mbed_official 18:da299f395b9e 539 * prescaled clock cycles (depends of \c ADC_PRESCALER value), thus
mbed_official 18:da299f395b9e 540 * controlling the ADC input impedance. Sampling time is set according to
mbed_official 18:da299f395b9e 541 * the formula:
mbed_official 18:da299f395b9e 542 * Sample time = (sample_length+1) * (ADCclk / 2).
mbed_official 18:da299f395b9e 543 */
mbed_official 18:da299f395b9e 544 uint8_t sample_length;
mbed_official 18:da299f395b9e 545 /** Window monitor configuration structure */
mbed_official 18:da299f395b9e 546 struct adc_window_config window;
mbed_official 18:da299f395b9e 547 /** Gain and offset correction configuration structure */
mbed_official 18:da299f395b9e 548 struct adc_correction_config correction;
mbed_official 18:da299f395b9e 549 /** Event action to take on incoming event */
mbed_official 18:da299f395b9e 550 enum adc_event_action event_action;
mbed_official 18:da299f395b9e 551 };
mbed_official 18:da299f395b9e 552
mbed_official 18:da299f395b9e 553 /**
mbed_official 18:da299f395b9e 554 * \brief ADC software device instance structure.
mbed_official 18:da299f395b9e 555 *
mbed_official 18:da299f395b9e 556 * ADC software instance structure, used to retain software state information
mbed_official 18:da299f395b9e 557 * of an associated hardware module instance.
mbed_official 18:da299f395b9e 558 *
mbed_official 18:da299f395b9e 559 * \note The fields of this structure should not be altered by the user
mbed_official 18:da299f395b9e 560 * application; they are reserved for module-internal use only.
mbed_official 18:da299f395b9e 561 */
mbed_official 18:da299f395b9e 562 struct adc_module {
mbed_official 18:da299f395b9e 563 #if !defined(__DOXYGEN__)
mbed_official 18:da299f395b9e 564 /** Pointer to ADC hardware module */
mbed_official 18:da299f395b9e 565 Adc *hw;
mbed_official 18:da299f395b9e 566 /** Keep reference configuration so we know when enable is called */
mbed_official 18:da299f395b9e 567 enum adc_reference reference;
mbed_official 18:da299f395b9e 568 # if ADC_CALLBACK_MODE == true
mbed_official 18:da299f395b9e 569 /** Array to store callback functions */
mbed_official 18:da299f395b9e 570 adc_callback_t callback[ADC_CALLBACK_N];
mbed_official 18:da299f395b9e 571 /** Pointer to buffer used for ADC results */
mbed_official 18:da299f395b9e 572 volatile uint16_t *job_buffer;
mbed_official 18:da299f395b9e 573 /** Remaining number of conversions in current job */
mbed_official 18:da299f395b9e 574 volatile uint16_t remaining_conversions;
mbed_official 18:da299f395b9e 575 /** Bit mask for callbacks registered */
mbed_official 18:da299f395b9e 576 uint8_t registered_callback_mask;
mbed_official 18:da299f395b9e 577 /** Bit mask for callbacks enabled */
mbed_official 18:da299f395b9e 578 uint8_t enabled_callback_mask;
mbed_official 18:da299f395b9e 579 /** Holds the status of the ongoing or last conversion job */
mbed_official 18:da299f395b9e 580 volatile enum status_code job_status;
mbed_official 18:da299f395b9e 581 /** If software triggering is needed */
mbed_official 18:da299f395b9e 582 bool software_trigger;
mbed_official 18:da299f395b9e 583 # endif
mbed_official 18:da299f395b9e 584 #endif
mbed_official 18:da299f395b9e 585 };
mbed_official 18:da299f395b9e 586
mbed_official 18:da299f395b9e 587 #if !defined(__DOXYGEN__)
mbed_official 18:da299f395b9e 588
mbed_official 18:da299f395b9e 589 /**
mbed_official 18:da299f395b9e 590 * \brief Determines if the hardware module(s) are currently synchronizing to the bus.
mbed_official 18:da299f395b9e 591 *
mbed_official 18:da299f395b9e 592 * Checks to see if the underlying hardware peripheral module(s) are currently
mbed_official 18:da299f395b9e 593 * synchronizing across multiple clock domains to the hardware bus. This
mbed_official 18:da299f395b9e 594 * function can be used to delay further operations on a module until such time
mbed_official 18:da299f395b9e 595 * that it is ready, to prevent blocking delays for synchronization in the
mbed_official 18:da299f395b9e 596 * user application.
mbed_official 18:da299f395b9e 597 *
mbed_official 18:da299f395b9e 598 * \param[in] module_inst Pointer to the ADC software instance struct
mbed_official 18:da299f395b9e 599 *
mbed_official 18:da299f395b9e 600 * \return Synchronization status of the underlying hardware module(s).
mbed_official 18:da299f395b9e 601 *
mbed_official 18:da299f395b9e 602 * \retval true if the module synchronization is ongoing
mbed_official 18:da299f395b9e 603 * \retval false if the module has completed synchronization
mbed_official 18:da299f395b9e 604 */
mbed_official 18:da299f395b9e 605 static inline bool adc_is_syncing(
mbed_official 18:da299f395b9e 606 struct adc_module *const module_inst)
mbed_official 18:da299f395b9e 607 {
mbed_official 18:da299f395b9e 608 /* Sanity check arguments */
mbed_official 18:da299f395b9e 609 Assert(module_inst);
mbed_official 18:da299f395b9e 610
mbed_official 18:da299f395b9e 611 Adc *const adc_module = module_inst->hw;
mbed_official 18:da299f395b9e 612
mbed_official 18:da299f395b9e 613 if (adc_module->SYNCBUSY.reg) {
mbed_official 18:da299f395b9e 614 return true;
mbed_official 18:da299f395b9e 615 }
mbed_official 18:da299f395b9e 616
mbed_official 18:da299f395b9e 617 return false;
mbed_official 18:da299f395b9e 618 }
mbed_official 18:da299f395b9e 619 #endif
mbed_official 18:da299f395b9e 620
mbed_official 18:da299f395b9e 621 /**
mbed_official 18:da299f395b9e 622 * \name Positive Input Sequence
mbed_official 18:da299f395b9e 623 * @{
mbed_official 18:da299f395b9e 624 */
mbed_official 18:da299f395b9e 625
mbed_official 18:da299f395b9e 626 /**
mbed_official 18:da299f395b9e 627 * \brief Enable positive input sequence mask for conversion.
mbed_official 18:da299f395b9e 628 *
mbed_official 18:da299f395b9e 629 * The sequence start from the lowest input, and go to the next enabled input
mbed_official 18:da299f395b9e 630 * automatically when the conversion is done. If no bits are set the
mbed_official 18:da299f395b9e 631 * sequence is disabled.
mbed_official 18:da299f395b9e 632 *
mbed_official 18:da299f395b9e 633 * \param[in] module_inst Pointer to the ADC software instance struct
mbed_official 18:da299f395b9e 634 * \param[in] eanble_seq_mask Sequence mask
mbed_official 18:da299f395b9e 635 */
mbed_official 18:da299f395b9e 636 static inline void adc_enable_positive_input_sequence(
mbed_official 18:da299f395b9e 637 struct adc_module *const module_inst,
mbed_official 18:da299f395b9e 638 uint32_t positive_input_sequence_mask_enable)
mbed_official 18:da299f395b9e 639 {
mbed_official 18:da299f395b9e 640 /* Sanity check arguments */
mbed_official 18:da299f395b9e 641 Assert(module_inst);
mbed_official 18:da299f395b9e 642
mbed_official 18:da299f395b9e 643 Adc *const adc_module = module_inst->hw;
mbed_official 18:da299f395b9e 644 adc_module->SEQCTRL.reg = positive_input_sequence_mask_enable;
mbed_official 18:da299f395b9e 645 }
mbed_official 18:da299f395b9e 646
mbed_official 18:da299f395b9e 647 /**
mbed_official 18:da299f395b9e 648 * \brief Disable positive input in the sequence.
mbed_official 18:da299f395b9e 649 *
mbed_official 18:da299f395b9e 650 * Disable positive input in the sequence.
mbed_official 18:da299f395b9e 651 *
mbed_official 18:da299f395b9e 652 * \param[in] module_inst Pointer to the ADC software instance struct
mbed_official 18:da299f395b9e 653 */
mbed_official 18:da299f395b9e 654 static inline void adc_disable_positive_input_sequence(
mbed_official 18:da299f395b9e 655 struct adc_module *const module_inst)
mbed_official 18:da299f395b9e 656 {
mbed_official 18:da299f395b9e 657 /* Sanity check arguments */
mbed_official 18:da299f395b9e 658 Assert(module_inst);
mbed_official 18:da299f395b9e 659
mbed_official 18:da299f395b9e 660 Adc *const adc_module = module_inst->hw;
mbed_official 18:da299f395b9e 661 adc_module->SEQCTRL.reg = 0;
mbed_official 18:da299f395b9e 662 }
mbed_official 18:da299f395b9e 663
mbed_official 18:da299f395b9e 664 /**
mbed_official 18:da299f395b9e 665 * \brief Get ADC sequence status.
mbed_official 18:da299f395b9e 666 *
mbed_official 18:da299f395b9e 667 * Check if a sequence is done and get last conversion done in the sequence.
mbed_official 18:da299f395b9e 668 *
mbed_official 18:da299f395b9e 669 * \param[in] module_inst Pointer to the ADC software instance struct
mbed_official 18:da299f395b9e 670 * \param[out] is_sequence_busy Sequence busy status
mbed_official 18:da299f395b9e 671 * \param[out] sequence_state This value identifies the last conversion
mbed_official 18:da299f395b9e 672 * done in the sequence
mbed_official 18:da299f395b9e 673 */
mbed_official 18:da299f395b9e 674 static inline void adc_get_sequence_status(
mbed_official 18:da299f395b9e 675 struct adc_module *const module_inst,
mbed_official 18:da299f395b9e 676 bool * is_sequence_busy,
mbed_official 18:da299f395b9e 677 uint8_t *sequence_state)
mbed_official 18:da299f395b9e 678 {
mbed_official 18:da299f395b9e 679 /* Sanity check arguments */
mbed_official 18:da299f395b9e 680 Assert(module_inst);
mbed_official 18:da299f395b9e 681 uint8_t temp = false;
mbed_official 18:da299f395b9e 682 Adc *const adc_module = module_inst->hw;
mbed_official 18:da299f395b9e 683 temp = adc_module->SEQSTATUS.reg;
mbed_official 18:da299f395b9e 684 if(temp & ADC_SEQSTATUS_SEQBUSY) {
mbed_official 18:da299f395b9e 685 *is_sequence_busy = true;
mbed_official 18:da299f395b9e 686 }
mbed_official 18:da299f395b9e 687 *sequence_state = temp & ADC_SEQSTATUS_SEQSTATE_Msk;
mbed_official 18:da299f395b9e 688 }
mbed_official 18:da299f395b9e 689
mbed_official 18:da299f395b9e 690 /** @} */
mbed_official 18:da299f395b9e 691
mbed_official 18:da299f395b9e 692 #ifdef FEATURE_ADC_SUPPORT_MASTER_SLAVE
mbed_official 18:da299f395b9e 693 /**
mbed_official 18:da299f395b9e 694 * \brief Set ADC master and slave mode.
mbed_official 18:da299f395b9e 695 *
mbed_official 18:da299f395b9e 696 * Enable ADC module Master-Slave Operation and select dual mode trigger.
mbed_official 18:da299f395b9e 697 *
mbed_official 18:da299f395b9e 698 * \param[in] master_inst Pointer to the master ADC software instance struct
mbed_official 18:da299f395b9e 699 * \param[in] slave_inst Pointer to the slave ADC software instance struct
mbed_official 18:da299f395b9e 700 * \param[in] dualsel Dual mode trigger selection
mbed_official 18:da299f395b9e 701 *
mbed_official 18:da299f395b9e 702 */
mbed_official 18:da299f395b9e 703 static inline void adc_set_master_slave_mode(
mbed_official 18:da299f395b9e 704 struct adc_module *const master_inst,
mbed_official 18:da299f395b9e 705 struct adc_module *const slave_inst,
mbed_official 18:da299f395b9e 706 enum adc_dual_mode_trigger_selection dualsel)
mbed_official 18:da299f395b9e 707 {
mbed_official 18:da299f395b9e 708 /* Sanity check arguments */
mbed_official 18:da299f395b9e 709 Assert(master_inst);
mbed_official 18:da299f395b9e 710 Assert(slave_inst);
mbed_official 18:da299f395b9e 711
mbed_official 18:da299f395b9e 712 slave_inst->hw->CTRLA.reg |= ADC_CTRLA_SLAVEEN;
mbed_official 18:da299f395b9e 713 master_inst->hw->CTRLC.reg |= dualsel;
mbed_official 18:da299f395b9e 714
mbed_official 18:da299f395b9e 715 };
mbed_official 18:da299f395b9e 716 #endif
mbed_official 18:da299f395b9e 717 /** @} */
mbed_official 18:da299f395b9e 718
mbed_official 18:da299f395b9e 719 #ifdef __cplusplus
mbed_official 18:da299f395b9e 720 }
mbed_official 18:da299f395b9e 721 #endif
mbed_official 18:da299f395b9e 722
mbed_official 18:da299f395b9e 723 /** @} */
mbed_official 18:da299f395b9e 724
mbed_official 18:da299f395b9e 725 #endif /* ADC_FEATURE_H_INCLUDED */
mbed_official 18:da299f395b9e 726