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