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