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:
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?

UserRevisionLine numberNew contents of line
AnnaBridge 145:64910690c574 1 /*
AnnaBridge 145:64910690c574 2 * Copyright (c) 2015, Freescale Semiconductor, Inc.
AnnaBridge 145:64910690c574 3 * All rights reserved.
AnnaBridge 145:64910690c574 4 *
AnnaBridge 145:64910690c574 5 * Redistribution and use in source and binary forms, with or without modification,
AnnaBridge 145:64910690c574 6 * are permitted provided that the following conditions are met:
AnnaBridge 145:64910690c574 7 *
AnnaBridge 145:64910690c574 8 * o Redistributions of source code must retain the above copyright notice, this list
AnnaBridge 145:64910690c574 9 * of conditions and the following disclaimer.
AnnaBridge 145:64910690c574 10 *
AnnaBridge 145:64910690c574 11 * o Redistributions in binary form must reproduce the above copyright notice, this
AnnaBridge 145:64910690c574 12 * list of conditions and the following disclaimer in the documentation and/or
AnnaBridge 145:64910690c574 13 * other materials provided with the distribution.
AnnaBridge 145:64910690c574 14 *
AnnaBridge 145:64910690c574 15 * o Neither the name of Freescale Semiconductor, Inc. nor the names of its
AnnaBridge 145:64910690c574 16 * contributors may be used to endorse or promote products derived from this
AnnaBridge 145:64910690c574 17 * software without specific prior written permission.
AnnaBridge 145:64910690c574 18 *
AnnaBridge 145:64910690c574 19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
AnnaBridge 145:64910690c574 20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
AnnaBridge 145:64910690c574 21 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
AnnaBridge 145:64910690c574 22 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
AnnaBridge 145:64910690c574 23 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
AnnaBridge 145:64910690c574 24 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
AnnaBridge 145:64910690c574 25 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
AnnaBridge 145:64910690c574 26 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
AnnaBridge 145:64910690c574 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
AnnaBridge 145:64910690c574 28 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
AnnaBridge 145:64910690c574 29 */
AnnaBridge 145:64910690c574 30
AnnaBridge 145:64910690c574 31 #ifndef _FSL_VREF_H_
AnnaBridge 145:64910690c574 32 #define _FSL_VREF_H_
AnnaBridge 145:64910690c574 33
AnnaBridge 145:64910690c574 34 #include "fsl_common.h"
AnnaBridge 145:64910690c574 35
AnnaBridge 145:64910690c574 36 /*!
AnnaBridge 145:64910690c574 37 * @addtogroup vref
AnnaBridge 145:64910690c574 38 * @{
AnnaBridge 145:64910690c574 39 */
AnnaBridge 145:64910690c574 40
AnnaBridge 145:64910690c574 41
AnnaBridge 145:64910690c574 42 /******************************************************************************
AnnaBridge 145:64910690c574 43 * Definitions
AnnaBridge 145:64910690c574 44 ******************************************************************************/
AnnaBridge 145:64910690c574 45
AnnaBridge 145:64910690c574 46 /*! @name Driver version */
AnnaBridge 145:64910690c574 47 /*@{*/
AnnaBridge 145:64910690c574 48 #define FSL_VREF_DRIVER_VERSION (MAKE_VERSION(2, 1, 0)) /*!< Version 2.1.0. */
AnnaBridge 145:64910690c574 49 /*@}*/
AnnaBridge 145:64910690c574 50
AnnaBridge 145:64910690c574 51 /* Those macros below defined to support SoC family which have VREFL (0.4V) reference */
AnnaBridge 145:64910690c574 52 #if defined(FSL_FEATURE_VREF_HAS_LOW_REFERENCE) && FSL_FEATURE_VREF_HAS_LOW_REFERENCE
AnnaBridge 145:64910690c574 53 #define VREF_SC_MODE_LV VREF_VREFH_SC_MODE_LV
AnnaBridge 145:64910690c574 54 #define VREF_SC_REGEN VREF_VREFH_SC_REGEN
AnnaBridge 145:64910690c574 55 #define VREF_SC_VREFEN VREF_VREFH_SC_VREFEN
AnnaBridge 145:64910690c574 56 #define VREF_SC_ICOMPEN VREF_VREFH_SC_ICOMPEN
AnnaBridge 145:64910690c574 57 #define VREF_SC_REGEN_MASK VREF_VREFH_SC_REGEN_MASK
AnnaBridge 145:64910690c574 58 #define VREF_SC_VREFST_MASK VREF_VREFH_SC_VREFST_MASK
AnnaBridge 145:64910690c574 59 #define VREF_SC_VREFEN_MASK VREF_VREFH_SC_VREFEN_MASK
AnnaBridge 145:64910690c574 60 #define VREF_SC_MODE_LV_MASK VREF_VREFH_SC_MODE_LV_MASK
AnnaBridge 145:64910690c574 61 #define VREF_SC_ICOMPEN_MASK VREF_VREFH_SC_ICOMPEN_MASK
AnnaBridge 145:64910690c574 62 #define TRM VREFH_TRM
AnnaBridge 145:64910690c574 63 #define VREF_TRM_TRIM VREF_VREFH_TRM_TRIM
AnnaBridge 145:64910690c574 64 #define VREF_TRM_CHOPEN_MASK VREF_VREFH_TRM_CHOPEN_MASK
AnnaBridge 145:64910690c574 65 #define VREF_TRM_TRIM_MASK VREF_VREFH_TRM_TRIM_MASK
AnnaBridge 145:64910690c574 66 #define VREF_TRM_CHOPEN_SHIFT VREF_VREFH_TRM_CHOPEN_SHIFT
AnnaBridge 145:64910690c574 67 #define VREF_TRM_TRIM_SHIFT VREF_VREFH_TRM_TRIM_SHIFT
AnnaBridge 145:64910690c574 68 #define VREF_SC_MODE_LV_SHIFT VREF_VREFH_SC_MODE_LV_SHIFT
AnnaBridge 145:64910690c574 69 #define VREF_SC_REGEN_SHIFT VREF_VREFH_SC_REGEN_SHIFT
AnnaBridge 145:64910690c574 70 #define VREF_SC_VREFST_SHIFT VREF_VREFH_SC_VREFST_SHIFT
AnnaBridge 145:64910690c574 71 #define VREF_SC_ICOMPEN_SHIFT VREF_VREFH_SC_ICOMPEN_SHIFT
AnnaBridge 145:64910690c574 72 #endif /* FSL_FEATURE_VREF_HAS_LOW_REFERENCE */
AnnaBridge 145:64910690c574 73
AnnaBridge 145:64910690c574 74 /*!
AnnaBridge 145:64910690c574 75 * @brief VREF modes.
AnnaBridge 145:64910690c574 76 */
AnnaBridge 145:64910690c574 77 typedef enum _vref_buffer_mode
AnnaBridge 145:64910690c574 78 {
AnnaBridge 145:64910690c574 79 kVREF_ModeBandgapOnly = 0U, /*!< Bandgap on only, for stabilization and startup */
AnnaBridge 145:64910690c574 80 #if defined(FSL_FEATURE_VREF_MODE_LV_TYPE) && FSL_FEATURE_VREF_MODE_LV_TYPE
AnnaBridge 145:64910690c574 81 kVREF_ModeHighPowerBuffer = 1U, /*!< High-power buffer mode enabled */
AnnaBridge 145:64910690c574 82 kVREF_ModeLowPowerBuffer = 2U /*!< Low-power buffer mode enabled */
AnnaBridge 145:64910690c574 83 #else
AnnaBridge 145:64910690c574 84 kVREF_ModeTightRegulationBuffer = 2U /*!< Tight regulation buffer enabled */
AnnaBridge 145:64910690c574 85 #endif /* FSL_FEATURE_VREF_MODE_LV_TYPE */
AnnaBridge 145:64910690c574 86 } vref_buffer_mode_t;
AnnaBridge 145:64910690c574 87
AnnaBridge 145:64910690c574 88 /*!
AnnaBridge 145:64910690c574 89 * @brief The description structure for the VREF module.
AnnaBridge 145:64910690c574 90 */
AnnaBridge 145:64910690c574 91 typedef struct _vref_config
AnnaBridge 145:64910690c574 92 {
AnnaBridge 145:64910690c574 93 vref_buffer_mode_t bufferMode; /*!< Buffer mode selection */
AnnaBridge 145:64910690c574 94 #if defined(FSL_FEATURE_VREF_HAS_LOW_REFERENCE) && FSL_FEATURE_VREF_HAS_LOW_REFERENCE
AnnaBridge 145:64910690c574 95 bool enableLowRef; /*!< Set VREFL (0.4 V) reference buffer enable or disable */
AnnaBridge 145:64910690c574 96 bool enableExternalVoltRef; /*!< Select external voltage reference or not (internal) */
AnnaBridge 145:64910690c574 97 #endif /* FSL_FEATURE_VREF_HAS_LOW_REFERENCE */
AnnaBridge 145:64910690c574 98 #if defined(FSL_FEATURE_VREF_HAS_TRM4) && FSL_FEATURE_VREF_HAS_TRM4
AnnaBridge 145:64910690c574 99 bool enable2V1VoltRef; /*!< Enable Internal Voltage Reference (2.1V) */
AnnaBridge 145:64910690c574 100 #endif /* FSL_FEATURE_VREF_HAS_TRM4 */
AnnaBridge 145:64910690c574 101 } vref_config_t;
AnnaBridge 145:64910690c574 102
AnnaBridge 145:64910690c574 103 /******************************************************************************
AnnaBridge 145:64910690c574 104 * API
AnnaBridge 145:64910690c574 105 ******************************************************************************/
AnnaBridge 145:64910690c574 106
AnnaBridge 145:64910690c574 107 #if defined(__cplusplus)
AnnaBridge 145:64910690c574 108 extern "C" {
AnnaBridge 145:64910690c574 109 #endif /* __cplusplus */
AnnaBridge 145:64910690c574 110
AnnaBridge 145:64910690c574 111 /*!
AnnaBridge 145:64910690c574 112 * @name VREF functional operation
AnnaBridge 145:64910690c574 113 * @{
AnnaBridge 145:64910690c574 114 */
AnnaBridge 145:64910690c574 115
AnnaBridge 145:64910690c574 116 /*!
AnnaBridge 145:64910690c574 117 * @brief Enables the clock gate and configures the VREF module according to the configuration structure.
AnnaBridge 145:64910690c574 118 *
AnnaBridge 145:64910690c574 119 * This function must be called before calling all other VREF driver functions,
AnnaBridge 145:64910690c574 120 * read/write registers, and configurations with user-defined settings.
AnnaBridge 145:64910690c574 121 * The example below shows how to set up vref_config_t parameters and
AnnaBridge 145:64910690c574 122 * how to call the VREF_Init function by passing in these parameters.
AnnaBridge 145:64910690c574 123 * This is an example.
AnnaBridge 145:64910690c574 124 * @code
AnnaBridge 145:64910690c574 125 * vref_config_t vrefConfig;
AnnaBridge 145:64910690c574 126 * vrefConfig.bufferMode = kVREF_ModeHighPowerBuffer;
AnnaBridge 145:64910690c574 127 * vrefConfig.enableExternalVoltRef = false;
AnnaBridge 145:64910690c574 128 * vrefConfig.enableLowRef = false;
AnnaBridge 145:64910690c574 129 * VREF_Init(VREF, &vrefConfig);
AnnaBridge 145:64910690c574 130 * @endcode
AnnaBridge 145:64910690c574 131 *
AnnaBridge 145:64910690c574 132 * @param base VREF peripheral address.
AnnaBridge 145:64910690c574 133 * @param config Pointer to the configuration structure.
AnnaBridge 145:64910690c574 134 */
AnnaBridge 145:64910690c574 135 void VREF_Init(VREF_Type *base, const vref_config_t *config);
AnnaBridge 145:64910690c574 136
AnnaBridge 145:64910690c574 137 /*!
AnnaBridge 145:64910690c574 138 * @brief Stops and disables the clock for the VREF module.
AnnaBridge 145:64910690c574 139 *
AnnaBridge 145:64910690c574 140 * This function should be called to shut down the module.
AnnaBridge 145:64910690c574 141 * This is an example.
AnnaBridge 145:64910690c574 142 * @code
AnnaBridge 145:64910690c574 143 * vref_config_t vrefUserConfig;
AnnaBridge 145:64910690c574 144 * VREF_Init(VREF);
AnnaBridge 145:64910690c574 145 * VREF_GetDefaultConfig(&vrefUserConfig);
AnnaBridge 145:64910690c574 146 * ...
AnnaBridge 145:64910690c574 147 * VREF_Deinit(VREF);
AnnaBridge 145:64910690c574 148 * @endcode
AnnaBridge 145:64910690c574 149 *
AnnaBridge 145:64910690c574 150 * @param base VREF peripheral address.
AnnaBridge 145:64910690c574 151 */
AnnaBridge 145:64910690c574 152 void VREF_Deinit(VREF_Type *base);
AnnaBridge 145:64910690c574 153
AnnaBridge 145:64910690c574 154 /*!
AnnaBridge 145:64910690c574 155 * @brief Initializes the VREF configuration structure.
AnnaBridge 145:64910690c574 156 *
AnnaBridge 145:64910690c574 157 * This function initializes the VREF configuration structure to default values.
AnnaBridge 145:64910690c574 158 * This is an example.
AnnaBridge 145:64910690c574 159 * @code
AnnaBridge 145:64910690c574 160 * vrefConfig->bufferMode = kVREF_ModeHighPowerBuffer;
AnnaBridge 145:64910690c574 161 * vrefConfig->enableExternalVoltRef = false;
AnnaBridge 145:64910690c574 162 * vrefConfig->enableLowRef = false;
AnnaBridge 145:64910690c574 163 * @endcode
AnnaBridge 145:64910690c574 164 *
AnnaBridge 145:64910690c574 165 * @param config Pointer to the initialization structure.
AnnaBridge 145:64910690c574 166 */
AnnaBridge 145:64910690c574 167 void VREF_GetDefaultConfig(vref_config_t *config);
AnnaBridge 145:64910690c574 168
AnnaBridge 145:64910690c574 169 /*!
AnnaBridge 145:64910690c574 170 * @brief Sets a TRIM value for the reference voltage.
AnnaBridge 145:64910690c574 171 *
AnnaBridge 145:64910690c574 172 * This function sets a TRIM value for the reference voltage.
AnnaBridge 145:64910690c574 173 * Note that the TRIM value maximum is 0x3F.
AnnaBridge 145:64910690c574 174 *
AnnaBridge 145:64910690c574 175 * @param base VREF peripheral address.
AnnaBridge 145:64910690c574 176 * @param trimValue Value of the trim register to set the output reference voltage (maximum 0x3F (6-bit)).
AnnaBridge 145:64910690c574 177 */
AnnaBridge 145:64910690c574 178 void VREF_SetTrimVal(VREF_Type *base, uint8_t trimValue);
AnnaBridge 145:64910690c574 179
AnnaBridge 145:64910690c574 180 /*!
AnnaBridge 145:64910690c574 181 * @brief Reads the value of the TRIM meaning output voltage.
AnnaBridge 145:64910690c574 182 *
AnnaBridge 145:64910690c574 183 * This function gets the TRIM value from the TRM register.
AnnaBridge 145:64910690c574 184 *
AnnaBridge 145:64910690c574 185 * @param base VREF peripheral address.
AnnaBridge 145:64910690c574 186 * @return Six-bit value of trim setting.
AnnaBridge 145:64910690c574 187 */
AnnaBridge 145:64910690c574 188 static inline uint8_t VREF_GetTrimVal(VREF_Type *base)
AnnaBridge 145:64910690c574 189 {
AnnaBridge 145:64910690c574 190 return (base->TRM & VREF_TRM_TRIM_MASK);
AnnaBridge 145:64910690c574 191 }
AnnaBridge 145:64910690c574 192
AnnaBridge 145:64910690c574 193 #if defined(FSL_FEATURE_VREF_HAS_TRM4) && FSL_FEATURE_VREF_HAS_TRM4
AnnaBridge 145:64910690c574 194 /*!
AnnaBridge 145:64910690c574 195 * @brief Sets a TRIM value for the reference voltage (2V1).
AnnaBridge 145:64910690c574 196 *
AnnaBridge 145:64910690c574 197 * This function sets a TRIM value for the reference voltage (2V1).
AnnaBridge 145:64910690c574 198 * Note that the TRIM value maximum is 0x3F.
AnnaBridge 145:64910690c574 199 *
AnnaBridge 145:64910690c574 200 * @param base VREF peripheral address.
AnnaBridge 145:64910690c574 201 * @param trimValue Value of the trim register to set the output reference voltage (maximum 0x3F (6-bit)).
AnnaBridge 145:64910690c574 202 */
AnnaBridge 145:64910690c574 203 void VREF_SetTrim2V1Val(VREF_Type *base, uint8_t trimValue);
AnnaBridge 145:64910690c574 204
AnnaBridge 145:64910690c574 205 /*!
AnnaBridge 145:64910690c574 206 * @brief Reads the value of the TRIM meaning output voltage (2V1).
AnnaBridge 145:64910690c574 207 *
AnnaBridge 145:64910690c574 208 * This function gets the TRIM value from the VREF_TRM4 register.
AnnaBridge 145:64910690c574 209 *
AnnaBridge 145:64910690c574 210 * @param base VREF peripheral address.
AnnaBridge 145:64910690c574 211 * @return Six-bit value of trim setting.
AnnaBridge 145:64910690c574 212 */
AnnaBridge 145:64910690c574 213 static inline uint8_t VREF_GetTrim2V1Val(VREF_Type *base)
AnnaBridge 145:64910690c574 214 {
AnnaBridge 145:64910690c574 215 return (base->TRM4 & VREF_TRM4_TRIM2V1_MASK);
AnnaBridge 145:64910690c574 216 }
AnnaBridge 145:64910690c574 217 #endif /* FSL_FEATURE_VREF_HAS_TRM4 */
AnnaBridge 145:64910690c574 218
AnnaBridge 145:64910690c574 219 #if defined(FSL_FEATURE_VREF_HAS_LOW_REFERENCE) && FSL_FEATURE_VREF_HAS_LOW_REFERENCE
AnnaBridge 145:64910690c574 220
AnnaBridge 145:64910690c574 221 /*!
AnnaBridge 145:64910690c574 222 * @brief Sets the TRIM value for the low voltage reference.
AnnaBridge 145:64910690c574 223 *
AnnaBridge 145:64910690c574 224 * This function sets the TRIM value for low reference voltage.
AnnaBridge 145:64910690c574 225 * Note the following.
AnnaBridge 145:64910690c574 226 * - The TRIM value maximum is 0x05U
AnnaBridge 145:64910690c574 227 * - The values 111b and 110b are not valid/allowed.
AnnaBridge 145:64910690c574 228 *
AnnaBridge 145:64910690c574 229 * @param base VREF peripheral address.
AnnaBridge 145:64910690c574 230 * @param trimValue Value of the trim register to set output low reference voltage (maximum 0x05U (3-bit)).
AnnaBridge 145:64910690c574 231 */
AnnaBridge 145:64910690c574 232 void VREF_SetLowReferenceTrimVal(VREF_Type *base, uint8_t trimValue);
AnnaBridge 145:64910690c574 233
AnnaBridge 145:64910690c574 234 /*!
AnnaBridge 145:64910690c574 235 * @brief Reads the value of the TRIM meaning output voltage.
AnnaBridge 145:64910690c574 236 *
AnnaBridge 145:64910690c574 237 * This function gets the TRIM value from the VREFL_TRM register.
AnnaBridge 145:64910690c574 238 *
AnnaBridge 145:64910690c574 239 * @param base VREF peripheral address.
AnnaBridge 145:64910690c574 240 * @return Three-bit value of the trim setting.
AnnaBridge 145:64910690c574 241 */
AnnaBridge 145:64910690c574 242 static inline uint8_t VREF_GetLowReferenceTrimVal(VREF_Type *base)
AnnaBridge 145:64910690c574 243 {
AnnaBridge 145:64910690c574 244 return (base->VREFL_TRM & VREF_VREFL_TRM_VREFL_TRIM_MASK);
AnnaBridge 145:64910690c574 245 }
AnnaBridge 145:64910690c574 246 #endif /* FSL_FEATURE_VREF_HAS_LOW_REFERENCE */
AnnaBridge 145:64910690c574 247
AnnaBridge 145:64910690c574 248 /*@}*/
AnnaBridge 145:64910690c574 249
AnnaBridge 145:64910690c574 250 #if defined(__cplusplus)
AnnaBridge 145:64910690c574 251 }
AnnaBridge 145:64910690c574 252 #endif /* __cplusplus */
AnnaBridge 145:64910690c574 253
AnnaBridge 145:64910690c574 254 /*! @}*/
AnnaBridge 145:64910690c574 255
AnnaBridge 145:64910690c574 256 #endif /* _FSL_VREF_H_ */