mbed library sources

Dependents:   Encrypted my_mbed lklk CyaSSL_DTLS_Cellular ... more

Superseded

This library was superseded by mbed-dev - https://os.mbed.com/users/mbed_official/code/mbed-dev/.

Development branch of the mbed library sources. This library is kept in synch with the latest changes from the mbed SDK and it is not guaranteed to work.

If you are looking for a stable and tested release, please import one of the official mbed library releases:

Import librarymbed

The official Mbed 2 C/C++ SDK provides the software platform and libraries to build your applications.

Committer:
mbed_official
Date:
Thu Apr 03 11:45:06 2014 +0100
Revision:
149:1fb5f62b92bd
Parent:
targets/hal/TARGET_Freescale/TARGET_KSDK_MCUS/TARGET_KSDK_CODE/hal/adc/fsl_adc_hal.h@146:f64d43ff0c18
Child:
324:406fd2029f23
Synchronized with git revision 220c0bb39ceee40016e1e86350c058963d01ed42

Full URL: https://github.com/mbedmicro/mbed/commit/220c0bb39ceee40016e1e86350c058963d01ed42/

Who changed what in which revision?

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