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