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:
Wed Feb 20 20:53:29 2019 +0000
Revision:
172:65be27845400
Parent:
171:3a7713b1edbc
mbed library release version 165

Who changed what in which revision?

UserRevisionLine numberNew contents of line
AnnaBridge 145:64910690c574 1 /*
AnnaBridge 145:64910690c574 2 * Copyright (c) 2015, Freescale Semiconductor, Inc.
AnnaBridge 145:64910690c574 3 * All rights reserved.
AnnaBridge 145:64910690c574 4 *
AnnaBridge 145:64910690c574 5 * Redistribution and use in source and binary forms, with or without modification,
AnnaBridge 145:64910690c574 6 * are permitted provided that the following conditions are met:
AnnaBridge 145:64910690c574 7 *
AnnaBridge 145:64910690c574 8 * o Redistributions of source code must retain the above copyright notice, this list
AnnaBridge 145:64910690c574 9 * of conditions and the following disclaimer.
AnnaBridge 145:64910690c574 10 *
AnnaBridge 145:64910690c574 11 * o Redistributions in binary form must reproduce the above copyright notice, this
AnnaBridge 145:64910690c574 12 * list of conditions and the following disclaimer in the documentation and/or
AnnaBridge 145:64910690c574 13 * other materials provided with the distribution.
AnnaBridge 145:64910690c574 14 *
AnnaBridge 145:64910690c574 15 * o Neither the name of Freescale Semiconductor, Inc. nor the names of its
AnnaBridge 145:64910690c574 16 * contributors may be used to endorse or promote products derived from this
AnnaBridge 145:64910690c574 17 * software without specific prior written permission.
AnnaBridge 145:64910690c574 18 *
AnnaBridge 145:64910690c574 19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
AnnaBridge 145:64910690c574 20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
AnnaBridge 145:64910690c574 21 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
AnnaBridge 145:64910690c574 22 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
AnnaBridge 145:64910690c574 23 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
AnnaBridge 145:64910690c574 24 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
AnnaBridge 145:64910690c574 25 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
AnnaBridge 145:64910690c574 26 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
AnnaBridge 145:64910690c574 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
AnnaBridge 145:64910690c574 28 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
AnnaBridge 145:64910690c574 29 */
AnnaBridge 145:64910690c574 30
AnnaBridge 145:64910690c574 31 #ifndef _FSL_ADC16_H_
AnnaBridge 145:64910690c574 32 #define _FSL_ADC16_H_
AnnaBridge 145:64910690c574 33
AnnaBridge 145:64910690c574 34 #include "fsl_common.h"
AnnaBridge 145:64910690c574 35
AnnaBridge 145:64910690c574 36 /*!
AnnaBridge 145:64910690c574 37 * @addtogroup adc16
AnnaBridge 145:64910690c574 38 * @{
AnnaBridge 145:64910690c574 39 */
AnnaBridge 145:64910690c574 40
AnnaBridge 145:64910690c574 41
AnnaBridge 145:64910690c574 42 /*******************************************************************************
AnnaBridge 145:64910690c574 43 * Definitions
AnnaBridge 145:64910690c574 44 ******************************************************************************/
AnnaBridge 145:64910690c574 45
AnnaBridge 145:64910690c574 46 /*! @name Driver version */
AnnaBridge 145:64910690c574 47 /*@{*/
AnnaBridge 145:64910690c574 48 /*! @brief ADC16 driver version 2.0.0. */
AnnaBridge 145:64910690c574 49 #define FSL_ADC16_DRIVER_VERSION (MAKE_VERSION(2, 0, 0))
AnnaBridge 145:64910690c574 50 /*@}*/
AnnaBridge 145:64910690c574 51
AnnaBridge 145:64910690c574 52 /*!
AnnaBridge 145:64910690c574 53 * @brief Channel status flags.
AnnaBridge 145:64910690c574 54 */
AnnaBridge 145:64910690c574 55 enum _adc16_channel_status_flags
AnnaBridge 145:64910690c574 56 {
AnnaBridge 145:64910690c574 57 kADC16_ChannelConversionDoneFlag = ADC_SC1_COCO_MASK, /*!< Conversion done. */
AnnaBridge 145:64910690c574 58 };
AnnaBridge 145:64910690c574 59
AnnaBridge 145:64910690c574 60 /*!
AnnaBridge 145:64910690c574 61 * @brief Converter status flags.
AnnaBridge 145:64910690c574 62 */
AnnaBridge 145:64910690c574 63 enum _adc16_status_flags
AnnaBridge 145:64910690c574 64 {
AnnaBridge 145:64910690c574 65 kADC16_ActiveFlag = ADC_SC2_ADACT_MASK, /*!< Converter is active. */
AnnaBridge 145:64910690c574 66 #if defined(FSL_FEATURE_ADC16_HAS_CALIBRATION) && FSL_FEATURE_ADC16_HAS_CALIBRATION
AnnaBridge 145:64910690c574 67 kADC16_CalibrationFailedFlag = ADC_SC3_CALF_MASK, /*!< Calibration is failed. */
AnnaBridge 145:64910690c574 68 #endif /* FSL_FEATURE_ADC16_HAS_CALIBRATION */
AnnaBridge 145:64910690c574 69 };
AnnaBridge 145:64910690c574 70
AnnaBridge 145:64910690c574 71 #if defined(FSL_FEATURE_ADC16_HAS_MUX_SELECT) && FSL_FEATURE_ADC16_HAS_MUX_SELECT
AnnaBridge 145:64910690c574 72 /*!
AnnaBridge 145:64910690c574 73 * @brief Channel multiplexer mode for each channel.
AnnaBridge 145:64910690c574 74 *
AnnaBridge 145:64910690c574 75 * For some ADC16 channels, there are two pin selections in channel multiplexer. For example, ADC0_SE4a and ADC0_SE4b
AnnaBridge 145:64910690c574 76 * are the different channels that share the same channel number.
AnnaBridge 145:64910690c574 77 */
AnnaBridge 145:64910690c574 78 typedef enum _adc_channel_mux_mode
AnnaBridge 145:64910690c574 79 {
AnnaBridge 145:64910690c574 80 kADC16_ChannelMuxA = 0U, /*!< For channel with channel mux a. */
AnnaBridge 145:64910690c574 81 kADC16_ChannelMuxB = 1U, /*!< For channel with channel mux b. */
AnnaBridge 145:64910690c574 82 } adc16_channel_mux_mode_t;
AnnaBridge 145:64910690c574 83 #endif /* FSL_FEATURE_ADC16_HAS_MUX_SELECT */
AnnaBridge 145:64910690c574 84
AnnaBridge 145:64910690c574 85 /*!
AnnaBridge 145:64910690c574 86 * @brief Clock divider for the converter.
AnnaBridge 145:64910690c574 87 */
AnnaBridge 145:64910690c574 88 typedef enum _adc16_clock_divider
AnnaBridge 145:64910690c574 89 {
AnnaBridge 145:64910690c574 90 kADC16_ClockDivider1 = 0U, /*!< For divider 1 from the input clock to the module. */
AnnaBridge 145:64910690c574 91 kADC16_ClockDivider2 = 1U, /*!< For divider 2 from the input clock to the module. */
AnnaBridge 145:64910690c574 92 kADC16_ClockDivider4 = 2U, /*!< For divider 4 from the input clock to the module. */
AnnaBridge 145:64910690c574 93 kADC16_ClockDivider8 = 3U, /*!< For divider 8 from the input clock to the module. */
AnnaBridge 145:64910690c574 94 } adc16_clock_divider_t;
AnnaBridge 145:64910690c574 95
AnnaBridge 145:64910690c574 96 /*!
AnnaBridge 145:64910690c574 97 *@brief Converter's resolution.
AnnaBridge 145:64910690c574 98 */
AnnaBridge 145:64910690c574 99 typedef enum _adc16_resolution
AnnaBridge 145:64910690c574 100 {
AnnaBridge 145:64910690c574 101 /* This group of enumeration is for internal use which is related to register setting. */
AnnaBridge 145:64910690c574 102 kADC16_Resolution8or9Bit = 0U, /*!< Single End 8-bit or Differential Sample 9-bit. */
AnnaBridge 145:64910690c574 103 kADC16_Resolution12or13Bit = 1U, /*!< Single End 12-bit or Differential Sample 13-bit. */
AnnaBridge 145:64910690c574 104 kADC16_Resolution10or11Bit = 2U, /*!< Single End 10-bit or Differential Sample 11-bit. */
AnnaBridge 145:64910690c574 105
AnnaBridge 145:64910690c574 106 /* This group of enumeration is for a public user. */
AnnaBridge 145:64910690c574 107 kADC16_ResolutionSE8Bit = kADC16_Resolution8or9Bit, /*!< Single End 8-bit. */
AnnaBridge 145:64910690c574 108 kADC16_ResolutionSE12Bit = kADC16_Resolution12or13Bit, /*!< Single End 12-bit. */
AnnaBridge 145:64910690c574 109 kADC16_ResolutionSE10Bit = kADC16_Resolution10or11Bit, /*!< Single End 10-bit. */
AnnaBridge 145:64910690c574 110 #if defined(FSL_FEATURE_ADC16_HAS_DIFF_MODE) && FSL_FEATURE_ADC16_HAS_DIFF_MODE
AnnaBridge 145:64910690c574 111 kADC16_ResolutionDF9Bit = kADC16_Resolution8or9Bit, /*!< Differential Sample 9-bit. */
AnnaBridge 145:64910690c574 112 kADC16_ResolutionDF13Bit = kADC16_Resolution12or13Bit, /*!< Differential Sample 13-bit. */
AnnaBridge 145:64910690c574 113 kADC16_ResolutionDF11Bit = kADC16_Resolution10or11Bit, /*!< Differential Sample 11-bit. */
AnnaBridge 145:64910690c574 114 #endif /* FSL_FEATURE_ADC16_HAS_DIFF_MODE */
AnnaBridge 145:64910690c574 115
AnnaBridge 145:64910690c574 116 #if defined(FSL_FEATURE_ADC16_MAX_RESOLUTION) && (FSL_FEATURE_ADC16_MAX_RESOLUTION >= 16U)
AnnaBridge 145:64910690c574 117 /* 16-bit is supported by default. */
AnnaBridge 145:64910690c574 118 kADC16_Resolution16Bit = 3U, /*!< Single End 16-bit or Differential Sample 16-bit. */
AnnaBridge 145:64910690c574 119 kADC16_ResolutionSE16Bit = kADC16_Resolution16Bit, /*!< Single End 16-bit. */
AnnaBridge 145:64910690c574 120 #if defined(FSL_FEATURE_ADC16_HAS_DIFF_MODE) && FSL_FEATURE_ADC16_HAS_DIFF_MODE
AnnaBridge 145:64910690c574 121 kADC16_ResolutionDF16Bit = kADC16_Resolution16Bit, /*!< Differential Sample 16-bit. */
AnnaBridge 145:64910690c574 122 #endif /* FSL_FEATURE_ADC16_HAS_DIFF_MODE */
AnnaBridge 145:64910690c574 123 #endif /* FSL_FEATURE_ADC16_MAX_RESOLUTION >= 16U */
AnnaBridge 145:64910690c574 124 } adc16_resolution_t;
AnnaBridge 145:64910690c574 125
AnnaBridge 145:64910690c574 126 /*!
AnnaBridge 145:64910690c574 127 * @brief Clock source.
AnnaBridge 145:64910690c574 128 */
AnnaBridge 145:64910690c574 129 typedef enum _adc16_clock_source
AnnaBridge 145:64910690c574 130 {
AnnaBridge 145:64910690c574 131 kADC16_ClockSourceAlt0 = 0U, /*!< Selection 0 of the clock source. */
AnnaBridge 145:64910690c574 132 kADC16_ClockSourceAlt1 = 1U, /*!< Selection 1 of the clock source. */
AnnaBridge 145:64910690c574 133 kADC16_ClockSourceAlt2 = 2U, /*!< Selection 2 of the clock source. */
AnnaBridge 145:64910690c574 134 kADC16_ClockSourceAlt3 = 3U, /*!< Selection 3 of the clock source. */
AnnaBridge 145:64910690c574 135
AnnaBridge 145:64910690c574 136 /* Chip defined clock source */
AnnaBridge 145:64910690c574 137 kADC16_ClockSourceAsynchronousClock = kADC16_ClockSourceAlt3, /*!< Using internal asynchronous clock. */
AnnaBridge 145:64910690c574 138 } adc16_clock_source_t;
AnnaBridge 145:64910690c574 139
AnnaBridge 145:64910690c574 140 /*!
AnnaBridge 145:64910690c574 141 * @brief Long sample mode.
AnnaBridge 145:64910690c574 142 */
AnnaBridge 145:64910690c574 143 typedef enum _adc16_long_sample_mode
AnnaBridge 145:64910690c574 144 {
AnnaBridge 145:64910690c574 145 kADC16_LongSampleCycle24 = 0U, /*!< 20 extra ADCK cycles, 24 ADCK cycles total. */
AnnaBridge 145:64910690c574 146 kADC16_LongSampleCycle16 = 1U, /*!< 12 extra ADCK cycles, 16 ADCK cycles total. */
AnnaBridge 145:64910690c574 147 kADC16_LongSampleCycle10 = 2U, /*!< 6 extra ADCK cycles, 10 ADCK cycles total. */
AnnaBridge 145:64910690c574 148 kADC16_LongSampleCycle6 = 3U, /*!< 2 extra ADCK cycles, 6 ADCK cycles total. */
AnnaBridge 145:64910690c574 149 kADC16_LongSampleDisabled = 4U, /*!< Disable the long sample feature. */
AnnaBridge 145:64910690c574 150 } adc16_long_sample_mode_t;
AnnaBridge 145:64910690c574 151
AnnaBridge 145:64910690c574 152 /*!
AnnaBridge 145:64910690c574 153 * @brief Reference voltage source.
AnnaBridge 145:64910690c574 154 */
AnnaBridge 145:64910690c574 155 typedef enum _adc16_reference_voltage_source
AnnaBridge 145:64910690c574 156 {
AnnaBridge 145:64910690c574 157 kADC16_ReferenceVoltageSourceVref = 0U, /*!< For external pins pair of VrefH and VrefL. */
AnnaBridge 145:64910690c574 158 kADC16_ReferenceVoltageSourceValt = 1U, /*!< For alternate reference pair of ValtH and ValtL. */
AnnaBridge 145:64910690c574 159 } adc16_reference_voltage_source_t;
AnnaBridge 145:64910690c574 160
AnnaBridge 145:64910690c574 161 #if defined(FSL_FEATURE_ADC16_HAS_HW_AVERAGE) && FSL_FEATURE_ADC16_HAS_HW_AVERAGE
AnnaBridge 145:64910690c574 162 /*!
AnnaBridge 145:64910690c574 163 * @brief Hardware average mode.
AnnaBridge 145:64910690c574 164 */
AnnaBridge 145:64910690c574 165 typedef enum _adc16_hardware_average_mode
AnnaBridge 145:64910690c574 166 {
AnnaBridge 145:64910690c574 167 kADC16_HardwareAverageCount4 = 0U, /*!< For hardware average with 4 samples. */
AnnaBridge 145:64910690c574 168 kADC16_HardwareAverageCount8 = 1U, /*!< For hardware average with 8 samples. */
AnnaBridge 145:64910690c574 169 kADC16_HardwareAverageCount16 = 2U, /*!< For hardware average with 16 samples. */
AnnaBridge 145:64910690c574 170 kADC16_HardwareAverageCount32 = 3U, /*!< For hardware average with 32 samples. */
AnnaBridge 145:64910690c574 171 kADC16_HardwareAverageDisabled = 4U, /*!< Disable the hardware average feature.*/
AnnaBridge 145:64910690c574 172 } adc16_hardware_average_mode_t;
AnnaBridge 145:64910690c574 173 #endif /* FSL_FEATURE_ADC16_HAS_HW_AVERAGE */
AnnaBridge 145:64910690c574 174
AnnaBridge 145:64910690c574 175 /*!
AnnaBridge 145:64910690c574 176 * @brief Hardware compare mode.
AnnaBridge 145:64910690c574 177 */
AnnaBridge 145:64910690c574 178 typedef enum _adc16_hardware_compare_mode
AnnaBridge 145:64910690c574 179 {
AnnaBridge 145:64910690c574 180 kADC16_HardwareCompareMode0 = 0U, /*!< x < value1. */
AnnaBridge 145:64910690c574 181 kADC16_HardwareCompareMode1 = 1U, /*!< x > value1. */
AnnaBridge 145:64910690c574 182 kADC16_HardwareCompareMode2 = 2U, /*!< if value1 <= value2, then x < value1 || x > value2;
AnnaBridge 145:64910690c574 183 else, value1 > x > value2. */
AnnaBridge 145:64910690c574 184 kADC16_HardwareCompareMode3 = 3U, /*!< if value1 <= value2, then value1 <= x <= value2;
AnnaBridge 145:64910690c574 185 else x >= value1 || x <= value2. */
AnnaBridge 145:64910690c574 186 } adc16_hardware_compare_mode_t;
AnnaBridge 145:64910690c574 187
AnnaBridge 145:64910690c574 188 #if defined(FSL_FEATURE_ADC16_HAS_PGA) && FSL_FEATURE_ADC16_HAS_PGA
AnnaBridge 145:64910690c574 189 /*!
AnnaBridge 145:64910690c574 190 * @brief PGA's Gain mode.
AnnaBridge 145:64910690c574 191 */
AnnaBridge 145:64910690c574 192 typedef enum _adc16_pga_gain
AnnaBridge 145:64910690c574 193 {
AnnaBridge 145:64910690c574 194 kADC16_PGAGainValueOf1 = 0U, /*!< For amplifier gain of 1. */
AnnaBridge 145:64910690c574 195 kADC16_PGAGainValueOf2 = 1U, /*!< For amplifier gain of 2. */
AnnaBridge 145:64910690c574 196 kADC16_PGAGainValueOf4 = 2U, /*!< For amplifier gain of 4. */
AnnaBridge 145:64910690c574 197 kADC16_PGAGainValueOf8 = 3U, /*!< For amplifier gain of 8. */
AnnaBridge 145:64910690c574 198 kADC16_PGAGainValueOf16 = 4U, /*!< For amplifier gain of 16. */
AnnaBridge 145:64910690c574 199 kADC16_PGAGainValueOf32 = 5U, /*!< For amplifier gain of 32. */
AnnaBridge 145:64910690c574 200 kADC16_PGAGainValueOf64 = 6U, /*!< For amplifier gain of 64. */
AnnaBridge 145:64910690c574 201 } adc16_pga_gain_t;
AnnaBridge 145:64910690c574 202 #endif /* FSL_FEATURE_ADC16_HAS_PGA */
AnnaBridge 145:64910690c574 203
AnnaBridge 145:64910690c574 204 /*!
AnnaBridge 145:64910690c574 205 * @brief ADC16 converter configuration.
AnnaBridge 145:64910690c574 206 */
AnnaBridge 145:64910690c574 207 typedef struct _adc16_config
AnnaBridge 145:64910690c574 208 {
AnnaBridge 145:64910690c574 209 adc16_reference_voltage_source_t referenceVoltageSource; /*!< Select the reference voltage source. */
AnnaBridge 145:64910690c574 210 adc16_clock_source_t clockSource; /*!< Select the input clock source to converter. */
AnnaBridge 145:64910690c574 211 bool enableAsynchronousClock; /*!< Enable the asynchronous clock output. */
AnnaBridge 145:64910690c574 212 adc16_clock_divider_t clockDivider; /*!< Select the divider of input clock source. */
AnnaBridge 145:64910690c574 213 adc16_resolution_t resolution; /*!< Select the sample resolution mode. */
AnnaBridge 145:64910690c574 214 adc16_long_sample_mode_t longSampleMode; /*!< Select the long sample mode. */
AnnaBridge 145:64910690c574 215 bool enableHighSpeed; /*!< Enable the high-speed mode. */
AnnaBridge 145:64910690c574 216 bool enableLowPower; /*!< Enable low power. */
AnnaBridge 145:64910690c574 217 bool enableContinuousConversion; /*!< Enable continuous conversion mode. */
AnnaBridge 145:64910690c574 218 } adc16_config_t;
AnnaBridge 145:64910690c574 219
AnnaBridge 145:64910690c574 220 /*!
AnnaBridge 145:64910690c574 221 * @brief ADC16 Hardware comparison configuration.
AnnaBridge 145:64910690c574 222 */
AnnaBridge 145:64910690c574 223 typedef struct _adc16_hardware_compare_config
AnnaBridge 145:64910690c574 224 {
AnnaBridge 145:64910690c574 225 adc16_hardware_compare_mode_t hardwareCompareMode; /*!< Select the hardware compare mode.
AnnaBridge 145:64910690c574 226 See "adc16_hardware_compare_mode_t". */
AnnaBridge 145:64910690c574 227 int16_t value1; /*!< Setting value1 for hardware compare mode. */
AnnaBridge 145:64910690c574 228 int16_t value2; /*!< Setting value2 for hardware compare mode. */
AnnaBridge 145:64910690c574 229 } adc16_hardware_compare_config_t;
AnnaBridge 145:64910690c574 230
AnnaBridge 145:64910690c574 231 /*!
AnnaBridge 145:64910690c574 232 * @brief ADC16 channel conversion configuration.
AnnaBridge 145:64910690c574 233 */
AnnaBridge 145:64910690c574 234 typedef struct _adc16_channel_config
AnnaBridge 145:64910690c574 235 {
AnnaBridge 145:64910690c574 236 uint32_t channelNumber; /*!< Setting the conversion channel number. The available range is 0-31.
AnnaBridge 145:64910690c574 237 See channel connection information for each chip in Reference
AnnaBridge 145:64910690c574 238 Manual document. */
AnnaBridge 145:64910690c574 239 bool enableInterruptOnConversionCompleted; /*!< Generate an interrupt request once the conversion is completed. */
AnnaBridge 145:64910690c574 240 #if defined(FSL_FEATURE_ADC16_HAS_DIFF_MODE) && FSL_FEATURE_ADC16_HAS_DIFF_MODE
AnnaBridge 145:64910690c574 241 bool enableDifferentialConversion; /*!< Using Differential sample mode. */
AnnaBridge 145:64910690c574 242 #endif /* FSL_FEATURE_ADC16_HAS_DIFF_MODE */
AnnaBridge 145:64910690c574 243 } adc16_channel_config_t;
AnnaBridge 145:64910690c574 244
AnnaBridge 145:64910690c574 245 #if defined(FSL_FEATURE_ADC16_HAS_PGA) && FSL_FEATURE_ADC16_HAS_PGA
AnnaBridge 145:64910690c574 246 /*!
AnnaBridge 145:64910690c574 247 * @brief ADC16 programmable gain amplifier configuration.
AnnaBridge 145:64910690c574 248 */
AnnaBridge 145:64910690c574 249 typedef struct _adc16_pga_config
AnnaBridge 145:64910690c574 250 {
AnnaBridge 145:64910690c574 251 adc16_pga_gain_t pgaGain; /*!< Setting PGA gain. */
AnnaBridge 145:64910690c574 252 bool enableRunInNormalMode; /*!< Enable PGA working in normal mode, or low power mode by default. */
AnnaBridge 145:64910690c574 253 #if defined(FSL_FEATURE_ADC16_HAS_PGA_CHOPPING) && FSL_FEATURE_ADC16_HAS_PGA_CHOPPING
AnnaBridge 145:64910690c574 254 bool disablePgaChopping; /*!< Disable the PGA chopping function.
AnnaBridge 145:64910690c574 255 The PGA employs chopping to remove/reduce offset and 1/f noise and offers
AnnaBridge 145:64910690c574 256 an offset measurement configuration that aids the offset calibration. */
AnnaBridge 145:64910690c574 257 #endif /* FSL_FEATURE_ADC16_HAS_PGA_CHOPPING */
AnnaBridge 145:64910690c574 258 #if defined(FSL_FEATURE_ADC16_HAS_PGA_OFFSET_MEASUREMENT) && FSL_FEATURE_ADC16_HAS_PGA_OFFSET_MEASUREMENT
AnnaBridge 145:64910690c574 259 bool enableRunInOffsetMeasurement; /*!< Enable the PGA working in offset measurement mode.
AnnaBridge 145:64910690c574 260 When this feature is enabled, the PGA disconnects itself from the external
AnnaBridge 145:64910690c574 261 inputs and auto-configures into offset measurement mode. With this field
AnnaBridge 145:64910690c574 262 set, run the ADC in the recommended settings and enable the maximum hardware
AnnaBridge 145:64910690c574 263 averaging to get the PGA offset number. The output is the
AnnaBridge 145:64910690c574 264 (PGA offset * (64+1)) for the given PGA setting. */
AnnaBridge 145:64910690c574 265 #endif /* FSL_FEATURE_ADC16_HAS_PGA_OFFSET_MEASUREMENT */
AnnaBridge 145:64910690c574 266 } adc16_pga_config_t;
AnnaBridge 145:64910690c574 267 #endif /* FSL_FEATURE_ADC16_HAS_PGA */
AnnaBridge 145:64910690c574 268
AnnaBridge 145:64910690c574 269 #if defined(__cplusplus)
AnnaBridge 145:64910690c574 270 extern "C" {
AnnaBridge 145:64910690c574 271 #endif
AnnaBridge 145:64910690c574 272
AnnaBridge 145:64910690c574 273 /*******************************************************************************
AnnaBridge 145:64910690c574 274 * API
AnnaBridge 145:64910690c574 275 ******************************************************************************/
AnnaBridge 145:64910690c574 276
AnnaBridge 145:64910690c574 277 /*!
AnnaBridge 145:64910690c574 278 * @name Initialization
AnnaBridge 145:64910690c574 279 * @{
AnnaBridge 145:64910690c574 280 */
AnnaBridge 145:64910690c574 281
AnnaBridge 145:64910690c574 282 /*!
AnnaBridge 145:64910690c574 283 * @brief Initializes the ADC16 module.
AnnaBridge 145:64910690c574 284 *
AnnaBridge 145:64910690c574 285 * @param base ADC16 peripheral base address.
AnnaBridge 145:64910690c574 286 * @param config Pointer to configuration structure. See "adc16_config_t".
AnnaBridge 145:64910690c574 287 */
AnnaBridge 145:64910690c574 288 void ADC16_Init(ADC_Type *base, const adc16_config_t *config);
AnnaBridge 145:64910690c574 289
AnnaBridge 145:64910690c574 290 /*!
AnnaBridge 145:64910690c574 291 * @brief De-initializes the ADC16 module.
AnnaBridge 145:64910690c574 292 *
AnnaBridge 145:64910690c574 293 * @param base ADC16 peripheral base address.
AnnaBridge 145:64910690c574 294 */
AnnaBridge 145:64910690c574 295 void ADC16_Deinit(ADC_Type *base);
AnnaBridge 145:64910690c574 296
AnnaBridge 145:64910690c574 297 /*!
AnnaBridge 145:64910690c574 298 * @brief Gets an available pre-defined settings for the converter's configuration.
AnnaBridge 145:64910690c574 299 *
AnnaBridge 145:64910690c574 300 * This function initializes the converter configuration structure with available settings. The default values are as follows.
AnnaBridge 145:64910690c574 301 * @code
AnnaBridge 145:64910690c574 302 * config->referenceVoltageSource = kADC16_ReferenceVoltageSourceVref;
AnnaBridge 145:64910690c574 303 * config->clockSource = kADC16_ClockSourceAsynchronousClock;
AnnaBridge 145:64910690c574 304 * config->enableAsynchronousClock = true;
AnnaBridge 145:64910690c574 305 * config->clockDivider = kADC16_ClockDivider8;
AnnaBridge 145:64910690c574 306 * config->resolution = kADC16_ResolutionSE12Bit;
AnnaBridge 145:64910690c574 307 * config->longSampleMode = kADC16_LongSampleDisabled;
AnnaBridge 145:64910690c574 308 * config->enableHighSpeed = false;
AnnaBridge 145:64910690c574 309 * config->enableLowPower = false;
AnnaBridge 145:64910690c574 310 * config->enableContinuousConversion = false;
AnnaBridge 145:64910690c574 311 * @endcode
AnnaBridge 145:64910690c574 312 * @param config Pointer to the configuration structure.
AnnaBridge 145:64910690c574 313 */
AnnaBridge 145:64910690c574 314 void ADC16_GetDefaultConfig(adc16_config_t *config);
AnnaBridge 145:64910690c574 315
AnnaBridge 145:64910690c574 316 #if defined(FSL_FEATURE_ADC16_HAS_CALIBRATION) && FSL_FEATURE_ADC16_HAS_CALIBRATION
AnnaBridge 145:64910690c574 317 /*!
AnnaBridge 145:64910690c574 318 * @brief Automates the hardware calibration.
AnnaBridge 145:64910690c574 319 *
AnnaBridge 145:64910690c574 320 * This auto calibration helps to adjust the plus/minus side gain automatically.
AnnaBridge 145:64910690c574 321 * Execute the calibration before using the converter. Note that the hardware trigger should be used
AnnaBridge 145:64910690c574 322 * during the calibration.
AnnaBridge 145:64910690c574 323 *
AnnaBridge 145:64910690c574 324 * @param base ADC16 peripheral base address.
AnnaBridge 145:64910690c574 325 *
AnnaBridge 145:64910690c574 326 * @return Execution status.
AnnaBridge 145:64910690c574 327 * @retval kStatus_Success Calibration is done successfully.
AnnaBridge 145:64910690c574 328 * @retval kStatus_Fail Calibration has failed.
AnnaBridge 145:64910690c574 329 */
AnnaBridge 145:64910690c574 330 status_t ADC16_DoAutoCalibration(ADC_Type *base);
AnnaBridge 145:64910690c574 331 #endif /* FSL_FEATURE_ADC16_HAS_CALIBRATION */
AnnaBridge 145:64910690c574 332
AnnaBridge 145:64910690c574 333 #if defined(FSL_FEATURE_ADC16_HAS_OFFSET_CORRECTION) && FSL_FEATURE_ADC16_HAS_OFFSET_CORRECTION
AnnaBridge 145:64910690c574 334 /*!
AnnaBridge 145:64910690c574 335 * @brief Sets the offset value for the conversion result.
AnnaBridge 145:64910690c574 336 *
AnnaBridge 145:64910690c574 337 * This offset value takes effect on the conversion result. If the offset value is not zero, the reading result
AnnaBridge 145:64910690c574 338 * is subtracted by it. Note, the hardware calibration fills the offset value automatically.
AnnaBridge 145:64910690c574 339 *
AnnaBridge 145:64910690c574 340 * @param base ADC16 peripheral base address.
AnnaBridge 145:64910690c574 341 * @param value Setting offset value.
AnnaBridge 145:64910690c574 342 */
AnnaBridge 145:64910690c574 343 static inline void ADC16_SetOffsetValue(ADC_Type *base, int16_t value)
AnnaBridge 145:64910690c574 344 {
AnnaBridge 145:64910690c574 345 base->OFS = (uint32_t)(value);
AnnaBridge 145:64910690c574 346 }
AnnaBridge 145:64910690c574 347 #endif /* FSL_FEATURE_ADC16_HAS_OFFSET_CORRECTION */
AnnaBridge 145:64910690c574 348
AnnaBridge 145:64910690c574 349 /* @} */
AnnaBridge 145:64910690c574 350
AnnaBridge 145:64910690c574 351 /*!
AnnaBridge 145:64910690c574 352 * @name Advanced Features
AnnaBridge 145:64910690c574 353 * @{
AnnaBridge 145:64910690c574 354 */
AnnaBridge 145:64910690c574 355
AnnaBridge 145:64910690c574 356 #if defined(FSL_FEATURE_ADC16_HAS_DMA) && FSL_FEATURE_ADC16_HAS_DMA
AnnaBridge 145:64910690c574 357 /*!
AnnaBridge 145:64910690c574 358 * @brief Enables generating the DMA trigger when the conversion is complete.
AnnaBridge 145:64910690c574 359 *
AnnaBridge 145:64910690c574 360 * @param base ADC16 peripheral base address.
AnnaBridge 145:64910690c574 361 * @param enable Switcher of the DMA feature. "true" means enabled, "false" means not enabled.
AnnaBridge 145:64910690c574 362 */
AnnaBridge 145:64910690c574 363 static inline void ADC16_EnableDMA(ADC_Type *base, bool enable)
AnnaBridge 145:64910690c574 364 {
AnnaBridge 145:64910690c574 365 if (enable)
AnnaBridge 145:64910690c574 366 {
AnnaBridge 145:64910690c574 367 base->SC2 |= ADC_SC2_DMAEN_MASK;
AnnaBridge 145:64910690c574 368 }
AnnaBridge 145:64910690c574 369 else
AnnaBridge 145:64910690c574 370 {
AnnaBridge 145:64910690c574 371 base->SC2 &= ~ADC_SC2_DMAEN_MASK;
AnnaBridge 145:64910690c574 372 }
AnnaBridge 145:64910690c574 373 }
AnnaBridge 145:64910690c574 374 #endif /* FSL_FEATURE_ADC16_HAS_DMA */
AnnaBridge 145:64910690c574 375
AnnaBridge 145:64910690c574 376 /*!
AnnaBridge 145:64910690c574 377 * @brief Enables the hardware trigger mode.
AnnaBridge 145:64910690c574 378 *
AnnaBridge 145:64910690c574 379 * @param base ADC16 peripheral base address.
AnnaBridge 145:64910690c574 380 * @param enable Switcher of the hardware trigger feature. "true" means enabled, "false" means not enabled.
AnnaBridge 145:64910690c574 381 */
AnnaBridge 145:64910690c574 382 static inline void ADC16_EnableHardwareTrigger(ADC_Type *base, bool enable)
AnnaBridge 145:64910690c574 383 {
AnnaBridge 145:64910690c574 384 if (enable)
AnnaBridge 145:64910690c574 385 {
AnnaBridge 145:64910690c574 386 base->SC2 |= ADC_SC2_ADTRG_MASK;
AnnaBridge 145:64910690c574 387 }
AnnaBridge 145:64910690c574 388 else
AnnaBridge 145:64910690c574 389 {
AnnaBridge 145:64910690c574 390 base->SC2 &= ~ADC_SC2_ADTRG_MASK;
AnnaBridge 145:64910690c574 391 }
AnnaBridge 145:64910690c574 392 }
AnnaBridge 145:64910690c574 393
AnnaBridge 145:64910690c574 394 #if defined(FSL_FEATURE_ADC16_HAS_MUX_SELECT) && FSL_FEATURE_ADC16_HAS_MUX_SELECT
AnnaBridge 145:64910690c574 395 /*!
AnnaBridge 145:64910690c574 396 * @brief Sets the channel mux mode.
AnnaBridge 145:64910690c574 397 *
AnnaBridge 145:64910690c574 398 * Some sample pins share the same channel index. The channel mux mode decides which pin is used for an
AnnaBridge 145:64910690c574 399 * indicated channel.
AnnaBridge 145:64910690c574 400 *
AnnaBridge 145:64910690c574 401 * @param base ADC16 peripheral base address.
AnnaBridge 145:64910690c574 402 * @param mode Setting channel mux mode. See "adc16_channel_mux_mode_t".
AnnaBridge 145:64910690c574 403 */
AnnaBridge 145:64910690c574 404 void ADC16_SetChannelMuxMode(ADC_Type *base, adc16_channel_mux_mode_t mode);
AnnaBridge 145:64910690c574 405 #endif /* FSL_FEATURE_ADC16_HAS_MUX_SELECT */
AnnaBridge 145:64910690c574 406
AnnaBridge 145:64910690c574 407 /*!
AnnaBridge 145:64910690c574 408 * @brief Configures the hardware compare mode.
AnnaBridge 145:64910690c574 409 *
AnnaBridge 145:64910690c574 410 * The hardware compare mode provides a way to process the conversion result automatically by using hardware. Only the result
AnnaBridge 145:64910690c574 411 * in the compare range is available. To compare the range, see "adc16_hardware_compare_mode_t" or the appopriate reference
AnnaBridge 145:64910690c574 412 * manual for more information.
AnnaBridge 145:64910690c574 413 *
AnnaBridge 145:64910690c574 414 * @param base ADC16 peripheral base address.
AnnaBridge 145:64910690c574 415 * @param config Pointer to the "adc16_hardware_compare_config_t" structure. Passing "NULL" disables the feature.
AnnaBridge 145:64910690c574 416 */
AnnaBridge 145:64910690c574 417 void ADC16_SetHardwareCompareConfig(ADC_Type *base, const adc16_hardware_compare_config_t *config);
AnnaBridge 145:64910690c574 418
AnnaBridge 145:64910690c574 419 #if defined(FSL_FEATURE_ADC16_HAS_HW_AVERAGE) && FSL_FEATURE_ADC16_HAS_HW_AVERAGE
AnnaBridge 145:64910690c574 420 /*!
AnnaBridge 145:64910690c574 421 * @brief Sets the hardware average mode.
AnnaBridge 145:64910690c574 422 *
AnnaBridge 145:64910690c574 423 * The hardware average mode provides a way to process the conversion result automatically by using hardware. The multiple
AnnaBridge 145:64910690c574 424 * conversion results are accumulated and averaged internally making them easier to read.
AnnaBridge 145:64910690c574 425 *
AnnaBridge 145:64910690c574 426 * @param base ADC16 peripheral base address.
AnnaBridge 145:64910690c574 427 * @param mode Setting the hardware average mode. See "adc16_hardware_average_mode_t".
AnnaBridge 145:64910690c574 428 */
AnnaBridge 145:64910690c574 429 void ADC16_SetHardwareAverage(ADC_Type *base, adc16_hardware_average_mode_t mode);
AnnaBridge 145:64910690c574 430 #endif /* FSL_FEATURE_ADC16_HAS_HW_AVERAGE */
AnnaBridge 145:64910690c574 431
AnnaBridge 145:64910690c574 432 #if defined(FSL_FEATURE_ADC16_HAS_PGA) && FSL_FEATURE_ADC16_HAS_PGA
AnnaBridge 145:64910690c574 433 /*!
AnnaBridge 145:64910690c574 434 * @brief Configures the PGA for the converter's front end.
AnnaBridge 145:64910690c574 435 *
AnnaBridge 145:64910690c574 436 * @param base ADC16 peripheral base address.
AnnaBridge 145:64910690c574 437 * @param config Pointer to the "adc16_pga_config_t" structure. Passing "NULL" disables the feature.
AnnaBridge 145:64910690c574 438 */
AnnaBridge 145:64910690c574 439 void ADC16_SetPGAConfig(ADC_Type *base, const adc16_pga_config_t *config);
AnnaBridge 145:64910690c574 440 #endif /* FSL_FEATURE_ADC16_HAS_PGA */
AnnaBridge 145:64910690c574 441
AnnaBridge 145:64910690c574 442 /*!
AnnaBridge 145:64910690c574 443 * @brief Gets the status flags of the converter.
AnnaBridge 145:64910690c574 444 *
AnnaBridge 145:64910690c574 445 * @param base ADC16 peripheral base address.
AnnaBridge 145:64910690c574 446 *
AnnaBridge 145:64910690c574 447 * @return Flags' mask if indicated flags are asserted. See "_adc16_status_flags".
AnnaBridge 145:64910690c574 448 */
AnnaBridge 145:64910690c574 449 uint32_t ADC16_GetStatusFlags(ADC_Type *base);
AnnaBridge 145:64910690c574 450
AnnaBridge 145:64910690c574 451 /*!
AnnaBridge 145:64910690c574 452 * @brief Clears the status flags of the converter.
AnnaBridge 145:64910690c574 453 *
AnnaBridge 145:64910690c574 454 * @param base ADC16 peripheral base address.
AnnaBridge 145:64910690c574 455 * @param mask Mask value for the cleared flags. See "_adc16_status_flags".
AnnaBridge 145:64910690c574 456 */
AnnaBridge 145:64910690c574 457 void ADC16_ClearStatusFlags(ADC_Type *base, uint32_t mask);
AnnaBridge 145:64910690c574 458
AnnaBridge 145:64910690c574 459 /* @} */
AnnaBridge 145:64910690c574 460
AnnaBridge 145:64910690c574 461 /*!
AnnaBridge 145:64910690c574 462 * @name Conversion Channel
AnnaBridge 145:64910690c574 463 * @{
AnnaBridge 145:64910690c574 464 */
AnnaBridge 145:64910690c574 465
AnnaBridge 145:64910690c574 466 /*!
AnnaBridge 145:64910690c574 467 * @brief Configures the conversion channel.
AnnaBridge 145:64910690c574 468 *
AnnaBridge 145:64910690c574 469 * This operation triggers the conversion when in software trigger mode. When in hardware trigger mode, this API
AnnaBridge 145:64910690c574 470 * configures the channel while the external trigger source helps to trigger the conversion.
AnnaBridge 145:64910690c574 471 *
AnnaBridge 145:64910690c574 472 * Note that the "Channel Group" has a detailed description.
AnnaBridge 145:64910690c574 473 * To allow sequential conversions of the ADC to be triggered by internal peripherals, the ADC has more than one
AnnaBridge 145:64910690c574 474 * group of status and control registers, one for each conversion. The channel group parameter indicates which group of
AnnaBridge 145:64910690c574 475 * registers are used, for example, channel group 0 is for Group A registers and channel group 1 is for Group B registers. The
AnnaBridge 145:64910690c574 476 * channel groups are used in a "ping-pong" approach to control the ADC operation. At any point, only one of
AnnaBridge 145:64910690c574 477 * the channel groups is actively controlling ADC conversions. The channel group 0 is used for both software and hardware
AnnaBridge 145:64910690c574 478 * trigger modes. Channel group 1 and greater indicates multiple channel group registers for
AnnaBridge 145:64910690c574 479 * use only in hardware trigger mode. See the chip configuration information in the appropriate MCU reference manual for the
AnnaBridge 145:64910690c574 480 * number of SC1n registers (channel groups) specific to this device. Channel group 1 or greater are not used
AnnaBridge 145:64910690c574 481 * for software trigger operation. Therefore, writing to these channel groups does not initiate a new conversion.
AnnaBridge 145:64910690c574 482 * Updating the channel group 0 while a different channel group is actively controlling a conversion is allowed and
AnnaBridge 145:64910690c574 483 * vice versa. Writing any of the channel group registers while that specific channel group is actively controlling a
AnnaBridge 145:64910690c574 484 * conversion aborts the current conversion.
AnnaBridge 145:64910690c574 485 *
AnnaBridge 145:64910690c574 486 * @param base ADC16 peripheral base address.
AnnaBridge 145:64910690c574 487 * @param channelGroup Channel group index.
AnnaBridge 145:64910690c574 488 * @param config Pointer to the "adc16_channel_config_t" structure for the conversion channel.
AnnaBridge 145:64910690c574 489 */
AnnaBridge 145:64910690c574 490 void ADC16_SetChannelConfig(ADC_Type *base, uint32_t channelGroup, const adc16_channel_config_t *config);
AnnaBridge 145:64910690c574 491
AnnaBridge 145:64910690c574 492 /*!
AnnaBridge 145:64910690c574 493 * @brief Gets the conversion value.
AnnaBridge 145:64910690c574 494 *
AnnaBridge 145:64910690c574 495 * @param base ADC16 peripheral base address.
AnnaBridge 145:64910690c574 496 * @param channelGroup Channel group index.
AnnaBridge 145:64910690c574 497 *
AnnaBridge 145:64910690c574 498 * @return Conversion value.
AnnaBridge 145:64910690c574 499 */
AnnaBridge 145:64910690c574 500 static inline uint32_t ADC16_GetChannelConversionValue(ADC_Type *base, uint32_t channelGroup)
AnnaBridge 145:64910690c574 501 {
AnnaBridge 145:64910690c574 502 assert(channelGroup < ADC_R_COUNT);
AnnaBridge 145:64910690c574 503
AnnaBridge 145:64910690c574 504 return base->R[channelGroup];
AnnaBridge 145:64910690c574 505 }
AnnaBridge 145:64910690c574 506
AnnaBridge 145:64910690c574 507 /*!
AnnaBridge 145:64910690c574 508 * @brief Gets the status flags of channel.
AnnaBridge 145:64910690c574 509 *
AnnaBridge 145:64910690c574 510 * @param base ADC16 peripheral base address.
AnnaBridge 145:64910690c574 511 * @param channelGroup Channel group index.
AnnaBridge 145:64910690c574 512 *
AnnaBridge 145:64910690c574 513 * @return Flags' mask if indicated flags are asserted. See "_adc16_channel_status_flags".
AnnaBridge 145:64910690c574 514 */
AnnaBridge 145:64910690c574 515 uint32_t ADC16_GetChannelStatusFlags(ADC_Type *base, uint32_t channelGroup);
AnnaBridge 145:64910690c574 516
AnnaBridge 145:64910690c574 517 /* @} */
AnnaBridge 145:64910690c574 518
AnnaBridge 145:64910690c574 519 #if defined(__cplusplus)
AnnaBridge 145:64910690c574 520 }
AnnaBridge 145:64910690c574 521 #endif
AnnaBridge 145:64910690c574 522 /*!
AnnaBridge 145:64910690c574 523 * @}
AnnaBridge 145:64910690c574 524 */
AnnaBridge 145:64910690c574 525 #endif /* _FSL_ADC16_H_ */