The official Mbed 2 C/C++ SDK provides the software platform and libraries to build your applications.
Dependents: hello SerialTestv11 SerialTestv12 Sierpinski ... more
mbed 2
This is the mbed 2 library. If you'd like to learn about Mbed OS please see the mbed-os docs.
TARGET_LPC54114/TOOLCHAIN_ARM_STD/fsl_adc.h@171:3a7713b1edbc, 2018-11-08 (annotated)
- Committer:
- AnnaBridge
- Date:
- Thu Nov 08 11:45:42 2018 +0000
- Revision:
- 171:3a7713b1edbc
- Parent:
- TARGET_LPC54114/TARGET_NXP/TARGET_MCUXpresso_MCUS/TARGET_LPC54114/drivers/fsl_adc.h@148:fd96258d940d
mbed library. Release version 164
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Kojto | 148:fd96258d940d | 1 | /* |
Kojto | 148:fd96258d940d | 2 | * Copyright (c) 2016, Freescale Semiconductor, Inc. |
Kojto | 148:fd96258d940d | 3 | * All rights reserved. |
Kojto | 148:fd96258d940d | 4 | * |
Kojto | 148:fd96258d940d | 5 | * Redistribution and use in source and binary forms, with or without modification, |
Kojto | 148:fd96258d940d | 6 | * are permitted provided that the following conditions are met: |
Kojto | 148:fd96258d940d | 7 | * |
Kojto | 148:fd96258d940d | 8 | * o Redistributions of source code must retain the above copyright notice, this list |
Kojto | 148:fd96258d940d | 9 | * of conditions and the following disclaimer. |
Kojto | 148:fd96258d940d | 10 | * |
Kojto | 148:fd96258d940d | 11 | * o Redistributions in binary form must reproduce the above copyright notice, this |
Kojto | 148:fd96258d940d | 12 | * list of conditions and the following disclaimer in the documentation and/or |
Kojto | 148:fd96258d940d | 13 | * other materials provided with the distribution. |
Kojto | 148:fd96258d940d | 14 | * |
Kojto | 148:fd96258d940d | 15 | * o Neither the name of Freescale Semiconductor, Inc. nor the names of its |
Kojto | 148:fd96258d940d | 16 | * contributors may be used to endorse or promote products derived from this |
Kojto | 148:fd96258d940d | 17 | * software without specific prior written permission. |
Kojto | 148:fd96258d940d | 18 | * |
Kojto | 148:fd96258d940d | 19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND |
Kojto | 148:fd96258d940d | 20 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
Kojto | 148:fd96258d940d | 21 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
Kojto | 148:fd96258d940d | 22 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR |
Kojto | 148:fd96258d940d | 23 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
Kojto | 148:fd96258d940d | 24 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
Kojto | 148:fd96258d940d | 25 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON |
Kojto | 148:fd96258d940d | 26 | * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
Kojto | 148:fd96258d940d | 27 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
Kojto | 148:fd96258d940d | 28 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
Kojto | 148:fd96258d940d | 29 | */ |
Kojto | 148:fd96258d940d | 30 | |
Kojto | 148:fd96258d940d | 31 | #ifndef __FSL_ADC_H__ |
Kojto | 148:fd96258d940d | 32 | #define __FSL_ADC_H__ |
Kojto | 148:fd96258d940d | 33 | |
Kojto | 148:fd96258d940d | 34 | #include "fsl_common.h" |
Kojto | 148:fd96258d940d | 35 | |
Kojto | 148:fd96258d940d | 36 | /*! |
Kojto | 148:fd96258d940d | 37 | * @addtogroup lpc_adc |
Kojto | 148:fd96258d940d | 38 | * @{ |
Kojto | 148:fd96258d940d | 39 | */ |
Kojto | 148:fd96258d940d | 40 | |
Kojto | 148:fd96258d940d | 41 | /*! @file */ |
Kojto | 148:fd96258d940d | 42 | |
Kojto | 148:fd96258d940d | 43 | /******************************************************************************* |
Kojto | 148:fd96258d940d | 44 | * Definitions |
Kojto | 148:fd96258d940d | 45 | ******************************************************************************/ |
Kojto | 148:fd96258d940d | 46 | |
Kojto | 148:fd96258d940d | 47 | /*! @name Driver version */ |
Kojto | 148:fd96258d940d | 48 | /*@{*/ |
Kojto | 148:fd96258d940d | 49 | /*! @brief ADC driver version 1.0.0. */ |
Kojto | 148:fd96258d940d | 50 | #define LPC_ADC_DRIVER_VERSION (MAKE_VERSION(2, 0, 0)) |
Kojto | 148:fd96258d940d | 51 | /*@}*/ |
Kojto | 148:fd96258d940d | 52 | |
Kojto | 148:fd96258d940d | 53 | /*! |
Kojto | 148:fd96258d940d | 54 | * @brief Flags |
Kojto | 148:fd96258d940d | 55 | */ |
Kojto | 148:fd96258d940d | 56 | enum _adc_status_flags |
Kojto | 148:fd96258d940d | 57 | { |
Kojto | 148:fd96258d940d | 58 | kADC_ThresholdCompareFlagOnChn0 = 1U << 0U, /*!< Threshold comparison event on Channel 0. */ |
Kojto | 148:fd96258d940d | 59 | kADC_ThresholdCompareFlagOnChn1 = 1U << 1U, /*!< Threshold comparison event on Channel 1. */ |
Kojto | 148:fd96258d940d | 60 | kADC_ThresholdCompareFlagOnChn2 = 1U << 2U, /*!< Threshold comparison event on Channel 2. */ |
Kojto | 148:fd96258d940d | 61 | kADC_ThresholdCompareFlagOnChn3 = 1U << 3U, /*!< Threshold comparison event on Channel 3. */ |
Kojto | 148:fd96258d940d | 62 | kADC_ThresholdCompareFlagOnChn4 = 1U << 4U, /*!< Threshold comparison event on Channel 4. */ |
Kojto | 148:fd96258d940d | 63 | kADC_ThresholdCompareFlagOnChn5 = 1U << 5U, /*!< Threshold comparison event on Channel 5. */ |
Kojto | 148:fd96258d940d | 64 | kADC_ThresholdCompareFlagOnChn6 = 1U << 6U, /*!< Threshold comparison event on Channel 6. */ |
Kojto | 148:fd96258d940d | 65 | kADC_ThresholdCompareFlagOnChn7 = 1U << 7U, /*!< Threshold comparison event on Channel 7. */ |
Kojto | 148:fd96258d940d | 66 | kADC_ThresholdCompareFlagOnChn8 = 1U << 8U, /*!< Threshold comparison event on Channel 8. */ |
Kojto | 148:fd96258d940d | 67 | kADC_ThresholdCompareFlagOnChn9 = 1U << 9U, /*!< Threshold comparison event on Channel 9. */ |
Kojto | 148:fd96258d940d | 68 | kADC_ThresholdCompareFlagOnChn10 = 1U << 10U, /*!< Threshold comparison event on Channel 10. */ |
Kojto | 148:fd96258d940d | 69 | kADC_ThresholdCompareFlagOnChn11 = 1U << 11U, /*!< Threshold comparison event on Channel 11. */ |
Kojto | 148:fd96258d940d | 70 | kADC_OverrunFlagForChn0 = |
Kojto | 148:fd96258d940d | 71 | 1U << 12U, /*!< Mirror the OVERRUN status flag from the result register for ADC channel 0. */ |
Kojto | 148:fd96258d940d | 72 | kADC_OverrunFlagForChn1 = |
Kojto | 148:fd96258d940d | 73 | 1U << 13U, /*!< Mirror the OVERRUN status flag from the result register for ADC channel 1. */ |
Kojto | 148:fd96258d940d | 74 | kADC_OverrunFlagForChn2 = |
Kojto | 148:fd96258d940d | 75 | 1U << 14U, /*!< Mirror the OVERRUN status flag from the result register for ADC channel 2. */ |
Kojto | 148:fd96258d940d | 76 | kADC_OverrunFlagForChn3 = |
Kojto | 148:fd96258d940d | 77 | 1U << 15U, /*!< Mirror the OVERRUN status flag from the result register for ADC channel 3. */ |
Kojto | 148:fd96258d940d | 78 | kADC_OverrunFlagForChn4 = |
Kojto | 148:fd96258d940d | 79 | 1U << 16U, /*!< Mirror the OVERRUN status flag from the result register for ADC channel 4. */ |
Kojto | 148:fd96258d940d | 80 | kADC_OverrunFlagForChn5 = |
Kojto | 148:fd96258d940d | 81 | 1U << 17U, /*!< Mirror the OVERRUN status flag from the result register for ADC channel 5. */ |
Kojto | 148:fd96258d940d | 82 | kADC_OverrunFlagForChn6 = |
Kojto | 148:fd96258d940d | 83 | 1U << 18U, /*!< Mirror the OVERRUN status flag from the result register for ADC channel 6. */ |
Kojto | 148:fd96258d940d | 84 | kADC_OverrunFlagForChn7 = |
Kojto | 148:fd96258d940d | 85 | 1U << 19U, /*!< Mirror the OVERRUN status flag from the result register for ADC channel 7. */ |
Kojto | 148:fd96258d940d | 86 | kADC_OverrunFlagForChn8 = |
Kojto | 148:fd96258d940d | 87 | 1U << 20U, /*!< Mirror the OVERRUN status flag from the result register for ADC channel 8. */ |
Kojto | 148:fd96258d940d | 88 | kADC_OverrunFlagForChn9 = |
Kojto | 148:fd96258d940d | 89 | 1U << 21U, /*!< Mirror the OVERRUN status flag from the result register for ADC channel 9. */ |
Kojto | 148:fd96258d940d | 90 | kADC_OverrunFlagForChn10 = |
Kojto | 148:fd96258d940d | 91 | 1U << 22U, /*!< Mirror the OVERRUN status flag from the result register for ADC channel 10. */ |
Kojto | 148:fd96258d940d | 92 | kADC_OverrunFlagForChn11 = |
Kojto | 148:fd96258d940d | 93 | 1U << 23U, /*!< Mirror the OVERRUN status flag from the result register for ADC channel 11. */ |
Kojto | 148:fd96258d940d | 94 | kADC_GlobalOverrunFlagForSeqA = 1U << 24U, /*!< Mirror the glabal OVERRUN status flag for conversion sequence A. */ |
Kojto | 148:fd96258d940d | 95 | kADC_GlobalOverrunFlagForSeqB = 1U << 25U, /*!< Mirror the global OVERRUN status flag for conversion sequence B. */ |
Kojto | 148:fd96258d940d | 96 | kADC_ConvSeqAInterruptFlag = 1U << 28U, /*!< Sequence A interrupt/DMA trigger. */ |
Kojto | 148:fd96258d940d | 97 | kADC_ConvSeqBInterruptFlag = 1U << 29U, /*!< Sequence B interrupt/DMA trigger. */ |
Kojto | 148:fd96258d940d | 98 | kADC_ThresholdCompareInterruptFlag = 1U << 30U, /*!< Threshold comparision interrupt flag. */ |
Kojto | 148:fd96258d940d | 99 | kADC_OverrunInterruptFlag = 1U << 31U, /*!< Overrun interrupt flag. */ |
Kojto | 148:fd96258d940d | 100 | }; |
Kojto | 148:fd96258d940d | 101 | |
Kojto | 148:fd96258d940d | 102 | /*! |
Kojto | 148:fd96258d940d | 103 | * @brief Interrupts |
Kojto | 148:fd96258d940d | 104 | * @note Not all the interrupt options are listed here |
Kojto | 148:fd96258d940d | 105 | */ |
Kojto | 148:fd96258d940d | 106 | enum _adc_interrupt_enable |
Kojto | 148:fd96258d940d | 107 | { |
Kojto | 148:fd96258d940d | 108 | kADC_ConvSeqAInterruptEnable = ADC_INTEN_SEQA_INTEN_MASK, /*!< Enable interrupt upon completion of each individual |
Kojto | 148:fd96258d940d | 109 | conversion in sequence A, or entire sequence. */ |
Kojto | 148:fd96258d940d | 110 | kADC_ConvSeqBInterruptEnable = ADC_INTEN_SEQB_INTEN_MASK, /*!< Enable interrupt upon completion of each individual |
Kojto | 148:fd96258d940d | 111 | conversion in sequence B, or entire sequence. */ |
Kojto | 148:fd96258d940d | 112 | kADC_OverrunInterruptEnable = ADC_INTEN_OVR_INTEN_MASK, /*!< Enable the detection of an overrun condition on any of |
Kojto | 148:fd96258d940d | 113 | the channel data registers will cause an overrun |
Kojto | 148:fd96258d940d | 114 | interrupt/DMA trigger. */ |
Kojto | 148:fd96258d940d | 115 | }; |
Kojto | 148:fd96258d940d | 116 | |
Kojto | 148:fd96258d940d | 117 | /*! |
Kojto | 148:fd96258d940d | 118 | * @brief Define selection of clock mode. |
Kojto | 148:fd96258d940d | 119 | */ |
Kojto | 148:fd96258d940d | 120 | typedef enum _adc_clock_mode |
Kojto | 148:fd96258d940d | 121 | { |
Kojto | 148:fd96258d940d | 122 | kADC_ClockSynchronousMode = |
Kojto | 148:fd96258d940d | 123 | 0U, /*!< The ADC clock would be derived from the system clock based on "clockDividerNumber". */ |
Kojto | 148:fd96258d940d | 124 | kADC_ClockAsynchronousMode = 1U, /*!< The ADC clock would be based on the SYSCON block's divider. */ |
Kojto | 148:fd96258d940d | 125 | } adc_clock_mode_t; |
Kojto | 148:fd96258d940d | 126 | |
Kojto | 148:fd96258d940d | 127 | /*! |
Kojto | 148:fd96258d940d | 128 | * @brief Define selection of resolution. |
Kojto | 148:fd96258d940d | 129 | */ |
Kojto | 148:fd96258d940d | 130 | typedef enum _adc_resolution |
Kojto | 148:fd96258d940d | 131 | { |
Kojto | 148:fd96258d940d | 132 | kADC_Resolution6bit = 0U, /*!< 6-bit resolution. */ |
Kojto | 148:fd96258d940d | 133 | kADC_Resolution8bit = 1U, /*!< 8-bit resolution. */ |
Kojto | 148:fd96258d940d | 134 | kADC_Resolution10bit = 2U, /*!< 10-bit resolution. */ |
Kojto | 148:fd96258d940d | 135 | kADC_Resolution12bit = 3U, /*!< 12-bit resolution. */ |
Kojto | 148:fd96258d940d | 136 | } adc_resolution_t; |
Kojto | 148:fd96258d940d | 137 | |
Kojto | 148:fd96258d940d | 138 | /*! |
Kojto | 148:fd96258d940d | 139 | * @brief Define selection of polarity of selected input trigger for conversion sequence. |
Kojto | 148:fd96258d940d | 140 | */ |
Kojto | 148:fd96258d940d | 141 | typedef enum _adc_trigger_polarity |
Kojto | 148:fd96258d940d | 142 | { |
Kojto | 148:fd96258d940d | 143 | kADC_TriggerPolarityNegativeEdge = 0U, /*!< A negative edge launches the conversion sequence on the trigger(s). */ |
Kojto | 148:fd96258d940d | 144 | kADC_TriggerPolarityPositiveEdge = 1U, /*!< A positive edge launches the conversion sequence on the trigger(s). */ |
Kojto | 148:fd96258d940d | 145 | } adc_trigger_polarity_t; |
Kojto | 148:fd96258d940d | 146 | |
Kojto | 148:fd96258d940d | 147 | /*! |
Kojto | 148:fd96258d940d | 148 | * @brief Define selection of conversion sequence's priority. |
Kojto | 148:fd96258d940d | 149 | */ |
Kojto | 148:fd96258d940d | 150 | typedef enum _adc_priority |
Kojto | 148:fd96258d940d | 151 | { |
Kojto | 148:fd96258d940d | 152 | kADC_PriorityLow = 0U, /*!< This sequence would be preempted when another sequence is started. */ |
Kojto | 148:fd96258d940d | 153 | kADC_PriorityHigh = 1U, /*!< This sequence would preempt other sequence even when is is started. */ |
Kojto | 148:fd96258d940d | 154 | } adc_priority_t; |
Kojto | 148:fd96258d940d | 155 | |
Kojto | 148:fd96258d940d | 156 | /*! |
Kojto | 148:fd96258d940d | 157 | * @brief Define selection of conversion sequence's interrupt. |
Kojto | 148:fd96258d940d | 158 | */ |
Kojto | 148:fd96258d940d | 159 | typedef enum _adc_seq_interrupt_mode |
Kojto | 148:fd96258d940d | 160 | { |
Kojto | 148:fd96258d940d | 161 | kADC_InterruptForEachConversion = 0U, /*!< The sequence interrupt/DMA trigger will be set at the end of each |
Kojto | 148:fd96258d940d | 162 | individual ADC conversion inside this conversion sequence. */ |
Kojto | 148:fd96258d940d | 163 | kADC_InterruptForEachSequence = 1U, /*!< The sequence interrupt/DMA trigger will be set when the entire set of |
Kojto | 148:fd96258d940d | 164 | this sequence conversions completes. */ |
Kojto | 148:fd96258d940d | 165 | } adc_seq_interrupt_mode_t; |
Kojto | 148:fd96258d940d | 166 | |
Kojto | 148:fd96258d940d | 167 | /*! |
Kojto | 148:fd96258d940d | 168 | * @brief Define status of threshold compare result. |
Kojto | 148:fd96258d940d | 169 | */ |
Kojto | 148:fd96258d940d | 170 | typedef enum _adc_threshold_compare_status |
Kojto | 148:fd96258d940d | 171 | { |
Kojto | 148:fd96258d940d | 172 | kADC_ThresholdCompareInRange = 0U, /*!< LOW threshold <= conversion value <= HIGH threshold. */ |
Kojto | 148:fd96258d940d | 173 | kADC_ThresholdCompareBelowRange = 1U, /*!< conversion value < LOW threshold. */ |
Kojto | 148:fd96258d940d | 174 | kADC_ThresholdCompareAboveRange = 2U, /*!< conversion value > HIGH threshold. */ |
Kojto | 148:fd96258d940d | 175 | } adc_threshold_compare_status_t; |
Kojto | 148:fd96258d940d | 176 | |
Kojto | 148:fd96258d940d | 177 | /*! |
Kojto | 148:fd96258d940d | 178 | * @brief Define status of threshold crossing detection result. |
Kojto | 148:fd96258d940d | 179 | */ |
Kojto | 148:fd96258d940d | 180 | typedef enum _adc_threshold_crossing_status |
Kojto | 148:fd96258d940d | 181 | { |
Kojto | 148:fd96258d940d | 182 | /* The conversion on this channel had the same relationship (above or below) to the threshold value established by |
Kojto | 148:fd96258d940d | 183 | * the designated LOW threshold value as did the previous conversion on this channel. */ |
Kojto | 148:fd96258d940d | 184 | kADC_ThresholdCrossingNoDetected = 0U, /*!< No threshold Crossing detected. */ |
Kojto | 148:fd96258d940d | 185 | |
Kojto | 148:fd96258d940d | 186 | /* Indicates that a threshold crossing in the downward direction has occurred - i.e. the previous sample on this |
Kojto | 148:fd96258d940d | 187 | * channel was above the threshold value established by the designated LOW threshold value and the current sample is |
Kojto | 148:fd96258d940d | 188 | * below that threshold. */ |
Kojto | 148:fd96258d940d | 189 | kADC_ThresholdCrossingDownward = 2U, /*!< Downward Threshold Crossing detected. */ |
Kojto | 148:fd96258d940d | 190 | |
Kojto | 148:fd96258d940d | 191 | /* Indicates that a thre shold crossing in the upward direction has occurred - i.e. the previous sample on this |
Kojto | 148:fd96258d940d | 192 | * channel was below the threshold value established by the designated LOW threshold value and the current sample is |
Kojto | 148:fd96258d940d | 193 | * above that threshold. */ |
Kojto | 148:fd96258d940d | 194 | kADC_ThresholdCrossingUpward = 3U, /*!< Upward Threshold Crossing Detected. */ |
Kojto | 148:fd96258d940d | 195 | } adc_threshold_crossing_status_t; |
Kojto | 148:fd96258d940d | 196 | |
Kojto | 148:fd96258d940d | 197 | /*! |
Kojto | 148:fd96258d940d | 198 | * @brief Define interrupt mode for threshold compare event. |
Kojto | 148:fd96258d940d | 199 | */ |
Kojto | 148:fd96258d940d | 200 | typedef enum _adc_threshold_interrupt_mode |
Kojto | 148:fd96258d940d | 201 | { |
Kojto | 148:fd96258d940d | 202 | kADC_ThresholdInterruptDisabled = 0U, /*!< Threshold comparison interrupt is disabled. */ |
Kojto | 148:fd96258d940d | 203 | kADC_ThresholdInterruptOnOutside = 1U, /*!< Threshold comparison interrupt is enabled on outside threshold. */ |
Kojto | 148:fd96258d940d | 204 | kADC_ThresholdInterruptOnCrossing = 2U, /*!< Threshold comparison interrupt is enabled on crossing threshold. */ |
Kojto | 148:fd96258d940d | 205 | } adc_threshold_interrupt_mode_t; |
Kojto | 148:fd96258d940d | 206 | |
Kojto | 148:fd96258d940d | 207 | /*! |
Kojto | 148:fd96258d940d | 208 | * @brief Define structure for configuring the block. |
Kojto | 148:fd96258d940d | 209 | */ |
Kojto | 148:fd96258d940d | 210 | typedef struct _adc_config |
Kojto | 148:fd96258d940d | 211 | { |
Kojto | 148:fd96258d940d | 212 | adc_clock_mode_t clockMode; /*!< Select the clock mode for ADC converter. */ |
Kojto | 148:fd96258d940d | 213 | uint32_t clockDividerNumber; /*!< This field is only available when using kADC_ClockSynchronousMode for "clockMode" |
Kojto | 148:fd96258d940d | 214 | field. The divider would be plused by 1 based on the value in this field. The |
Kojto | 148:fd96258d940d | 215 | available range is in 8 bits. */ |
Kojto | 148:fd96258d940d | 216 | adc_resolution_t resolution; /*!< Select the conversion bits. */ |
Kojto | 148:fd96258d940d | 217 | bool enableBypassCalibration; /*!< By default, a calibration cycle must be performed each time the chip is |
Kojto | 148:fd96258d940d | 218 | powered-up. Re-calibration may be warranted periodically - especially if |
Kojto | 148:fd96258d940d | 219 | operating conditions have changed. To enable this option would avoid the need to |
Kojto | 148:fd96258d940d | 220 | calibrate if offset error is not a concern in the application. */ |
Kojto | 148:fd96258d940d | 221 | uint32_t sampleTimeNumber; /*!< By default, with value as "0U", the sample period would be 2.5 ADC clocks. Then, |
Kojto | 148:fd96258d940d | 222 | to plus the "sampleTimeNumber" value here. The available value range is in 3 bits.*/ |
Kojto | 148:fd96258d940d | 223 | } adc_config_t; |
Kojto | 148:fd96258d940d | 224 | |
Kojto | 148:fd96258d940d | 225 | /*! |
Kojto | 148:fd96258d940d | 226 | * @brief Define structure for configuring conversion sequence. |
Kojto | 148:fd96258d940d | 227 | */ |
Kojto | 148:fd96258d940d | 228 | typedef struct _adc_conv_seq_config |
Kojto | 148:fd96258d940d | 229 | { |
Kojto | 148:fd96258d940d | 230 | uint32_t channelMask; /*!< Selects which one or more of the ADC channels will be sampled and converted when this |
Kojto | 148:fd96258d940d | 231 | sequence is launched. The masked channels would be involved in current conversion |
Kojto | 148:fd96258d940d | 232 | sequence, beginning with the lowest-order. The available range is in 12-bit. */ |
Kojto | 148:fd96258d940d | 233 | uint32_t triggerMask; /*!< Selects which one or more of the available hardware trigger sources will cause this |
Kojto | 148:fd96258d940d | 234 | conversion sequence to be initiated. The available range is 6-bit.*/ |
Kojto | 148:fd96258d940d | 235 | adc_trigger_polarity_t triggerPolarity; /*!< Select the trigger to lauch conversion sequence. */ |
Kojto | 148:fd96258d940d | 236 | bool enableSyncBypass; /*!< To enable this feature allows the hardware trigger input to bypass synchronization |
Kojto | 148:fd96258d940d | 237 | flip-flop stages and therefore shorten the time between the trigger input signal and the |
Kojto | 148:fd96258d940d | 238 | start of a conversion. */ |
Kojto | 148:fd96258d940d | 239 | bool enableSingleStep; /*!< When enabling this feature, a trigger will launch a single conversion on the next |
Kojto | 148:fd96258d940d | 240 | channel in the sequence instead of the default response of launching an entire sequence |
Kojto | 148:fd96258d940d | 241 | of conversions. */ |
Kojto | 148:fd96258d940d | 242 | adc_seq_interrupt_mode_t interruptMode; /*!< Select the interrpt/DMA trigger mode. */ |
Kojto | 148:fd96258d940d | 243 | } adc_conv_seq_config_t; |
Kojto | 148:fd96258d940d | 244 | |
Kojto | 148:fd96258d940d | 245 | /*! |
Kojto | 148:fd96258d940d | 246 | * @brief Define structure of keeping conversion result information. |
Kojto | 148:fd96258d940d | 247 | */ |
Kojto | 148:fd96258d940d | 248 | typedef struct _adc_result_info |
Kojto | 148:fd96258d940d | 249 | { |
Kojto | 148:fd96258d940d | 250 | uint32_t result; /*!< Keey the conversion data value. */ |
Kojto | 148:fd96258d940d | 251 | adc_threshold_compare_status_t thresholdCompareStatus; /*!< Keep the threshold compare status. */ |
Kojto | 148:fd96258d940d | 252 | adc_threshold_crossing_status_t thresholdCorssingStatus; /*!< Keep the threshold crossing status. */ |
Kojto | 148:fd96258d940d | 253 | uint32_t channelNumber; /*!< Keep the channel number for this conversion. */ |
Kojto | 148:fd96258d940d | 254 | bool overrunFlag; /*!< Keep the status whether the conversion is overrun or not. */ |
Kojto | 148:fd96258d940d | 255 | /* The data available flag would be returned by the reading result API. */ |
Kojto | 148:fd96258d940d | 256 | } adc_result_info_t; |
Kojto | 148:fd96258d940d | 257 | |
Kojto | 148:fd96258d940d | 258 | #if defined(__cplusplus) |
Kojto | 148:fd96258d940d | 259 | extern "C" { |
Kojto | 148:fd96258d940d | 260 | #endif |
Kojto | 148:fd96258d940d | 261 | |
Kojto | 148:fd96258d940d | 262 | /******************************************************************************* |
Kojto | 148:fd96258d940d | 263 | * API |
Kojto | 148:fd96258d940d | 264 | ******************************************************************************/ |
Kojto | 148:fd96258d940d | 265 | |
Kojto | 148:fd96258d940d | 266 | /*! |
Kojto | 148:fd96258d940d | 267 | * @name Initialization and Deinitialization |
Kojto | 148:fd96258d940d | 268 | * @{ |
Kojto | 148:fd96258d940d | 269 | */ |
Kojto | 148:fd96258d940d | 270 | |
Kojto | 148:fd96258d940d | 271 | /*! |
Kojto | 148:fd96258d940d | 272 | * @brief Initialize the ADC module. |
Kojto | 148:fd96258d940d | 273 | * |
Kojto | 148:fd96258d940d | 274 | * @param base ADC peripheral base address. |
Kojto | 148:fd96258d940d | 275 | * @param config Pointer to configuration structure, see to #adc_config_t. |
Kojto | 148:fd96258d940d | 276 | */ |
Kojto | 148:fd96258d940d | 277 | void ADC_Init(ADC_Type *base, const adc_config_t *config); |
Kojto | 148:fd96258d940d | 278 | |
Kojto | 148:fd96258d940d | 279 | /*! |
Kojto | 148:fd96258d940d | 280 | * @brief Deinitialize the ADC module. |
Kojto | 148:fd96258d940d | 281 | * |
Kojto | 148:fd96258d940d | 282 | * @param base ADC peripheral base address. |
Kojto | 148:fd96258d940d | 283 | */ |
Kojto | 148:fd96258d940d | 284 | void ADC_Deinit(ADC_Type *base); |
Kojto | 148:fd96258d940d | 285 | |
Kojto | 148:fd96258d940d | 286 | /*! |
Kojto | 148:fd96258d940d | 287 | * @brief Gets an available pre-defined settings for initial configuration. |
Kojto | 148:fd96258d940d | 288 | * |
Kojto | 148:fd96258d940d | 289 | * This function initializes the initial configuration structure with an available settings. The default values are: |
Kojto | 148:fd96258d940d | 290 | * @code |
Kojto | 148:fd96258d940d | 291 | * config->clockMode = kADC_ClockSynchronousMode; |
Kojto | 148:fd96258d940d | 292 | * config->clockDividerNumber = 0U; |
Kojto | 148:fd96258d940d | 293 | * config->resolution = kADC_Resolution12bit; |
Kojto | 148:fd96258d940d | 294 | * config->enableBypassCalibration = false; |
Kojto | 148:fd96258d940d | 295 | * config->sampleTimeNumber = 0U; |
Kojto | 148:fd96258d940d | 296 | * @endcode |
Kojto | 148:fd96258d940d | 297 | * @param config Pointer to configuration structure. |
Kojto | 148:fd96258d940d | 298 | */ |
Kojto | 148:fd96258d940d | 299 | void ADC_GetDefaultConfig(adc_config_t *config); |
Kojto | 148:fd96258d940d | 300 | |
Kojto | 148:fd96258d940d | 301 | /*! |
Kojto | 148:fd96258d940d | 302 | * @brief Do the self hardware calibration. |
Kojto | 148:fd96258d940d | 303 | * |
Kojto | 148:fd96258d940d | 304 | * @param base ADC peripheral base address. |
Kojto | 148:fd96258d940d | 305 | * @retval true Calibration succeed. |
Kojto | 148:fd96258d940d | 306 | * @retval false Calibration failed. |
Kojto | 148:fd96258d940d | 307 | */ |
Kojto | 148:fd96258d940d | 308 | bool ADC_DoSelfCalibration(ADC_Type *base); |
Kojto | 148:fd96258d940d | 309 | |
Kojto | 148:fd96258d940d | 310 | /*! |
Kojto | 148:fd96258d940d | 311 | * @brief Enable the internal temperature sensor measurement. |
Kojto | 148:fd96258d940d | 312 | * |
Kojto | 148:fd96258d940d | 313 | * When enabling the internal temperature sensor measurement, the channel 0 would be connected to internal sensor |
Kojto | 148:fd96258d940d | 314 | * instead of external pin. |
Kojto | 148:fd96258d940d | 315 | * |
Kojto | 148:fd96258d940d | 316 | * @param base ADC peripheral base address. |
Kojto | 148:fd96258d940d | 317 | * @param enable Switcher to enable the feature or not. |
Kojto | 148:fd96258d940d | 318 | */ |
Kojto | 148:fd96258d940d | 319 | static inline void ADC_EnableTemperatureSensor(ADC_Type *base, bool enable) |
Kojto | 148:fd96258d940d | 320 | { |
Kojto | 148:fd96258d940d | 321 | if (enable) |
Kojto | 148:fd96258d940d | 322 | { |
Kojto | 148:fd96258d940d | 323 | base->INSEL = (base->INSEL & ~ADC_INSEL_SEL_MASK) | ADC_INSEL_SEL(0x3); |
Kojto | 148:fd96258d940d | 324 | } |
Kojto | 148:fd96258d940d | 325 | else |
Kojto | 148:fd96258d940d | 326 | { |
Kojto | 148:fd96258d940d | 327 | base->INSEL = (base->INSEL & ~ADC_INSEL_SEL_MASK) | ADC_INSEL_SEL(0); |
Kojto | 148:fd96258d940d | 328 | } |
Kojto | 148:fd96258d940d | 329 | } |
Kojto | 148:fd96258d940d | 330 | |
Kojto | 148:fd96258d940d | 331 | /* @} */ |
Kojto | 148:fd96258d940d | 332 | |
Kojto | 148:fd96258d940d | 333 | /*! |
Kojto | 148:fd96258d940d | 334 | * @name Control conversion sequence A. |
Kojto | 148:fd96258d940d | 335 | * @{ |
Kojto | 148:fd96258d940d | 336 | */ |
Kojto | 148:fd96258d940d | 337 | |
Kojto | 148:fd96258d940d | 338 | /*! |
Kojto | 148:fd96258d940d | 339 | * @brief Enable the conversion sequence A. |
Kojto | 148:fd96258d940d | 340 | * |
Kojto | 148:fd96258d940d | 341 | * In order to avoid spuriously triggering the sequence, the trigger to conversion sequence should be ready before the |
Kojto | 148:fd96258d940d | 342 | * sequence is ready. when the sequence is disabled, the trigger would be ignored. Also, it is suggested to disable the |
Kojto | 148:fd96258d940d | 343 | * sequence during changing the sequence's setting. |
Kojto | 148:fd96258d940d | 344 | * |
Kojto | 148:fd96258d940d | 345 | * @param base ADC peripheral base address. |
Kojto | 148:fd96258d940d | 346 | * @param enable Switcher to enable the feature or not. |
Kojto | 148:fd96258d940d | 347 | */ |
Kojto | 148:fd96258d940d | 348 | static inline void ADC_EnableConvSeqA(ADC_Type *base, bool enable) |
Kojto | 148:fd96258d940d | 349 | { |
Kojto | 148:fd96258d940d | 350 | if (enable) |
Kojto | 148:fd96258d940d | 351 | { |
Kojto | 148:fd96258d940d | 352 | base->SEQ_CTRL[0] |= ADC_SEQ_CTRL_SEQ_ENA_MASK; |
Kojto | 148:fd96258d940d | 353 | } |
Kojto | 148:fd96258d940d | 354 | else |
Kojto | 148:fd96258d940d | 355 | { |
Kojto | 148:fd96258d940d | 356 | base->SEQ_CTRL[0] &= ~ADC_SEQ_CTRL_SEQ_ENA_MASK; |
Kojto | 148:fd96258d940d | 357 | } |
Kojto | 148:fd96258d940d | 358 | } |
Kojto | 148:fd96258d940d | 359 | |
Kojto | 148:fd96258d940d | 360 | /*! |
Kojto | 148:fd96258d940d | 361 | * @brief Configure the conversion sequence A. |
Kojto | 148:fd96258d940d | 362 | * |
Kojto | 148:fd96258d940d | 363 | * @param base ADC peripheral base address. |
Kojto | 148:fd96258d940d | 364 | * @param config Pointer to configuration structure, see to #adc_conv_seq_config_t. |
Kojto | 148:fd96258d940d | 365 | */ |
Kojto | 148:fd96258d940d | 366 | void ADC_SetConvSeqAConfig(ADC_Type *base, const adc_conv_seq_config_t *config); |
Kojto | 148:fd96258d940d | 367 | |
Kojto | 148:fd96258d940d | 368 | /*! |
Kojto | 148:fd96258d940d | 369 | * @brief Do trigger the sequence's conversion by software. |
Kojto | 148:fd96258d940d | 370 | * |
Kojto | 148:fd96258d940d | 371 | * @param base ADC peripheral base address. |
Kojto | 148:fd96258d940d | 372 | */ |
Kojto | 148:fd96258d940d | 373 | static inline void ADC_DoSoftwareTriggerConvSeqA(ADC_Type *base) |
Kojto | 148:fd96258d940d | 374 | { |
Kojto | 148:fd96258d940d | 375 | base->SEQ_CTRL[0] |= ADC_SEQ_CTRL_START_MASK; |
Kojto | 148:fd96258d940d | 376 | } |
Kojto | 148:fd96258d940d | 377 | |
Kojto | 148:fd96258d940d | 378 | /*! |
Kojto | 148:fd96258d940d | 379 | * @brief Enable the burst conversion of sequence A. |
Kojto | 148:fd96258d940d | 380 | * |
Kojto | 148:fd96258d940d | 381 | * Enable the burst mode would cause the conversion sequence to be cntinuously cycled through. Other triggers would be |
Kojto | 148:fd96258d940d | 382 | * ignored while this mode is enabled. Repeated conversions could be halted by disabling this mode. And the sequence |
Kojto | 148:fd96258d940d | 383 | * currently in process will be completed before cnversions are terminated. |
Kojto | 148:fd96258d940d | 384 | * Note that a new sequence could begin just before the burst mode is disabled. |
Kojto | 148:fd96258d940d | 385 | * |
Kojto | 148:fd96258d940d | 386 | * @param base ADC peripheral base address. |
Kojto | 148:fd96258d940d | 387 | * @param enable Switcher to enable this feature. |
Kojto | 148:fd96258d940d | 388 | */ |
Kojto | 148:fd96258d940d | 389 | static inline void ADC_EnableConvSeqABurstMode(ADC_Type *base, bool enable) |
Kojto | 148:fd96258d940d | 390 | { |
Kojto | 148:fd96258d940d | 391 | if (enable) |
Kojto | 148:fd96258d940d | 392 | { |
Kojto | 148:fd96258d940d | 393 | base->SEQ_CTRL[0] |= ADC_SEQ_CTRL_BURST_MASK; |
Kojto | 148:fd96258d940d | 394 | } |
Kojto | 148:fd96258d940d | 395 | else |
Kojto | 148:fd96258d940d | 396 | { |
Kojto | 148:fd96258d940d | 397 | base->SEQ_CTRL[0] &= ~ADC_SEQ_CTRL_BURST_MASK; |
Kojto | 148:fd96258d940d | 398 | } |
Kojto | 148:fd96258d940d | 399 | } |
Kojto | 148:fd96258d940d | 400 | |
Kojto | 148:fd96258d940d | 401 | /*! |
Kojto | 148:fd96258d940d | 402 | * @brief Set the high priority for conversion sequence A. |
Kojto | 148:fd96258d940d | 403 | * |
Kojto | 148:fd96258d940d | 404 | * @param base ADC peripheral bass address. |
Kojto | 148:fd96258d940d | 405 | */ |
Kojto | 148:fd96258d940d | 406 | static inline void ADC_SetConvSeqAHighPriority(ADC_Type *base) |
Kojto | 148:fd96258d940d | 407 | { |
Kojto | 148:fd96258d940d | 408 | base->SEQ_CTRL[0] |= ADC_SEQ_CTRL_LOWPRIO_MASK; |
Kojto | 148:fd96258d940d | 409 | } |
Kojto | 148:fd96258d940d | 410 | |
Kojto | 148:fd96258d940d | 411 | /* @} */ |
Kojto | 148:fd96258d940d | 412 | |
Kojto | 148:fd96258d940d | 413 | /*! |
Kojto | 148:fd96258d940d | 414 | * @name Control conversion sequence B. |
Kojto | 148:fd96258d940d | 415 | * @{ |
Kojto | 148:fd96258d940d | 416 | */ |
Kojto | 148:fd96258d940d | 417 | |
Kojto | 148:fd96258d940d | 418 | /*! |
Kojto | 148:fd96258d940d | 419 | * @brief Enable the conversion sequence B. |
Kojto | 148:fd96258d940d | 420 | * |
Kojto | 148:fd96258d940d | 421 | * In order to avoid spuriously triggering the sequence, the trigger to conversion sequence should be ready before the |
Kojto | 148:fd96258d940d | 422 | * sequence is ready. when the sequence is disabled, the trigger would be ignored. Also, it is suggested to disable the |
Kojto | 148:fd96258d940d | 423 | * sequence during changing the sequence's setting. |
Kojto | 148:fd96258d940d | 424 | * |
Kojto | 148:fd96258d940d | 425 | * @param base ADC peripheral base address. |
Kojto | 148:fd96258d940d | 426 | * @param enable Switcher to enable the feature or not. |
Kojto | 148:fd96258d940d | 427 | */ |
Kojto | 148:fd96258d940d | 428 | static inline void ADC_EnableConvSeqB(ADC_Type *base, bool enable) |
Kojto | 148:fd96258d940d | 429 | { |
Kojto | 148:fd96258d940d | 430 | if (enable) |
Kojto | 148:fd96258d940d | 431 | { |
Kojto | 148:fd96258d940d | 432 | base->SEQ_CTRL[1] |= ADC_SEQ_CTRL_SEQ_ENA_MASK; |
Kojto | 148:fd96258d940d | 433 | } |
Kojto | 148:fd96258d940d | 434 | else |
Kojto | 148:fd96258d940d | 435 | { |
Kojto | 148:fd96258d940d | 436 | base->SEQ_CTRL[1] &= ~ADC_SEQ_CTRL_SEQ_ENA_MASK; |
Kojto | 148:fd96258d940d | 437 | } |
Kojto | 148:fd96258d940d | 438 | } |
Kojto | 148:fd96258d940d | 439 | |
Kojto | 148:fd96258d940d | 440 | /*! |
Kojto | 148:fd96258d940d | 441 | * @brief Configure the conversion sequence B. |
Kojto | 148:fd96258d940d | 442 | * |
Kojto | 148:fd96258d940d | 443 | * @param base ADC peripheral base address. |
Kojto | 148:fd96258d940d | 444 | * @param config Pointer to configuration structure, see to #adc_conv_seq_config_t. |
Kojto | 148:fd96258d940d | 445 | */ |
Kojto | 148:fd96258d940d | 446 | void ADC_SetConvSeqBConfig(ADC_Type *base, const adc_conv_seq_config_t *config); |
Kojto | 148:fd96258d940d | 447 | |
Kojto | 148:fd96258d940d | 448 | /*! |
Kojto | 148:fd96258d940d | 449 | * @brief Do trigger the sequence's conversion by software. |
Kojto | 148:fd96258d940d | 450 | * |
Kojto | 148:fd96258d940d | 451 | * @param base ADC peripheral base address. |
Kojto | 148:fd96258d940d | 452 | */ |
Kojto | 148:fd96258d940d | 453 | static inline void ADC_DoSoftwareTriggerConvSeqB(ADC_Type *base) |
Kojto | 148:fd96258d940d | 454 | { |
Kojto | 148:fd96258d940d | 455 | base->SEQ_CTRL[1] |= ADC_SEQ_CTRL_START_MASK; |
Kojto | 148:fd96258d940d | 456 | } |
Kojto | 148:fd96258d940d | 457 | |
Kojto | 148:fd96258d940d | 458 | /*! |
Kojto | 148:fd96258d940d | 459 | * @brief Enable the burst conversion of sequence B. |
Kojto | 148:fd96258d940d | 460 | * |
Kojto | 148:fd96258d940d | 461 | * Enable the burst mode would cause the conversion sequence to be continuously cycled through. Other triggers would be |
Kojto | 148:fd96258d940d | 462 | * ignored while this mode is enabled. Repeated conversions could be halted by disabling this mode. And the sequence |
Kojto | 148:fd96258d940d | 463 | * currently in process will be completed before cnversions are terminated. |
Kojto | 148:fd96258d940d | 464 | * Note that a new sequence could begin just before the burst mode is disabled. |
Kojto | 148:fd96258d940d | 465 | * |
Kojto | 148:fd96258d940d | 466 | * @param base ADC peripheral base address. |
Kojto | 148:fd96258d940d | 467 | * @param enable Switcher to enable this feature. |
Kojto | 148:fd96258d940d | 468 | */ |
Kojto | 148:fd96258d940d | 469 | static inline void ADC_EnableConvSeqBBurstMode(ADC_Type *base, bool enable) |
Kojto | 148:fd96258d940d | 470 | { |
Kojto | 148:fd96258d940d | 471 | if (enable) |
Kojto | 148:fd96258d940d | 472 | { |
Kojto | 148:fd96258d940d | 473 | base->SEQ_CTRL[1] |= ADC_SEQ_CTRL_BURST_MASK; |
Kojto | 148:fd96258d940d | 474 | } |
Kojto | 148:fd96258d940d | 475 | else |
Kojto | 148:fd96258d940d | 476 | { |
Kojto | 148:fd96258d940d | 477 | base->SEQ_CTRL[1] &= ~ADC_SEQ_CTRL_BURST_MASK; |
Kojto | 148:fd96258d940d | 478 | } |
Kojto | 148:fd96258d940d | 479 | } |
Kojto | 148:fd96258d940d | 480 | |
Kojto | 148:fd96258d940d | 481 | /*! |
Kojto | 148:fd96258d940d | 482 | * @brief Set the high priority for conversion sequence B. |
Kojto | 148:fd96258d940d | 483 | * |
Kojto | 148:fd96258d940d | 484 | * @param base ADC peripheral bass address. |
Kojto | 148:fd96258d940d | 485 | */ |
Kojto | 148:fd96258d940d | 486 | static inline void ADC_SetConvSeqBHighPriority(ADC_Type *base) |
Kojto | 148:fd96258d940d | 487 | { |
Kojto | 148:fd96258d940d | 488 | base->SEQ_CTRL[0] &= ~ADC_SEQ_CTRL_LOWPRIO_MASK; |
Kojto | 148:fd96258d940d | 489 | } |
Kojto | 148:fd96258d940d | 490 | |
Kojto | 148:fd96258d940d | 491 | /* @} */ |
Kojto | 148:fd96258d940d | 492 | |
Kojto | 148:fd96258d940d | 493 | /*! |
Kojto | 148:fd96258d940d | 494 | * @name Data result. |
Kojto | 148:fd96258d940d | 495 | * @{ |
Kojto | 148:fd96258d940d | 496 | */ |
Kojto | 148:fd96258d940d | 497 | |
Kojto | 148:fd96258d940d | 498 | /*! |
Kojto | 148:fd96258d940d | 499 | * @brief Get the global ADC conversion infomation of sequence A. |
Kojto | 148:fd96258d940d | 500 | * |
Kojto | 148:fd96258d940d | 501 | * @param base ADC peripheral base address. |
Kojto | 148:fd96258d940d | 502 | * @param info Pointer to information structure, see to #adc_result_info_t; |
Kojto | 148:fd96258d940d | 503 | * @retval true The conversion result is ready. |
Kojto | 148:fd96258d940d | 504 | * @retval false The conversion result is not ready yet. |
Kojto | 148:fd96258d940d | 505 | */ |
Kojto | 148:fd96258d940d | 506 | bool ADC_GetConvSeqAGlobalConversionResult(ADC_Type *base, adc_result_info_t *info); |
Kojto | 148:fd96258d940d | 507 | |
Kojto | 148:fd96258d940d | 508 | /*! |
Kojto | 148:fd96258d940d | 509 | * @brief Get the global ADC conversion infomation of sequence B. |
Kojto | 148:fd96258d940d | 510 | * |
Kojto | 148:fd96258d940d | 511 | * @param base ADC peripheral base address. |
Kojto | 148:fd96258d940d | 512 | * @param info Pointer to information structure, see to #adc_result_info_t; |
Kojto | 148:fd96258d940d | 513 | * @retval true The conversion result is ready. |
Kojto | 148:fd96258d940d | 514 | * @retval false The conversion result is not ready yet. |
Kojto | 148:fd96258d940d | 515 | */ |
Kojto | 148:fd96258d940d | 516 | bool ADC_GetConvSeqBGlobalConversionResult(ADC_Type *base, adc_result_info_t *info); |
Kojto | 148:fd96258d940d | 517 | |
Kojto | 148:fd96258d940d | 518 | /*! |
Kojto | 148:fd96258d940d | 519 | * @brief Get the channel's ADC conversion completed under each conversion sequence. |
Kojto | 148:fd96258d940d | 520 | * |
Kojto | 148:fd96258d940d | 521 | * @param base ADC peripheral base address. |
Kojto | 148:fd96258d940d | 522 | * @param channel The indicated channel number. |
Kojto | 148:fd96258d940d | 523 | * @param info Pointer to information structure, see to #adc_result_info_t; |
Kojto | 148:fd96258d940d | 524 | * @retval true The conversion result is ready. |
Kojto | 148:fd96258d940d | 525 | * @retval false The conversion result is not ready yet. |
Kojto | 148:fd96258d940d | 526 | */ |
Kojto | 148:fd96258d940d | 527 | bool ADC_GetChannelConversionResult(ADC_Type *base, uint32_t channel, adc_result_info_t *info); |
Kojto | 148:fd96258d940d | 528 | |
Kojto | 148:fd96258d940d | 529 | /* @} */ |
Kojto | 148:fd96258d940d | 530 | |
Kojto | 148:fd96258d940d | 531 | /*! |
Kojto | 148:fd96258d940d | 532 | * @name Threshold function. |
Kojto | 148:fd96258d940d | 533 | * @{ |
Kojto | 148:fd96258d940d | 534 | */ |
Kojto | 148:fd96258d940d | 535 | |
Kojto | 148:fd96258d940d | 536 | /*! |
Kojto | 148:fd96258d940d | 537 | * @brief Set the threshhold pair 0 with low and high value. |
Kojto | 148:fd96258d940d | 538 | * |
Kojto | 148:fd96258d940d | 539 | * @param base ADC peripheral base address. |
Kojto | 148:fd96258d940d | 540 | * @param lowValue LOW threshold value. |
Kojto | 148:fd96258d940d | 541 | * @param highValue HIGH threshold value. |
Kojto | 148:fd96258d940d | 542 | */ |
Kojto | 148:fd96258d940d | 543 | static inline void ADC_SetThresholdPair0(ADC_Type *base, uint32_t lowValue, uint32_t highValue) |
Kojto | 148:fd96258d940d | 544 | { |
Kojto | 148:fd96258d940d | 545 | base->THR0_LOW = ADC_THR0_LOW_THRLOW(lowValue); |
Kojto | 148:fd96258d940d | 546 | base->THR0_HIGH = ADC_THR0_HIGH_THRHIGH(highValue); |
Kojto | 148:fd96258d940d | 547 | } |
Kojto | 148:fd96258d940d | 548 | |
Kojto | 148:fd96258d940d | 549 | /*! |
Kojto | 148:fd96258d940d | 550 | * @brief Set the threshhold pair 1 with low and high value. |
Kojto | 148:fd96258d940d | 551 | * |
Kojto | 148:fd96258d940d | 552 | * @param base ADC peripheral base address. |
Kojto | 148:fd96258d940d | 553 | * @param lowValue LOW threshold value. The available value is with 12-bit. |
Kojto | 148:fd96258d940d | 554 | * @param highValue HIGH threshold value. The available value is with 12-bit. |
Kojto | 148:fd96258d940d | 555 | */ |
Kojto | 148:fd96258d940d | 556 | static inline void ADC_SetThresholdPair1(ADC_Type *base, uint32_t lowValue, uint32_t highValue) |
Kojto | 148:fd96258d940d | 557 | { |
Kojto | 148:fd96258d940d | 558 | base->THR1_LOW = ADC_THR1_LOW_THRLOW(lowValue); |
Kojto | 148:fd96258d940d | 559 | base->THR1_HIGH = ADC_THR1_HIGH_THRHIGH(highValue); |
Kojto | 148:fd96258d940d | 560 | } |
Kojto | 148:fd96258d940d | 561 | |
Kojto | 148:fd96258d940d | 562 | /*! |
Kojto | 148:fd96258d940d | 563 | * @brief Set given channels to apply the threshold pare 0. |
Kojto | 148:fd96258d940d | 564 | * |
Kojto | 148:fd96258d940d | 565 | * @param base ADC peripheral base address. |
Kojto | 148:fd96258d940d | 566 | * @param channelMask Indicated channels' mask. |
Kojto | 148:fd96258d940d | 567 | */ |
Kojto | 148:fd96258d940d | 568 | static inline void ADC_SetChannelWithThresholdPair0(ADC_Type *base, uint32_t channelMask) |
Kojto | 148:fd96258d940d | 569 | { |
Kojto | 148:fd96258d940d | 570 | base->CHAN_THRSEL &= ~(channelMask); |
Kojto | 148:fd96258d940d | 571 | } |
Kojto | 148:fd96258d940d | 572 | |
Kojto | 148:fd96258d940d | 573 | /*! |
Kojto | 148:fd96258d940d | 574 | * @brief Set given channels to apply the threshold pare 1. |
Kojto | 148:fd96258d940d | 575 | * |
Kojto | 148:fd96258d940d | 576 | * @param base ADC peripheral base address. |
Kojto | 148:fd96258d940d | 577 | * @param channelMask Indicated channels' mask. |
Kojto | 148:fd96258d940d | 578 | */ |
Kojto | 148:fd96258d940d | 579 | static inline void ADC_SetChannelWithThresholdPair1(ADC_Type *base, uint32_t channelMask) |
Kojto | 148:fd96258d940d | 580 | { |
Kojto | 148:fd96258d940d | 581 | base->CHAN_THRSEL |= channelMask; |
Kojto | 148:fd96258d940d | 582 | } |
Kojto | 148:fd96258d940d | 583 | |
Kojto | 148:fd96258d940d | 584 | /* @} */ |
Kojto | 148:fd96258d940d | 585 | |
Kojto | 148:fd96258d940d | 586 | /*! |
Kojto | 148:fd96258d940d | 587 | * @name Interrupts. |
Kojto | 148:fd96258d940d | 588 | * @{ |
Kojto | 148:fd96258d940d | 589 | */ |
Kojto | 148:fd96258d940d | 590 | |
Kojto | 148:fd96258d940d | 591 | /*! |
Kojto | 148:fd96258d940d | 592 | * @brief Enable interrupts for conversion sequences. |
Kojto | 148:fd96258d940d | 593 | * |
Kojto | 148:fd96258d940d | 594 | * @param base ADC peripheral base address. |
Kojto | 148:fd96258d940d | 595 | * @param mask Mask of interrupt mask value for global block except each channal, see to #_adc_interrupt_enable. |
Kojto | 148:fd96258d940d | 596 | */ |
Kojto | 148:fd96258d940d | 597 | static inline void ADC_EnableInterrupts(ADC_Type *base, uint32_t mask) |
Kojto | 148:fd96258d940d | 598 | { |
Kojto | 148:fd96258d940d | 599 | base->INTEN |= (0x7 & mask); |
Kojto | 148:fd96258d940d | 600 | } |
Kojto | 148:fd96258d940d | 601 | |
Kojto | 148:fd96258d940d | 602 | /*! |
Kojto | 148:fd96258d940d | 603 | * @brief Disable interrupts for conversion sequence. |
Kojto | 148:fd96258d940d | 604 | * |
Kojto | 148:fd96258d940d | 605 | * @param base ADC peripheral base address. |
Kojto | 148:fd96258d940d | 606 | * @param mask Mask of interrupt mask value for global block except each channel, see to #_adc_interrupt_enable. |
Kojto | 148:fd96258d940d | 607 | */ |
Kojto | 148:fd96258d940d | 608 | static inline void ADC_DisableInterrupts(ADC_Type *base, uint32_t mask) |
Kojto | 148:fd96258d940d | 609 | { |
Kojto | 148:fd96258d940d | 610 | base->INTEN &= ~(0x7 & mask); |
Kojto | 148:fd96258d940d | 611 | } |
Kojto | 148:fd96258d940d | 612 | |
Kojto | 148:fd96258d940d | 613 | /*! |
Kojto | 148:fd96258d940d | 614 | * @brief Enable the interrupt of shreshold compare event for each channel. |
Kojto | 148:fd96258d940d | 615 | * |
Kojto | 148:fd96258d940d | 616 | * @param base ADC peripheral base address. |
Kojto | 148:fd96258d940d | 617 | * @param channel Channel number. |
Kojto | 148:fd96258d940d | 618 | * @param mode Interrupt mode for threshold compare event, see to #adc_threshold_interrupt_mode_t. |
Kojto | 148:fd96258d940d | 619 | */ |
Kojto | 148:fd96258d940d | 620 | static inline void ADC_EnableShresholdCompareInterrupt(ADC_Type *base, |
Kojto | 148:fd96258d940d | 621 | uint32_t channel, |
Kojto | 148:fd96258d940d | 622 | adc_threshold_interrupt_mode_t mode) |
Kojto | 148:fd96258d940d | 623 | { |
Kojto | 148:fd96258d940d | 624 | base->INTEN = (base->INTEN & ~(0x3U << ((channel << 1U) + 3U))) | ((uint32_t)(mode) << ((channel << 1U) + 3U)); |
Kojto | 148:fd96258d940d | 625 | } |
Kojto | 148:fd96258d940d | 626 | |
Kojto | 148:fd96258d940d | 627 | /* @} */ |
Kojto | 148:fd96258d940d | 628 | |
Kojto | 148:fd96258d940d | 629 | /*! |
Kojto | 148:fd96258d940d | 630 | * @name Status. |
Kojto | 148:fd96258d940d | 631 | * @{ |
Kojto | 148:fd96258d940d | 632 | */ |
Kojto | 148:fd96258d940d | 633 | |
Kojto | 148:fd96258d940d | 634 | /*! |
Kojto | 148:fd96258d940d | 635 | * @brief Get status flags of ADC module. |
Kojto | 148:fd96258d940d | 636 | * |
Kojto | 148:fd96258d940d | 637 | * @param base ADC peripheral base address. |
Kojto | 148:fd96258d940d | 638 | * @return Mask of status flags of module, see to #_adc_status_flags. |
Kojto | 148:fd96258d940d | 639 | */ |
Kojto | 148:fd96258d940d | 640 | static inline uint32_t ADC_GetStatusFlags(ADC_Type *base) |
Kojto | 148:fd96258d940d | 641 | { |
Kojto | 148:fd96258d940d | 642 | return base->FLAGS; |
Kojto | 148:fd96258d940d | 643 | } |
Kojto | 148:fd96258d940d | 644 | |
Kojto | 148:fd96258d940d | 645 | /*! |
Kojto | 148:fd96258d940d | 646 | * @brief Clear status flags of ADC module. |
Kojto | 148:fd96258d940d | 647 | * |
Kojto | 148:fd96258d940d | 648 | * @param base ADC peripheral base address. |
Kojto | 148:fd96258d940d | 649 | * @param mask Mask of status flags of module, see to #_adc_status_flags. |
Kojto | 148:fd96258d940d | 650 | */ |
Kojto | 148:fd96258d940d | 651 | static inline void ADC_ClearStatusFlags(ADC_Type *base, uint32_t mask) |
Kojto | 148:fd96258d940d | 652 | { |
Kojto | 148:fd96258d940d | 653 | base->FLAGS = mask; /* Write 1 to clear. */ |
Kojto | 148:fd96258d940d | 654 | } |
Kojto | 148:fd96258d940d | 655 | |
Kojto | 148:fd96258d940d | 656 | /* @} */ |
Kojto | 148:fd96258d940d | 657 | |
Kojto | 148:fd96258d940d | 658 | #if defined(__cplusplus) |
Kojto | 148:fd96258d940d | 659 | } |
Kojto | 148:fd96258d940d | 660 | #endif |
Kojto | 148:fd96258d940d | 661 | |
Kojto | 148:fd96258d940d | 662 | /* @} */ |
Kojto | 148:fd96258d940d | 663 | |
Kojto | 148:fd96258d940d | 664 | #endif /* __FSL_ADC_H__ */ |