meh

Fork of mbed by mbed official

Committer:
bogdanm
Date:
Mon Apr 07 18:28:36 2014 +0100
Revision:
82:6473597d706e
Child:
90:cb3d968589d8
Release 82 of the mbed library

Main changes:

- support for K64F
- Revisited Nordic code structure
- Test infrastructure improvements
- various bug fixes

Who changed what in which revision?

UserRevisionLine numberNew contents of line
bogdanm 82:6473597d706e 1 /*
bogdanm 82:6473597d706e 2 * Copyright (c) 2013 - 2014, Freescale Semiconductor, Inc.
bogdanm 82:6473597d706e 3 * All rights reserved.
bogdanm 82:6473597d706e 4 *
bogdanm 82:6473597d706e 5 * Redistribution and use in source and binary forms, with or without modification,
bogdanm 82:6473597d706e 6 * are permitted provided that the following conditions are met:
bogdanm 82:6473597d706e 7 *
bogdanm 82:6473597d706e 8 * o Redistributions of source code must retain the above copyright notice, this list
bogdanm 82:6473597d706e 9 * of conditions and the following disclaimer.
bogdanm 82:6473597d706e 10 *
bogdanm 82:6473597d706e 11 * o Redistributions in binary form must reproduce the above copyright notice, this
bogdanm 82:6473597d706e 12 * list of conditions and the following disclaimer in the documentation and/or
bogdanm 82:6473597d706e 13 * other materials provided with the distribution.
bogdanm 82:6473597d706e 14 *
bogdanm 82:6473597d706e 15 * o Neither the name of Freescale Semiconductor, Inc. nor the names of its
bogdanm 82:6473597d706e 16 * contributors may be used to endorse or promote products derived from this
bogdanm 82:6473597d706e 17 * software without specific prior written permission.
bogdanm 82:6473597d706e 18 *
bogdanm 82:6473597d706e 19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
bogdanm 82:6473597d706e 20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
bogdanm 82:6473597d706e 21 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
bogdanm 82:6473597d706e 22 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
bogdanm 82:6473597d706e 23 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
bogdanm 82:6473597d706e 24 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
bogdanm 82:6473597d706e 25 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
bogdanm 82:6473597d706e 26 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
bogdanm 82:6473597d706e 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
bogdanm 82:6473597d706e 28 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
bogdanm 82:6473597d706e 29 */
bogdanm 82:6473597d706e 30
bogdanm 82:6473597d706e 31 #ifndef __FSL_ADC_HAL_H__
bogdanm 82:6473597d706e 32 #define __FSL_ADC_HAL_H__
bogdanm 82:6473597d706e 33
bogdanm 82:6473597d706e 34 #include <assert.h>
bogdanm 82:6473597d706e 35 #include <stdint.h>
bogdanm 82:6473597d706e 36 #include <stdbool.h>
bogdanm 82:6473597d706e 37 #include "fsl_adc_features.h"
bogdanm 82:6473597d706e 38 #include "fsl_device_registers.h"
bogdanm 82:6473597d706e 39
bogdanm 82:6473597d706e 40 /*!
bogdanm 82:6473597d706e 41 * @addtogroup adc_hal
bogdanm 82:6473597d706e 42 * @{
bogdanm 82:6473597d706e 43 */
bogdanm 82:6473597d706e 44
bogdanm 82:6473597d706e 45 /*! @file*/
bogdanm 82:6473597d706e 46
bogdanm 82:6473597d706e 47 /*******************************************************************************
bogdanm 82:6473597d706e 48 * Definitions
bogdanm 82:6473597d706e 49 ******************************************************************************/
bogdanm 82:6473597d706e 50
bogdanm 82:6473597d706e 51 /*! @brief Defines the selection of the clock source that ADC module uses.*/
bogdanm 82:6473597d706e 52 typedef enum _adc_clock_source_mode
bogdanm 82:6473597d706e 53 {
bogdanm 82:6473597d706e 54 kAdcClockSourceBusClk = 0U, /*!< Use bus clock.*/
bogdanm 82:6473597d706e 55 kAdcClockSourceBusClk2 = 1U, /*!< Use bus clock / 2.*/
bogdanm 82:6473597d706e 56 kAdcClockSourceAlternate = 2U, /*!< Use the optional external clock.*/
bogdanm 82:6473597d706e 57 kAdcClockSourceAsynchrounous = 3U, /*!< Use ADC's internal asynchronous clock. */
bogdanm 82:6473597d706e 58 } adc_clock_source_mode_t;
bogdanm 82:6473597d706e 59
bogdanm 82:6473597d706e 60 /*! @brief Defines the selection of the clock divider.*/
bogdanm 82:6473597d706e 61 typedef enum _adc_clock_divider_mode
bogdanm 82:6473597d706e 62 {
bogdanm 82:6473597d706e 63 kAdcClockDivider1 = 0U, /*!< Divide 1.*/
bogdanm 82:6473597d706e 64 kAdcClockDivider2 = 1U, /*!< Divide 2.*/
bogdanm 82:6473597d706e 65 kAdcClockDivider4 = 2U, /*!< Divide 4.*/
bogdanm 82:6473597d706e 66 kAdcClockDivider8 = 3U, /*!< Divide 8.*/
bogdanm 82:6473597d706e 67 } adc_clock_divider_mode_t;
bogdanm 82:6473597d706e 68
bogdanm 82:6473597d706e 69 /*! @brief Defines the selection of the voltage source that ADC module uses.*/
bogdanm 82:6473597d706e 70 typedef enum _adc_reference_voltage_mode
bogdanm 82:6473597d706e 71 {
bogdanm 82:6473597d706e 72 kAdcVoltageVref = 0U, /*!< Use V_REFH & V_REFL as ref source pin.*/
bogdanm 82:6473597d706e 73 kAdcVoltageValt = 1U, /*!< Use V_ALTH & V_REFL as ref source pin.*/
bogdanm 82:6473597d706e 74 } adc_reference_voltage_mode_t;
bogdanm 82:6473597d706e 75
bogdanm 82:6473597d706e 76 /*! @brief Defines the selection of the long sample extra cycle configuration.*/
bogdanm 82:6473597d706e 77 typedef enum _adc_long_sample_mode
bogdanm 82:6473597d706e 78 {
bogdanm 82:6473597d706e 79 kAdcLongSampleExtra20 = 0U, /*!< Extra 20 cycles, total 24 cycles, default.*/
bogdanm 82:6473597d706e 80 kAdcLongSampleExtra12 = 1U, /*!< Extra 12 cycles.*/
bogdanm 82:6473597d706e 81 kAdcLongSampleExtra6 = 2U, /*!< Extra 6 cycles.*/
bogdanm 82:6473597d706e 82 kAdcLongSampleExtra2 = 3U, /*!< Extra 2 cycles.*/
bogdanm 82:6473597d706e 83 } adc_long_sample_mode_t;
bogdanm 82:6473597d706e 84
bogdanm 82:6473597d706e 85 /*! @brief Defines the selection of the sample resolution.*/
bogdanm 82:6473597d706e 86 typedef enum _adc_resolution_mode
bogdanm 82:6473597d706e 87 {
bogdanm 82:6473597d706e 88 kAdcSingleDiff8or9 = 0U, /*!< 8-bits in single-end or 9-bits in differential.*/
bogdanm 82:6473597d706e 89 kAdcSingleDiff12or13 = 1U, /*!< 12-bits in single-end or 13-bits in differential.*/
bogdanm 82:6473597d706e 90 kAdcSingleDiff10or11 = 2U, /*!< 10-bits in single-end or 11-bits in differential.*/
bogdanm 82:6473597d706e 91 kAdcSingleDiff16 = 3U, /*!< 16-bits both in single-end and differential.*/
bogdanm 82:6473597d706e 92 } adc_resolution_mode_t;
bogdanm 82:6473597d706e 93
bogdanm 82:6473597d706e 94 /*! @brief Defines the selection of the A/B group mux.*/
bogdanm 82:6473597d706e 95 typedef enum _adc_group_mux_mode
bogdanm 82:6473597d706e 96 {
bogdanm 82:6473597d706e 97 kAdcChannelMuxA = 0U, /*!< Mux A group is active.*/
bogdanm 82:6473597d706e 98 kAdcChannelMuxB = 1U, /*!< Mux B group is active.*/
bogdanm 82:6473597d706e 99 } adc_group_mux_mode_t;
bogdanm 82:6473597d706e 100
bogdanm 82:6473597d706e 101 /*! @brief Defines the selection of the time in a hard average mode.*/
bogdanm 82:6473597d706e 102 typedef enum _adc_hw_average_mode
bogdanm 82:6473597d706e 103 {
bogdanm 82:6473597d706e 104 kAdcHwAverageCount4 = 0U, /*!< Average the result after accumulating 4 conversion.*/
bogdanm 82:6473597d706e 105 kAdcHwAverageCount8 = 1U, /*!< Average the result after accumulating 8 conversion.*/
bogdanm 82:6473597d706e 106 kAdcHwAverageCount16 = 2U, /*!< Average the result after accumulating 16 conversion.*/
bogdanm 82:6473597d706e 107 kAdcHwAverageCount32 = 3U, /*!< Average the result after accumulating 32 conversion.*/
bogdanm 82:6473597d706e 108 } adc_hw_average_mode_t;
bogdanm 82:6473597d706e 109
bogdanm 82:6473597d706e 110 /*! @brief Defines the selection of the channel inside the ADC module.*/
bogdanm 82:6473597d706e 111 typedef enum _adc_channel_mode
bogdanm 82:6473597d706e 112 {
bogdanm 82:6473597d706e 113 kAdcChannel0 = 0U, /*!< ADC channel 0.*/
bogdanm 82:6473597d706e 114 kAdcChannell = 1U, /*!< ADC channel 1.*/
bogdanm 82:6473597d706e 115 kAdcChannel2 = 2U, /*!< ADC channel 2.*/
bogdanm 82:6473597d706e 116 kAdcChannel3 = 3U, /*!< ADC channel 3.*/
bogdanm 82:6473597d706e 117 kAdcChannel4 = 4U, /*!< ADC channel 4.*/
bogdanm 82:6473597d706e 118 kAdcChannel5 = 5U, /*!< ADC channel 5.*/
bogdanm 82:6473597d706e 119 kAdcChannel6 = 6U, /*!< ADC channel 6.*/
bogdanm 82:6473597d706e 120 kAdcChannel7 = 7U, /*!< ADC channel 7.*/
bogdanm 82:6473597d706e 121 kAdcChannel8 = 8U, /*!< ADC channel 8.*/
bogdanm 82:6473597d706e 122 kAdcChannel9 = 9U, /*!< ADC channel 9.*/
bogdanm 82:6473597d706e 123 kAdcChannel10 = 10U, /*!< ADC channel 10.*/
bogdanm 82:6473597d706e 124 kAdcChannel11 = 11U, /*!< ADC channel 11.*/
bogdanm 82:6473597d706e 125 kAdcChannel12 = 12U, /*!< ADC channel 12.*/
bogdanm 82:6473597d706e 126 kAdcChannel13 = 13U, /*!< ADC channel 13.*/
bogdanm 82:6473597d706e 127 kAdcChannel14 = 14U, /*!< ADC channel 14.*/
bogdanm 82:6473597d706e 128 kAdcChannel15 = 15U, /*!< ADC channel 15.*/
bogdanm 82:6473597d706e 129 kAdcChannel16 = 16U, /*!< ADC channel 16.*/
bogdanm 82:6473597d706e 130 kAdcChannel17 = 17U, /*!< ADC channel 17.*/
bogdanm 82:6473597d706e 131 kAdcChannel18 = 18U, /*!< ADC channel 18.*/
bogdanm 82:6473597d706e 132 kAdcChannel19 = 19U, /*!< ADC channel 19.*/
bogdanm 82:6473597d706e 133 kAdcChannel20 = 20U, /*!< ADC channel 20.*/
bogdanm 82:6473597d706e 134 kAdcChannel21 = 21U, /*!< ADC channel 21.*/
bogdanm 82:6473597d706e 135 kAdcChannel22 = 22U, /*!< ADC channel 22.*/
bogdanm 82:6473597d706e 136 kAdcChannel23 = 23U, /*!< ADC channel 23.*/
bogdanm 82:6473597d706e 137 kAdcChannelTemperature = 26U, /*!< Internal temperature sensor.*/
bogdanm 82:6473597d706e 138 kAdcChannelBandgap = 27U, /*!< Internal band gap.*/
bogdanm 82:6473597d706e 139 kAdcChannelReferenceVoltageHigh = 29U, /*!< Internal ref voltage High.*/
bogdanm 82:6473597d706e 140 kAdcChannelReferenceVoltageLow = 30U, /*!< Internal ref voltage L.*/
bogdanm 82:6473597d706e 141 kAdcChannelDisable = 31U /*!< Disable the sample process.*/
bogdanm 82:6473597d706e 142 } adc_channel_mode_t;
bogdanm 82:6473597d706e 143
bogdanm 82:6473597d706e 144 /*! @brief Defines the status returned from the ADC API.*/
bogdanm 82:6473597d706e 145 typedef enum _adc_status
bogdanm 82:6473597d706e 146 {
bogdanm 82:6473597d706e 147 kStatus_ADC_Success = 0U,
bogdanm 82:6473597d706e 148 kStatus_ADC_InvalidArgument = 1U,/*!< Parameter is not available for the current configuration.*/
bogdanm 82:6473597d706e 149 kStatus_ADC_Failed = 2U /*!< Function operation failed. */
bogdanm 82:6473597d706e 150 } adc_status_t;
bogdanm 82:6473597d706e 151
bogdanm 82:6473597d706e 152 #if FSL_FEATURE_ADC_HAS_PGA
bogdanm 82:6473597d706e 153 /*! @brief Defines the selection of the Programmable Gain Amplifier mode.*/
bogdanm 82:6473597d706e 154 typedef enum _adc_pga_mode
bogdanm 82:6473597d706e 155 {
bogdanm 82:6473597d706e 156 kAdcPga1 = 0U, /*!< Gain is 1*/
bogdanm 82:6473597d706e 157 kAdcPga2 = 1U, /*!< Gain is 2*/
bogdanm 82:6473597d706e 158 kAdcPga4 = 2U, /*!< Gain is 4*/
bogdanm 82:6473597d706e 159 kAdcPga8 = 3U, /*!< Gain is 8*/
bogdanm 82:6473597d706e 160 kAdcPga16 = 4U, /*!< Gain is 16*/
bogdanm 82:6473597d706e 161 kAdcPga32 = 5U, /*!< Gain is 32*/
bogdanm 82:6473597d706e 162 kAdcPga64 = 6U /*!< Gain is 64*/
bogdanm 82:6473597d706e 163 } adc_pga_mode_t;
bogdanm 82:6473597d706e 164 #endif /* FSL_FEATURE_ADC_HAS_PGA */
bogdanm 82:6473597d706e 165
bogdanm 82:6473597d706e 166 /*******************************************************************************
bogdanm 82:6473597d706e 167 * API
bogdanm 82:6473597d706e 168 ******************************************************************************/
bogdanm 82:6473597d706e 169
bogdanm 82:6473597d706e 170 #if defined(__cplusplus)
bogdanm 82:6473597d706e 171 extern "C" {
bogdanm 82:6473597d706e 172 #endif
bogdanm 82:6473597d706e 173
bogdanm 82:6473597d706e 174 /*!
bogdanm 82:6473597d706e 175 * @brief Starts the calibration process.
bogdanm 82:6473597d706e 176 *
bogdanm 82:6473597d706e 177 * This function clears the calibration flag bit and sets the enable bit
bogdanm 82:6473597d706e 178 * to start the calibration.
bogdanm 82:6473597d706e 179 *
bogdanm 82:6473597d706e 180 * @param instance ADC instance ID.
bogdanm 82:6473597d706e 181 */
bogdanm 82:6473597d706e 182 adc_status_t adc_hal_start_calibration(uint32_t instance);
bogdanm 82:6473597d706e 183
bogdanm 82:6473597d706e 184 /*!
bogdanm 82:6473597d706e 185 * @brief Ends the calibration process.
bogdanm 82:6473597d706e 186 *
bogdanm 82:6473597d706e 187 * This function clears the calibration enable bit to end the calibration.
bogdanm 82:6473597d706e 188 *
bogdanm 82:6473597d706e 189 * @param instance ADC instance ID.
bogdanm 82:6473597d706e 190 */
bogdanm 82:6473597d706e 191 static inline void adc_hal_end_calibration(uint32_t instance)
bogdanm 82:6473597d706e 192 {
bogdanm 82:6473597d706e 193 assert(instance < HW_ADC_INSTANCE_COUNT);
bogdanm 82:6473597d706e 194 BW_ADC_SC3_CAL(instance, 0U);
bogdanm 82:6473597d706e 195 }
bogdanm 82:6473597d706e 196
bogdanm 82:6473597d706e 197 /*!
bogdanm 82:6473597d706e 198 * @brief Gets and calculates the plus-side calibration parameter.
bogdanm 82:6473597d706e 199 *
bogdanm 82:6473597d706e 200 * This function gets the CLP0 - CLP4 and CLPS, accumulates them, and
bogdanm 82:6473597d706e 201 * returns the value that can be set to the PG directly.
bogdanm 82:6473597d706e 202 *
bogdanm 82:6473597d706e 203 * @param instance ADC instance ID.
bogdanm 82:6473597d706e 204 * @return the value that can be set to PG directly.
bogdanm 82:6473597d706e 205 */
bogdanm 82:6473597d706e 206 uint32_t adc_hal_get_calibration_PG(uint32_t instance);
bogdanm 82:6473597d706e 207
bogdanm 82:6473597d706e 208 /*!
bogdanm 82:6473597d706e 209 * @brief Sets the plus-side calibration parameter to the ADC instance.
bogdanm 82:6473597d706e 210 *
bogdanm 82:6473597d706e 211 * This function sets the PG register directly.
bogdanm 82:6473597d706e 212 *
bogdanm 82:6473597d706e 213 * @param instance ADC instance ID.
bogdanm 82:6473597d706e 214 * @param val the value that can be set to PG directly.
bogdanm 82:6473597d706e 215 */
bogdanm 82:6473597d706e 216 static inline void adc_hal_set_calibration_PG(uint32_t instance, uint32_t val)
bogdanm 82:6473597d706e 217 {
bogdanm 82:6473597d706e 218 assert(instance < HW_ADC_INSTANCE_COUNT);
bogdanm 82:6473597d706e 219 HW_ADC_PG_WR(instance, val);
bogdanm 82:6473597d706e 220 }
bogdanm 82:6473597d706e 221
bogdanm 82:6473597d706e 222 /*!
bogdanm 82:6473597d706e 223 * @brief Gets and calculates the minus-side calibration parameter.
bogdanm 82:6473597d706e 224 *
bogdanm 82:6473597d706e 225 * This function gets the CLM0 - CLM4 and CLMS, accumulates them, and
bogdanm 82:6473597d706e 226 * returns the value that can be set to the MG directly.
bogdanm 82:6473597d706e 227 *
bogdanm 82:6473597d706e 228 * @param instance ADC instance ID.
bogdanm 82:6473597d706e 229 * @return the value that can be set to MG directly.
bogdanm 82:6473597d706e 230 */
bogdanm 82:6473597d706e 231 uint32_t adc_hal_get_calibration_MG(uint32_t instance);
bogdanm 82:6473597d706e 232
bogdanm 82:6473597d706e 233 /*!
bogdanm 82:6473597d706e 234 * @brief Sets the minus-side calibration parameter to the ADC instance.
bogdanm 82:6473597d706e 235 *
bogdanm 82:6473597d706e 236 * This function sets the MG register directly.
bogdanm 82:6473597d706e 237 *
bogdanm 82:6473597d706e 238 * @param instance ADC instance ID.
bogdanm 82:6473597d706e 239 * @param val the value that can be set to MG directly.
bogdanm 82:6473597d706e 240 */
bogdanm 82:6473597d706e 241 static inline void adc_hal_set_calibration_MG(uint32_t instance, uint32_t val)
bogdanm 82:6473597d706e 242 {
bogdanm 82:6473597d706e 243 assert(instance < HW_ADC_INSTANCE_COUNT);
bogdanm 82:6473597d706e 244 HW_ADC_MG_WR(instance, val);
bogdanm 82:6473597d706e 245 }
bogdanm 82:6473597d706e 246
bogdanm 82:6473597d706e 247 /*!
bogdanm 82:6473597d706e 248 * @brief Gets the offset value after the auto-calibration.
bogdanm 82:6473597d706e 249 *
bogdanm 82:6473597d706e 250 * If the user wants to adjust the offset value according to the application,
bogdanm 82:6473597d706e 251 * the origin offset value will be a reference.
bogdanm 82:6473597d706e 252 *
bogdanm 82:6473597d706e 253 * @param instance ADC instance ID.
bogdanm 82:6473597d706e 254 * @return The offset value created by auto-calibration.
bogdanm 82:6473597d706e 255 */
bogdanm 82:6473597d706e 256 static inline uint32_t adc_hal_get_calibration_offset(uint32_t instance)
bogdanm 82:6473597d706e 257 {
bogdanm 82:6473597d706e 258 assert(instance < HW_ADC_INSTANCE_COUNT);
bogdanm 82:6473597d706e 259 return BR_ADC_OFS_OFS(instance);
bogdanm 82:6473597d706e 260 }
bogdanm 82:6473597d706e 261
bogdanm 82:6473597d706e 262 /*!
bogdanm 82:6473597d706e 263 * @brief Sets the offset value for manual calibration.
bogdanm 82:6473597d706e 264 *
bogdanm 82:6473597d706e 265 * This function is to set the user selected or calibration generated offset
bogdanm 82:6473597d706e 266 * error correction value. The value set here is subtracted from the conversion
bogdanm 82:6473597d706e 267 * and the result is transferred into the result registers (Rn). If the result
bogdanm 82:6473597d706e 268 * is above the maximum or below the minimum result value, it is forced to the
bogdanm 82:6473597d706e 269 * appropriate limit for the current mode of operation.
bogdanm 82:6473597d706e 270 *
bogdanm 82:6473597d706e 271 * @param instance ADC instance ID.
bogdanm 82:6473597d706e 272 * @param value The manual offset value.
bogdanm 82:6473597d706e 273 */
bogdanm 82:6473597d706e 274 static inline void adc_hal_set_calibration_offset(uint32_t instance,
bogdanm 82:6473597d706e 275 uint32_t value)
bogdanm 82:6473597d706e 276 {
bogdanm 82:6473597d706e 277 assert(instance < HW_ADC_INSTANCE_COUNT);
bogdanm 82:6473597d706e 278 BW_ADC_OFS_OFS(instance, value);
bogdanm 82:6473597d706e 279 }
bogdanm 82:6473597d706e 280
bogdanm 82:6473597d706e 281 /*!
bogdanm 82:6473597d706e 282 * @brief Sets the selection of the clock source.
bogdanm 82:6473597d706e 283 *
bogdanm 82:6473597d706e 284 * The selection of ADC clock source can see to the type definition of
bogdanm 82:6473597d706e 285 * adc_clock_source_mode_t.
bogdanm 82:6473597d706e 286 * This function selects the input clock source to generate the internal
bogdanm 82:6473597d706e 287 * clock, ADCK. Note that when the ADACK clock source is selected, it does not
bogdanm 82:6473597d706e 288 * have to be activated prior to the start of the conversion. When it is
bogdanm 82:6473597d706e 289 * selected and it is not activated prior to start a conversion , the
bogdanm 82:6473597d706e 290 * asynchronous clock will be activated at the start of a conversion and shuts
bogdanm 82:6473597d706e 291 * off when conversions are terminated. In this case, there is an associated
bogdanm 82:6473597d706e 292 * clock startup delay each time the clock source is re-activated.
bogdanm 82:6473597d706e 293 *
bogdanm 82:6473597d706e 294 * @param instance ADC instance ID.
bogdanm 82:6473597d706e 295 * @param mode The indicated clock source mode.
bogdanm 82:6473597d706e 296 */
bogdanm 82:6473597d706e 297 static inline void adc_hal_set_clock_source_mode(uint32_t instance,
bogdanm 82:6473597d706e 298 adc_clock_source_mode_t mode)
bogdanm 82:6473597d706e 299 {
bogdanm 82:6473597d706e 300 assert(instance < HW_ADC_INSTANCE_COUNT);
bogdanm 82:6473597d706e 301 BW_ADC_CFG1_ADICLK(instance, (uint32_t)(mode));
bogdanm 82:6473597d706e 302 }
bogdanm 82:6473597d706e 303
bogdanm 82:6473597d706e 304 /*!
bogdanm 82:6473597d706e 305 * @brief Switches the asynchronous clock on/off.
bogdanm 82:6473597d706e 306 *
bogdanm 82:6473597d706e 307 * When enables the ADC's asynchronous clock source and the clock source output
bogdanm 82:6473597d706e 308 * regardless of the conversion and input clock select status of the ADC. Based
bogdanm 82:6473597d706e 309 * on MCU configuration, the asynchronous clock may be used by other modules.
bogdanm 82:6473597d706e 310 * Setting this mode allows the clock to be used even while the ADC is idle or
bogdanm 82:6473597d706e 311 * operating from a different clock source. Also, latency of initiating a single
bogdanm 82:6473597d706e 312 * or first-continuous conversion with the asynchronous clock selected is
bogdanm 82:6473597d706e 313 * reduced since the ADACK clock is already operational.
bogdanm 82:6473597d706e 314 *
bogdanm 82:6473597d706e 315 * @param instance ADC instance ID.
bogdanm 82:6473597d706e 316 * @param isEnabled The switcher.
bogdanm 82:6473597d706e 317 */
bogdanm 82:6473597d706e 318 static inline void adc_hal_configure_asynchronous_clock(uint32_t instance,
bogdanm 82:6473597d706e 319 bool isEnabled)
bogdanm 82:6473597d706e 320 {
bogdanm 82:6473597d706e 321 assert(instance < HW_ADC_INSTANCE_COUNT);
bogdanm 82:6473597d706e 322 BW_ADC_CFG2_ADACKEN(instance, (isEnabled ? 1U : 0U));
bogdanm 82:6473597d706e 323 }
bogdanm 82:6473597d706e 324
bogdanm 82:6473597d706e 325 /*!
bogdanm 82:6473597d706e 326 * @brief Sets the selection of the clock divider.
bogdanm 82:6473597d706e 327 *
bogdanm 82:6473597d706e 328 * The selection of ADC's clock divider can see to the type definition of the
bogdanm 82:6473597d706e 329 * adc_clock_divider_mode_t.
bogdanm 82:6473597d706e 330 * This function selects the divide ratio used by the ADC to generate the
bogdanm 82:6473597d706e 331 * internal clock ADCK.
bogdanm 82:6473597d706e 332 *
bogdanm 82:6473597d706e 333 * @param instance ADC instance ID.
bogdanm 82:6473597d706e 334 * @param mode The selection of the divider.
bogdanm 82:6473597d706e 335 */
bogdanm 82:6473597d706e 336 static inline void adc_hal_set_clock_divider_mode(uint32_t instance,
bogdanm 82:6473597d706e 337 adc_clock_divider_mode_t mode)
bogdanm 82:6473597d706e 338 {
bogdanm 82:6473597d706e 339 assert(instance < HW_ADC_INSTANCE_COUNT);
bogdanm 82:6473597d706e 340 BW_ADC_CFG1_ADIV(instance, (uint32_t)(mode));
bogdanm 82:6473597d706e 341 }
bogdanm 82:6473597d706e 342
bogdanm 82:6473597d706e 343 /*!
bogdanm 82:6473597d706e 344 * @brief Sets the selection of the reference voltage source.
bogdanm 82:6473597d706e 345 *
bogdanm 82:6473597d706e 346 * The selection of ADC's reference voltage can see to the type definition of
bogdanm 82:6473597d706e 347 * adc_reference_voltage_mode_t.
bogdanm 82:6473597d706e 348 * This function selects the voltage reference source used for conversions.
bogdanm 82:6473597d706e 349 *
bogdanm 82:6473597d706e 350 * @param instance ADC instance ID.
bogdanm 82:6473597d706e 351 * @param mode The selection of the reference voltage source.
bogdanm 82:6473597d706e 352 */
bogdanm 82:6473597d706e 353 static inline void adc_hal_set_reference_voltage_mode(uint32_t instance,
bogdanm 82:6473597d706e 354 adc_reference_voltage_mode_t mode)
bogdanm 82:6473597d706e 355 {
bogdanm 82:6473597d706e 356 assert(instance < HW_ADC_INSTANCE_COUNT);
bogdanm 82:6473597d706e 357 BW_ADC_SC2_REFSEL(instance, (uint32_t)(mode));
bogdanm 82:6473597d706e 358 }
bogdanm 82:6473597d706e 359
bogdanm 82:6473597d706e 360 /*!
bogdanm 82:6473597d706e 361 * @brief Switches the high speed mode on/off .
bogdanm 82:6473597d706e 362 *
bogdanm 82:6473597d706e 363 * This function configures the ADC for high speed operations. The
bogdanm 82:6473597d706e 364 * conversion sequence is altered (2 ADCK cycles added to the conversion time)
bogdanm 82:6473597d706e 365 * to allow higher speed conversion clocks.
bogdanm 82:6473597d706e 366 *
bogdanm 82:6473597d706e 367 * @param instance ADC instance ID.
bogdanm 82:6473597d706e 368 * @param isEnabled The switcher.
bogdanm 82:6473597d706e 369 */
bogdanm 82:6473597d706e 370 static inline void adc_hal_configure_high_speed(uint32_t instance,
bogdanm 82:6473597d706e 371 bool isEnabled)
bogdanm 82:6473597d706e 372 {
bogdanm 82:6473597d706e 373 assert(instance < HW_ADC_INSTANCE_COUNT);
bogdanm 82:6473597d706e 374 BW_ADC_CFG2_ADHSC(instance, (isEnabled ? 1U : 0U));
bogdanm 82:6473597d706e 375 }
bogdanm 82:6473597d706e 376
bogdanm 82:6473597d706e 377 /*!
bogdanm 82:6473597d706e 378 * @brief Switch the long sample mode on/off.
bogdanm 82:6473597d706e 379 *
bogdanm 82:6473597d706e 380 * This function selects between the different sample times based on the
bogdanm 82:6473597d706e 381 * conversion mode selected. It adjusts the sample period to allow
bogdanm 82:6473597d706e 382 * higher impedance inputs to be accurately sampled or to maximize conversion
bogdanm 82:6473597d706e 383 * speed for lower impedance inputs. Longer sample times can also be used to
bogdanm 82:6473597d706e 384 * lower overall power consumption if the continuous conversions are enabled and the
bogdanm 82:6473597d706e 385 * high conversion rates are not required. In fact this will be able to charge
bogdanm 82:6473597d706e 386 * the SAR in a timely manner way without affecting the SAR configuration.
bogdanm 82:6473597d706e 387 *
bogdanm 82:6473597d706e 388 * @param instance ADC instance ID.
bogdanm 82:6473597d706e 389 * @param isEnabled The switcher.
bogdanm 82:6473597d706e 390 */
bogdanm 82:6473597d706e 391 static inline void adc_hal_configure_long_sample(uint32_t instance,
bogdanm 82:6473597d706e 392 bool isEnabled)
bogdanm 82:6473597d706e 393 {
bogdanm 82:6473597d706e 394 assert(instance < HW_ADC_INSTANCE_COUNT);
bogdanm 82:6473597d706e 395 BW_ADC_CFG1_ADLSMP(instance, (isEnabled ? 1U : 0U));
bogdanm 82:6473597d706e 396 }
bogdanm 82:6473597d706e 397
bogdanm 82:6473597d706e 398 /*!
bogdanm 82:6473597d706e 399 * @brief Sets the selection of the long sample mode.
bogdanm 82:6473597d706e 400 *
bogdanm 82:6473597d706e 401 * The selection of ADC long sample mode can see to the type definition of the
bogdanm 82:6473597d706e 402 * adc_long_sample_mode_t.
bogdanm 82:6473597d706e 403 * This function selects the long sample mode that indicating the different
bogdanm 82:6473597d706e 404 * count of extra ADCK cycles are needed.
bogdanm 82:6473597d706e 405 *
bogdanm 82:6473597d706e 406 * @param instance ADC instance ID.
bogdanm 82:6473597d706e 407 * @param mode The selection of long sample mode.
bogdanm 82:6473597d706e 408 */
bogdanm 82:6473597d706e 409 static inline void adc_hal_set_long_sample_mode(uint32_t instance,
bogdanm 82:6473597d706e 410 adc_long_sample_mode_t mode)
bogdanm 82:6473597d706e 411 {
bogdanm 82:6473597d706e 412 assert(instance < HW_ADC_INSTANCE_COUNT);
bogdanm 82:6473597d706e 413 BW_ADC_CFG2_ADLSTS(instance, (uint32_t)(mode));
bogdanm 82:6473597d706e 414 }
bogdanm 82:6473597d706e 415
bogdanm 82:6473597d706e 416 /*!
bogdanm 82:6473597d706e 417 * @brief Switches the low power mode on/off.
bogdanm 82:6473597d706e 418 *
bogdanm 82:6473597d706e 419 * This function controls the power configuration of the successive approximation
bogdanm 82:6473597d706e 420 * converter. This optimizes power consumption when higher sample rates are not
bogdanm 82:6473597d706e 421 * required.
bogdanm 82:6473597d706e 422 *
bogdanm 82:6473597d706e 423 * @param instance ADC instance ID.
bogdanm 82:6473597d706e 424 * @param isEnabled The switcher.
bogdanm 82:6473597d706e 425 */
bogdanm 82:6473597d706e 426 static inline void adc_hal_configure_low_power(uint32_t instance, bool isEnabled)
bogdanm 82:6473597d706e 427 {
bogdanm 82:6473597d706e 428 assert(instance < HW_ADC_INSTANCE_COUNT);
bogdanm 82:6473597d706e 429 BW_ADC_CFG1_ADLPC(instance, (isEnabled ? 1U : 0U));
bogdanm 82:6473597d706e 430 }
bogdanm 82:6473597d706e 431
bogdanm 82:6473597d706e 432 /*!
bogdanm 82:6473597d706e 433 * @brief Sets the selection of the resolution mode.
bogdanm 82:6473597d706e 434 *
bogdanm 82:6473597d706e 435 * The selection of ADC resolution mode can see to the type definition of the
bogdanm 82:6473597d706e 436 * adc_resolution_mode_t.
bogdanm 82:6473597d706e 437 * This function selects the ADC resolution mode. Note that the
bogdanm 82:6473597d706e 438 * differential conversion is different to single-end conversion.
bogdanm 82:6473597d706e 439 *
bogdanm 82:6473597d706e 440 * @param instance ADC instance ID.
bogdanm 82:6473597d706e 441 * @param mode The selection of resolution mode.
bogdanm 82:6473597d706e 442 */
bogdanm 82:6473597d706e 443 static inline void adc_hal_set_resolution_mode(uint32_t instance,
bogdanm 82:6473597d706e 444 adc_resolution_mode_t mode)
bogdanm 82:6473597d706e 445 {
bogdanm 82:6473597d706e 446 assert(instance < HW_ADC_INSTANCE_COUNT);
bogdanm 82:6473597d706e 447 BW_ADC_CFG1_MODE(instance, (uint32_t)(mode));
bogdanm 82:6473597d706e 448 }
bogdanm 82:6473597d706e 449
bogdanm 82:6473597d706e 450 /*!
bogdanm 82:6473597d706e 451 * @brief Switches the continuous conversion mode on/off.
bogdanm 82:6473597d706e 452 *
bogdanm 82:6473597d706e 453 * This function configures the continuous conversions or sets of conversions if
bogdanm 82:6473597d706e 454 * the hardware average function is enabled after initiating a conversion.
bogdanm 82:6473597d706e 455 *
bogdanm 82:6473597d706e 456 * @param instance ADC instance ID.
bogdanm 82:6473597d706e 457 * @param isEnabled The switcher.
bogdanm 82:6473597d706e 458 */
bogdanm 82:6473597d706e 459 static inline void adc_hal_configure_continuous_conversion(uint32_t instance,
bogdanm 82:6473597d706e 460 bool isEnabled)
bogdanm 82:6473597d706e 461 {
bogdanm 82:6473597d706e 462 assert(instance < HW_ADC_INSTANCE_COUNT);
bogdanm 82:6473597d706e 463 BW_ADC_SC3_ADCO(instance, (isEnabled ? 1U : 0U));
bogdanm 82:6473597d706e 464 }
bogdanm 82:6473597d706e 465
bogdanm 82:6473597d706e 466 /*!
bogdanm 82:6473597d706e 467 * @brief Switches the hardware trigger mode on/off .
bogdanm 82:6473597d706e 468 *
bogdanm 82:6473597d706e 469 * This function selects the type of trigger used for initiating a conversion.
bogdanm 82:6473597d706e 470 * Two types of triggers can be selected: software trigger and hardware trigger.
bogdanm 82:6473597d706e 471 * When software trigger is selected, a conversion is initiated following a
bogdanm 82:6473597d706e 472 * write to SC1A. When hardware trigger is selected, a conversion is initiated
bogdanm 82:6473597d706e 473 * following the assertion of the external events. The event will come through
bogdanm 82:6473597d706e 474 * the signal on the line of ADHWT input after a pulse of ADHWTSn input inside SOC.
bogdanm 82:6473597d706e 475 *
bogdanm 82:6473597d706e 476 * @param instance ADC instance ID.
bogdanm 82:6473597d706e 477 * @param isEnabled The switcher.
bogdanm 82:6473597d706e 478 */
bogdanm 82:6473597d706e 479 static inline void adc_hal_configure_hw_trigger(uint32_t instance, bool isEnabled)
bogdanm 82:6473597d706e 480 {
bogdanm 82:6473597d706e 481 assert(instance < HW_ADC_INSTANCE_COUNT);
bogdanm 82:6473597d706e 482 BW_ADC_SC2_ADTRG(instance, (isEnabled ? 1U : 0U));
bogdanm 82:6473597d706e 483 }
bogdanm 82:6473597d706e 484
bogdanm 82:6473597d706e 485 /*!
bogdanm 82:6473597d706e 486 * @brief Switches the hardware average mode on/off.
bogdanm 82:6473597d706e 487 *
bogdanm 82:6473597d706e 488 * This function enables the hardware average function of the ADC.
bogdanm 82:6473597d706e 489 *
bogdanm 82:6473597d706e 490 * @param instance ADC instance ID.
bogdanm 82:6473597d706e 491 * @param isEnabled The switcher.
bogdanm 82:6473597d706e 492 */
bogdanm 82:6473597d706e 493 static inline void adc_hal_configure_hw_average(uint32_t instance, bool isEnabled)
bogdanm 82:6473597d706e 494 {
bogdanm 82:6473597d706e 495 assert(instance < HW_ADC_INSTANCE_COUNT);
bogdanm 82:6473597d706e 496 BW_ADC_SC3_AVGE(instance, (isEnabled ? 1U : 0U));
bogdanm 82:6473597d706e 497 }
bogdanm 82:6473597d706e 498
bogdanm 82:6473597d706e 499 /*!
bogdanm 82:6473597d706e 500 * @brief Sets the selection of the hardware average mode.
bogdanm 82:6473597d706e 501 *
bogdanm 82:6473597d706e 502 * The selection of ADC hardware average mode can see to the type definition
bogdanm 82:6473597d706e 503 * of the adc_hw_average_mode_t.
bogdanm 82:6473597d706e 504 * This function determines how many ADC conversions are averaged to create
bogdanm 82:6473597d706e 505 * the ADC average result.
bogdanm 82:6473597d706e 506 *
bogdanm 82:6473597d706e 507 * @param instance ADC instance ID.
bogdanm 82:6473597d706e 508 * @param mode The selection of hardware average mode.
bogdanm 82:6473597d706e 509 */
bogdanm 82:6473597d706e 510 static inline void adc_hal_set_hw_average_mode(uint32_t instance,
bogdanm 82:6473597d706e 511 adc_hw_average_mode_t mode)
bogdanm 82:6473597d706e 512 {
bogdanm 82:6473597d706e 513 assert(instance < HW_ADC_INSTANCE_COUNT);
bogdanm 82:6473597d706e 514 BW_ADC_SC3_AVGS(instance, (uint32_t)(mode));
bogdanm 82:6473597d706e 515 }
bogdanm 82:6473597d706e 516
bogdanm 82:6473597d706e 517 /*!
bogdanm 82:6473597d706e 518 * @brief Switches the hardware compare mode on/off.
bogdanm 82:6473597d706e 519 *
bogdanm 82:6473597d706e 520 * This function enables the compare function.
bogdanm 82:6473597d706e 521 *
bogdanm 82:6473597d706e 522 * @param instance ADC instance ID.
bogdanm 82:6473597d706e 523 * @param isEnabled The switcher.
bogdanm 82:6473597d706e 524 */
bogdanm 82:6473597d706e 525 static inline void adc_hal_configure_hw_compare(uint32_t instance, bool isEnabled)
bogdanm 82:6473597d706e 526 {
bogdanm 82:6473597d706e 527 assert(instance < HW_ADC_INSTANCE_COUNT);
bogdanm 82:6473597d706e 528 BW_ADC_SC2_ACFE(instance, (isEnabled ? 1U : 0U));
bogdanm 82:6473597d706e 529 }
bogdanm 82:6473597d706e 530
bogdanm 82:6473597d706e 531 /*!
bogdanm 82:6473597d706e 532 * @brief Switches the hardware compare greater configuration on/off .
bogdanm 82:6473597d706e 533 *
bogdanm 82:6473597d706e 534 * This function configures the compare function to check the conversion
bogdanm 82:6473597d706e 535 * result relative to the compare value register(s) (CV1 and CV2). To enable
bogdanm 82:6473597d706e 536 * will configure greater than or equal to threshold, outside range inclusive
bogdanm 82:6473597d706e 537 * and inside range inclusive functionality based on the values placed in the
bogdanm 82:6473597d706e 538 * CV1 and CV2 registers. Otherwise, it will configure less than threshold,
bogdanm 82:6473597d706e 539 * outside range not inclusive and inside range not inclusive functionality
bogdanm 82:6473597d706e 540 * based on the values placed in the CV1 and CV2 registers.
bogdanm 82:6473597d706e 541 *
bogdanm 82:6473597d706e 542 *
bogdanm 82:6473597d706e 543 * @param instance ADC instance ID.
bogdanm 82:6473597d706e 544 * @param isEnabled The switcher.
bogdanm 82:6473597d706e 545 */
bogdanm 82:6473597d706e 546 static inline void adc_hal_configure_hw_compare_greater(uint32_t instance,
bogdanm 82:6473597d706e 547 bool isEnabled)
bogdanm 82:6473597d706e 548 {
bogdanm 82:6473597d706e 549 assert(instance < HW_ADC_INSTANCE_COUNT);
bogdanm 82:6473597d706e 550 BW_ADC_SC2_ACFGT(instance, (isEnabled ? 1U : 0U));
bogdanm 82:6473597d706e 551 }
bogdanm 82:6473597d706e 552
bogdanm 82:6473597d706e 553 /*!
bogdanm 82:6473597d706e 554 * @brief Switches the hardware compare range configuration on/off .
bogdanm 82:6473597d706e 555 *
bogdanm 82:6473597d706e 556 * This function configures the compare function to check if the conversion
bogdanm 82:6473597d706e 557 * result of the input being monitored is either inside or outside the range
bogdanm 82:6473597d706e 558 * formed by the compare value registers (CV1 and CV2). However, the actual
bogdanm 82:6473597d706e 559 * compare range should be determined alone with the function of
bogdanm 82:6473597d706e 560 * adc_hal_configure_hw_compare_greater() as well.
bogdanm 82:6473597d706e 561 *
bogdanm 82:6473597d706e 562 * @param instance ADC instance ID.
bogdanm 82:6473597d706e 563 * @param isEnabled The switcher.
bogdanm 82:6473597d706e 564 */
bogdanm 82:6473597d706e 565 static inline void adc_hal_configure_hw_compare_in_range(uint32_t instance,
bogdanm 82:6473597d706e 566 bool isEnabled)
bogdanm 82:6473597d706e 567 {
bogdanm 82:6473597d706e 568 assert(instance < HW_ADC_INSTANCE_COUNT);
bogdanm 82:6473597d706e 569 BW_ADC_SC2_ACREN(instance, (isEnabled ? 1U : 0U));
bogdanm 82:6473597d706e 570 }
bogdanm 82:6473597d706e 571
bogdanm 82:6473597d706e 572 /*!
bogdanm 82:6473597d706e 573 * @brief Sets the value1 in the hardware compare.
bogdanm 82:6473597d706e 574 *
bogdanm 82:6473597d706e 575 * This function sets the value of the CV1 register.
bogdanm 82:6473597d706e 576 *
bogdanm 82:6473597d706e 577 * @param instance ADC instance ID.
bogdanm 82:6473597d706e 578 * @param value The setting value.
bogdanm 82:6473597d706e 579 */
bogdanm 82:6473597d706e 580 static inline void adc_hal_set_hw_compare_value1(uint32_t instance, uint32_t value)
bogdanm 82:6473597d706e 581 {
bogdanm 82:6473597d706e 582 assert(instance < HW_ADC_INSTANCE_COUNT);
bogdanm 82:6473597d706e 583 BW_ADC_CV1_CV(instance, value);
bogdanm 82:6473597d706e 584 }
bogdanm 82:6473597d706e 585
bogdanm 82:6473597d706e 586 /*!
bogdanm 82:6473597d706e 587 * @brief Sets the value2 in the hardware compare.
bogdanm 82:6473597d706e 588 *
bogdanm 82:6473597d706e 589 * This function sets the value of the CV2 register.
bogdanm 82:6473597d706e 590 *
bogdanm 82:6473597d706e 591 * @param instance ADC instance ID.
bogdanm 82:6473597d706e 592 * @param value The setting value.
bogdanm 82:6473597d706e 593 */
bogdanm 82:6473597d706e 594 static inline void adc_hal_set_hw_compare_value2(uint32_t instance, uint32_t value)
bogdanm 82:6473597d706e 595 {
bogdanm 82:6473597d706e 596 assert(instance < HW_ADC_INSTANCE_COUNT);
bogdanm 82:6473597d706e 597 BW_ADC_CV2_CV(instance, value);
bogdanm 82:6473597d706e 598 }
bogdanm 82:6473597d706e 599
bogdanm 82:6473597d706e 600 /*!
bogdanm 82:6473597d706e 601 * @brief Switches the ADC DMA trigger on/off.
bogdanm 82:6473597d706e 602 *
bogdanm 82:6473597d706e 603 * When DMA is enabled, it asserts the ADC DMA request during the ADC
bogdanm 82:6473597d706e 604 * conversion complete event noted by the assertion of any of the ADC COCO flags.
bogdanm 82:6473597d706e 605 *
bogdanm 82:6473597d706e 606 * @param instance ADC instance ID.
bogdanm 82:6473597d706e 607 * @param isEnabled The switcher.
bogdanm 82:6473597d706e 608 */
bogdanm 82:6473597d706e 609 static inline void adc_hal_configure_dma(uint32_t instance, bool isEnabled)
bogdanm 82:6473597d706e 610 {
bogdanm 82:6473597d706e 611 assert(instance < HW_ADC_INSTANCE_COUNT);
bogdanm 82:6473597d706e 612 BW_ADC_SC2_DMAEN(instance, (isEnabled ? 1U : 0U));
bogdanm 82:6473597d706e 613 }
bogdanm 82:6473597d706e 614
bogdanm 82:6473597d706e 615 /*!
bogdanm 82:6473597d706e 616 * @brief Switches off the ADC channel conversion.
bogdanm 82:6473597d706e 617 *
bogdanm 82:6473597d706e 618 * Here the "NUll" channel is set to the conversion channel.
bogdanm 82:6473597d706e 619 *
bogdanm 82:6473597d706e 620 * @param instance ADC instance ID.
bogdanm 82:6473597d706e 621 * @param group The group mux index.
bogdanm 82:6473597d706e 622 */
bogdanm 82:6473597d706e 623 static inline void adc_hal_disable(uint32_t instance, uint32_t group)
bogdanm 82:6473597d706e 624 {
bogdanm 82:6473597d706e 625 assert(instance < HW_ADC_INSTANCE_COUNT);
bogdanm 82:6473597d706e 626 assert(group < HW_ADC_SC1n_COUNT);
bogdanm 82:6473597d706e 627 BW_ADC_SC1n_ADCH(instance, group, (uint32_t)(kAdcChannelDisable));
bogdanm 82:6473597d706e 628 }
bogdanm 82:6473597d706e 629
bogdanm 82:6473597d706e 630 /*!
bogdanm 82:6473597d706e 631 * @brief Sets the channel number and switches on the conversion.
bogdanm 82:6473597d706e 632 *
bogdanm 82:6473597d706e 633 * When the available channel is set, the conversion begins to execute.
bogdanm 82:6473597d706e 634 *
bogdanm 82:6473597d706e 635 * @param instance ADC instance ID.
bogdanm 82:6473597d706e 636 * @param group The group mux index.
bogdanm 82:6473597d706e 637 * @param mode The selection of channel number.
bogdanm 82:6473597d706e 638 * @param isDifferential the selection of differential input.
bogdanm 82:6473597d706e 639 */
bogdanm 82:6473597d706e 640 static inline void adc_hal_enable(uint32_t instance, uint32_t group,
bogdanm 82:6473597d706e 641 adc_channel_mode_t mode, bool isDifferential)
bogdanm 82:6473597d706e 642 {
bogdanm 82:6473597d706e 643 assert(instance < HW_ADC_INSTANCE_COUNT);
bogdanm 82:6473597d706e 644 assert(group < HW_ADC_SC1n_COUNT);
bogdanm 82:6473597d706e 645 BW_ADC_SC1n_DIFF(instance, group, (isDifferential ? 1U : 0U));
bogdanm 82:6473597d706e 646 /* Set new channel will restart the conversion. */
bogdanm 82:6473597d706e 647 BW_ADC_SC1n_ADCH(instance, group, (uint32_t)(mode));
bogdanm 82:6473597d706e 648 }
bogdanm 82:6473597d706e 649
bogdanm 82:6473597d706e 650 /*!
bogdanm 82:6473597d706e 651 * @brief Switches the ADC interrupt trigger on/off .
bogdanm 82:6473597d706e 652 *
bogdanm 82:6473597d706e 653 * This function enables conversion complete interrupts. When COCO is
bogdanm 82:6473597d706e 654 * set while the respective AIEN is high, an interrupt is asserted.
bogdanm 82:6473597d706e 655 *
bogdanm 82:6473597d706e 656 * @param instance ADC instance ID.
bogdanm 82:6473597d706e 657 * @param group The group mux index.
bogdanm 82:6473597d706e 658 * @param inEnable The switcher.
bogdanm 82:6473597d706e 659 */
bogdanm 82:6473597d706e 660 static inline void adc_hal_configure_interrupt(uint32_t instance, uint32_t group,
bogdanm 82:6473597d706e 661 bool isEnabled)
bogdanm 82:6473597d706e 662 {
bogdanm 82:6473597d706e 663 assert(instance < HW_ADC_INSTANCE_COUNT);
bogdanm 82:6473597d706e 664 assert(group < HW_ADC_SC1n_COUNT);
bogdanm 82:6473597d706e 665 BW_ADC_SC1n_AIEN(instance, group, (isEnabled ? 1U : 0U));
bogdanm 82:6473597d706e 666 }
bogdanm 82:6473597d706e 667
bogdanm 82:6473597d706e 668 /*!
bogdanm 82:6473597d706e 669 * @brief Checks whether the ADC is in process.
bogdanm 82:6473597d706e 670 *
bogdanm 82:6473597d706e 671 * This function indicates that a conversion or hardware averaging is in
bogdanm 82:6473597d706e 672 * progress. ADACT is set when a conversion is initiated and cleared when a
bogdanm 82:6473597d706e 673 * conversion is completed or aborted. Note that if the continuous conversion
bogdanm 82:6473597d706e 674 * is been use, this function will always return true.
bogdanm 82:6473597d706e 675 *
bogdanm 82:6473597d706e 676 * @param instance ADC instance ID.
bogdanm 82:6473597d706e 677 * @return true if it is.
bogdanm 82:6473597d706e 678 */
bogdanm 82:6473597d706e 679 static inline bool adc_hal_is_in_process(uint32_t instance)
bogdanm 82:6473597d706e 680 {
bogdanm 82:6473597d706e 681 assert(instance < HW_ADC_INSTANCE_COUNT);
bogdanm 82:6473597d706e 682 return BR_ADC_SC2_ADACT(instance);
bogdanm 82:6473597d706e 683 }
bogdanm 82:6473597d706e 684
bogdanm 82:6473597d706e 685 /*!
bogdanm 82:6473597d706e 686 * @brief Checks whether the channel conversion is complete.
bogdanm 82:6473597d706e 687 *
bogdanm 82:6473597d706e 688 * This function indicates whether each conversion is completed.
bogdanm 82:6473597d706e 689 *
bogdanm 82:6473597d706e 690 * @param instance ADC instance ID.
bogdanm 82:6473597d706e 691 * @param group The grout mux index.
bogdanm 82:6473597d706e 692 * @return true if it is.
bogdanm 82:6473597d706e 693 */
bogdanm 82:6473597d706e 694 static inline bool adc_hal_is_conversion_completed(uint32_t instance, uint32_t group)
bogdanm 82:6473597d706e 695 {
bogdanm 82:6473597d706e 696 assert(instance < HW_ADC_INSTANCE_COUNT);
bogdanm 82:6473597d706e 697 assert(group < HW_ADC_SC1n_COUNT);
bogdanm 82:6473597d706e 698 return BR_ADC_SC1n_COCO(instance, group);
bogdanm 82:6473597d706e 699 }
bogdanm 82:6473597d706e 700
bogdanm 82:6473597d706e 701 /*!
bogdanm 82:6473597d706e 702 * @brief Checks whether the calibration failed.
bogdanm 82:6473597d706e 703 *
bogdanm 82:6473597d706e 704 * This function displays the result of the calibration sequence.
bogdanm 82:6473597d706e 705 *
bogdanm 82:6473597d706e 706 * @param instance ADC instance ID.
bogdanm 82:6473597d706e 707 * @return true if it is.
bogdanm 82:6473597d706e 708 */
bogdanm 82:6473597d706e 709 static inline bool adc_hal_is_calibration_fail(uint32_t instance)
bogdanm 82:6473597d706e 710 {
bogdanm 82:6473597d706e 711 assert(instance < HW_ADC_INSTANCE_COUNT);
bogdanm 82:6473597d706e 712 return BR_ADC_SC3_CALF(instance);
bogdanm 82:6473597d706e 713 }
bogdanm 82:6473597d706e 714
bogdanm 82:6473597d706e 715 /*!
bogdanm 82:6473597d706e 716 * @brief Gets the conversion value.
bogdanm 82:6473597d706e 717 *
bogdanm 82:6473597d706e 718 * This function returns the conversion value kept in the Rn Register. Unused bits
bogdanm 82:6473597d706e 719 * in the Rn register are cleared in unsigned right justified modes and carry
bogdanm 82:6473597d706e 720 * the sign bit (MSB) in sign extended 2's complement modes.
bogdanm 82:6473597d706e 721 *
bogdanm 82:6473597d706e 722 * @param instance ADC instance ID.
bogdanm 82:6473597d706e 723 * @param group The group mux index.
bogdanm 82:6473597d706e 724 */
bogdanm 82:6473597d706e 725 static inline uint32_t adc_hal_get_conversion_value(uint32_t instance,
bogdanm 82:6473597d706e 726 uint32_t group)
bogdanm 82:6473597d706e 727 {
bogdanm 82:6473597d706e 728 assert(instance < HW_ADC_INSTANCE_COUNT);
bogdanm 82:6473597d706e 729 assert(group < HW_ADC_SC1n_COUNT);
bogdanm 82:6473597d706e 730 return BR_ADC_Rn_D(instance, group);
bogdanm 82:6473597d706e 731 }
bogdanm 82:6473597d706e 732
bogdanm 82:6473597d706e 733 /*!
bogdanm 82:6473597d706e 734 * @brief Sets the current group mux that executes the conversion.
bogdanm 82:6473597d706e 735 *
bogdanm 82:6473597d706e 736 * ADC Mux select bit changes the ADC group setting to select between
bogdanm 82:6473597d706e 737 * alternate sets of ADC channels. It will activate group A or group B.
bogdanm 82:6473597d706e 738 *
bogdanm 82:6473597d706e 739 * @param instance ADC instance ID.
bogdanm 82:6473597d706e 740 * @param group The group mux index.
bogdanm 82:6473597d706e 741 */
bogdanm 82:6473597d706e 742 static inline void adc_hal_set_group_mux(uint32_t instance, adc_group_mux_mode_t group)
bogdanm 82:6473597d706e 743 {
bogdanm 82:6473597d706e 744 assert(instance < HW_ADC_INSTANCE_COUNT);
bogdanm 82:6473597d706e 745 assert(group < HW_ADC_SC1n_COUNT);
bogdanm 82:6473597d706e 746 BW_ADC_CFG2_MUXSEL(instance, (uint32_t)group);
bogdanm 82:6473597d706e 747 }
bogdanm 82:6473597d706e 748
bogdanm 82:6473597d706e 749 #if FSL_FEATURE_ADC_HAS_PGA
bogdanm 82:6473597d706e 750 /*!
bogdanm 82:6473597d706e 751 * @brief Switches on/off to enable the ADC Programmable Gain Amplifier.
bogdanm 82:6473597d706e 752 *
bogdanm 82:6473597d706e 753 * The Programmable Gain Amplifier (PGA) is designed to increase the dynamic
bogdanm 82:6473597d706e 754 * range by amplifying low-amplitude signals before they are fed to the 16-bit
bogdanm 82:6473597d706e 755 * SAR ADC. The gain of this amplifier ranges between 1 to 64 in (2^N) steps.
bogdanm 82:6473597d706e 756 *
bogdanm 82:6473597d706e 757 * @param instance ADC instance ID.
bogdanm 82:6473597d706e 758 * @param isEnabled The switcher.
bogdanm 82:6473597d706e 759 */
bogdanm 82:6473597d706e 760 static inline void adc_hal_configure_pga(uint32_t instance, bool isEnabled)
bogdanm 82:6473597d706e 761 {
bogdanm 82:6473597d706e 762 assert(instance < HW_ADC_INSTANCE_COUNT);
bogdanm 82:6473597d706e 763 BW_ADC_PGA_PGAEN(instance, (isEnabled ? 1U : 0U));
bogdanm 82:6473597d706e 764 }
bogdanm 82:6473597d706e 765
bogdanm 82:6473597d706e 766 /*!
bogdanm 82:6473597d706e 767 * @brief Switches on/off to enable the PGA chopping mode.
bogdanm 82:6473597d706e 768 *
bogdanm 82:6473597d706e 769 * The PGA employs chopping to remove/reduce offset and 1/f noise and offers an
bogdanm 82:6473597d706e 770 * offset measurement configuration that aids the offset calibration.
bogdanm 82:6473597d706e 771 *
bogdanm 82:6473597d706e 772 * @param instance ADC instance ID.
bogdanm 82:6473597d706e 773 * @param isEnabled The switcher.
bogdanm 82:6473597d706e 774 */
bogdanm 82:6473597d706e 775 static inline void adc_hal_configure_pga_chopping(uint32_t instance,
bogdanm 82:6473597d706e 776 bool isEnabled)
bogdanm 82:6473597d706e 777 {
bogdanm 82:6473597d706e 778 assert(instance < HW_ADC_INSTANCE_COUNT);
bogdanm 82:6473597d706e 779 BW_ADC_PGA_PGACHPb(instance, (isEnabled ? 0U : 1U));
bogdanm 82:6473597d706e 780 }
bogdanm 82:6473597d706e 781
bogdanm 82:6473597d706e 782 /*!
bogdanm 82:6473597d706e 783 * @brief Switches on/off to enable the PGA in a low power mode.
bogdanm 82:6473597d706e 784 *
bogdanm 82:6473597d706e 785 * This function configures the PGA running in low power mode.
bogdanm 82:6473597d706e 786 *
bogdanm 82:6473597d706e 787 * @param instance ADC instance ID.
bogdanm 82:6473597d706e 788 * @param isEnabled The switcher.
bogdanm 82:6473597d706e 789 */
bogdanm 82:6473597d706e 790 static inline void adc_hal_configure_pga_in_low_power(uint32_t instance,
bogdanm 82:6473597d706e 791 bool isEnabled)
bogdanm 82:6473597d706e 792 {
bogdanm 82:6473597d706e 793 assert(instance < HW_ADC_INSTANCE_COUNT);
bogdanm 82:6473597d706e 794 BW_ADC_PGA_PGALPb(instance, (isEnabled ? 0U : 1U));
bogdanm 82:6473597d706e 795 }
bogdanm 82:6473597d706e 796
bogdanm 82:6473597d706e 797 /*!
bogdanm 82:6473597d706e 798 * @brief Switches on/off to enable the offset measurement mode.
bogdanm 82:6473597d706e 799 *
bogdanm 82:6473597d706e 800 * When this function is asserted, the PGA disconnects from the external
bogdanm 82:6473597d706e 801 * inputs and auto-configures into offset measurement mode. With this function is
bogdanm 82:6473597d706e 802 * asserted, run the ADC in recommended settings and enable maximum
bogdanm 82:6473597d706e 803 * hardware averaging to get the PGA offset number. The output is
bogdanm 82:6473597d706e 804 * (PGA offset * (64+1)) for a given PGA setting.
bogdanm 82:6473597d706e 805 *
bogdanm 82:6473597d706e 806 * @param instance ADC instance ID.
bogdanm 82:6473597d706e 807 * @param isEnabled The switcher.
bogdanm 82:6473597d706e 808 */
bogdanm 82:6473597d706e 809 static inline void adc_hal_configure_pga_offset_measurement(uint32_t instance,
bogdanm 82:6473597d706e 810 bool isEnabled)
bogdanm 82:6473597d706e 811 {
bogdanm 82:6473597d706e 812 assert(instance < HW_ADC_INSTANCE_COUNT);
bogdanm 82:6473597d706e 813 BW_ADC_PGA_PGAOFSM(instance, (isEnabled ? 0U : 1U));
bogdanm 82:6473597d706e 814 }
bogdanm 82:6473597d706e 815
bogdanm 82:6473597d706e 816 /*!
bogdanm 82:6473597d706e 817 * @brief Sets the selection of the PGA gain mode.
bogdanm 82:6473597d706e 818 *
bogdanm 82:6473597d706e 819 * The selection of the PGA gain mode can see to the type definition of the adc_pga_mode_t.
bogdanm 82:6473597d706e 820 *
bogdanm 82:6473597d706e 821 * @param instance ADC instance ID.
bogdanm 82:6473597d706e 822 * @param mode The selection of gain.
bogdanm 82:6473597d706e 823 */
bogdanm 82:6473597d706e 824 static inline void adc_hal_set_pga_gain_mode(uint32_t instance,
bogdanm 82:6473597d706e 825 adc_pga_mode_t mode)
bogdanm 82:6473597d706e 826 {
bogdanm 82:6473597d706e 827 assert(instance < HW_ADC_INSTANCE_COUNT);
bogdanm 82:6473597d706e 828 BW_ADC_PGA_PGAG(instance, (uint32_t)(mode));
bogdanm 82:6473597d706e 829 }
bogdanm 82:6473597d706e 830
bogdanm 82:6473597d706e 831 /*!
bogdanm 82:6473597d706e 832 * @brief Gets the selection of the current PGA gain mode.
bogdanm 82:6473597d706e 833 *
bogdanm 82:6473597d706e 834 * This function returns the selection of the current PGA gain mode status.
bogdanm 82:6473597d706e 835 *
bogdanm 82:6473597d706e 836 * @param instance ADC instance ID.
bogdanm 82:6473597d706e 837 * @return Current selection of gain mode.
bogdanm 82:6473597d706e 838 */
bogdanm 82:6473597d706e 839 static inline adc_pga_mode_t adc_hal_get_pga_gain_mode(uint32_t instance)
bogdanm 82:6473597d706e 840 {
bogdanm 82:6473597d706e 841 assert(instance < HW_ADC_INSTANCE_COUNT);
bogdanm 82:6473597d706e 842
bogdanm 82:6473597d706e 843 return (adc_pga_mode_t)(BR_ADC_PGA_PGAG(instance));
bogdanm 82:6473597d706e 844 }
bogdanm 82:6473597d706e 845
bogdanm 82:6473597d706e 846 #endif /* FSL_FEATURE_ADC_HAS_PGA */
bogdanm 82:6473597d706e 847
bogdanm 82:6473597d706e 848 #if defined(__cplusplus)
bogdanm 82:6473597d706e 849 }
bogdanm 82:6473597d706e 850 #endif
bogdanm 82:6473597d706e 851
bogdanm 82:6473597d706e 852 /*! @}*/
bogdanm 82:6473597d706e 853
bogdanm 82:6473597d706e 854 #endif /* __FSL_ADC_HAL_H__ */
bogdanm 82:6473597d706e 855 /*******************************************************************************
bogdanm 82:6473597d706e 856 * EOF
bogdanm 82:6473597d706e 857 *******************************************************************************/