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.

Committer:
AnnaBridge
Date:
Thu Nov 08 11:45:42 2018 +0000
Revision:
171:3a7713b1edbc
Parent:
TARGET_MAX32625PICO/TARGET_Maxim/TARGET_MAX32625/mxc/adc.h@169:a7c7b631e539
mbed library. Release version 164

Who changed what in which revision?

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