fsl_vref.h 9.0 KB

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