mbed library sources

Dependents:   Encrypted my_mbed lklk CyaSSL_DTLS_Cellular ... more

Superseded

This library was superseded by mbed-dev - https://os.mbed.com/users/mbed_official/code/mbed-dev/.

Development branch of the mbed library sources. This library is kept in synch with the latest changes from the mbed SDK and it is not guaranteed to work.

If you are looking for a stable and tested release, please import one of the official mbed library releases:

Import librarymbed

The official Mbed 2 C/C++ SDK provides the software platform and libraries to build your applications.

Committer:
mbed_official
Date:
Wed Jul 01 09:45:11 2015 +0100
Revision:
579:53297373a894
Child:
592:a274ee790e56
Synchronized with git revision d5b4d2ab9c47edb4dc5776e7177b0c2263459081

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

Initial version of drivers for SAMR21

Who changed what in which revision?

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