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_SDT32620B/TOOLCHAIN_IAR/adc.h@172:65be27845400, 2019-02-20 (annotated)
- Committer:
- AnnaBridge
- Date:
- Wed Feb 20 20:53:29 2019 +0000
- Revision:
- 172:65be27845400
- Parent:
- 171:3a7713b1edbc
mbed library release version 165
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
AnnaBridge | 167:84c0a372a020 | 1 | /** |
AnnaBridge | 167:84c0a372a020 | 2 | * @file |
AnnaBridge | 167:84c0a372a020 | 3 | * @brief Analog to Digital Converter function prototypes and data types. |
AnnaBridge | 167:84c0a372a020 | 4 | */ |
AnnaBridge | 167:84c0a372a020 | 5 | |
AnnaBridge | 167:84c0a372a020 | 6 | /* **************************************************************************** |
AnnaBridge | 167:84c0a372a020 | 7 | * Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved. |
AnnaBridge | 167:84c0a372a020 | 8 | * |
AnnaBridge | 167:84c0a372a020 | 9 | * Permission is hereby granted, free of charge, to any person obtaining a |
AnnaBridge | 167:84c0a372a020 | 10 | * copy of this software and associated documentation files (the "Software"), |
AnnaBridge | 167:84c0a372a020 | 11 | * to deal in the Software without restriction, including without limitation |
AnnaBridge | 167:84c0a372a020 | 12 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, |
AnnaBridge | 167:84c0a372a020 | 13 | * and/or sell copies of the Software, and to permit persons to whom the |
AnnaBridge | 167:84c0a372a020 | 14 | * Software is furnished to do so, subject to the following conditions: |
AnnaBridge | 167:84c0a372a020 | 15 | * |
AnnaBridge | 167:84c0a372a020 | 16 | * The above copyright notice and this permission notice shall be included |
AnnaBridge | 167:84c0a372a020 | 17 | * in all copies or substantial portions of the Software. |
AnnaBridge | 167:84c0a372a020 | 18 | * |
AnnaBridge | 167:84c0a372a020 | 19 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS |
AnnaBridge | 167:84c0a372a020 | 20 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
AnnaBridge | 167:84c0a372a020 | 21 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. |
AnnaBridge | 167:84c0a372a020 | 22 | * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES |
AnnaBridge | 167:84c0a372a020 | 23 | * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, |
AnnaBridge | 167:84c0a372a020 | 24 | * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR |
AnnaBridge | 167:84c0a372a020 | 25 | * OTHER DEALINGS IN THE SOFTWARE. |
AnnaBridge | 167:84c0a372a020 | 26 | * |
AnnaBridge | 167:84c0a372a020 | 27 | * Except as contained in this notice, the name of Maxim Integrated |
AnnaBridge | 167:84c0a372a020 | 28 | * Products, Inc. shall not be used except as stated in the Maxim Integrated |
AnnaBridge | 167:84c0a372a020 | 29 | * Products, Inc. Branding Policy. |
AnnaBridge | 167:84c0a372a020 | 30 | * |
AnnaBridge | 167:84c0a372a020 | 31 | * The mere transfer of this software does not imply any licenses |
AnnaBridge | 167:84c0a372a020 | 32 | * of trade secrets, proprietary technology, copyrights, patents, |
AnnaBridge | 167:84c0a372a020 | 33 | * trademarks, maskwork rights, or any other form of intellectual |
AnnaBridge | 167:84c0a372a020 | 34 | * property whatsoever. Maxim Integrated Products, Inc. retains all |
AnnaBridge | 167:84c0a372a020 | 35 | * ownership rights. |
AnnaBridge | 167:84c0a372a020 | 36 | * |
AnnaBridge | 167:84c0a372a020 | 37 | * $Date: 2017-02-14 18:08:19 -0600 (Tue, 14 Feb 2017) $ |
AnnaBridge | 167:84c0a372a020 | 38 | * $Revision: 26419 $ |
AnnaBridge | 167:84c0a372a020 | 39 | * |
AnnaBridge | 167:84c0a372a020 | 40 | *************************************************************************** */ |
AnnaBridge | 167:84c0a372a020 | 41 | |
AnnaBridge | 167:84c0a372a020 | 42 | /* Define to prevent redundant inclusion */ |
AnnaBridge | 167:84c0a372a020 | 43 | #ifndef _ADC_H |
AnnaBridge | 167:84c0a372a020 | 44 | #define _ADC_H |
AnnaBridge | 167:84c0a372a020 | 45 | |
AnnaBridge | 167:84c0a372a020 | 46 | /* **** Includes **** */ |
AnnaBridge | 167:84c0a372a020 | 47 | #include <stdint.h> |
AnnaBridge | 167:84c0a372a020 | 48 | /** |
AnnaBridge | 167:84c0a372a020 | 49 | * @ingroup periphlibs |
AnnaBridge | 167:84c0a372a020 | 50 | * @defgroup group_adc ADC |
AnnaBridge | 167:84c0a372a020 | 51 | * @brief 10-Bit Analog to Digital Converter |
AnnaBridge | 167:84c0a372a020 | 52 | * @{ |
AnnaBridge | 167:84c0a372a020 | 53 | */ |
AnnaBridge | 167:84c0a372a020 | 54 | #include "adc_regs.h" |
AnnaBridge | 167:84c0a372a020 | 55 | |
AnnaBridge | 167:84c0a372a020 | 56 | #ifdef __cplusplus |
AnnaBridge | 167:84c0a372a020 | 57 | extern "C" { |
AnnaBridge | 167:84c0a372a020 | 58 | #endif |
AnnaBridge | 167:84c0a372a020 | 59 | |
AnnaBridge | 167:84c0a372a020 | 60 | |
AnnaBridge | 167:84c0a372a020 | 61 | |
AnnaBridge | 167:84c0a372a020 | 62 | /** |
AnnaBridge | 167:84c0a372a020 | 63 | * @page adc_overview ADC Overview and Usage |
AnnaBridge | 167:84c0a372a020 | 64 | * The ADC supports both synchronous and asynchronous access. |
AnnaBridge | 167:84c0a372a020 | 65 | * <b>Usage Examples</b> |
AnnaBridge | 167:84c0a372a020 | 66 | * @snippet snippets/adc_snippet.c ADC Synchronous Example |
AnnaBridge | 167:84c0a372a020 | 67 | * |
AnnaBridge | 167:84c0a372a020 | 68 | * @snippet snippets/adc_snippet.c ADC Asynchronous Example |
AnnaBridge | 167:84c0a372a020 | 69 | * |
AnnaBridge | 167:84c0a372a020 | 70 | */ |
AnnaBridge | 167:84c0a372a020 | 71 | |
AnnaBridge | 167:84c0a372a020 | 72 | /* **** Definitions **** */ |
AnnaBridge | 167:84c0a372a020 | 73 | |
AnnaBridge | 167:84c0a372a020 | 74 | /** |
AnnaBridge | 167:84c0a372a020 | 75 | * Enumeration type for ADC Channel Selection. See \ref ADC_CHSEL_values "ADC Channel Select Values" for additional information. |
AnnaBridge | 167:84c0a372a020 | 76 | */ |
AnnaBridge | 167:84c0a372a020 | 77 | typedef enum { |
AnnaBridge | 167:84c0a372a020 | 78 | ADC_CH_0 = MXC_V_ADC_CTRL_ADC_CHSEL_AIN0, /**< Channel 0 Select */ |
AnnaBridge | 167:84c0a372a020 | 79 | ADC_CH_1 = MXC_V_ADC_CTRL_ADC_CHSEL_AIN1, /**< Channel 1 Select */ |
AnnaBridge | 167:84c0a372a020 | 80 | ADC_CH_2 = MXC_V_ADC_CTRL_ADC_CHSEL_AIN2, /**< Channel 2 Select */ |
AnnaBridge | 167:84c0a372a020 | 81 | ADC_CH_3 = MXC_V_ADC_CTRL_ADC_CHSEL_AIN3, /**< Channel 3 Select */ |
AnnaBridge | 167:84c0a372a020 | 82 | ADC_CH_0_DIV_5 = MXC_V_ADC_CTRL_ADC_CHSEL_AIN0_DIV_5, /**< Channel 0 divided by 5 */ |
AnnaBridge | 167:84c0a372a020 | 83 | ADC_CH_1_DIV_5 = MXC_V_ADC_CTRL_ADC_CHSEL_AIN1_DIV_5, /**< Channel 1 divided by 5 */ |
AnnaBridge | 167:84c0a372a020 | 84 | ADC_CH_VDDB_DIV_4 = MXC_V_ADC_CTRL_ADC_CHSEL_VDDB_DIV_4, /**< VDDB divided by 4 */ |
AnnaBridge | 167:84c0a372a020 | 85 | ADC_CH_VDD18 = MXC_V_ADC_CTRL_ADC_CHSEL_VDD18, /**< VDD18 input select */ |
AnnaBridge | 167:84c0a372a020 | 86 | ADC_CH_VDD12 = MXC_V_ADC_CTRL_ADC_CHSEL_VDD12, /**< VDD12 input select */ |
AnnaBridge | 167:84c0a372a020 | 87 | ADC_CH_VRTC_DIV_2 = MXC_V_ADC_CTRL_ADC_CHSEL_VRTC_DIV_2, /**< VRTC divided by 2 */ |
AnnaBridge | 167:84c0a372a020 | 88 | ADC_CH_TMON = MXC_V_ADC_CTRL_ADC_CHSEL_TMON, /**< TMON input select */ |
AnnaBridge | 167:84c0a372a020 | 89 | #if (MXC_ADC_REV > 0) |
AnnaBridge | 167:84c0a372a020 | 90 | ADC_CH_VDDIO_DIV_4 = MXC_V_ADC_CTRL_ADC_CHSEL_VDDIO_DIV_4, /**< VDDIO divided by 4 select */ |
AnnaBridge | 167:84c0a372a020 | 91 | ADC_CH_VDDIOH_DIV_4 = MXC_V_ADC_CTRL_ADC_CHSEL_VDDIOH_DIV_4, /**< VDDIOH divided by 4 select */ |
AnnaBridge | 167:84c0a372a020 | 92 | #endif |
AnnaBridge | 167:84c0a372a020 | 93 | ADC_CH_MAX /**< Max enum value for channel selection */ |
AnnaBridge | 167:84c0a372a020 | 94 | } mxc_adc_chsel_t; |
AnnaBridge | 167:84c0a372a020 | 95 | |
AnnaBridge | 167:84c0a372a020 | 96 | /** |
AnnaBridge | 167:84c0a372a020 | 97 | * Enumeration type for the ADC limit register to set |
AnnaBridge | 167:84c0a372a020 | 98 | */ |
AnnaBridge | 167:84c0a372a020 | 99 | typedef enum { |
AnnaBridge | 167:84c0a372a020 | 100 | ADC_LIMIT_0 = 0, /**< ADC Limit Register 0 */ |
AnnaBridge | 167:84c0a372a020 | 101 | ADC_LIMIT_1 = 1, /**< ADC Limit Register 1 */ |
AnnaBridge | 167:84c0a372a020 | 102 | ADC_LIMIT_2 = 2, /**< ADC Limit Register 2 */ |
AnnaBridge | 167:84c0a372a020 | 103 | ADC_LIMIT_3 = 3, /**< ADC Limit Register 3 */ |
AnnaBridge | 167:84c0a372a020 | 104 | ADC_LIMIT_MAX /**< Number of Limit registers */ |
AnnaBridge | 167:84c0a372a020 | 105 | } mxc_adc_limitsel_t; |
AnnaBridge | 167:84c0a372a020 | 106 | |
AnnaBridge | 167:84c0a372a020 | 107 | /** |
AnnaBridge | 167:84c0a372a020 | 108 | * Mask for all Interrupt Flag Fields |
AnnaBridge | 167:84c0a372a020 | 109 | */ |
AnnaBridge | 167:84c0a372a020 | 110 | #define ADC_IF_MASK (0xffffffffUL << MXC_F_ADC_INTR_ADC_DONE_IF_POS) |
AnnaBridge | 167:84c0a372a020 | 111 | |
AnnaBridge | 167:84c0a372a020 | 112 | /** |
AnnaBridge | 167:84c0a372a020 | 113 | * Mask for all Interrupt Enable Fields |
AnnaBridge | 167:84c0a372a020 | 114 | */ |
AnnaBridge | 167:84c0a372a020 | 115 | #define ADC_IE_MASK (0xffffffffUL >> MXC_F_ADC_INTR_ADC_DONE_IF_POS) |
AnnaBridge | 167:84c0a372a020 | 116 | |
AnnaBridge | 167:84c0a372a020 | 117 | /* **** Function Prototypes **** */ |
AnnaBridge | 167:84c0a372a020 | 118 | |
AnnaBridge | 167:84c0a372a020 | 119 | /** |
AnnaBridge | 167:84c0a372a020 | 120 | * @brief Initialize the ADC hardware |
AnnaBridge | 167:84c0a372a020 | 121 | * |
AnnaBridge | 167:84c0a372a020 | 122 | * @return #E_NO_ERROR if successful |
AnnaBridge | 167:84c0a372a020 | 123 | */ |
AnnaBridge | 167:84c0a372a020 | 124 | int ADC_Init(void); |
AnnaBridge | 167:84c0a372a020 | 125 | |
AnnaBridge | 167:84c0a372a020 | 126 | /** |
AnnaBridge | 167:84c0a372a020 | 127 | * @brief Start ADC conversion on the selected channel |
AnnaBridge | 167:84c0a372a020 | 128 | * |
AnnaBridge | 167:84c0a372a020 | 129 | * @param channel Channel select from #mxc_adc_chsel_t |
AnnaBridge | 167:84c0a372a020 | 130 | * @param adc_scale Enable the ADC input scaling mode if non-zero |
AnnaBridge | 167:84c0a372a020 | 131 | * @param bypass Bypass input buffer stage if non-zero |
AnnaBridge | 167:84c0a372a020 | 132 | */ |
AnnaBridge | 167:84c0a372a020 | 133 | void ADC_StartConvert(mxc_adc_chsel_t channel, unsigned int adc_scale, unsigned int bypass); |
AnnaBridge | 167:84c0a372a020 | 134 | |
AnnaBridge | 167:84c0a372a020 | 135 | /** |
AnnaBridge | 167:84c0a372a020 | 136 | * @brief Gets the result from the previous ADC conversion |
AnnaBridge | 167:84c0a372a020 | 137 | * |
AnnaBridge | 167:84c0a372a020 | 138 | * @param outdata Pointer to store the ADC data conversion |
AnnaBridge | 167:84c0a372a020 | 139 | * result. |
AnnaBridge | 167:84c0a372a020 | 140 | * @return #E_OVERFLOW ADC overflow error |
AnnaBridge | 167:84c0a372a020 | 141 | * @return #E_NO_ERROR Data returned in outdata parameter |
AnnaBridge | 167:84c0a372a020 | 142 | */ |
AnnaBridge | 167:84c0a372a020 | 143 | int ADC_GetData(uint16_t *outdata); |
AnnaBridge | 167:84c0a372a020 | 144 | |
AnnaBridge | 167:84c0a372a020 | 145 | /** |
AnnaBridge | 167:84c0a372a020 | 146 | * @brief Set the data limits for an ADC channel monitor |
AnnaBridge | 167:84c0a372a020 | 147 | * |
AnnaBridge | 167:84c0a372a020 | 148 | * @param unit Which data limit unit to configure |
AnnaBridge | 167:84c0a372a020 | 149 | * @param channel Channel select from mxc_adc_chsel_t |
AnnaBridge | 167:84c0a372a020 | 150 | * @param low_enable Enable the lower limit on this monitor |
AnnaBridge | 167:84c0a372a020 | 151 | * @param low_limit Value for lower limit monitor |
AnnaBridge | 167:84c0a372a020 | 152 | * @param high_enable Enable the upper limit on this monitor |
AnnaBridge | 167:84c0a372a020 | 153 | * @param high_limit Value for upper limit monitor |
AnnaBridge | 167:84c0a372a020 | 154 | * |
AnnaBridge | 167:84c0a372a020 | 155 | * @return #E_BAD_PARAM ADC limit or channel greater than supported |
AnnaBridge | 167:84c0a372a020 | 156 | * @return #E_NO_ERROR ADC limit set successfully |
AnnaBridge | 167:84c0a372a020 | 157 | */ |
AnnaBridge | 167:84c0a372a020 | 158 | int ADC_SetLimit(mxc_adc_limitsel_t unit, mxc_adc_chsel_t channel, |
AnnaBridge | 167:84c0a372a020 | 159 | unsigned int low_enable, unsigned int low_limit, |
AnnaBridge | 167:84c0a372a020 | 160 | unsigned int high_enable, unsigned int high_limit); |
AnnaBridge | 167:84c0a372a020 | 161 | |
AnnaBridge | 167:84c0a372a020 | 162 | /** |
AnnaBridge | 167:84c0a372a020 | 163 | * @brief Get interrupt flags |
AnnaBridge | 167:84c0a372a020 | 164 | * |
AnnaBridge | 167:84c0a372a020 | 165 | * @return ADC Interrupt flags bit mask. See the @ref ADC_INTR_IF_Register |
AnnaBridge | 167:84c0a372a020 | 166 | * "ADC_INTR Register" for the interrupt flag masks. |
AnnaBridge | 167:84c0a372a020 | 167 | */ |
AnnaBridge | 167:84c0a372a020 | 168 | __STATIC_INLINE uint32_t ADC_GetFlags() |
AnnaBridge | 167:84c0a372a020 | 169 | { |
AnnaBridge | 167:84c0a372a020 | 170 | return (MXC_ADC->intr & ADC_IF_MASK); |
AnnaBridge | 167:84c0a372a020 | 171 | } |
AnnaBridge | 167:84c0a372a020 | 172 | |
AnnaBridge | 167:84c0a372a020 | 173 | /** |
AnnaBridge | 167:84c0a372a020 | 174 | * @brief Clear interrupt flag(s) using the mask parameter. All bits set in |
AnnaBridge | 167:84c0a372a020 | 175 | * the parameter will be cleared. |
AnnaBridge | 167:84c0a372a020 | 176 | * |
AnnaBridge | 167:84c0a372a020 | 177 | * @param mask Interrupt flags to clear. See the @ref ADC_INTR_IF_Register |
AnnaBridge | 167:84c0a372a020 | 178 | * "ADC_INTR Register" for the interrupt flag masks. |
AnnaBridge | 167:84c0a372a020 | 179 | */ |
AnnaBridge | 167:84c0a372a020 | 180 | __STATIC_INLINE void ADC_ClearFlags(uint32_t mask) |
AnnaBridge | 167:84c0a372a020 | 181 | { |
AnnaBridge | 167:84c0a372a020 | 182 | MXC_ADC->intr = ((MXC_ADC->intr & ADC_IF_MASK) | mask); |
AnnaBridge | 167:84c0a372a020 | 183 | } |
AnnaBridge | 167:84c0a372a020 | 184 | |
AnnaBridge | 167:84c0a372a020 | 185 | /** |
AnnaBridge | 167:84c0a372a020 | 186 | * @brief Get the Status of the ADC |
AnnaBridge | 167:84c0a372a020 | 187 | * |
AnnaBridge | 167:84c0a372a020 | 188 | * @return ADC status register. See @ref ADC_STATUS_Register "ADC_STATUS |
AnnaBridge | 167:84c0a372a020 | 189 | * Register" for details. |
AnnaBridge | 167:84c0a372a020 | 190 | */ |
AnnaBridge | 167:84c0a372a020 | 191 | __STATIC_INLINE uint32_t ADC_GetStatus() |
AnnaBridge | 167:84c0a372a020 | 192 | { |
AnnaBridge | 167:84c0a372a020 | 193 | return (MXC_ADC->status); |
AnnaBridge | 167:84c0a372a020 | 194 | } |
AnnaBridge | 167:84c0a372a020 | 195 | |
AnnaBridge | 167:84c0a372a020 | 196 | /** |
AnnaBridge | 167:84c0a372a020 | 197 | * @brief Enables the ADC interrupts specified by the mask parameter |
AnnaBridge | 167:84c0a372a020 | 198 | * |
AnnaBridge | 167:84c0a372a020 | 199 | * @param mask ADC interrupts to enable. See @ref ADC_INTR_IE_Register |
AnnaBridge | 167:84c0a372a020 | 200 | * "ADC_INTR Register" for the interrupt enable bit masks. |
AnnaBridge | 167:84c0a372a020 | 201 | */ |
AnnaBridge | 167:84c0a372a020 | 202 | __STATIC_INLINE void ADC_EnableINT(uint32_t mask) |
AnnaBridge | 167:84c0a372a020 | 203 | { |
AnnaBridge | 167:84c0a372a020 | 204 | MXC_ADC->intr = ((MXC_ADC->intr & ADC_IE_MASK) | mask); |
AnnaBridge | 167:84c0a372a020 | 205 | } |
AnnaBridge | 167:84c0a372a020 | 206 | |
AnnaBridge | 167:84c0a372a020 | 207 | /** |
AnnaBridge | 167:84c0a372a020 | 208 | * @brief Disable ADC interrupts based on mask |
AnnaBridge | 167:84c0a372a020 | 209 | * |
AnnaBridge | 167:84c0a372a020 | 210 | * @param mask ADC interrupts to disable. See @ref ADC_INTR_IE_Register |
AnnaBridge | 167:84c0a372a020 | 211 | * "ADC_INTR Register" for the interrupt enable bit masks. |
AnnaBridge | 167:84c0a372a020 | 212 | */ |
AnnaBridge | 167:84c0a372a020 | 213 | __STATIC_INLINE void ADC_DisableINT(uint32_t mask) |
AnnaBridge | 167:84c0a372a020 | 214 | { |
AnnaBridge | 167:84c0a372a020 | 215 | MXC_ADC->intr = ((MXC_ADC->intr & ADC_IE_MASK) & ~mask); |
AnnaBridge | 167:84c0a372a020 | 216 | } |
AnnaBridge | 167:84c0a372a020 | 217 | /**@} end of group_adc */ |
AnnaBridge | 167:84c0a372a020 | 218 | |
AnnaBridge | 167:84c0a372a020 | 219 | #ifdef __cplusplus |
AnnaBridge | 167:84c0a372a020 | 220 | } |
AnnaBridge | 167:84c0a372a020 | 221 | #endif |
AnnaBridge | 167:84c0a372a020 | 222 | |
AnnaBridge | 167:84c0a372a020 | 223 | #endif /* _ADC_H */ |