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.

Committer:
AnnaBridge
Date:
Thu Nov 08 11:45:42 2018 +0000
Revision:
171:3a7713b1edbc
Parent:
TARGET_SAMD21G18A/TARGET_Atmel/TARGET_SAM_CortexM0P/drivers/adc/adc.h@111:4336505e4b1c
mbed library. Release version 164

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Kojto 111:4336505e4b1c 1 /**
Kojto 111:4336505e4b1c 2 * \file
Kojto 111:4336505e4b1c 3 *
Kojto 111:4336505e4b1c 4 * \brief SAM Peripheral Analog-to-Digital Converter Driver
Kojto 111:4336505e4b1c 5 *
Kojto 111:4336505e4b1c 6 * Copyright (C) 2012-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
Kojto 111:4336505e4b1c 47 #ifndef ADC_H_INCLUDED
Kojto 111:4336505e4b1c 48 #define ADC_H_INCLUDED
Kojto 111:4336505e4b1c 49
Kojto 111:4336505e4b1c 50 /**
Kojto 111:4336505e4b1c 51 * \defgroup asfdoc_sam0_adc_group SAM Analog-to-Digital Converter (ADC) Driver
Kojto 111:4336505e4b1c 52 *
Kojto 111:4336505e4b1c 53 * This driver for Atmel&reg; | SMART ARM&reg;-based microcontrollers provides an interface for the configuration
Kojto 111:4336505e4b1c 54 * and management of the device's Analog-to-Digital Converter functionality, for
Kojto 111:4336505e4b1c 55 * the conversion of analog voltages into a corresponding digital form.
Kojto 111:4336505e4b1c 56 * The following driver Application Programming Interface (API) modes are covered by this manual:
Kojto 111:4336505e4b1c 57 * - Polled APIs
Kojto 111:4336505e4b1c 58 * \if ADC_CALLBACK_MODE
Kojto 111:4336505e4b1c 59 * - Callback APIs
Kojto 111:4336505e4b1c 60 * \endif
Kojto 111:4336505e4b1c 61 *
Kojto 111:4336505e4b1c 62 * The following peripheral is used by this module:
Kojto 111:4336505e4b1c 63 * - ADC (Analog-to-Digital Converter)
Kojto 111:4336505e4b1c 64 *
Kojto 111:4336505e4b1c 65 * The following devices can use this module:
Kojto 111:4336505e4b1c 66 * \if DEVICE_SAML21_SUPPORT
Kojto 111:4336505e4b1c 67 * - Atmel | SMART SAM L21
Kojto 111:4336505e4b1c 68 * - Atmel | SMART SAM C20/C21
Kojto 111:4336505e4b1c 69 * \else
Kojto 111:4336505e4b1c 70 * - Atmel | SMART SAM D20/D21
Kojto 111:4336505e4b1c 71 * - Atmel | SMART SAM R21
Kojto 111:4336505e4b1c 72 * - Atmel | SMART SAM D10/D11
Kojto 111:4336505e4b1c 73 * - Atmel | SMART SAM DA0/DA1
Kojto 111:4336505e4b1c 74 * \endif
Kojto 111:4336505e4b1c 75 *
Kojto 111:4336505e4b1c 76 * The outline of this documentation is as follows:
Kojto 111:4336505e4b1c 77 * - \ref asfdoc_sam0_adc_prerequisites
Kojto 111:4336505e4b1c 78 * - \ref asfdoc_sam0_adc_module_overview
Kojto 111:4336505e4b1c 79 * - \ref asfdoc_sam0_adc_special_considerations
Kojto 111:4336505e4b1c 80 * - \ref asfdoc_sam0_adc_extra_info
Kojto 111:4336505e4b1c 81 * - \ref asfdoc_sam0_adc_examples
Kojto 111:4336505e4b1c 82 * - \ref asfdoc_sam0_adc_api_overview
Kojto 111:4336505e4b1c 83 *
Kojto 111:4336505e4b1c 84 *
Kojto 111:4336505e4b1c 85 * \section asfdoc_sam0_adc_prerequisites Prerequisites
Kojto 111:4336505e4b1c 86 *
Kojto 111:4336505e4b1c 87 * There are no prerequisites for this module.
Kojto 111:4336505e4b1c 88 *
Kojto 111:4336505e4b1c 89 *
Kojto 111:4336505e4b1c 90 * \section asfdoc_sam0_adc_module_overview Module Overview
Kojto 111:4336505e4b1c 91 *
Kojto 111:4336505e4b1c 92 * This driver provides an interface for the Analog-to-Digital conversion
Kojto 111:4336505e4b1c 93 * functions on the device, to convert analog voltages to a corresponding
Kojto 111:4336505e4b1c 94 * digital value. The ADC has up to 12-bit resolution, and is capable of
Kojto 111:4336505e4b1c 95 * \if DEVICE_SAML21_SUPPORT
Kojto 111:4336505e4b1c 96 * converting up to 1,000,000 samples per second (MSPS).
Kojto 111:4336505e4b1c 97 * \else
Kojto 111:4336505e4b1c 98 * converting up to 500K samples per second (KSPS).
Kojto 111:4336505e4b1c 99 * \endif
Kojto 111:4336505e4b1c 100 *
Kojto 111:4336505e4b1c 101 * The ADC has a compare function for accurate monitoring of user defined
Kojto 111:4336505e4b1c 102 * thresholds with minimum software intervention required.
Kojto 111:4336505e4b1c 103 * The ADC may be configured for 8-, 10-, or 12-bit result, reducing the
Kojto 111:4336505e4b1c 104 * conversion time. ADC conversion results are provided left or right adjusted
Kojto 111:4336505e4b1c 105 * which eases calculation when the result is represented as a signed integer.
Kojto 111:4336505e4b1c 106 *
Kojto 111:4336505e4b1c 107 * The input selection is flexible, and both single-ended and differential
Kojto 111:4336505e4b1c 108 * measurements can be made. For differential measurements, an optional gain
Kojto 111:4336505e4b1c 109 * stage is available to increase the dynamic range. In addition, several
Kojto 111:4336505e4b1c 110 * internal signal inputs are available. The ADC can provide both signed and
Kojto 111:4336505e4b1c 111 * unsigned results.
Kojto 111:4336505e4b1c 112 *
Kojto 111:4336505e4b1c 113 * The ADC measurements can either be started by application software or an
Kojto 111:4336505e4b1c 114 * incoming event from another peripheral in the device, and both internal and
Kojto 111:4336505e4b1c 115 * external reference voltages can be selected.
Kojto 111:4336505e4b1c 116 *
Kojto 111:4336505e4b1c 117 * \note Internal references will be enabled by the driver, but not disabled.
Kojto 111:4336505e4b1c 118 * Any reference not used by the application should be disabled by the application.
Kojto 111:4336505e4b1c 119 *
Kojto 111:4336505e4b1c 120 * A simplified block diagram of the ADC can be seen in
Kojto 111:4336505e4b1c 121 * \ref asfdoc_sam0_adc_module_block_diagram "the figure below".
Kojto 111:4336505e4b1c 122 *
Kojto 111:4336505e4b1c 123 * \anchor asfdoc_sam0_adc_module_block_diagram
Kojto 111:4336505e4b1c 124 * \dot
Kojto 111:4336505e4b1c 125 * digraph overview {
Kojto 111:4336505e4b1c 126 * splines = false;
Kojto 111:4336505e4b1c 127 * rankdir=LR;
Kojto 111:4336505e4b1c 128 *
Kojto 111:4336505e4b1c 129 * mux1 [label="Positive input", shape=box];
Kojto 111:4336505e4b1c 130 * mux2 [label="Negative input", shape=box];
Kojto 111:4336505e4b1c 131 *
Kojto 111:4336505e4b1c 132 *
Kojto 111:4336505e4b1c 133 * mux3 [label="Reference", shape=box];
Kojto 111:4336505e4b1c 134 *
Kojto 111:4336505e4b1c 135 * adc [label="ADC", shape=polygon, sides=5, orientation=90, distortion=-0.6, style=filled, fillcolor=darkolivegreen1, height=1, width=1];
Kojto 111:4336505e4b1c 136 * prescaler [label="PRESCALER", shape=box, style=filled, fillcolor=lightblue];
Kojto 111:4336505e4b1c 137 *
Kojto 111:4336505e4b1c 138 * mux1 -> adc;
Kojto 111:4336505e4b1c 139 * mux2 -> adc;
Kojto 111:4336505e4b1c 140 * mux3 -> adc:sw;
Kojto 111:4336505e4b1c 141 * prescaler -> adc;
Kojto 111:4336505e4b1c 142 *
Kojto 111:4336505e4b1c 143 * postproc [label="Post processing", shape=box];
Kojto 111:4336505e4b1c 144 * result [label="RESULT", shape=box, style=filled, fillcolor=lightblue];
Kojto 111:4336505e4b1c 145 *
Kojto 111:4336505e4b1c 146 * adc:e -> postproc:w;
Kojto 111:4336505e4b1c 147 * postproc:e -> result:w;
Kojto 111:4336505e4b1c 148 *
Kojto 111:4336505e4b1c 149 * {rank=same; mux1 mux2}
Kojto 111:4336505e4b1c 150 * {rank=same; prescaler adc}
Kojto 111:4336505e4b1c 151 *
Kojto 111:4336505e4b1c 152 * }
Kojto 111:4336505e4b1c 153 * \enddot
Kojto 111:4336505e4b1c 154 *
Kojto 111:4336505e4b1c 155 *
Kojto 111:4336505e4b1c 156 * \subsection asfdoc_sam0_adc_module_overview_prescaler Sample Clock Prescaler
Kojto 111:4336505e4b1c 157 * The ADC features a prescaler, which enables conversion at lower clock rates
Kojto 111:4336505e4b1c 158 * than the input Generic Clock to the ADC module. This feature can be used to
Kojto 111:4336505e4b1c 159 * lower the synchronization time of the digital interface to the ADC module
Kojto 111:4336505e4b1c 160 * via a high speed Generic Clock frequency, while still allowing the ADC
Kojto 111:4336505e4b1c 161 * sampling rate to be reduced.
Kojto 111:4336505e4b1c 162 *
Kojto 111:4336505e4b1c 163 * \subsection asfdoc_sam0_adc_module_overview_resolution ADC Resolution
Kojto 111:4336505e4b1c 164 * The ADC supports full 8-, 10-, or 12-bit resolution. Hardware
Kojto 111:4336505e4b1c 165 * oversampling and decimation can be used to increase the
Kojto 111:4336505e4b1c 166 * effective resolution at the expense of throughput. Using oversampling and
Kojto 111:4336505e4b1c 167 * decimation mode the ADC resolution is increased from 12-bit to an effective
Kojto 111:4336505e4b1c 168 * 13-, 14-, 15-, or 16-bit. In these modes the conversion rate is reduced, as
Kojto 111:4336505e4b1c 169 * a greater number of samples is used to achieve the increased resolution. The
Kojto 111:4336505e4b1c 170 * available resolutions and effective conversion rate is listed in
Kojto 111:4336505e4b1c 171 * \ref asfdoc_sam0_adc_module_conversion_rate "the table below".
Kojto 111:4336505e4b1c 172 *
Kojto 111:4336505e4b1c 173 * \anchor asfdoc_sam0_adc_module_conversion_rate
Kojto 111:4336505e4b1c 174 * <table>
Kojto 111:4336505e4b1c 175 * <caption>Effective ADC Conversion Speed Using Oversampling</caption>
Kojto 111:4336505e4b1c 176 * <tr>
Kojto 111:4336505e4b1c 177 * <th>Resolution</th>
Kojto 111:4336505e4b1c 178 * <th>Effective conversion rate</th>
Kojto 111:4336505e4b1c 179 * </tr>
Kojto 111:4336505e4b1c 180 * <tr>
Kojto 111:4336505e4b1c 181 * <td>13-bit</td>
Kojto 111:4336505e4b1c 182 * <td>Conversion rate divided by 4</td>
Kojto 111:4336505e4b1c 183 * </tr>
Kojto 111:4336505e4b1c 184 * <tr>
Kojto 111:4336505e4b1c 185 * <td>14-bit</td>
Kojto 111:4336505e4b1c 186 * <td>Conversion rate divided by 16</td>
Kojto 111:4336505e4b1c 187 * </tr>
Kojto 111:4336505e4b1c 188 * <tr>
Kojto 111:4336505e4b1c 189 * <td>15-bit</td>
Kojto 111:4336505e4b1c 190 * <td>Conversion rate divided by 64</td>
Kojto 111:4336505e4b1c 191 * </tr>
Kojto 111:4336505e4b1c 192 * <tr>
Kojto 111:4336505e4b1c 193 * <td>16-bit</td>
Kojto 111:4336505e4b1c 194 * <td>Conversion rate divided by 256</td>
Kojto 111:4336505e4b1c 195 * </tr>
Kojto 111:4336505e4b1c 196 * </table>
Kojto 111:4336505e4b1c 197 *
Kojto 111:4336505e4b1c 198 * \subsection asfdoc_sam0_adc_module_overview_conversion Conversion Modes
Kojto 111:4336505e4b1c 199 * ADC conversions can be software triggered on demand by the user application,
Kojto 111:4336505e4b1c 200 * if continuous sampling is not required. It is also possible to configure the
Kojto 111:4336505e4b1c 201 * ADC in free running mode, where new conversions are started as soon as the
Kojto 111:4336505e4b1c 202 * previous conversion is completed, or configure the ADC to scan across a
Kojto 111:4336505e4b1c 203 * number of input pins (see \ref asfdoc_sam0_adc_module_overview_pin_scan).
Kojto 111:4336505e4b1c 204 *
Kojto 111:4336505e4b1c 205 * \subsection asfdoc_sam0_adc_module_overview_diff_mode Differential and Single-ended Conversion
Kojto 111:4336505e4b1c 206 * The ADC has two conversion modes; differential and single-ended. When
Kojto 111:4336505e4b1c 207 * measuring signals where the positive input pin is always at a higher voltage
Kojto 111:4336505e4b1c 208 * than the negative input pin, the single-ended conversion mode should be used
Kojto 111:4336505e4b1c 209 * in order to achieve a full 12-bit output resolution.
Kojto 111:4336505e4b1c 210 *
Kojto 111:4336505e4b1c 211 * If however the positive input pin voltage may drop below the negative input
Kojto 111:4336505e4b1c 212 * pin the signed differential mode should be used.
Kojto 111:4336505e4b1c 213 *
Kojto 111:4336505e4b1c 214 * \subsection asfdoc_sam0_adc_module_overview_sample_time Sample Time
Kojto 111:4336505e4b1c 215 * The sample time for each ADC conversion is configurable as a number of half
Kojto 111:4336505e4b1c 216 * prescaled ADC clock cycles (depending on the prescaler value), allowing the
Kojto 111:4336505e4b1c 217 * user application to achieve faster or slower sampling depending on the
Kojto 111:4336505e4b1c 218 * source impedance of the ADC input channels. For applications with high
Kojto 111:4336505e4b1c 219 * impedance inputs the sample time can be increased to give the ADC an adequate
Kojto 111:4336505e4b1c 220 * time to sample and convert the input channel.
Kojto 111:4336505e4b1c 221 *
Kojto 111:4336505e4b1c 222 * The resulting sampling time is given by the following equation:
Kojto 111:4336505e4b1c 223 * \f[
Kojto 111:4336505e4b1c 224 * t_{SAMPLE} = (sample\_length+1) \times \frac{ADC_{CLK}} {2}
Kojto 111:4336505e4b1c 225 * \f]
Kojto 111:4336505e4b1c 226 *
Kojto 111:4336505e4b1c 227 * \subsection asfdoc_sam0_adc_module_overview_averaging Averaging
Kojto 111:4336505e4b1c 228 * The ADC can be configured to trade conversion speed for accuracy by averaging
Kojto 111:4336505e4b1c 229 * multiple samples in hardware. This feature is suitable when operating in
Kojto 111:4336505e4b1c 230 * noisy conditions.
Kojto 111:4336505e4b1c 231 *
Kojto 111:4336505e4b1c 232 * You can specify any number of samples to accumulate (up to 1024) and the
Kojto 111:4336505e4b1c 233 * divide ratio to use (up to divide by 128). To modify these settings the
Kojto 111:4336505e4b1c 234 * ADC_RESOLUTION_CUSTOM needs to be set as the resolution. When this is set
Kojto 111:4336505e4b1c 235 * the number of samples to accumulate and the division ratio can be set by
Kojto 111:4336505e4b1c 236 * the configuration struct members \ref adc_config.accumulate_samples and
Kojto 111:4336505e4b1c 237 * \ref adc_config.divide_result. When using this mode the ADC result register
Kojto 111:4336505e4b1c 238 * will be set to be 16-bit wide to accommodate the larger result sizes
Kojto 111:4336505e4b1c 239 * produced by the accumulator.
Kojto 111:4336505e4b1c 240 *
Kojto 111:4336505e4b1c 241 * The effective ADC conversion rate will be reduced by a factor of the number
Kojto 111:4336505e4b1c 242 * of accumulated samples;
Kojto 111:4336505e4b1c 243 * however, the effective resolution will be increased according to
Kojto 111:4336505e4b1c 244 * \ref asfdoc_sam0_adc_module_hw_av_resolution "the table below".
Kojto 111:4336505e4b1c 245 *
Kojto 111:4336505e4b1c 246 * \anchor asfdoc_sam0_adc_module_hw_av_resolution
Kojto 111:4336505e4b1c 247 * <table>
Kojto 111:4336505e4b1c 248 * <caption>Effective ADC Resolution From Various Hardware Averaging Modes</caption>
Kojto 111:4336505e4b1c 249 * <tr>
Kojto 111:4336505e4b1c 250 * <th>Number of samples</tr>
Kojto 111:4336505e4b1c 251 * <th>Final result</tr>
Kojto 111:4336505e4b1c 252 * </tr>
Kojto 111:4336505e4b1c 253 * <tr>
Kojto 111:4336505e4b1c 254 * <td>1</td>
Kojto 111:4336505e4b1c 255 * <td>12-bit</td>
Kojto 111:4336505e4b1c 256 * </tr>
Kojto 111:4336505e4b1c 257 * <tr>
Kojto 111:4336505e4b1c 258 * <td>2</td>
Kojto 111:4336505e4b1c 259 * <td>13-bit</td>
Kojto 111:4336505e4b1c 260 * </tr>
Kojto 111:4336505e4b1c 261 * <tr>
Kojto 111:4336505e4b1c 262 * <td>4</td>
Kojto 111:4336505e4b1c 263 * <td>14-bit</td>
Kojto 111:4336505e4b1c 264 * </tr>
Kojto 111:4336505e4b1c 265 * <tr>
Kojto 111:4336505e4b1c 266 * <td>8</td>
Kojto 111:4336505e4b1c 267 * <td>15-bit</td>
Kojto 111:4336505e4b1c 268 * </tr>
Kojto 111:4336505e4b1c 269 * <tr>
Kojto 111:4336505e4b1c 270 * <td>16</td>
Kojto 111:4336505e4b1c 271 * <td>16-bit</td>
Kojto 111:4336505e4b1c 272 * </tr>
Kojto 111:4336505e4b1c 273 * <tr>
Kojto 111:4336505e4b1c 274 * <td>32</td>
Kojto 111:4336505e4b1c 275 * <td>16-bit</td>
Kojto 111:4336505e4b1c 276 * </tr>
Kojto 111:4336505e4b1c 277 * <tr>
Kojto 111:4336505e4b1c 278 * <td>64</td>
Kojto 111:4336505e4b1c 279 * <td>16-bit</td>
Kojto 111:4336505e4b1c 280 * </tr>
Kojto 111:4336505e4b1c 281 * <tr>
Kojto 111:4336505e4b1c 282 * <td>128</td>
Kojto 111:4336505e4b1c 283 * <td>16-bit</td>
Kojto 111:4336505e4b1c 284 * </tr>
Kojto 111:4336505e4b1c 285 * <tr>
Kojto 111:4336505e4b1c 286 * <td>256</td>
Kojto 111:4336505e4b1c 287 * <td>16-bit</td>
Kojto 111:4336505e4b1c 288 * </tr>
Kojto 111:4336505e4b1c 289 * <tr>
Kojto 111:4336505e4b1c 290 * <td>512</td>
Kojto 111:4336505e4b1c 291 * <td>16-bit</td>
Kojto 111:4336505e4b1c 292 * </tr>
Kojto 111:4336505e4b1c 293 * <tr>
Kojto 111:4336505e4b1c 294 * <td>1024</td>
Kojto 111:4336505e4b1c 295 * <td>16-bit</td>
Kojto 111:4336505e4b1c 296 * </tr>
Kojto 111:4336505e4b1c 297 * </table>
Kojto 111:4336505e4b1c 298 *
Kojto 111:4336505e4b1c 299 *
Kojto 111:4336505e4b1c 300 * \subsection asfdoc_sam0_adc_module_overview_offset_corr Offset and Gain Correction
Kojto 111:4336505e4b1c 301 * Inherent gain and offset errors affect the absolute accuracy of the ADC.
Kojto 111:4336505e4b1c 302 *
Kojto 111:4336505e4b1c 303 * The offset error is defined as the deviation of the ADC's actual transfer
Kojto 111:4336505e4b1c 304 * function from ideal straight line at zero input voltage.
Kojto 111:4336505e4b1c 305 *
Kojto 111:4336505e4b1c 306 * The gain error is defined as the deviation of the last output step's
Kojto 111:4336505e4b1c 307 * midpoint from the ideal straight line, after compensating for offset error.
Kojto 111:4336505e4b1c 308 *
Kojto 111:4336505e4b1c 309 * The offset correction value is subtracted from the converted data before the
Kojto 111:4336505e4b1c 310 * result is ready. The gain correction value is multiplied with the offset
Kojto 111:4336505e4b1c 311 * corrected value.
Kojto 111:4336505e4b1c 312 *
Kojto 111:4336505e4b1c 313 * The equation for both offset and gain error compensation is shown below:
Kojto 111:4336505e4b1c 314 * \f[
Kojto 111:4336505e4b1c 315 * ADC_{RESULT} = (VALUE_{CONV} + CORR_{OFFSET}) \times CORR_{GAIN}
Kojto 111:4336505e4b1c 316 * \f]
Kojto 111:4336505e4b1c 317 *
Kojto 111:4336505e4b1c 318 * When enabled, a given set of offset and gain correction values can be applied
Kojto 111:4336505e4b1c 319 * to the sampled data in hardware, giving a corrected stream of sample data to
Kojto 111:4336505e4b1c 320 * the user application at the cost of an increased sample latency.
Kojto 111:4336505e4b1c 321 *
Kojto 111:4336505e4b1c 322 * In single conversion, a latency of 13 ADC Generic Clock cycles is added for
Kojto 111:4336505e4b1c 323 * the final sample result availability. As the correction time is always less
Kojto 111:4336505e4b1c 324 * than the propagation delay, in free running mode this latency appears only
Kojto 111:4336505e4b1c 325 * during the first conversion. After the first conversion is complete, future
Kojto 111:4336505e4b1c 326 * conversion results are available at the defined sampling rate.
Kojto 111:4336505e4b1c 327 *
Kojto 111:4336505e4b1c 328 * \subsection asfdoc_sam0_adc_module_overview_pin_scan Pin Scan
Kojto 111:4336505e4b1c 329 * In pin scan mode, the first ADC conversion will begin from the configured
Kojto 111:4336505e4b1c 330 * positive channel, plus the requested starting offset. When the first
Kojto 111:4336505e4b1c 331 * conversion is completed, the next conversion will start at the next positive
Kojto 111:4336505e4b1c 332 * input channel and so on, until all requested pins to scan have been sampled
Kojto 111:4336505e4b1c 333 * and converted.
Kojto 111:4336505e4b1c 334 * SAM L21 has automatic sequences feature instead of pin scan mode. In automatic
Kojto 111:4336505e4b1c 335 * sequence mode, all of 32 positives inputs can be included in a sequence. The
Kojto 111:4336505e4b1c 336 * sequence starts from the lowest input, and go to the next enabled input
Kojto 111:4336505e4b1c 337 * automatically.
Kojto 111:4336505e4b1c 338 *
Kojto 111:4336505e4b1c 339 * Pin scanning gives a simple mechanism to sample a large number of physical
Kojto 111:4336505e4b1c 340 * input channel samples, using a single physical ADC channel.
Kojto 111:4336505e4b1c 341 *
Kojto 111:4336505e4b1c 342 * \subsection asfdoc_sam0_adc_module_overview_window_monitor Window Monitor
Kojto 111:4336505e4b1c 343 * The ADC module window monitor function can be used to automatically compare
Kojto 111:4336505e4b1c 344 * the conversion result against a preconfigured pair of upper and lower
Kojto 111:4336505e4b1c 345 * threshold values.
Kojto 111:4336505e4b1c 346 *
Kojto 111:4336505e4b1c 347 * The threshold values are evaluated differently, depending on whether
Kojto 111:4336505e4b1c 348 * differential or single-ended mode is selected. In differential mode, the
Kojto 111:4336505e4b1c 349 * upper and lower thresholds are evaluated as signed values for the comparison,
Kojto 111:4336505e4b1c 350 * while in single-ended mode the comparisons are made as a set of unsigned
Kojto 111:4336505e4b1c 351 * values.
Kojto 111:4336505e4b1c 352 *
Kojto 111:4336505e4b1c 353 * The significant bits of the lower window monitor threshold and upper window
Kojto 111:4336505e4b1c 354 * monitor threshold values are user-configurable, and follow the overall ADC
Kojto 111:4336505e4b1c 355 * sampling bit precision set when the ADC is configured by the user application.
Kojto 111:4336505e4b1c 356 * For example, only the eight lower bits of the window threshold values will be
Kojto 111:4336505e4b1c 357 * compared to the sampled data whilst the ADC is configured in 8-bit mode.
Kojto 111:4336505e4b1c 358 * In addition, if using differential mode, the 8<SUP>th</SUP> bit will be considered as
Kojto 111:4336505e4b1c 359 * the sign bit even if bit 9 is zero.
Kojto 111:4336505e4b1c 360 *
Kojto 111:4336505e4b1c 361 * \subsection asfdoc_sam0_adc_module_overview_events Events
Kojto 111:4336505e4b1c 362 * Event generation and event actions are configurable in the ADC.
Kojto 111:4336505e4b1c 363 *
Kojto 111:4336505e4b1c 364 * The ADC has two actions that can be triggered upon event reception:
Kojto 111:4336505e4b1c 365 * \li Start conversion
Kojto 111:4336505e4b1c 366 * \li Flush pipeline and start conversion
Kojto 111:4336505e4b1c 367 *
Kojto 111:4336505e4b1c 368 * The ADC can generate two events:
Kojto 111:4336505e4b1c 369 * \li Window monitor
Kojto 111:4336505e4b1c 370 * \li Result ready
Kojto 111:4336505e4b1c 371 *
Kojto 111:4336505e4b1c 372 * If the event actions are enabled in the configuration, any incoming event
Kojto 111:4336505e4b1c 373 * will trigger the action.
Kojto 111:4336505e4b1c 374 *
Kojto 111:4336505e4b1c 375 * If the window monitor event is enabled, an event will be generated
Kojto 111:4336505e4b1c 376 * when the configured window condition is detected.
Kojto 111:4336505e4b1c 377 *
Kojto 111:4336505e4b1c 378 * If the result ready event is enabled, an event will be generated when a
Kojto 111:4336505e4b1c 379 * conversion is completed.
Kojto 111:4336505e4b1c 380 *
Kojto 111:4336505e4b1c 381 * \note The connection of events between modules requires the use of the
Kojto 111:4336505e4b1c 382 * \ref asfdoc_sam0_events_group "SAM Event System Driver (EVENTS)"
Kojto 111:4336505e4b1c 383 * to route output event of one module to the the input event of another.
Kojto 111:4336505e4b1c 384 * For more information on event routing, refer to the event driver
Kojto 111:4336505e4b1c 385 * documentation.
Kojto 111:4336505e4b1c 386 *
Kojto 111:4336505e4b1c 387 *
Kojto 111:4336505e4b1c 388 * \section asfdoc_sam0_adc_special_considerations Special Considerations
Kojto 111:4336505e4b1c 389 *
Kojto 111:4336505e4b1c 390 * An integrated analog temperature sensor is available for use with the ADC.
Kojto 111:4336505e4b1c 391 * The bandgap voltage, as well as the scaled I/O and core voltages can also be
Kojto 111:4336505e4b1c 392 * measured by the ADC. For internal ADC inputs, the internal source(s) may need
Kojto 111:4336505e4b1c 393 * to be manually enabled by the user application before they can be measured.
Kojto 111:4336505e4b1c 394 *
Kojto 111:4336505e4b1c 395 *
Kojto 111:4336505e4b1c 396 * \section asfdoc_sam0_adc_extra_info Extra Information
Kojto 111:4336505e4b1c 397 *
Kojto 111:4336505e4b1c 398 * For extra information, see \ref asfdoc_sam0_adc_extra. This includes:
Kojto 111:4336505e4b1c 399 * - \ref asfdoc_sam0_adc_extra_acronyms
Kojto 111:4336505e4b1c 400 * - \ref asfdoc_sam0_adc_extra_dependencies
Kojto 111:4336505e4b1c 401 * - \ref asfdoc_sam0_adc_extra_errata
Kojto 111:4336505e4b1c 402 * - \ref asfdoc_sam0_adc_extra_history
Kojto 111:4336505e4b1c 403 *
Kojto 111:4336505e4b1c 404 *
Kojto 111:4336505e4b1c 405 * \section asfdoc_sam0_adc_examples Examples
Kojto 111:4336505e4b1c 406 *
Kojto 111:4336505e4b1c 407 * For a list of examples related to this driver, see
Kojto 111:4336505e4b1c 408 * \ref asfdoc_sam0_adc_exqsg.
Kojto 111:4336505e4b1c 409 *
Kojto 111:4336505e4b1c 410 *
Kojto 111:4336505e4b1c 411 * \section asfdoc_sam0_adc_api_overview API Overview
Kojto 111:4336505e4b1c 412 * @{
Kojto 111:4336505e4b1c 413 */
Kojto 111:4336505e4b1c 414
Kojto 111:4336505e4b1c 415 #ifdef __cplusplus
Kojto 111:4336505e4b1c 416 extern "C" {
Kojto 111:4336505e4b1c 417 #endif
Kojto 111:4336505e4b1c 418
Kojto 111:4336505e4b1c 419 #include <compiler.h>
Kojto 111:4336505e4b1c 420 #include <system.h>
Kojto 111:4336505e4b1c 421 #include <adc_feature.h>
Kojto 111:4336505e4b1c 422
Kojto 111:4336505e4b1c 423 /**
Kojto 111:4336505e4b1c 424 * \name Module Status Flags
Kojto 111:4336505e4b1c 425 *
Kojto 111:4336505e4b1c 426 * ADC status flags, returned by \ref adc_get_status() and cleared by
Kojto 111:4336505e4b1c 427 * \ref adc_clear_status().
Kojto 111:4336505e4b1c 428 *
Kojto 111:4336505e4b1c 429 * @{
Kojto 111:4336505e4b1c 430 */
Kojto 111:4336505e4b1c 431
Kojto 111:4336505e4b1c 432 /** ADC result ready. */
Kojto 111:4336505e4b1c 433 #define ADC_STATUS_RESULT_READY (1UL << 0)
Kojto 111:4336505e4b1c 434 /** Window monitor match. */
Kojto 111:4336505e4b1c 435 #define ADC_STATUS_WINDOW (1UL << 1)
Kojto 111:4336505e4b1c 436 /** ADC result overwritten before read. */
Kojto 111:4336505e4b1c 437 #define ADC_STATUS_OVERRUN (1UL << 2)
Kojto 111:4336505e4b1c 438
Kojto 111:4336505e4b1c 439 /** @} */
Kojto 111:4336505e4b1c 440
Kojto 111:4336505e4b1c 441 #if ADC_CALLBACK_MODE == true
Kojto 111:4336505e4b1c 442 # if (ADC_INST_NUM > 1)
Kojto 111:4336505e4b1c 443 # define _ADC_INTERRUPT_VECT_NUM(n, unused) \
Kojto 111:4336505e4b1c 444 SYSTEM_INTERRUPT_MODULE_ADC##n,
Kojto 111:4336505e4b1c 445 /**
Kojto 111:4336505e4b1c 446 * \internal Get the interrupt vector for the given device instance
Kojto 111:4336505e4b1c 447 *
Kojto 111:4336505e4b1c 448 * \param[in] The ADC module instance number
Kojto 111:4336505e4b1c 449 *
Kojto 111:4336505e4b1c 450 * \return Interrupt vector for of the given ADC module instance.
Kojto 111:4336505e4b1c 451 */
Kojto 111:4336505e4b1c 452 static enum system_interrupt_vector _adc_interrupt_get_interrupt_vector(
Kojto 111:4336505e4b1c 453 uint32_t inst_num)
Kojto 111:4336505e4b1c 454 {
Kojto 111:4336505e4b1c 455 static uint8_t adc_interrupt_vectors[ADC_INST_NUM] = {
Kojto 111:4336505e4b1c 456 MREPEAT(ADC_INST_NUM, _ADC_INTERRUPT_VECT_NUM, 0)
Kojto 111:4336505e4b1c 457 };
Kojto 111:4336505e4b1c 458
Kojto 111:4336505e4b1c 459 return (enum system_interrupt_vector)adc_interrupt_vectors[inst_num];
Kojto 111:4336505e4b1c 460 }
Kojto 111:4336505e4b1c 461 # endif
Kojto 111:4336505e4b1c 462 #endif
Kojto 111:4336505e4b1c 463
Kojto 111:4336505e4b1c 464 #if !defined(__DOXYGEN__)
Kojto 111:4336505e4b1c 465 uint8_t _adc_get_inst_index(
Kojto 111:4336505e4b1c 466 Adc *const hw);
Kojto 111:4336505e4b1c 467 #endif
Kojto 111:4336505e4b1c 468
Kojto 111:4336505e4b1c 469 /**
Kojto 111:4336505e4b1c 470 * \name Driver Initialization and Configuration
Kojto 111:4336505e4b1c 471 * @{
Kojto 111:4336505e4b1c 472 */
Kojto 111:4336505e4b1c 473 enum status_code adc_init(
Kojto 111:4336505e4b1c 474 struct adc_module *const module_inst,
Kojto 111:4336505e4b1c 475 Adc *hw,
Kojto 111:4336505e4b1c 476 struct adc_config *config);
Kojto 111:4336505e4b1c 477
Kojto 111:4336505e4b1c 478 void adc_get_config_defaults(
Kojto 111:4336505e4b1c 479 struct adc_config *const config);
Kojto 111:4336505e4b1c 480
Kojto 111:4336505e4b1c 481 #if (SAMD) || (SAMR21)
Kojto 111:4336505e4b1c 482 void adc_regular_ain_channel(
Kojto 111:4336505e4b1c 483 uint32_t *pin_array, uint8_t size);
Kojto 111:4336505e4b1c 484 #endif
Kojto 111:4336505e4b1c 485
Kojto 111:4336505e4b1c 486 /** @} */
Kojto 111:4336505e4b1c 487
Kojto 111:4336505e4b1c 488 /**
Kojto 111:4336505e4b1c 489 * \name Status Management
Kojto 111:4336505e4b1c 490 * @{
Kojto 111:4336505e4b1c 491 */
Kojto 111:4336505e4b1c 492
Kojto 111:4336505e4b1c 493 /**
Kojto 111:4336505e4b1c 494 * \brief Retrieves the current module status.
Kojto 111:4336505e4b1c 495 *
Kojto 111:4336505e4b1c 496 * Retrieves the status of the module, giving overall state information.
Kojto 111:4336505e4b1c 497 *
Kojto 111:4336505e4b1c 498 * \param[in] module_inst Pointer to the ADC software instance struct
Kojto 111:4336505e4b1c 499 *
Kojto 111:4336505e4b1c 500 * \return Bitmask of \c ADC_STATUS_* flags.
Kojto 111:4336505e4b1c 501 *
Kojto 111:4336505e4b1c 502 * \retval ADC_STATUS_RESULT_READY ADC result is ready to be read
Kojto 111:4336505e4b1c 503 * \retval ADC_STATUS_WINDOW ADC has detected a value inside the set
Kojto 111:4336505e4b1c 504 * window range
Kojto 111:4336505e4b1c 505 * \retval ADC_STATUS_OVERRUN ADC result has overrun
Kojto 111:4336505e4b1c 506 */
Kojto 111:4336505e4b1c 507 static inline uint32_t adc_get_status(
Kojto 111:4336505e4b1c 508 struct adc_module *const module_inst)
Kojto 111:4336505e4b1c 509 {
Kojto 111:4336505e4b1c 510 /* Sanity check arguments */
Kojto 111:4336505e4b1c 511 Assert(module_inst);
Kojto 111:4336505e4b1c 512 Assert(module_inst->hw);
Kojto 111:4336505e4b1c 513
Kojto 111:4336505e4b1c 514 Adc *const adc_module = module_inst->hw;
Kojto 111:4336505e4b1c 515
Kojto 111:4336505e4b1c 516 uint32_t int_flags = adc_module->INTFLAG.reg;
Kojto 111:4336505e4b1c 517
Kojto 111:4336505e4b1c 518 uint32_t status_flags = 0;
Kojto 111:4336505e4b1c 519
Kojto 111:4336505e4b1c 520 /* Check for ADC Result Ready */
Kojto 111:4336505e4b1c 521 if (int_flags & ADC_INTFLAG_RESRDY) {
Kojto 111:4336505e4b1c 522 status_flags |= ADC_STATUS_RESULT_READY;
Kojto 111:4336505e4b1c 523 }
Kojto 111:4336505e4b1c 524
Kojto 111:4336505e4b1c 525 /* Check for ADC Window Match */
Kojto 111:4336505e4b1c 526 if (int_flags & ADC_INTFLAG_WINMON) {
Kojto 111:4336505e4b1c 527 status_flags |= ADC_STATUS_WINDOW;
Kojto 111:4336505e4b1c 528 }
Kojto 111:4336505e4b1c 529
Kojto 111:4336505e4b1c 530 /* Check for ADC Overrun */
Kojto 111:4336505e4b1c 531 if (int_flags & ADC_INTFLAG_OVERRUN) {
Kojto 111:4336505e4b1c 532 status_flags |= ADC_STATUS_OVERRUN;
Kojto 111:4336505e4b1c 533 }
Kojto 111:4336505e4b1c 534
Kojto 111:4336505e4b1c 535 return status_flags;
Kojto 111:4336505e4b1c 536 }
Kojto 111:4336505e4b1c 537
Kojto 111:4336505e4b1c 538 /**
Kojto 111:4336505e4b1c 539 * \brief Clears a module status flag.
Kojto 111:4336505e4b1c 540 *
Kojto 111:4336505e4b1c 541 * Clears the given status flag of the module.
Kojto 111:4336505e4b1c 542 *
Kojto 111:4336505e4b1c 543 * \param[in] module_inst Pointer to the ADC software instance struct
Kojto 111:4336505e4b1c 544 * \param[in] status_flags Bitmask of \c ADC_STATUS_* flags to clear
Kojto 111:4336505e4b1c 545 */
Kojto 111:4336505e4b1c 546 static inline void adc_clear_status(
Kojto 111:4336505e4b1c 547 struct adc_module *const module_inst,
Kojto 111:4336505e4b1c 548 const uint32_t status_flags)
Kojto 111:4336505e4b1c 549 {
Kojto 111:4336505e4b1c 550 /* Sanity check arguments */
Kojto 111:4336505e4b1c 551 Assert(module_inst);
Kojto 111:4336505e4b1c 552 Assert(module_inst->hw);
Kojto 111:4336505e4b1c 553
Kojto 111:4336505e4b1c 554 Adc *const adc_module = module_inst->hw;
Kojto 111:4336505e4b1c 555
Kojto 111:4336505e4b1c 556 uint32_t int_flags = 0;
Kojto 111:4336505e4b1c 557
Kojto 111:4336505e4b1c 558 /* Check for ADC Result Ready */
Kojto 111:4336505e4b1c 559 if (status_flags & ADC_STATUS_RESULT_READY) {
Kojto 111:4336505e4b1c 560 int_flags |= ADC_INTFLAG_RESRDY;
Kojto 111:4336505e4b1c 561 }
Kojto 111:4336505e4b1c 562
Kojto 111:4336505e4b1c 563 /* Check for ADC Window Match */
Kojto 111:4336505e4b1c 564 if (status_flags & ADC_STATUS_WINDOW) {
Kojto 111:4336505e4b1c 565 int_flags |= ADC_INTFLAG_WINMON;
Kojto 111:4336505e4b1c 566 }
Kojto 111:4336505e4b1c 567
Kojto 111:4336505e4b1c 568 /* Check for ADC Overrun */
Kojto 111:4336505e4b1c 569 if (status_flags & ADC_STATUS_OVERRUN) {
Kojto 111:4336505e4b1c 570 int_flags |= ADC_INTFLAG_OVERRUN;
Kojto 111:4336505e4b1c 571 }
Kojto 111:4336505e4b1c 572
Kojto 111:4336505e4b1c 573 /* Clear interrupt flag */
Kojto 111:4336505e4b1c 574 adc_module->INTFLAG.reg = int_flags;
Kojto 111:4336505e4b1c 575 }
Kojto 111:4336505e4b1c 576 /** @} */
Kojto 111:4336505e4b1c 577
Kojto 111:4336505e4b1c 578 /**
Kojto 111:4336505e4b1c 579 * \name Enable, Disable, and Reset ADC Module, Start Conversion and Read Result
Kojto 111:4336505e4b1c 580 * @{
Kojto 111:4336505e4b1c 581 */
Kojto 111:4336505e4b1c 582
Kojto 111:4336505e4b1c 583 /**
Kojto 111:4336505e4b1c 584 * \brief Enables the ADC module.
Kojto 111:4336505e4b1c 585 *
Kojto 111:4336505e4b1c 586 * Enables an ADC module that has previously been configured. If any internal reference
Kojto 111:4336505e4b1c 587 * is selected it will be enabled.
Kojto 111:4336505e4b1c 588 *
Kojto 111:4336505e4b1c 589 * \param[in] module_inst Pointer to the ADC software instance struct
Kojto 111:4336505e4b1c 590 */
Kojto 111:4336505e4b1c 591 static inline enum status_code adc_enable(
Kojto 111:4336505e4b1c 592 struct adc_module *const module_inst)
Kojto 111:4336505e4b1c 593 {
Kojto 111:4336505e4b1c 594 Assert(module_inst);
Kojto 111:4336505e4b1c 595 Assert(module_inst->hw);
Kojto 111:4336505e4b1c 596
Kojto 111:4336505e4b1c 597 Adc *const adc_module = module_inst->hw;
Kojto 111:4336505e4b1c 598
Kojto 111:4336505e4b1c 599 while (adc_is_syncing(module_inst)) {
Kojto 111:4336505e4b1c 600 /* Wait for synchronization */
Kojto 111:4336505e4b1c 601 }
Kojto 111:4336505e4b1c 602
Kojto 111:4336505e4b1c 603 #if ADC_CALLBACK_MODE == true
Kojto 111:4336505e4b1c 604 # if (ADC_INST_NUM > 1)
Kojto 111:4336505e4b1c 605 system_interrupt_enable(_adc_interrupt_get_interrupt_vector(
Kojto 111:4336505e4b1c 606 _adc_get_inst_index(adc_module)));
Kojto 111:4336505e4b1c 607 # elif (SAMC20)
Kojto 111:4336505e4b1c 608 system_interrupt_enable(SYSTEM_INTERRUPT_MODULE_ADC0);
Kojto 111:4336505e4b1c 609 # else
Kojto 111:4336505e4b1c 610 system_interrupt_enable(SYSTEM_INTERRUPT_MODULE_ADC);
Kojto 111:4336505e4b1c 611 # endif
Kojto 111:4336505e4b1c 612 #endif
Kojto 111:4336505e4b1c 613
Kojto 111:4336505e4b1c 614 adc_module->CTRLA.reg |= ADC_CTRLA_ENABLE;
Kojto 111:4336505e4b1c 615
Kojto 111:4336505e4b1c 616 while (adc_is_syncing(module_inst)) {
Kojto 111:4336505e4b1c 617 /* Wait for synchronization */
Kojto 111:4336505e4b1c 618 }
Kojto 111:4336505e4b1c 619 return STATUS_OK;
Kojto 111:4336505e4b1c 620 }
Kojto 111:4336505e4b1c 621
Kojto 111:4336505e4b1c 622 /**
Kojto 111:4336505e4b1c 623 * \brief Disables the ADC module.
Kojto 111:4336505e4b1c 624 *
Kojto 111:4336505e4b1c 625 * Disables an ADC module that was previously enabled.
Kojto 111:4336505e4b1c 626 *
Kojto 111:4336505e4b1c 627 * \param[in] module_inst Pointer to the ADC software instance struct
Kojto 111:4336505e4b1c 628 */
Kojto 111:4336505e4b1c 629 static inline enum status_code adc_disable(
Kojto 111:4336505e4b1c 630 struct adc_module *const module_inst)
Kojto 111:4336505e4b1c 631 {
Kojto 111:4336505e4b1c 632 Assert(module_inst);
Kojto 111:4336505e4b1c 633 Assert(module_inst->hw);
Kojto 111:4336505e4b1c 634
Kojto 111:4336505e4b1c 635 Adc *const adc_module = module_inst->hw;
Kojto 111:4336505e4b1c 636
Kojto 111:4336505e4b1c 637 #if ADC_CALLBACK_MODE == true
Kojto 111:4336505e4b1c 638 # if (ADC_INST_NUM > 1)
Kojto 111:4336505e4b1c 639 system_interrupt_disable(_adc_interrupt_get_interrupt_vector(
Kojto 111:4336505e4b1c 640 _adc_get_inst_index(adc_module)));
Kojto 111:4336505e4b1c 641 # elif (SAMC20)
Kojto 111:4336505e4b1c 642 system_interrupt_disable(SYSTEM_INTERRUPT_MODULE_ADC0);
Kojto 111:4336505e4b1c 643 # else
Kojto 111:4336505e4b1c 644 system_interrupt_disable(SYSTEM_INTERRUPT_MODULE_ADC);
Kojto 111:4336505e4b1c 645 # endif
Kojto 111:4336505e4b1c 646 #endif
Kojto 111:4336505e4b1c 647
Kojto 111:4336505e4b1c 648 while (adc_is_syncing(module_inst)) {
Kojto 111:4336505e4b1c 649 /* Wait for synchronization */
Kojto 111:4336505e4b1c 650 }
Kojto 111:4336505e4b1c 651
Kojto 111:4336505e4b1c 652 adc_module->CTRLA.reg &= ~ADC_CTRLA_ENABLE;
Kojto 111:4336505e4b1c 653
Kojto 111:4336505e4b1c 654 while (adc_is_syncing(module_inst)) {
Kojto 111:4336505e4b1c 655 /* Wait for synchronization */
Kojto 111:4336505e4b1c 656 }
Kojto 111:4336505e4b1c 657 return STATUS_OK;
Kojto 111:4336505e4b1c 658 }
Kojto 111:4336505e4b1c 659
Kojto 111:4336505e4b1c 660 /**
Kojto 111:4336505e4b1c 661 * \brief Resets the ADC module.
Kojto 111:4336505e4b1c 662 *
Kojto 111:4336505e4b1c 663 * Resets an ADC module, clearing all module state and registers to their
Kojto 111:4336505e4b1c 664 * default values.
Kojto 111:4336505e4b1c 665 *
Kojto 111:4336505e4b1c 666 * \param[in] module_inst Pointer to the ADC software instance struct
Kojto 111:4336505e4b1c 667 */
Kojto 111:4336505e4b1c 668 static inline enum status_code adc_reset(
Kojto 111:4336505e4b1c 669 struct adc_module *const module_inst)
Kojto 111:4336505e4b1c 670 {
Kojto 111:4336505e4b1c 671 /* Sanity check arguments */
Kojto 111:4336505e4b1c 672 Assert(module_inst);
Kojto 111:4336505e4b1c 673 Assert(module_inst->hw);
Kojto 111:4336505e4b1c 674
Kojto 111:4336505e4b1c 675 Adc *const adc_module = module_inst->hw;
Kojto 111:4336505e4b1c 676
Kojto 111:4336505e4b1c 677 /* Disable to make sure the pipeline is flushed before reset */
Kojto 111:4336505e4b1c 678 adc_disable(module_inst);
Kojto 111:4336505e4b1c 679
Kojto 111:4336505e4b1c 680 /* Software reset the module */
Kojto 111:4336505e4b1c 681 adc_module->CTRLA.reg |= ADC_CTRLA_SWRST;
Kojto 111:4336505e4b1c 682
Kojto 111:4336505e4b1c 683 while (adc_is_syncing(module_inst)) {
Kojto 111:4336505e4b1c 684 /* Wait for synchronization */
Kojto 111:4336505e4b1c 685 }
Kojto 111:4336505e4b1c 686 return STATUS_OK;
Kojto 111:4336505e4b1c 687 }
Kojto 111:4336505e4b1c 688
Kojto 111:4336505e4b1c 689
Kojto 111:4336505e4b1c 690 /**
Kojto 111:4336505e4b1c 691 * \brief Enables an ADC event input or output.
Kojto 111:4336505e4b1c 692 *
Kojto 111:4336505e4b1c 693 * Enables one or more input or output events to or from the ADC module. See
Kojto 111:4336505e4b1c 694 * \ref adc_events "Struct adc_events" for a list of events this module supports.
Kojto 111:4336505e4b1c 695 *
Kojto 111:4336505e4b1c 696 * \note Events cannot be altered while the module is enabled.
Kojto 111:4336505e4b1c 697 *
Kojto 111:4336505e4b1c 698 * \param[in] module_inst Software instance for the ADC peripheral
Kojto 111:4336505e4b1c 699 * \param[in] events Struct containing flags of events to enable
Kojto 111:4336505e4b1c 700 */
Kojto 111:4336505e4b1c 701 static inline void adc_enable_events(
Kojto 111:4336505e4b1c 702 struct adc_module *const module_inst,
Kojto 111:4336505e4b1c 703 struct adc_events *const events)
Kojto 111:4336505e4b1c 704 {
Kojto 111:4336505e4b1c 705 /* Sanity check arguments */
Kojto 111:4336505e4b1c 706 Assert(module_inst);
Kojto 111:4336505e4b1c 707 Assert(module_inst->hw);
Kojto 111:4336505e4b1c 708 Assert(events);
Kojto 111:4336505e4b1c 709
Kojto 111:4336505e4b1c 710 Adc *const adc_module = module_inst->hw;
Kojto 111:4336505e4b1c 711
Kojto 111:4336505e4b1c 712 uint32_t event_mask = 0;
Kojto 111:4336505e4b1c 713
Kojto 111:4336505e4b1c 714 /* Configure Window Monitor event */
Kojto 111:4336505e4b1c 715 if (events->generate_event_on_window_monitor) {
Kojto 111:4336505e4b1c 716 event_mask |= ADC_EVCTRL_WINMONEO;
Kojto 111:4336505e4b1c 717 }
Kojto 111:4336505e4b1c 718
Kojto 111:4336505e4b1c 719 /* Configure Result Ready event */
Kojto 111:4336505e4b1c 720 if (events->generate_event_on_conversion_done) {
Kojto 111:4336505e4b1c 721 event_mask |= ADC_EVCTRL_RESRDYEO;
Kojto 111:4336505e4b1c 722 }
Kojto 111:4336505e4b1c 723
Kojto 111:4336505e4b1c 724 adc_module->EVCTRL.reg |= event_mask;
Kojto 111:4336505e4b1c 725 }
Kojto 111:4336505e4b1c 726
Kojto 111:4336505e4b1c 727 /**
Kojto 111:4336505e4b1c 728 * \brief Disables an ADC event input or output.
Kojto 111:4336505e4b1c 729 *
Kojto 111:4336505e4b1c 730 * Disables one or more input or output events to or from the ADC module. See
Kojto 111:4336505e4b1c 731 * \ref adc_events "Struct adc_events" for a list of events this module supports.
Kojto 111:4336505e4b1c 732 *
Kojto 111:4336505e4b1c 733 * \note Events cannot be altered while the module is enabled.
Kojto 111:4336505e4b1c 734 *
Kojto 111:4336505e4b1c 735 * \param[in] module_inst Software instance for the ADC peripheral
Kojto 111:4336505e4b1c 736 * \param[in] events Struct containing flags of events to disable
Kojto 111:4336505e4b1c 737 */
Kojto 111:4336505e4b1c 738 static inline void adc_disable_events(
Kojto 111:4336505e4b1c 739 struct adc_module *const module_inst,
Kojto 111:4336505e4b1c 740 struct adc_events *const events)
Kojto 111:4336505e4b1c 741 {
Kojto 111:4336505e4b1c 742 /* Sanity check arguments */
Kojto 111:4336505e4b1c 743 Assert(module_inst);
Kojto 111:4336505e4b1c 744 Assert(module_inst->hw);
Kojto 111:4336505e4b1c 745 Assert(events);
Kojto 111:4336505e4b1c 746
Kojto 111:4336505e4b1c 747 Adc *const adc_module = module_inst->hw;
Kojto 111:4336505e4b1c 748
Kojto 111:4336505e4b1c 749 uint32_t event_mask = 0;
Kojto 111:4336505e4b1c 750
Kojto 111:4336505e4b1c 751 /* Configure Window Monitor event */
Kojto 111:4336505e4b1c 752 if (events->generate_event_on_window_monitor) {
Kojto 111:4336505e4b1c 753 event_mask |= ADC_EVCTRL_WINMONEO;
Kojto 111:4336505e4b1c 754 }
Kojto 111:4336505e4b1c 755
Kojto 111:4336505e4b1c 756 /* Configure Result Ready event */
Kojto 111:4336505e4b1c 757 if (events->generate_event_on_conversion_done) {
Kojto 111:4336505e4b1c 758 event_mask |= ADC_EVCTRL_RESRDYEO;
Kojto 111:4336505e4b1c 759 }
Kojto 111:4336505e4b1c 760
Kojto 111:4336505e4b1c 761 adc_module->EVCTRL.reg &= ~event_mask;
Kojto 111:4336505e4b1c 762 }
Kojto 111:4336505e4b1c 763
Kojto 111:4336505e4b1c 764 /**
Kojto 111:4336505e4b1c 765 * \brief Starts an ADC conversion.
Kojto 111:4336505e4b1c 766 *
Kojto 111:4336505e4b1c 767 * Starts a new ADC conversion.
Kojto 111:4336505e4b1c 768 *
Kojto 111:4336505e4b1c 769 * \param[in] module_inst Pointer to the ADC software instance struct
Kojto 111:4336505e4b1c 770 */
Kojto 111:4336505e4b1c 771 static inline void adc_start_conversion(
Kojto 111:4336505e4b1c 772 struct adc_module *const module_inst)
Kojto 111:4336505e4b1c 773 {
Kojto 111:4336505e4b1c 774 Assert(module_inst);
Kojto 111:4336505e4b1c 775 Assert(module_inst->hw);
Kojto 111:4336505e4b1c 776
Kojto 111:4336505e4b1c 777 Adc *const adc_module = module_inst->hw;
Kojto 111:4336505e4b1c 778
Kojto 111:4336505e4b1c 779 while (adc_is_syncing(module_inst)) {
Kojto 111:4336505e4b1c 780 /* Wait for synchronization */
Kojto 111:4336505e4b1c 781 }
Kojto 111:4336505e4b1c 782
Kojto 111:4336505e4b1c 783 adc_module->SWTRIG.reg |= ADC_SWTRIG_START;
Kojto 111:4336505e4b1c 784
Kojto 111:4336505e4b1c 785 while (adc_is_syncing(module_inst)) {
Kojto 111:4336505e4b1c 786 /* Wait for synchronization */
Kojto 111:4336505e4b1c 787 }
Kojto 111:4336505e4b1c 788 }
Kojto 111:4336505e4b1c 789
Kojto 111:4336505e4b1c 790 /**
Kojto 111:4336505e4b1c 791 * \brief Reads the ADC result.
Kojto 111:4336505e4b1c 792 *
Kojto 111:4336505e4b1c 793 * Reads the result from an ADC conversion that was previously started.
Kojto 111:4336505e4b1c 794 *
Kojto 111:4336505e4b1c 795 * \param[in] module_inst Pointer to the ADC software instance struct
Kojto 111:4336505e4b1c 796 * \param[out] result Pointer to store the result value in
Kojto 111:4336505e4b1c 797 *
Kojto 111:4336505e4b1c 798 * \return Status of the ADC read request.
Kojto 111:4336505e4b1c 799 * \retval STATUS_OK The result was retrieved successfully
Kojto 111:4336505e4b1c 800 * \retval STATUS_BUSY A conversion result was not ready
Kojto 111:4336505e4b1c 801 * \retval STATUS_ERR_OVERFLOW The result register has been overwritten by the
Kojto 111:4336505e4b1c 802 * ADC module before the result was read by the software
Kojto 111:4336505e4b1c 803 */
Kojto 111:4336505e4b1c 804 static inline enum status_code adc_read(
Kojto 111:4336505e4b1c 805 struct adc_module *const module_inst,
Kojto 111:4336505e4b1c 806 uint16_t *result)
Kojto 111:4336505e4b1c 807 {
Kojto 111:4336505e4b1c 808 Assert(module_inst);
Kojto 111:4336505e4b1c 809 Assert(module_inst->hw);
Kojto 111:4336505e4b1c 810 Assert(result);
Kojto 111:4336505e4b1c 811
Kojto 111:4336505e4b1c 812 if (!(adc_get_status(module_inst) & ADC_STATUS_RESULT_READY)) {
Kojto 111:4336505e4b1c 813 /* Result not ready */
Kojto 111:4336505e4b1c 814 return STATUS_BUSY;
Kojto 111:4336505e4b1c 815 }
Kojto 111:4336505e4b1c 816
Kojto 111:4336505e4b1c 817 Adc *const adc_module = module_inst->hw;
Kojto 111:4336505e4b1c 818
Kojto 111:4336505e4b1c 819 #if (SAMD) || (SAMR21)
Kojto 111:4336505e4b1c 820 while (adc_is_syncing(module_inst)) {
Kojto 111:4336505e4b1c 821 /* Wait for synchronization */
Kojto 111:4336505e4b1c 822 }
Kojto 111:4336505e4b1c 823 #endif
Kojto 111:4336505e4b1c 824
Kojto 111:4336505e4b1c 825 /* Get ADC result */
Kojto 111:4336505e4b1c 826 *result = adc_module->RESULT.reg;
Kojto 111:4336505e4b1c 827
Kojto 111:4336505e4b1c 828 /* Reset ready flag */
Kojto 111:4336505e4b1c 829 adc_clear_status(module_inst, ADC_STATUS_RESULT_READY);
Kojto 111:4336505e4b1c 830
Kojto 111:4336505e4b1c 831 if (adc_get_status(module_inst) & ADC_STATUS_OVERRUN) {
Kojto 111:4336505e4b1c 832 adc_clear_status(module_inst, ADC_STATUS_OVERRUN);
Kojto 111:4336505e4b1c 833 return STATUS_ERR_OVERFLOW;
Kojto 111:4336505e4b1c 834 }
Kojto 111:4336505e4b1c 835
Kojto 111:4336505e4b1c 836 return STATUS_OK;
Kojto 111:4336505e4b1c 837 }
Kojto 111:4336505e4b1c 838
Kojto 111:4336505e4b1c 839 /** @} */
Kojto 111:4336505e4b1c 840
Kojto 111:4336505e4b1c 841 /**
Kojto 111:4336505e4b1c 842 * \name Runtime Changes of ADC Module
Kojto 111:4336505e4b1c 843 * @{
Kojto 111:4336505e4b1c 844 */
Kojto 111:4336505e4b1c 845
Kojto 111:4336505e4b1c 846 /**
Kojto 111:4336505e4b1c 847 * \brief Flushes the ADC pipeline.
Kojto 111:4336505e4b1c 848 *
Kojto 111:4336505e4b1c 849 * Flushes the pipeline and restarts the ADC clock on the next peripheral clock
Kojto 111:4336505e4b1c 850 * edge. All conversions in progress will be lost. When flush is complete, the
Kojto 111:4336505e4b1c 851 * module will resume where it left off.
Kojto 111:4336505e4b1c 852 *
Kojto 111:4336505e4b1c 853 * \param[in] module_inst Pointer to the ADC software instance struct
Kojto 111:4336505e4b1c 854 */
Kojto 111:4336505e4b1c 855 static inline void adc_flush(
Kojto 111:4336505e4b1c 856 struct adc_module *const module_inst)
Kojto 111:4336505e4b1c 857 {
Kojto 111:4336505e4b1c 858 Assert(module_inst);
Kojto 111:4336505e4b1c 859 Assert(module_inst->hw);
Kojto 111:4336505e4b1c 860
Kojto 111:4336505e4b1c 861 Adc *const adc_module = module_inst->hw;
Kojto 111:4336505e4b1c 862
Kojto 111:4336505e4b1c 863 while (adc_is_syncing(module_inst)) {
Kojto 111:4336505e4b1c 864 /* Wait for synchronization */
Kojto 111:4336505e4b1c 865 }
Kojto 111:4336505e4b1c 866
Kojto 111:4336505e4b1c 867 adc_module->SWTRIG.reg |= ADC_SWTRIG_FLUSH;
Kojto 111:4336505e4b1c 868
Kojto 111:4336505e4b1c 869 while (adc_is_syncing(module_inst)) {
Kojto 111:4336505e4b1c 870 /* Wait for synchronization */
Kojto 111:4336505e4b1c 871 }
Kojto 111:4336505e4b1c 872 }
Kojto 111:4336505e4b1c 873 void adc_set_window_mode(
Kojto 111:4336505e4b1c 874 struct adc_module *const module_inst,
Kojto 111:4336505e4b1c 875 const enum adc_window_mode window_mode,
Kojto 111:4336505e4b1c 876 const int16_t window_lower_value,
Kojto 111:4336505e4b1c 877 const int16_t window_upper_value);
Kojto 111:4336505e4b1c 878
Kojto 111:4336505e4b1c 879 /**
Kojto 111:4336505e4b1c 880 * \brief Sets positive ADC input pin.
Kojto 111:4336505e4b1c 881 *
Kojto 111:4336505e4b1c 882 * Sets the positive ADC input pin selection.
Kojto 111:4336505e4b1c 883 *
Kojto 111:4336505e4b1c 884 * \param[in] module_inst Pointer to the ADC software instance struct
Kojto 111:4336505e4b1c 885 * \param[in] positive_input Positive input pin
Kojto 111:4336505e4b1c 886 */
Kojto 111:4336505e4b1c 887 static inline void adc_set_positive_input(
Kojto 111:4336505e4b1c 888 struct adc_module *const module_inst,
Kojto 111:4336505e4b1c 889 const enum adc_positive_input positive_input)
Kojto 111:4336505e4b1c 890 {
Kojto 111:4336505e4b1c 891 /* Sanity check arguments */
Kojto 111:4336505e4b1c 892 Assert(module_inst);
Kojto 111:4336505e4b1c 893 Assert(module_inst->hw);
Kojto 111:4336505e4b1c 894
Kojto 111:4336505e4b1c 895 Adc *const adc_module = module_inst->hw;
Kojto 111:4336505e4b1c 896
Kojto 111:4336505e4b1c 897 while (adc_is_syncing(module_inst)) {
Kojto 111:4336505e4b1c 898 /* Wait for synchronization */
Kojto 111:4336505e4b1c 899 }
Kojto 111:4336505e4b1c 900
Kojto 111:4336505e4b1c 901 /* Set positive input pin */
Kojto 111:4336505e4b1c 902 adc_module->INPUTCTRL.reg =
Kojto 111:4336505e4b1c 903 (adc_module->INPUTCTRL.reg & ~ADC_INPUTCTRL_MUXPOS_Msk) |
Kojto 111:4336505e4b1c 904 (positive_input);
Kojto 111:4336505e4b1c 905
Kojto 111:4336505e4b1c 906 while (adc_is_syncing(module_inst)) {
Kojto 111:4336505e4b1c 907 /* Wait for synchronization */
Kojto 111:4336505e4b1c 908 }
Kojto 111:4336505e4b1c 909 }
Kojto 111:4336505e4b1c 910
Kojto 111:4336505e4b1c 911
Kojto 111:4336505e4b1c 912 /**
Kojto 111:4336505e4b1c 913 * \brief Sets negative ADC input pin for differential mode.
Kojto 111:4336505e4b1c 914 *
Kojto 111:4336505e4b1c 915 * Sets the negative ADC input pin, when the ADC is configured in differential
Kojto 111:4336505e4b1c 916 * mode.
Kojto 111:4336505e4b1c 917 *
Kojto 111:4336505e4b1c 918 * \param[in] module_inst Pointer to the ADC software instance struct
Kojto 111:4336505e4b1c 919 * \param[in] negative_input Negative input pin
Kojto 111:4336505e4b1c 920 */
Kojto 111:4336505e4b1c 921 static inline void adc_set_negative_input(
Kojto 111:4336505e4b1c 922 struct adc_module *const module_inst,
Kojto 111:4336505e4b1c 923 const enum adc_negative_input negative_input)
Kojto 111:4336505e4b1c 924 {
Kojto 111:4336505e4b1c 925 /* Sanity check arguments */
Kojto 111:4336505e4b1c 926 Assert(module_inst);
Kojto 111:4336505e4b1c 927 Assert(module_inst->hw);
Kojto 111:4336505e4b1c 928
Kojto 111:4336505e4b1c 929 Adc *const adc_module = module_inst->hw;
Kojto 111:4336505e4b1c 930
Kojto 111:4336505e4b1c 931 while (adc_is_syncing(module_inst)) {
Kojto 111:4336505e4b1c 932 /* Wait for synchronization */
Kojto 111:4336505e4b1c 933 }
Kojto 111:4336505e4b1c 934
Kojto 111:4336505e4b1c 935 /* Set negative input pin */
Kojto 111:4336505e4b1c 936 adc_module->INPUTCTRL.reg =
Kojto 111:4336505e4b1c 937 (adc_module->INPUTCTRL.reg & ~ADC_INPUTCTRL_MUXNEG_Msk) |
Kojto 111:4336505e4b1c 938 (negative_input);
Kojto 111:4336505e4b1c 939
Kojto 111:4336505e4b1c 940 while (adc_is_syncing(module_inst)) {
Kojto 111:4336505e4b1c 941 /* Wait for synchronization */
Kojto 111:4336505e4b1c 942 }
Kojto 111:4336505e4b1c 943 }
Kojto 111:4336505e4b1c 944
Kojto 111:4336505e4b1c 945 /** @} */
Kojto 111:4336505e4b1c 946
Kojto 111:4336505e4b1c 947 #if ADC_CALLBACK_MODE == true
Kojto 111:4336505e4b1c 948 /**
Kojto 111:4336505e4b1c 949 * \name Enable and Disable Interrupts
Kojto 111:4336505e4b1c 950 * @{
Kojto 111:4336505e4b1c 951 */
Kojto 111:4336505e4b1c 952
Kojto 111:4336505e4b1c 953 /**
Kojto 111:4336505e4b1c 954 * \brief Enable interrupt.
Kojto 111:4336505e4b1c 955 *
Kojto 111:4336505e4b1c 956 * Enable the given interrupt request from the ADC module.
Kojto 111:4336505e4b1c 957 *
Kojto 111:4336505e4b1c 958 * \param[in] module_inst Pointer to the ADC software instance struct
Kojto 111:4336505e4b1c 959 * \param[in] interrupt Interrupt to enable
Kojto 111:4336505e4b1c 960 */
Kojto 111:4336505e4b1c 961 static inline void adc_enable_interrupt(struct adc_module *const module_inst,
Kojto 111:4336505e4b1c 962 enum adc_interrupt_flag interrupt)
Kojto 111:4336505e4b1c 963 {
Kojto 111:4336505e4b1c 964 /* Sanity check arguments */
Kojto 111:4336505e4b1c 965 Assert(module_inst);
Kojto 111:4336505e4b1c 966 Assert(module_inst->hw);
Kojto 111:4336505e4b1c 967
Kojto 111:4336505e4b1c 968 Adc *const adc_module = module_inst->hw;
Kojto 111:4336505e4b1c 969 /* Enable interrupt */
Kojto 111:4336505e4b1c 970 adc_module->INTENSET.reg = interrupt;
Kojto 111:4336505e4b1c 971 }
Kojto 111:4336505e4b1c 972
Kojto 111:4336505e4b1c 973 /**
Kojto 111:4336505e4b1c 974 * \brief Disable interrupt.
Kojto 111:4336505e4b1c 975 *
Kojto 111:4336505e4b1c 976 * Disable the given interrupt request from the ADC module.
Kojto 111:4336505e4b1c 977 *
Kojto 111:4336505e4b1c 978 * \param[in] module_inst Pointer to the ADC software instance struct
Kojto 111:4336505e4b1c 979 * \param[in] interrupt Interrupt to disable
Kojto 111:4336505e4b1c 980 */
Kojto 111:4336505e4b1c 981 static inline void adc_disable_interrupt(struct adc_module *const module_inst,
Kojto 111:4336505e4b1c 982 enum adc_interrupt_flag interrupt)
Kojto 111:4336505e4b1c 983 {
Kojto 111:4336505e4b1c 984 /* Sanity check arguments */
Kojto 111:4336505e4b1c 985 Assert(module_inst);
Kojto 111:4336505e4b1c 986 Assert(module_inst->hw);
Kojto 111:4336505e4b1c 987
Kojto 111:4336505e4b1c 988 Adc *const adc_module = module_inst->hw;
Kojto 111:4336505e4b1c 989 /* Enable interrupt */
Kojto 111:4336505e4b1c 990 adc_module->INTENCLR.reg = interrupt;
Kojto 111:4336505e4b1c 991 }
Kojto 111:4336505e4b1c 992
Kojto 111:4336505e4b1c 993 /** @} */
Kojto 111:4336505e4b1c 994 #endif /* ADC_CALLBACK_MODE == true */
Kojto 111:4336505e4b1c 995
Kojto 111:4336505e4b1c 996 #ifdef __cplusplus
Kojto 111:4336505e4b1c 997 }
Kojto 111:4336505e4b1c 998 #endif
Kojto 111:4336505e4b1c 999
Kojto 111:4336505e4b1c 1000 /** @} */
Kojto 111:4336505e4b1c 1001
Kojto 111:4336505e4b1c 1002
Kojto 111:4336505e4b1c 1003 /**
Kojto 111:4336505e4b1c 1004 * \page asfdoc_sam0_adc_extra Extra Information for ADC Driver
Kojto 111:4336505e4b1c 1005 *
Kojto 111:4336505e4b1c 1006 * \section asfdoc_sam0_adc_extra_acronyms Acronyms
Kojto 111:4336505e4b1c 1007 * Below is a table listing the acronyms used in this module, along with their
Kojto 111:4336505e4b1c 1008 * intended meanings.
Kojto 111:4336505e4b1c 1009 *
Kojto 111:4336505e4b1c 1010 * <table>
Kojto 111:4336505e4b1c 1011 * <tr>
Kojto 111:4336505e4b1c 1012 * <th>Acronym</th>
Kojto 111:4336505e4b1c 1013 * <th>Description</th>
Kojto 111:4336505e4b1c 1014 * </tr>
Kojto 111:4336505e4b1c 1015 * <tr>
Kojto 111:4336505e4b1c 1016 * <td>ADC</td>
Kojto 111:4336505e4b1c 1017 * <td>Analog-to-Digital Converter</td>
Kojto 111:4336505e4b1c 1018 * </tr>
Kojto 111:4336505e4b1c 1019 * <tr>
Kojto 111:4336505e4b1c 1020 * <td>DAC</td>
Kojto 111:4336505e4b1c 1021 * <td>Digital-to-Analog Converter</td>
Kojto 111:4336505e4b1c 1022 * </tr>
Kojto 111:4336505e4b1c 1023 * <tr>
Kojto 111:4336505e4b1c 1024 * <td>LSB</td>
Kojto 111:4336505e4b1c 1025 * <td>Least Significant Bit</td>
Kojto 111:4336505e4b1c 1026 * </tr>
Kojto 111:4336505e4b1c 1027 * <tr>
Kojto 111:4336505e4b1c 1028 * <td>MSB</td>
Kojto 111:4336505e4b1c 1029 * <td>Most Significant Bit</td>
Kojto 111:4336505e4b1c 1030 * </tr>
Kojto 111:4336505e4b1c 1031 * <tr>
Kojto 111:4336505e4b1c 1032 * <td>DMA</td>
Kojto 111:4336505e4b1c 1033 * <td>Direct Memory Access</td>
Kojto 111:4336505e4b1c 1034 * </tr>
Kojto 111:4336505e4b1c 1035 * </table>
Kojto 111:4336505e4b1c 1036 *
Kojto 111:4336505e4b1c 1037 *
Kojto 111:4336505e4b1c 1038 * \section asfdoc_sam0_adc_extra_dependencies Dependencies
Kojto 111:4336505e4b1c 1039 * This driver has the following dependencies:
Kojto 111:4336505e4b1c 1040 *
Kojto 111:4336505e4b1c 1041 * - \ref asfdoc_sam0_system_pinmux_group "System Pin Multiplexer Driver"
Kojto 111:4336505e4b1c 1042 *
Kojto 111:4336505e4b1c 1043 *
Kojto 111:4336505e4b1c 1044 * \section asfdoc_sam0_adc_extra_errata Errata
Kojto 111:4336505e4b1c 1045 * There are no errata related to this driver.
Kojto 111:4336505e4b1c 1046 *
Kojto 111:4336505e4b1c 1047 *
Kojto 111:4336505e4b1c 1048 * \section asfdoc_sam0_adc_extra_history Module History
Kojto 111:4336505e4b1c 1049 * An overview of the module history is presented in the table below, with
Kojto 111:4336505e4b1c 1050 * details on the enhancements and fixes made to the module since its first
Kojto 111:4336505e4b1c 1051 * release. The current version of this corresponds to the newest version in
Kojto 111:4336505e4b1c 1052 * the table.
Kojto 111:4336505e4b1c 1053 *
Kojto 111:4336505e4b1c 1054 * <table>
Kojto 111:4336505e4b1c 1055 * <tr>
Kojto 111:4336505e4b1c 1056 * <th>Changelog</th>
Kojto 111:4336505e4b1c 1057 * </tr>
Kojto 111:4336505e4b1c 1058 * \if DEVICE_SAML21_SUPPORT
Kojto 111:4336505e4b1c 1059 * <tr>
Kojto 111:4336505e4b1c 1060 * <td>Initial Release</td>
Kojto 111:4336505e4b1c 1061 * </tr>
Kojto 111:4336505e4b1c 1062 * \else
Kojto 111:4336505e4b1c 1063 * <tr>
Kojto 111:4336505e4b1c 1064 * <td>Added support for SAMR21</td>
Kojto 111:4336505e4b1c 1065 * </tr>
Kojto 111:4336505e4b1c 1066 * <tr>
Kojto 111:4336505e4b1c 1067 * <td>Added support for SAMD21 and new DMA quick start guide</td>
Kojto 111:4336505e4b1c 1068 * </tr>
Kojto 111:4336505e4b1c 1069 * <tr>
Kojto 111:4336505e4b1c 1070 * <td>Added ADC calibration constant loading from the device signature
Kojto 111:4336505e4b1c 1071 * row when the module is initialized</td>
Kojto 111:4336505e4b1c 1072 * </tr>
Kojto 111:4336505e4b1c 1073 * <tr>
Kojto 111:4336505e4b1c 1074 * <td>Initial Release</td>
Kojto 111:4336505e4b1c 1075 * </tr>
Kojto 111:4336505e4b1c 1076 * \endif
Kojto 111:4336505e4b1c 1077 * </table>
Kojto 111:4336505e4b1c 1078 */
Kojto 111:4336505e4b1c 1079
Kojto 111:4336505e4b1c 1080 /**
Kojto 111:4336505e4b1c 1081 * \page asfdoc_sam0_adc_exqsg Examples for ADC Driver
Kojto 111:4336505e4b1c 1082 *
Kojto 111:4336505e4b1c 1083 * This is a list of the available Quick Start guides (QSGs) and example
Kojto 111:4336505e4b1c 1084 * applications for \ref asfdoc_sam0_adc_group. QSGs are simple examples with
Kojto 111:4336505e4b1c 1085 * step-by-step instructions to configure and use this driver in a selection of
Kojto 111:4336505e4b1c 1086 * use cases. Note that a QSG can be compiled as a standalone application or be
Kojto 111:4336505e4b1c 1087 * added to the user application.
Kojto 111:4336505e4b1c 1088 *
Kojto 111:4336505e4b1c 1089 * - \subpage asfdoc_sam0_adc_basic_use_case
Kojto 111:4336505e4b1c 1090 * \if ADC_CALLBACK_MODE
Kojto 111:4336505e4b1c 1091 * - \subpage asfdoc_sam0_adc_basic_use_case_callback
Kojto 111:4336505e4b1c 1092 * \endif
Kojto 111:4336505e4b1c 1093 * - \subpage asfdoc_sam0_adc_dma_use_case
Kojto 111:4336505e4b1c 1094 *
Kojto 111:4336505e4b1c 1095 * \page asfdoc_sam0_adc_document_revision_history Document Revision History
Kojto 111:4336505e4b1c 1096 *
Kojto 111:4336505e4b1c 1097 * <table>
Kojto 111:4336505e4b1c 1098 * <tr>
Kojto 111:4336505e4b1c 1099 * <th>Doc. Rev.</td>
Kojto 111:4336505e4b1c 1100 * <th>Date</td>
Kojto 111:4336505e4b1c 1101 * <th>Comments</td>
Kojto 111:4336505e4b1c 1102 * </tr>
Kojto 111:4336505e4b1c 1103 * \if DEVICE_SAML21_SUPPORT
Kojto 111:4336505e4b1c 1104 * <tr>
Kojto 111:4336505e4b1c 1105 * <td>42451A</td>
Kojto 111:4336505e4b1c 1106 * <td>07/2015</td>
Kojto 111:4336505e4b1c 1107 * <td>Initial document release</td>
Kojto 111:4336505e4b1c 1108 * </tr>
Kojto 111:4336505e4b1c 1109 * \else
Kojto 111:4336505e4b1c 1110 * <tr>
Kojto 111:4336505e4b1c 1111 * <td>42109E</td>
Kojto 111:4336505e4b1c 1112 * <td>04/2015</td>
Kojto 111:4336505e4b1c 1113 * <td>Added support for SAMDAx.</td>
Kojto 111:4336505e4b1c 1114 * </tr>
Kojto 111:4336505e4b1c 1115 * <tr>
Kojto 111:4336505e4b1c 1116 * <td>42109D</td>
Kojto 111:4336505e4b1c 1117 * <td>12/2014</td>
Kojto 111:4336505e4b1c 1118 * <td>Added support for SAMR21 and SAMD10/D11</td>
Kojto 111:4336505e4b1c 1119 * </tr>
Kojto 111:4336505e4b1c 1120 * <tr>
Kojto 111:4336505e4b1c 1121 * <td>42109C</td>
Kojto 111:4336505e4b1c 1122 * <td>01/2014</td>
Kojto 111:4336505e4b1c 1123 * <td>Added support for SAMD21</td>
Kojto 111:4336505e4b1c 1124 * </tr>
Kojto 111:4336505e4b1c 1125 * <tr>
Kojto 111:4336505e4b1c 1126 * <td>42109B</td>
Kojto 111:4336505e4b1c 1127 * <td>06/2013</td>
Kojto 111:4336505e4b1c 1128 * <td>Added additional documentation on the event system. Corrected
Kojto 111:4336505e4b1c 1129 * documentation typos.</td>
Kojto 111:4336505e4b1c 1130 * </tr>
Kojto 111:4336505e4b1c 1131 * <tr>
Kojto 111:4336505e4b1c 1132 * <td>42109A</td>
Kojto 111:4336505e4b1c 1133 * <td>06/2013</td>
Kojto 111:4336505e4b1c 1134 * <td>Initial release</td>
Kojto 111:4336505e4b1c 1135 * </tr>
Kojto 111:4336505e4b1c 1136 * \endif
Kojto 111:4336505e4b1c 1137 * </table>
Kojto 111:4336505e4b1c 1138 */
Kojto 111:4336505e4b1c 1139
Kojto 111:4336505e4b1c 1140 #endif /* ADC_H_INCLUDED */