mbed library sources

Fork of mbed-src by mbed official

Committer:
mbed_official
Date:
Fri Jul 17 09:15:10 2015 +0100
Revision:
592:a274ee790e56
Parent:
579:53297373a894
Synchronized with git revision e7144f83a8d75df80c4877936b6ffe552b0be9e6

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

More API implementation for SAMR21

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mbed_official 579:53297373a894 1 #ifndef ADC_FEATURE_H_INCLUDED
mbed_official 579:53297373a894 2 #define ADC_FEATURE_H_INCLUDED
mbed_official 579:53297373a894 3
mbed_official 579:53297373a894 4
mbed_official 579:53297373a894 5 #ifdef __cplusplus
mbed_official 579:53297373a894 6 extern "C" {
mbed_official 579:53297373a894 7 #endif
mbed_official 579:53297373a894 8
mbed_official 579:53297373a894 9 #if ADC_CALLBACK_MODE == true
mbed_official 579:53297373a894 10 # include <system_interrupt.h>
mbed_official 579:53297373a894 11
mbed_official 579:53297373a894 12 #if !defined(__DOXYGEN__)
mbed_official 579:53297373a894 13 extern struct adc_module *_adc_instances[ADC_INST_NUM];
mbed_official 579:53297373a894 14 #endif
mbed_official 579:53297373a894 15
mbed_official 579:53297373a894 16 /** Forward definition of the device instance. */
mbed_official 579:53297373a894 17 struct adc_module;
mbed_official 579:53297373a894 18
mbed_official 579:53297373a894 19 /** Type of the callback functions. */
mbed_official 579:53297373a894 20 typedef void (*adc_callback_t)(const struct adc_module *const module);
mbed_official 579:53297373a894 21
mbed_official 579:53297373a894 22 /**
mbed_official 579:53297373a894 23 * \brief ADC Callback enum
mbed_official 579:53297373a894 24 *
mbed_official 579:53297373a894 25 * Callback types for ADC callback driver.
mbed_official 579:53297373a894 26 *
mbed_official 579:53297373a894 27 */
mbed_official 579:53297373a894 28 enum adc_callback {
mbed_official 579:53297373a894 29 /** Callback for buffer received. */
mbed_official 579:53297373a894 30 ADC_CALLBACK_READ_BUFFER,
mbed_official 579:53297373a894 31 /** Callback when window is hit. */
mbed_official 579:53297373a894 32 ADC_CALLBACK_WINDOW,
mbed_official 579:53297373a894 33 /** Callback for error. */
mbed_official 579:53297373a894 34 ADC_CALLBACK_ERROR,
mbed_official 579:53297373a894 35 # if !defined(__DOXYGEN__)
mbed_official 579:53297373a894 36 /** Number of available callbacks. */
mbed_official 579:53297373a894 37 ADC_CALLBACK_N,
mbed_official 579:53297373a894 38 # endif
mbed_official 579:53297373a894 39 };
mbed_official 579:53297373a894 40
mbed_official 579:53297373a894 41 #endif
mbed_official 579:53297373a894 42
mbed_official 579:53297373a894 43 /**
mbed_official 579:53297373a894 44 * \addtogroup asfdoc_sam0_adc_group
mbed_official 579:53297373a894 45 * @{
mbed_official 579:53297373a894 46 */
mbed_official 579:53297373a894 47
mbed_official 579:53297373a894 48 /**
mbed_official 579:53297373a894 49 * \brief ADC reference voltage enum
mbed_official 579:53297373a894 50 *
mbed_official 579:53297373a894 51 * Enum for the possible reference voltages for the ADC.
mbed_official 579:53297373a894 52 *
mbed_official 579:53297373a894 53 */
mbed_official 579:53297373a894 54 enum adc_reference {
mbed_official 579:53297373a894 55 /** 1.0V voltage reference. */
mbed_official 579:53297373a894 56 ADC_REFERENCE_INT1V = ADC_REFCTRL_REFSEL_INT1V,
mbed_official 579:53297373a894 57 /** 1/1.48V<SUB>CC</SUB> reference. */
mbed_official 579:53297373a894 58 ADC_REFERENCE_INTVCC0 = ADC_REFCTRL_REFSEL_INTVCC0,
mbed_official 579:53297373a894 59 /** 1/2V<SUB>CC</SUB> (only for internal V<SUB>CC</SUB> > 2.1V). */
mbed_official 579:53297373a894 60 ADC_REFERENCE_INTVCC1 = ADC_REFCTRL_REFSEL_INTVCC1,
mbed_official 579:53297373a894 61 /** External reference A. */
mbed_official 579:53297373a894 62 ADC_REFERENCE_AREFA = ADC_REFCTRL_REFSEL_AREFA,
mbed_official 579:53297373a894 63 /** External reference B. */
mbed_official 579:53297373a894 64 ADC_REFERENCE_AREFB = ADC_REFCTRL_REFSEL_AREFB,
mbed_official 579:53297373a894 65 };
mbed_official 579:53297373a894 66
mbed_official 579:53297373a894 67 /**
mbed_official 579:53297373a894 68 * \brief ADC clock prescaler enum
mbed_official 579:53297373a894 69 *
mbed_official 579:53297373a894 70 * Enum for the possible clock prescaler values for the ADC.
mbed_official 579:53297373a894 71 *
mbed_official 579:53297373a894 72 */
mbed_official 579:53297373a894 73 enum adc_clock_prescaler {
mbed_official 579:53297373a894 74 /** ADC clock division factor 4. */
mbed_official 579:53297373a894 75 ADC_CLOCK_PRESCALER_DIV4 = ADC_CTRLB_PRESCALER_DIV4,
mbed_official 579:53297373a894 76 /** ADC clock division factor 8. */
mbed_official 579:53297373a894 77 ADC_CLOCK_PRESCALER_DIV8 = ADC_CTRLB_PRESCALER_DIV8,
mbed_official 579:53297373a894 78 /** ADC clock division factor 16. */
mbed_official 579:53297373a894 79 ADC_CLOCK_PRESCALER_DIV16 = ADC_CTRLB_PRESCALER_DIV16,
mbed_official 579:53297373a894 80 /** ADC clock division factor 32. */
mbed_official 579:53297373a894 81 ADC_CLOCK_PRESCALER_DIV32 = ADC_CTRLB_PRESCALER_DIV32,
mbed_official 579:53297373a894 82 /** ADC clock division factor 64. */
mbed_official 579:53297373a894 83 ADC_CLOCK_PRESCALER_DIV64 = ADC_CTRLB_PRESCALER_DIV64,
mbed_official 579:53297373a894 84 /** ADC clock division factor 128. */
mbed_official 579:53297373a894 85 ADC_CLOCK_PRESCALER_DIV128 = ADC_CTRLB_PRESCALER_DIV128,
mbed_official 579:53297373a894 86 /** ADC clock division factor 256. */
mbed_official 579:53297373a894 87 ADC_CLOCK_PRESCALER_DIV256 = ADC_CTRLB_PRESCALER_DIV256,
mbed_official 579:53297373a894 88 /** ADC clock division factor 512. */
mbed_official 579:53297373a894 89 ADC_CLOCK_PRESCALER_DIV512 = ADC_CTRLB_PRESCALER_DIV512,
mbed_official 579:53297373a894 90 };
mbed_official 579:53297373a894 91
mbed_official 579:53297373a894 92 /**
mbed_official 579:53297373a894 93 * \brief ADC resolution enum
mbed_official 579:53297373a894 94 *
mbed_official 579:53297373a894 95 * Enum for the possible resolution values for the ADC.
mbed_official 579:53297373a894 96 *
mbed_official 579:53297373a894 97 */
mbed_official 579:53297373a894 98 enum adc_resolution {
mbed_official 579:53297373a894 99 /** ADC 12-bit resolution. */
mbed_official 579:53297373a894 100 ADC_RESOLUTION_12BIT = ADC_CTRLB_RESSEL_12BIT,
mbed_official 579:53297373a894 101 /** ADC 16-bit resolution using oversampling and decimation. */
mbed_official 579:53297373a894 102 ADC_RESOLUTION_16BIT = ADC_CTRLB_RESSEL_16BIT,
mbed_official 579:53297373a894 103 /** ADC 10-bit resolution. */
mbed_official 579:53297373a894 104 ADC_RESOLUTION_10BIT = ADC_CTRLB_RESSEL_10BIT,
mbed_official 579:53297373a894 105 /** ADC 8-bit resolution. */
mbed_official 579:53297373a894 106 ADC_RESOLUTION_8BIT = ADC_CTRLB_RESSEL_8BIT,
mbed_official 579:53297373a894 107 /** ADC 13-bit resolution using oversampling and decimation. */
mbed_official 579:53297373a894 108 ADC_RESOLUTION_13BIT,
mbed_official 579:53297373a894 109 /** ADC 14-bit resolution using oversampling and decimation. */
mbed_official 579:53297373a894 110 ADC_RESOLUTION_14BIT,
mbed_official 579:53297373a894 111 /** ADC 15-bit resolution using oversampling and decimation. */
mbed_official 579:53297373a894 112 ADC_RESOLUTION_15BIT,
mbed_official 579:53297373a894 113 /** ADC 16-bit result register for use with averaging. When using this mode
mbed_official 579:53297373a894 114 * the ADC result register will be set to 16-bit wide, and the number of
mbed_official 579:53297373a894 115 * samples to accumulate and the division factor is configured by the
mbed_official 579:53297373a894 116 * \ref adc_config.accumulate_samples and \ref adc_config.divide_result
mbed_official 579:53297373a894 117 * members in the configuration struct.
mbed_official 579:53297373a894 118 */
mbed_official 579:53297373a894 119 ADC_RESOLUTION_CUSTOM,
mbed_official 579:53297373a894 120 };
mbed_official 579:53297373a894 121
mbed_official 579:53297373a894 122 /**
mbed_official 579:53297373a894 123 * \brief ADC window monitor mode enum
mbed_official 579:53297373a894 124 *
mbed_official 579:53297373a894 125 * Enum for the possible window monitor modes for the ADC.
mbed_official 579:53297373a894 126 *
mbed_official 579:53297373a894 127 */
mbed_official 579:53297373a894 128 enum adc_window_mode {
mbed_official 579:53297373a894 129 /** No window mode. */
mbed_official 579:53297373a894 130 ADC_WINDOW_MODE_DISABLE = ADC_WINCTRL_WINMODE_DISABLE,
mbed_official 579:53297373a894 131 /** RESULT > WINLT. */
mbed_official 579:53297373a894 132 ADC_WINDOW_MODE_ABOVE_LOWER = ADC_WINCTRL_WINMODE_MODE1,
mbed_official 579:53297373a894 133 /** RESULT < WINUT. */
mbed_official 579:53297373a894 134 ADC_WINDOW_MODE_BELOW_UPPER = ADC_WINCTRL_WINMODE_MODE2,
mbed_official 579:53297373a894 135 /** WINLT < RESULT < WINUT. */
mbed_official 579:53297373a894 136 ADC_WINDOW_MODE_BETWEEN = ADC_WINCTRL_WINMODE_MODE3,
mbed_official 579:53297373a894 137 /** !(WINLT < RESULT < WINUT). */
mbed_official 579:53297373a894 138 ADC_WINDOW_MODE_BETWEEN_INVERTED = ADC_WINCTRL_WINMODE_MODE4,
mbed_official 579:53297373a894 139 };
mbed_official 579:53297373a894 140
mbed_official 579:53297373a894 141 /**
mbed_official 579:53297373a894 142 * \brief ADC gain factor selection enum
mbed_official 579:53297373a894 143 *
mbed_official 579:53297373a894 144 * Enum for the possible gain factor values for the ADC.
mbed_official 579:53297373a894 145 *
mbed_official 579:53297373a894 146 */
mbed_official 579:53297373a894 147 enum adc_gain_factor {
mbed_official 579:53297373a894 148 /** 1x gain. */
mbed_official 579:53297373a894 149 ADC_GAIN_FACTOR_1X = ADC_INPUTCTRL_GAIN_1X,
mbed_official 579:53297373a894 150 /** 2x gain. */
mbed_official 579:53297373a894 151 ADC_GAIN_FACTOR_2X = ADC_INPUTCTRL_GAIN_2X,
mbed_official 579:53297373a894 152 /** 4x gain. */
mbed_official 579:53297373a894 153 ADC_GAIN_FACTOR_4X = ADC_INPUTCTRL_GAIN_4X,
mbed_official 579:53297373a894 154 /** 8x gain. */
mbed_official 579:53297373a894 155 ADC_GAIN_FACTOR_8X = ADC_INPUTCTRL_GAIN_8X,
mbed_official 579:53297373a894 156 /** 16x gain. */
mbed_official 579:53297373a894 157 ADC_GAIN_FACTOR_16X = ADC_INPUTCTRL_GAIN_16X,
mbed_official 579:53297373a894 158 /** 1/2x gain. */
mbed_official 579:53297373a894 159 ADC_GAIN_FACTOR_DIV2 = ADC_INPUTCTRL_GAIN_DIV2,
mbed_official 579:53297373a894 160 };
mbed_official 579:53297373a894 161
mbed_official 579:53297373a894 162 /**
mbed_official 579:53297373a894 163 * \brief ADC event action enum
mbed_official 579:53297373a894 164 *
mbed_official 579:53297373a894 165 * Enum for the possible actions to take on an incoming event.
mbed_official 579:53297373a894 166 *
mbed_official 579:53297373a894 167 */
mbed_official 579:53297373a894 168 enum adc_event_action {
mbed_official 579:53297373a894 169 /** Event action disabled. */
mbed_official 579:53297373a894 170 ADC_EVENT_ACTION_DISABLED = 0,
mbed_official 579:53297373a894 171 /** Flush ADC and start conversion. */
mbed_official 579:53297373a894 172 ADC_EVENT_ACTION_FLUSH_START_CONV = ADC_EVCTRL_SYNCEI,
mbed_official 579:53297373a894 173 /** Start conversion. */
mbed_official 579:53297373a894 174 ADC_EVENT_ACTION_START_CONV = ADC_EVCTRL_STARTEI,
mbed_official 579:53297373a894 175 };
mbed_official 579:53297373a894 176
mbed_official 579:53297373a894 177 /**
mbed_official 579:53297373a894 178 * \brief ADC positive MUX input selection enum
mbed_official 579:53297373a894 179 *
mbed_official 579:53297373a894 180 * Enum for the possible positive MUX input selections for the ADC.
mbed_official 579:53297373a894 181 *
mbed_official 579:53297373a894 182 */
mbed_official 579:53297373a894 183 enum adc_positive_input {
mbed_official 579:53297373a894 184 /** ADC0 pin. */
mbed_official 579:53297373a894 185 ADC_POSITIVE_INPUT_PIN0 = ADC_INPUTCTRL_MUXPOS_PIN0,
mbed_official 579:53297373a894 186 /** ADC1 pin. */
mbed_official 579:53297373a894 187 ADC_POSITIVE_INPUT_PIN1 = ADC_INPUTCTRL_MUXPOS_PIN1,
mbed_official 579:53297373a894 188 /** ADC2 pin. */
mbed_official 579:53297373a894 189 ADC_POSITIVE_INPUT_PIN2 = ADC_INPUTCTRL_MUXPOS_PIN2,
mbed_official 579:53297373a894 190 /** ADC3 pin. */
mbed_official 579:53297373a894 191 ADC_POSITIVE_INPUT_PIN3 = ADC_INPUTCTRL_MUXPOS_PIN3,
mbed_official 579:53297373a894 192 /** ADC4 pin. */
mbed_official 579:53297373a894 193 ADC_POSITIVE_INPUT_PIN4 = ADC_INPUTCTRL_MUXPOS_PIN4,
mbed_official 579:53297373a894 194 /** ADC5 pin. */
mbed_official 579:53297373a894 195 ADC_POSITIVE_INPUT_PIN5 = ADC_INPUTCTRL_MUXPOS_PIN5,
mbed_official 579:53297373a894 196 /** ADC6 pin. */
mbed_official 579:53297373a894 197 ADC_POSITIVE_INPUT_PIN6 = ADC_INPUTCTRL_MUXPOS_PIN6,
mbed_official 579:53297373a894 198 /** ADC7 pin. */
mbed_official 579:53297373a894 199 ADC_POSITIVE_INPUT_PIN7 = ADC_INPUTCTRL_MUXPOS_PIN7,
mbed_official 579:53297373a894 200 /** ADC8 pin. */
mbed_official 579:53297373a894 201 ADC_POSITIVE_INPUT_PIN8 = ADC_INPUTCTRL_MUXPOS_PIN8,
mbed_official 579:53297373a894 202 /** ADC9 pin. */
mbed_official 579:53297373a894 203 ADC_POSITIVE_INPUT_PIN9 = ADC_INPUTCTRL_MUXPOS_PIN9,
mbed_official 579:53297373a894 204 /** ADC10 pin. */
mbed_official 579:53297373a894 205 ADC_POSITIVE_INPUT_PIN10 = ADC_INPUTCTRL_MUXPOS_PIN10,
mbed_official 579:53297373a894 206 /** ADC11 pin. */
mbed_official 579:53297373a894 207 ADC_POSITIVE_INPUT_PIN11 = ADC_INPUTCTRL_MUXPOS_PIN11,
mbed_official 579:53297373a894 208 /** ADC12 pin. */
mbed_official 579:53297373a894 209 ADC_POSITIVE_INPUT_PIN12 = ADC_INPUTCTRL_MUXPOS_PIN12,
mbed_official 579:53297373a894 210 /** ADC13 pin. */
mbed_official 579:53297373a894 211 ADC_POSITIVE_INPUT_PIN13 = ADC_INPUTCTRL_MUXPOS_PIN13,
mbed_official 579:53297373a894 212 /** ADC14 pin. */
mbed_official 579:53297373a894 213 ADC_POSITIVE_INPUT_PIN14 = ADC_INPUTCTRL_MUXPOS_PIN14,
mbed_official 579:53297373a894 214 /** ADC15 pin. */
mbed_official 579:53297373a894 215 ADC_POSITIVE_INPUT_PIN15 = ADC_INPUTCTRL_MUXPOS_PIN15,
mbed_official 579:53297373a894 216 /** ADC16 pin. */
mbed_official 579:53297373a894 217 ADC_POSITIVE_INPUT_PIN16 = ADC_INPUTCTRL_MUXPOS_PIN16,
mbed_official 579:53297373a894 218 /** ADC17 pin. */
mbed_official 579:53297373a894 219 ADC_POSITIVE_INPUT_PIN17 = ADC_INPUTCTRL_MUXPOS_PIN17,
mbed_official 579:53297373a894 220 /** ADC18 pin. */
mbed_official 579:53297373a894 221 ADC_POSITIVE_INPUT_PIN18 = ADC_INPUTCTRL_MUXPOS_PIN18,
mbed_official 579:53297373a894 222 /** ADC19 pin. */
mbed_official 579:53297373a894 223 ADC_POSITIVE_INPUT_PIN19 = ADC_INPUTCTRL_MUXPOS_PIN19,
mbed_official 579:53297373a894 224 /** Temperature reference. */
mbed_official 579:53297373a894 225 ADC_POSITIVE_INPUT_TEMP = ADC_INPUTCTRL_MUXPOS_TEMP,
mbed_official 579:53297373a894 226 /** Bandgap voltage. */
mbed_official 579:53297373a894 227 ADC_POSITIVE_INPUT_BANDGAP = ADC_INPUTCTRL_MUXPOS_BANDGAP,
mbed_official 579:53297373a894 228 /** 1/4 scaled core supply. */
mbed_official 579:53297373a894 229 ADC_POSITIVE_INPUT_SCALEDCOREVCC = ADC_INPUTCTRL_MUXPOS_SCALEDCOREVCC,
mbed_official 579:53297373a894 230 /** 1/4 scaled I/O supply. */
mbed_official 579:53297373a894 231 ADC_POSITIVE_INPUT_SCALEDIOVCC = ADC_INPUTCTRL_MUXPOS_SCALEDIOVCC,
mbed_official 579:53297373a894 232 /** DAC input. */
mbed_official 579:53297373a894 233 ADC_POSITIVE_INPUT_DAC = ADC_INPUTCTRL_MUXPOS_DAC,
mbed_official 579:53297373a894 234 };
mbed_official 579:53297373a894 235
mbed_official 579:53297373a894 236 /**
mbed_official 579:53297373a894 237 * \brief ADC negative MUX input selection enum
mbed_official 579:53297373a894 238 *
mbed_official 579:53297373a894 239 * Enum for the possible negative MUX input selections for the ADC.
mbed_official 579:53297373a894 240 *
mbed_official 579:53297373a894 241 */
mbed_official 579:53297373a894 242 enum adc_negative_input {
mbed_official 579:53297373a894 243 /** ADC0 pin. */
mbed_official 579:53297373a894 244 ADC_NEGATIVE_INPUT_PIN0 = ADC_INPUTCTRL_MUXNEG_PIN0,
mbed_official 579:53297373a894 245 /** ADC1 pin. */
mbed_official 579:53297373a894 246 ADC_NEGATIVE_INPUT_PIN1 = ADC_INPUTCTRL_MUXNEG_PIN1,
mbed_official 579:53297373a894 247 /** ADC2 pin. */
mbed_official 579:53297373a894 248 ADC_NEGATIVE_INPUT_PIN2 = ADC_INPUTCTRL_MUXNEG_PIN2,
mbed_official 579:53297373a894 249 /** ADC3 pin. */
mbed_official 579:53297373a894 250 ADC_NEGATIVE_INPUT_PIN3 = ADC_INPUTCTRL_MUXNEG_PIN3,
mbed_official 579:53297373a894 251 /** ADC4 pin. */
mbed_official 579:53297373a894 252 ADC_NEGATIVE_INPUT_PIN4 = ADC_INPUTCTRL_MUXNEG_PIN4,
mbed_official 579:53297373a894 253 /** ADC5 pin. */
mbed_official 579:53297373a894 254 ADC_NEGATIVE_INPUT_PIN5 = ADC_INPUTCTRL_MUXNEG_PIN5,
mbed_official 579:53297373a894 255 /** ADC6 pin. */
mbed_official 579:53297373a894 256 ADC_NEGATIVE_INPUT_PIN6 = ADC_INPUTCTRL_MUXNEG_PIN6,
mbed_official 579:53297373a894 257 /** ADC7 pin. */
mbed_official 579:53297373a894 258 ADC_NEGATIVE_INPUT_PIN7 = ADC_INPUTCTRL_MUXNEG_PIN7,
mbed_official 579:53297373a894 259 /** Internal ground. */
mbed_official 579:53297373a894 260 ADC_NEGATIVE_INPUT_GND = ADC_INPUTCTRL_MUXNEG_GND,
mbed_official 579:53297373a894 261 /** I/O ground. */
mbed_official 579:53297373a894 262 ADC_NEGATIVE_INPUT_IOGND = ADC_INPUTCTRL_MUXNEG_IOGND,
mbed_official 579:53297373a894 263 };
mbed_official 579:53297373a894 264
mbed_official 579:53297373a894 265 /**
mbed_official 579:53297373a894 266 * \brief ADC number of accumulated samples enum
mbed_official 579:53297373a894 267 *
mbed_official 579:53297373a894 268 * Enum for the possible numbers of ADC samples to accumulate.
mbed_official 579:53297373a894 269 * This setting is only used when the \ref ADC_RESOLUTION_CUSTOM
mbed_official 579:53297373a894 270 * resolution setting is used.
mbed_official 579:53297373a894 271 *
mbed_official 579:53297373a894 272 */
mbed_official 579:53297373a894 273 enum adc_accumulate_samples {
mbed_official 579:53297373a894 274 /** No averaging. */
mbed_official 579:53297373a894 275 ADC_ACCUMULATE_DISABLE = ADC_AVGCTRL_SAMPLENUM_1,
mbed_official 579:53297373a894 276 /** Average 2 samples. */
mbed_official 579:53297373a894 277 ADC_ACCUMULATE_SAMPLES_2 = ADC_AVGCTRL_SAMPLENUM_2,
mbed_official 579:53297373a894 278 /** Average 4 samples. */
mbed_official 579:53297373a894 279 ADC_ACCUMULATE_SAMPLES_4 = ADC_AVGCTRL_SAMPLENUM_4,
mbed_official 579:53297373a894 280 /** Average 8 samples. */
mbed_official 579:53297373a894 281 ADC_ACCUMULATE_SAMPLES_8 = ADC_AVGCTRL_SAMPLENUM_8,
mbed_official 579:53297373a894 282 /** Average 16 samples. */
mbed_official 579:53297373a894 283 ADC_ACCUMULATE_SAMPLES_16 = ADC_AVGCTRL_SAMPLENUM_16,
mbed_official 579:53297373a894 284 /** Average 32 samples. */
mbed_official 579:53297373a894 285 ADC_ACCUMULATE_SAMPLES_32 = ADC_AVGCTRL_SAMPLENUM_32,
mbed_official 579:53297373a894 286 /** Average 64 samples. */
mbed_official 579:53297373a894 287 ADC_ACCUMULATE_SAMPLES_64 = ADC_AVGCTRL_SAMPLENUM_64,
mbed_official 579:53297373a894 288 /** Average 128 samples. */
mbed_official 579:53297373a894 289 ADC_ACCUMULATE_SAMPLES_128 = ADC_AVGCTRL_SAMPLENUM_128,
mbed_official 579:53297373a894 290 /** Average 265 samples. */
mbed_official 579:53297373a894 291 ADC_ACCUMULATE_SAMPLES_256 = ADC_AVGCTRL_SAMPLENUM_256,
mbed_official 579:53297373a894 292 /** Average 512 samples. */
mbed_official 579:53297373a894 293 ADC_ACCUMULATE_SAMPLES_512 = ADC_AVGCTRL_SAMPLENUM_512,
mbed_official 579:53297373a894 294 /** Average 1024 samples. */
mbed_official 579:53297373a894 295 ADC_ACCUMULATE_SAMPLES_1024 = ADC_AVGCTRL_SAMPLENUM_1024,
mbed_official 579:53297373a894 296 };
mbed_official 579:53297373a894 297
mbed_official 579:53297373a894 298 /**
mbed_official 579:53297373a894 299 * \brief ADC possible dividers for the result register
mbed_official 579:53297373a894 300 *
mbed_official 579:53297373a894 301 * Enum for the possible division factors to use when accumulating
mbed_official 579:53297373a894 302 * multiple samples. To keep the same resolution for the averaged
mbed_official 579:53297373a894 303 * result and the actual input value, the division factor must
mbed_official 579:53297373a894 304 * be equal to the number of samples accumulated. This setting is only
mbed_official 579:53297373a894 305 * used when the \ref ADC_RESOLUTION_CUSTOM resolution setting is used.
mbed_official 579:53297373a894 306 */
mbed_official 579:53297373a894 307 enum adc_divide_result {
mbed_official 579:53297373a894 308 /** Don't divide result register after accumulation. */
mbed_official 579:53297373a894 309 ADC_DIVIDE_RESULT_DISABLE = 0,
mbed_official 579:53297373a894 310 /** Divide result register by 2 after accumulation. */
mbed_official 579:53297373a894 311 ADC_DIVIDE_RESULT_2 = 1,
mbed_official 579:53297373a894 312 /** Divide result register by 4 after accumulation. */
mbed_official 579:53297373a894 313 ADC_DIVIDE_RESULT_4 = 2,
mbed_official 579:53297373a894 314 /** Divide result register by 8 after accumulation. */
mbed_official 579:53297373a894 315 ADC_DIVIDE_RESULT_8 = 3,
mbed_official 579:53297373a894 316 /** Divide result register by 16 after accumulation. */
mbed_official 579:53297373a894 317 ADC_DIVIDE_RESULT_16 = 4,
mbed_official 579:53297373a894 318 /** Divide result register by 32 after accumulation. */
mbed_official 579:53297373a894 319 ADC_DIVIDE_RESULT_32 = 5,
mbed_official 579:53297373a894 320 /** Divide result register by 64 after accumulation. */
mbed_official 579:53297373a894 321 ADC_DIVIDE_RESULT_64 = 6,
mbed_official 579:53297373a894 322 /** Divide result register by 128 after accumulation. */
mbed_official 579:53297373a894 323 ADC_DIVIDE_RESULT_128 = 7,
mbed_official 579:53297373a894 324 };
mbed_official 579:53297373a894 325
mbed_official 579:53297373a894 326 #if ADC_CALLBACK_MODE == true
mbed_official 579:53297373a894 327 /**
mbed_official 579:53297373a894 328 * Enum for the possible ADC interrupt flags.
mbed_official 579:53297373a894 329 */
mbed_official 579:53297373a894 330 enum adc_interrupt_flag {
mbed_official 579:53297373a894 331 /** ADC result ready. */
mbed_official 579:53297373a894 332 ADC_INTERRUPT_RESULT_READY = ADC_INTFLAG_RESRDY,
mbed_official 579:53297373a894 333 /** Window monitor match. */
mbed_official 579:53297373a894 334 ADC_INTERRUPT_WINDOW = ADC_INTFLAG_WINMON,
mbed_official 579:53297373a894 335 /** ADC result overwritten before read. */
mbed_official 579:53297373a894 336 ADC_INTERRUPT_OVERRUN = ADC_INTFLAG_OVERRUN,
mbed_official 579:53297373a894 337 };
mbed_official 579:53297373a894 338 #endif
mbed_official 579:53297373a894 339
mbed_official 579:53297373a894 340 /**
mbed_official 579:53297373a894 341 * \brief ADC oversampling and decimation enum
mbed_official 579:53297373a894 342 *
mbed_official 579:53297373a894 343 * Enum for the possible numbers of bits resolution can be increased by when
mbed_official 579:53297373a894 344 * using oversampling and decimation.
mbed_official 579:53297373a894 345 *
mbed_official 579:53297373a894 346 */
mbed_official 579:53297373a894 347 enum adc_oversampling_and_decimation {
mbed_official 579:53297373a894 348 /** Don't use oversampling and decimation mode. */
mbed_official 579:53297373a894 349 ADC_OVERSAMPLING_AND_DECIMATION_DISABLE = 0,
mbed_official 579:53297373a894 350 /** 1 bit resolution increase. */
mbed_official 579:53297373a894 351 ADC_OVERSAMPLING_AND_DECIMATION_1BIT,
mbed_official 579:53297373a894 352 /** 2 bits resolution increase. */
mbed_official 579:53297373a894 353 ADC_OVERSAMPLING_AND_DECIMATION_2BIT,
mbed_official 579:53297373a894 354 /** 3 bits resolution increase. */
mbed_official 579:53297373a894 355 ADC_OVERSAMPLING_AND_DECIMATION_3BIT,
mbed_official 579:53297373a894 356 /** 4 bits resolution increase. */
mbed_official 579:53297373a894 357 ADC_OVERSAMPLING_AND_DECIMATION_4BIT
mbed_official 579:53297373a894 358 };
mbed_official 579:53297373a894 359
mbed_official 579:53297373a894 360 /**
mbed_official 579:53297373a894 361 * \brief Window monitor configuration structure
mbed_official 579:53297373a894 362 *
mbed_official 579:53297373a894 363 * Window monitor configuration structure.
mbed_official 579:53297373a894 364 */
mbed_official 579:53297373a894 365 struct adc_window_config {
mbed_official 579:53297373a894 366 /** Selected window mode. */
mbed_official 579:53297373a894 367 enum adc_window_mode window_mode;
mbed_official 579:53297373a894 368 /** Lower window value. */
mbed_official 579:53297373a894 369 int32_t window_lower_value;
mbed_official 579:53297373a894 370 /** Upper window value. */
mbed_official 579:53297373a894 371 int32_t window_upper_value;
mbed_official 579:53297373a894 372 };
mbed_official 579:53297373a894 373
mbed_official 579:53297373a894 374 /**
mbed_official 579:53297373a894 375 * \brief ADC event enable/disable structure.
mbed_official 579:53297373a894 376 *
mbed_official 579:53297373a894 377 * Event flags for the ADC module. This is used to enable and
mbed_official 579:53297373a894 378 * disable events via \ref adc_enable_events() and \ref adc_disable_events().
mbed_official 579:53297373a894 379 */
mbed_official 579:53297373a894 380 struct adc_events {
mbed_official 579:53297373a894 381 /** Enable event generation on conversion done. */
mbed_official 579:53297373a894 382 bool generate_event_on_conversion_done;
mbed_official 579:53297373a894 383 /** Enable event generation on window monitor. */
mbed_official 579:53297373a894 384 bool generate_event_on_window_monitor;
mbed_official 579:53297373a894 385 };
mbed_official 579:53297373a894 386
mbed_official 579:53297373a894 387 /**
mbed_official 579:53297373a894 388 * \brief Gain and offset correction configuration structure
mbed_official 579:53297373a894 389 *
mbed_official 579:53297373a894 390 * Gain and offset correction configuration structure.
mbed_official 579:53297373a894 391 * Part of the \ref adc_config struct and will be initialized by
mbed_official 579:53297373a894 392 * \ref adc_get_config_defaults.
mbed_official 579:53297373a894 393 */
mbed_official 579:53297373a894 394 struct adc_correction_config {
mbed_official 579:53297373a894 395 /**
mbed_official 579:53297373a894 396 * Enables correction for gain and offset based on values of gain_correction and
mbed_official 579:53297373a894 397 * offset_correction if set to true.
mbed_official 579:53297373a894 398 */
mbed_official 579:53297373a894 399 bool correction_enable;
mbed_official 579:53297373a894 400 /**
mbed_official 579:53297373a894 401 * This value defines how the ADC conversion result is compensated for gain
mbed_official 579:53297373a894 402 * error before written to the result register. This is a fractional value,
mbed_official 579:53297373a894 403 * 1-bit integer plus an 11-bit fraction, therefore
mbed_official 579:53297373a894 404 * 1/2 <= gain_correction < 2. Valid \c gain_correction values ranges from
mbed_official 579:53297373a894 405 * \c 0b010000000000 to \c 0b111111111111.
mbed_official 579:53297373a894 406 */
mbed_official 579:53297373a894 407 uint16_t gain_correction;
mbed_official 579:53297373a894 408 /**
mbed_official 579:53297373a894 409 * This value defines how the ADC conversion result is compensated for
mbed_official 579:53297373a894 410 * offset error before written to the result register. This is a 12-bit
mbed_official 579:53297373a894 411 * value in two鈥檚 complement format.
mbed_official 579:53297373a894 412 */
mbed_official 579:53297373a894 413 int16_t offset_correction;
mbed_official 579:53297373a894 414 };
mbed_official 579:53297373a894 415
mbed_official 579:53297373a894 416 /**
mbed_official 579:53297373a894 417 * \brief Pin scan configuration structure
mbed_official 579:53297373a894 418 *
mbed_official 579:53297373a894 419 * Pin scan configuration structure. Part of the \ref adc_config struct and will
mbed_official 579:53297373a894 420 * be initialized by \ref adc_get_config_defaults.
mbed_official 579:53297373a894 421 */
mbed_official 579:53297373a894 422 struct adc_pin_scan_config {
mbed_official 579:53297373a894 423 /**
mbed_official 579:53297373a894 424 * Offset (relative to selected positive input) of the first input pin to be
mbed_official 579:53297373a894 425 * used in pin scan mode.
mbed_official 579:53297373a894 426 */
mbed_official 579:53297373a894 427 uint8_t offset_start_scan;
mbed_official 579:53297373a894 428 /**
mbed_official 579:53297373a894 429 * Number of input pins to scan in pin scan mode. A value below two will
mbed_official 579:53297373a894 430 * disable pin scan mode.
mbed_official 579:53297373a894 431 */
mbed_official 579:53297373a894 432 uint8_t inputs_to_scan;
mbed_official 579:53297373a894 433 };
mbed_official 579:53297373a894 434
mbed_official 579:53297373a894 435 /**
mbed_official 579:53297373a894 436 * \brief ADC configuration structure
mbed_official 579:53297373a894 437 *
mbed_official 579:53297373a894 438 * Configuration structure for an ADC instance. This structure should be
mbed_official 579:53297373a894 439 * initialized by the \ref adc_get_config_defaults()
mbed_official 579:53297373a894 440 * function before being modified by the user application.
mbed_official 579:53297373a894 441 */
mbed_official 579:53297373a894 442 struct adc_config {
mbed_official 579:53297373a894 443 /** GCLK generator used to clock the peripheral. */
mbed_official 579:53297373a894 444 enum gclk_generator clock_source;
mbed_official 579:53297373a894 445 /** Voltage reference. */
mbed_official 579:53297373a894 446 enum adc_reference reference;
mbed_official 579:53297373a894 447 /** Clock prescaler. */
mbed_official 579:53297373a894 448 enum adc_clock_prescaler clock_prescaler;
mbed_official 579:53297373a894 449 /** Result resolution. */
mbed_official 579:53297373a894 450 enum adc_resolution resolution;
mbed_official 579:53297373a894 451 /** Gain factor. */
mbed_official 579:53297373a894 452 enum adc_gain_factor gain_factor;
mbed_official 579:53297373a894 453 /** Positive MUX input. */
mbed_official 579:53297373a894 454 enum adc_positive_input positive_input;
mbed_official 579:53297373a894 455 /** Negative MUX input. */
mbed_official 579:53297373a894 456 enum adc_negative_input negative_input;
mbed_official 579:53297373a894 457 /** Number of ADC samples to accumulate when using the
mbed_official 579:53297373a894 458 * \c ADC_RESOLUTION_CUSTOM mode.
mbed_official 579:53297373a894 459 */
mbed_official 579:53297373a894 460 enum adc_accumulate_samples accumulate_samples;
mbed_official 579:53297373a894 461 /** Division ration when using the ADC_RESOLUTION_CUSTOM mode. */
mbed_official 579:53297373a894 462 enum adc_divide_result divide_result;
mbed_official 579:53297373a894 463 /** Left adjusted result. */
mbed_official 579:53297373a894 464 bool left_adjust;
mbed_official 579:53297373a894 465 /** Enables differential mode if true. */
mbed_official 579:53297373a894 466 bool differential_mode;
mbed_official 579:53297373a894 467 /** Enables free running mode if true. */
mbed_official 579:53297373a894 468 bool freerunning;
mbed_official 579:53297373a894 469 /** Enables ADC in standby sleep mode if true. */
mbed_official 579:53297373a894 470 bool run_in_standby;
mbed_official 579:53297373a894 471 /**
mbed_official 579:53297373a894 472 * Enables reference buffer offset compensation if true.
mbed_official 579:53297373a894 473 * This will increase the accuracy of the gain stage, but decreases the input
mbed_official 579:53297373a894 474 * impedance; therefore the startup time of the reference must be increased.
mbed_official 579:53297373a894 475 */
mbed_official 579:53297373a894 476 bool reference_compensation_enable;
mbed_official 579:53297373a894 477 /**
mbed_official 579:53297373a894 478 * This value (0-63) control the ADC sampling time in number of half ADC
mbed_official 579:53297373a894 479 * prescaled clock cycles (depends of \c ADC_PRESCALER value), thus
mbed_official 579:53297373a894 480 * controlling the ADC input impedance. Sampling time is set according to
mbed_official 579:53297373a894 481 * the formula:
mbed_official 579:53297373a894 482 * Sample time = (sample_length+1) * (ADCclk / 2)
mbed_official 579:53297373a894 483 */
mbed_official 579:53297373a894 484 uint8_t sample_length;
mbed_official 579:53297373a894 485 /** Window monitor configuration structure. */
mbed_official 579:53297373a894 486 struct adc_window_config window;
mbed_official 579:53297373a894 487 /** Gain and offset correction configuration structure. */
mbed_official 579:53297373a894 488 struct adc_correction_config correction;
mbed_official 579:53297373a894 489 /** Event action to take on incoming event. */
mbed_official 579:53297373a894 490 enum adc_event_action event_action;
mbed_official 579:53297373a894 491 /** Pin scan configuration structure. */
mbed_official 579:53297373a894 492 struct adc_pin_scan_config pin_scan;
mbed_official 579:53297373a894 493 };
mbed_official 579:53297373a894 494
mbed_official 579:53297373a894 495 /**
mbed_official 579:53297373a894 496 * \brief ADC software device instance structure.
mbed_official 579:53297373a894 497 *
mbed_official 579:53297373a894 498 * ADC software instance structure, used to retain software state information
mbed_official 579:53297373a894 499 * of an associated hardware module instance.
mbed_official 579:53297373a894 500 *
mbed_official 579:53297373a894 501 * \note The fields of this structure should not be altered by the user
mbed_official 579:53297373a894 502 * application; they are reserved for module-internal use only.
mbed_official 579:53297373a894 503 */
mbed_official 579:53297373a894 504 struct adc_module {
mbed_official 579:53297373a894 505 #if !defined(__DOXYGEN__)
mbed_official 579:53297373a894 506 /** Pointer to ADC hardware module. */
mbed_official 579:53297373a894 507 Adc *hw;
mbed_official 579:53297373a894 508 /** Keep reference configuration so we know when enable is called. */
mbed_official 579:53297373a894 509 enum adc_reference reference;
mbed_official 579:53297373a894 510 # if ADC_CALLBACK_MODE == true
mbed_official 579:53297373a894 511 /** Array to store callback functions. */
mbed_official 579:53297373a894 512 adc_callback_t callback[ADC_CALLBACK_N];
mbed_official 579:53297373a894 513 /** Pointer to buffer used for ADC results. */
mbed_official 579:53297373a894 514 volatile uint16_t *job_buffer;
mbed_official 579:53297373a894 515 /** Remaining number of conversions in current job. */
mbed_official 579:53297373a894 516 volatile uint16_t remaining_conversions;
mbed_official 579:53297373a894 517 /** Bit mask for callbacks registered. */
mbed_official 579:53297373a894 518 uint8_t registered_callback_mask;
mbed_official 579:53297373a894 519 /** Bit mask for callbacks enabled. */
mbed_official 579:53297373a894 520 uint8_t enabled_callback_mask;
mbed_official 579:53297373a894 521 /** Holds the status of the ongoing or last conversion job. */
mbed_official 579:53297373a894 522 volatile enum status_code job_status;
mbed_official 579:53297373a894 523 /** If software triggering is needed. */
mbed_official 579:53297373a894 524 bool software_trigger;
mbed_official 579:53297373a894 525 # endif
mbed_official 579:53297373a894 526 #endif
mbed_official 579:53297373a894 527 };
mbed_official 579:53297373a894 528
mbed_official 579:53297373a894 529 #if !defined(__DOXYGEN__)
mbed_official 579:53297373a894 530
mbed_official 579:53297373a894 531 /**
mbed_official 579:53297373a894 532 * \brief Determines if the hardware module(s) are currently synchronizing to the bus.
mbed_official 579:53297373a894 533 *
mbed_official 579:53297373a894 534 * Checks to see if the underlying hardware peripheral module(s) are currently
mbed_official 579:53297373a894 535 * synchronizing across multiple clock domains to the hardware bus. This
mbed_official 579:53297373a894 536 * function can be used to delay further operations on a module until such time
mbed_official 579:53297373a894 537 * that it is ready, to prevent blocking delays for synchronization in the
mbed_official 579:53297373a894 538 * user application.
mbed_official 579:53297373a894 539 *
mbed_official 579:53297373a894 540 * \param[in] module_inst Pointer to the ADC software instance struct
mbed_official 579:53297373a894 541 *
mbed_official 579:53297373a894 542 * \return Synchronization status of the underlying hardware module(s).
mbed_official 579:53297373a894 543 *
mbed_official 579:53297373a894 544 * \retval true if the module synchronization is ongoing
mbed_official 579:53297373a894 545 * \retval false if the module has completed synchronization
mbed_official 579:53297373a894 546 */
mbed_official 579:53297373a894 547 static inline bool adc_is_syncing(
mbed_official 579:53297373a894 548 struct adc_module *const module_inst)
mbed_official 579:53297373a894 549 {
mbed_official 579:53297373a894 550 /* Sanity check arguments */
mbed_official 579:53297373a894 551 Assert(module_inst);
mbed_official 579:53297373a894 552
mbed_official 579:53297373a894 553 Adc *const adc_module = module_inst->hw;
mbed_official 579:53297373a894 554
mbed_official 579:53297373a894 555 if (adc_module->STATUS.reg & ADC_STATUS_SYNCBUSY) {
mbed_official 579:53297373a894 556 return true;
mbed_official 579:53297373a894 557 }
mbed_official 579:53297373a894 558
mbed_official 579:53297373a894 559 return false;
mbed_official 579:53297373a894 560 }
mbed_official 579:53297373a894 561 #endif
mbed_official 579:53297373a894 562
mbed_official 579:53297373a894 563 /**
mbed_official 579:53297373a894 564 * \name ADC Gain and Pin Scan Mode
mbed_official 579:53297373a894 565 * @{
mbed_official 579:53297373a894 566 */
mbed_official 579:53297373a894 567
mbed_official 579:53297373a894 568 /**
mbed_official 579:53297373a894 569 * \brief Sets ADC gain factor
mbed_official 579:53297373a894 570 *
mbed_official 579:53297373a894 571 * Sets the ADC gain factor to a specified gain setting.
mbed_official 579:53297373a894 572 *
mbed_official 579:53297373a894 573 * \param[in] module_inst Pointer to the ADC software instance struct
mbed_official 579:53297373a894 574 * \param[in] gain_factor Gain factor value to set
mbed_official 579:53297373a894 575 */
mbed_official 579:53297373a894 576 static inline void adc_set_gain(
mbed_official 579:53297373a894 577 struct adc_module *const module_inst,
mbed_official 579:53297373a894 578 const enum adc_gain_factor gain_factor)
mbed_official 579:53297373a894 579 {
mbed_official 579:53297373a894 580 /* Sanity check arguments */
mbed_official 579:53297373a894 581 Assert(module_inst);
mbed_official 579:53297373a894 582 Assert(module_inst->hw);
mbed_official 579:53297373a894 583
mbed_official 579:53297373a894 584 Adc *const adc_module = module_inst->hw;
mbed_official 579:53297373a894 585
mbed_official 579:53297373a894 586 while (adc_is_syncing(module_inst)) {
mbed_official 579:53297373a894 587 /* Wait for synchronization */
mbed_official 579:53297373a894 588 }
mbed_official 579:53297373a894 589
mbed_official 579:53297373a894 590 /* Set new gain factor */
mbed_official 579:53297373a894 591 adc_module->INPUTCTRL.reg =
mbed_official 579:53297373a894 592 (adc_module->INPUTCTRL.reg & ~ADC_INPUTCTRL_GAIN_Msk) |
mbed_official 579:53297373a894 593 (gain_factor);
mbed_official 579:53297373a894 594 }
mbed_official 579:53297373a894 595
mbed_official 579:53297373a894 596 /**
mbed_official 579:53297373a894 597 * \brief Sets the ADC pin scan mode
mbed_official 579:53297373a894 598 *
mbed_official 579:53297373a894 599 * Configures the pin scan mode of the ADC module. In pin scan mode, the first
mbed_official 579:53297373a894 600 * conversion will start at the configured positive input + start_offset. When
mbed_official 579:53297373a894 601 * a conversion is done, a conversion will start on the next input, until
mbed_official 579:53297373a894 602 * \c inputs_to_scan number of conversions are made.
mbed_official 579:53297373a894 603 *
mbed_official 579:53297373a894 604 * \param[in] module_inst Pointer to the ADC software instance struct
mbed_official 579:53297373a894 605 * \param[in] inputs_to_scan Number of input pins to perform a conversion on
mbed_official 579:53297373a894 606 * (must be two or more)
mbed_official 579:53297373a894 607 * \param[in] start_offset Offset of first pin to scan (relative to
mbed_official 579:53297373a894 608 * configured positive input)
mbed_official 579:53297373a894 609 *
mbed_official 579:53297373a894 610 * \return Status of the pin scan configuration set request.
mbed_official 579:53297373a894 611 *
mbed_official 579:53297373a894 612 * \retval STATUS_OK Pin scan mode has been set successfully
mbed_official 579:53297373a894 613 * \retval STATUS_ERR_INVALID_ARG Number of input pins to scan or offset has
mbed_official 579:53297373a894 614 * an invalid value
mbed_official 579:53297373a894 615 */
mbed_official 579:53297373a894 616 static inline enum status_code adc_set_pin_scan_mode(
mbed_official 579:53297373a894 617 struct adc_module *const module_inst,
mbed_official 579:53297373a894 618 uint8_t inputs_to_scan,
mbed_official 579:53297373a894 619 const uint8_t start_offset)
mbed_official 579:53297373a894 620
mbed_official 579:53297373a894 621 {
mbed_official 579:53297373a894 622 /* Sanity check arguments */
mbed_official 579:53297373a894 623 Assert(module_inst);
mbed_official 579:53297373a894 624 Assert(module_inst->hw);
mbed_official 579:53297373a894 625
mbed_official 579:53297373a894 626 Adc *const adc_module = module_inst->hw;
mbed_official 579:53297373a894 627
mbed_official 579:53297373a894 628 if (inputs_to_scan > 0) {
mbed_official 579:53297373a894 629 /*
mbed_official 579:53297373a894 630 * Number of input sources included is the value written to INPUTSCAN
mbed_official 579:53297373a894 631 * plus 1.
mbed_official 579:53297373a894 632 */
mbed_official 579:53297373a894 633 inputs_to_scan--;
mbed_official 579:53297373a894 634 }
mbed_official 579:53297373a894 635
mbed_official 579:53297373a894 636 if (inputs_to_scan > (ADC_INPUTCTRL_INPUTSCAN_Msk >> ADC_INPUTCTRL_INPUTSCAN_Pos) ||
mbed_official 579:53297373a894 637 start_offset > (ADC_INPUTCTRL_INPUTOFFSET_Msk >> ADC_INPUTCTRL_INPUTOFFSET_Pos)) {
mbed_official 579:53297373a894 638 /* Invalid number of input pins */
mbed_official 579:53297373a894 639 return STATUS_ERR_INVALID_ARG;
mbed_official 579:53297373a894 640 }
mbed_official 579:53297373a894 641
mbed_official 579:53297373a894 642 while (adc_is_syncing(module_inst)) {
mbed_official 579:53297373a894 643 /* Wait for synchronization */
mbed_official 579:53297373a894 644 }
mbed_official 579:53297373a894 645
mbed_official 579:53297373a894 646 /* Set pin scan mode */
mbed_official 579:53297373a894 647 adc_module->INPUTCTRL.reg =
mbed_official 579:53297373a894 648 (adc_module->INPUTCTRL.reg &
mbed_official 579:53297373a894 649 ~(ADC_INPUTCTRL_INPUTSCAN_Msk | ADC_INPUTCTRL_INPUTOFFSET_Msk)) |
mbed_official 579:53297373a894 650 (start_offset << ADC_INPUTCTRL_INPUTOFFSET_Pos) |
mbed_official 579:53297373a894 651 (inputs_to_scan << ADC_INPUTCTRL_INPUTSCAN_Pos);
mbed_official 579:53297373a894 652
mbed_official 579:53297373a894 653 return STATUS_OK;
mbed_official 579:53297373a894 654 }
mbed_official 579:53297373a894 655
mbed_official 579:53297373a894 656 /**
mbed_official 579:53297373a894 657 * \brief Disables pin scan mode
mbed_official 579:53297373a894 658 *
mbed_official 579:53297373a894 659 * Disables pin scan mode. The next conversion will be made on only one pin
mbed_official 579:53297373a894 660 * (the configured positive input pin).
mbed_official 579:53297373a894 661 *
mbed_official 579:53297373a894 662 * \param[in] module_inst Pointer to the ADC software instance struct
mbed_official 579:53297373a894 663 */
mbed_official 579:53297373a894 664 static inline void adc_disable_pin_scan_mode(
mbed_official 579:53297373a894 665 struct adc_module *const module_inst)
mbed_official 579:53297373a894 666 {
mbed_official 579:53297373a894 667 /* Disable pin scan mode */
mbed_official 579:53297373a894 668 adc_set_pin_scan_mode(module_inst, 0, 0);
mbed_official 579:53297373a894 669 }
mbed_official 579:53297373a894 670
mbed_official 579:53297373a894 671 /** @} */
mbed_official 579:53297373a894 672
mbed_official 579:53297373a894 673 /** @} */
mbed_official 579:53297373a894 674
mbed_official 579:53297373a894 675 #ifdef __cplusplus
mbed_official 579:53297373a894 676 }
mbed_official 579:53297373a894 677 #endif
mbed_official 579:53297373a894 678
mbed_official 579:53297373a894 679 #endif /* ADC_FEATURE_H_INCLUDED */
mbed_official 579:53297373a894 680