1 /*
2  * Copyright 2019-2023 NXP
3  * All rights reserved.
4  *
5  * SPDX-License-Identifier: BSD-3-Clause
6  */
7 
8 #ifndef FSL_VREF_H_
9 #define FSL_VREF_H_
10 
11 #include "fsl_common.h"
12 
13 /*!
14  * @addtogroup vref
15  * @{
16  */
17 
18 /******************************************************************************
19  * Definitions
20  ******************************************************************************/
21 
22 /*! @name Driver version */
23 /*! @{ */
24 #define FSL_VREF_DRIVER_VERSION (MAKE_VERSION(2, 2, 2)) /*!< Version 2.2.2. */
25 /*! @} */
26 
27 /*! @brief VREF buffer modes. */
28 typedef enum _vref_buffer_mode
29 {
30     kVREF_ModeBandgapOnly     = 0U, /*!< Bandgap enabled/standby. */
31     kVREF_ModeLowPowerBuffer  = 1U, /*!< Low-power buffer mode enabled */
32     kVREF_ModeHighPowerBuffer = 2U, /*!< High-power buffer mode enabled */
33 } vref_buffer_mode_t;
34 
35 /*! @brief The description structure for the VREF module. */
36 typedef struct _vref_config
37 {
38     vref_buffer_mode_t bufferMode;       /*!< Buffer mode selection */
39     bool enableInternalVoltageRegulator; /*!< Provide additional supply noise rejection. */
40     bool enableChopOscillator;           /*!< Enable Chop oscillator.*/
41     bool enableHCBandgap;                /*!< Enable High-Accurate bandgap.*/
42     bool enableCurvatureCompensation;    /*!< Enable second order curvature compensation. */
43     bool enableLowPowerBuff;             /*!< Provides bias current for other peripherals.*/
44 
45 } vref_config_t;
46 
47 /******************************************************************************
48  * API
49  ******************************************************************************/
50 
51 #if defined(__cplusplus)
52 extern "C" {
53 #endif /* __cplusplus */
54 
55 /*!
56  * @name Initialization and deinitialization
57  * @{
58  */
59 
60 /*!
61  * @brief Enables the clock gate and configures the VREF module according to the configuration structure.
62  *
63  * This function must be called before calling all other VREF driver functions, read/write registers, and
64  * configurations with user-defined settings. The example below shows how to set up vref_config_t parameters
65  * and how to call the VREF_Init function by passing in these parameters.
66  * @code
67  *    vref_config_t vrefConfig;
68  *    VREF_GetDefaultConfig(VREF, &vrefConfig);
69  *    vrefConfig.bufferMode = kVREF_ModeHighPowerBuffer;
70  *    VREF_Init(VREF, &vrefConfig);
71  * @endcode
72  *
73  * @param base VREF peripheral address.
74  * @param config Pointer to the configuration structure.
75  */
76 void VREF_Init(VREF_Type *base, const vref_config_t *config);
77 
78 /*!
79  * @brief Stops and disables the clock for the VREF module.
80  *
81  * This function should be called to shut down the module.
82  * This is an example.
83  * @code
84  *    vref_config_t vrefUserConfig;
85  *    VREF_GetDefaultConfig(VREF, &vrefUserConfig);
86  *    VREF_Init(VREF, &vrefUserConfig);
87  *    ...
88  *    VREF_Deinit(VREF);
89  * @endcode
90  *
91  * @param base VREF peripheral address.
92  */
93 void VREF_Deinit(VREF_Type *base);
94 
95 /*!
96  * @brief Initializes the VREF configuration structure.
97  *
98  * This function initializes the VREF configuration structure to default values.
99  * This is an example.
100  * @code
101  *    config->bufferMode = kVREF_ModeHighPowerBuffer;
102  *    config->enableInternalVoltageRegulator = true;
103  *    config->enableChopOscillator           = true;
104  *    config->enableHCBandgap                = true;
105  *    config->enableCurvatureCompensation    = true;
106  *    config->enableLowPowerBuff             = true;
107  * @endcode
108  *
109  * @param config Pointer to the initialization structure.
110  */
111 void VREF_GetDefaultConfig(vref_config_t *config);
112 
113 /*! @} */
114 
115 /*!
116  * @name Trim functions
117  * @{
118  */
119 
120 /*!
121  * @brief Sets a TRIM value for the accurate 1.0V bandgap output.
122  *
123  * This function sets a TRIM value for the reference voltage. It will trim the accurate 1.0V bandgap by 0.5mV each step.
124  *
125  * @param base VREF peripheral address.
126  * @param trimValue Value of the trim register to set the output reference voltage (maximum 0x3F (6-bit)).
127  */
128 void VREF_SetVrefTrimVal(VREF_Type *base, uint8_t trimValue);
129 
130 /*!
131  * @brief Sets a TRIM value for the accurate buffered VREF output.
132  *
133  * This function sets a TRIM value for the reference voltage. If buffer mode be set to other values (Buf21
134  * enabled), it will trim the VREF_OUT by 0.1V each step from 1.0V to 2.1V.
135  *
136  * @note When Buf21 is enabled, the value of UTRIM[TRIM2V1] should be ranged from 0b0000 to 0b1011 in order to trim the
137  * output voltage from 1.0V to 2.1V, other values will make the VREF_OUT to default value, 1.0V.
138  *
139  * @param base VREF peripheral address.
140  * @param trim21Value Value of the trim register to set the output reference voltage (maximum 0xF (4-bit)).
141  */
142 void VREF_SetTrim21Val(VREF_Type *base, uint8_t trim21Value);
143 
144 /*!
145  * @brief Reads the trim value.
146  *
147  * This function gets the TRIM value from the UTRIM register. It reads UTRIM[VREFTRIM] (13:8)
148  *
149  * @param base VREF peripheral address.
150  * @return 6-bit value of trim setting.
151  */
152 uint8_t VREF_GetVrefTrimVal(VREF_Type *base);
153 
154 /*!
155  * @brief Reads the VREF 2.1V trim value.
156  *
157  * This function gets the TRIM value from the UTRIM register. It reads UTRIM[TRIM2V1] (3:0),
158  *
159  * @param base VREF peripheral address.
160  * @return 4-bit value of trim setting.
161  */
162 uint8_t VREF_GetTrim21Val(VREF_Type *base);
163 
164 /*! @} */
165 
166 #if defined(__cplusplus)
167 }
168 #endif /* __cplusplus */
169 
170 /*! @}*/
171 
172 #endif /* FSL_VREF_H_ */
173