fsl_vref.h 8.8 KB

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