1 /**
2 ****************************************************************************************
3 *
4 * @file gr55xx_ll_comp.h
5 * @author BLE Driver Team
6 * @brief Header file containing functions prototypes of COMP LL library.
7 *
8 ****************************************************************************************
9 * @attention
10 #####Copyright (c) 2019 GOODIX
11 All rights reserved.
12
13 Redistribution and use in source and binary forms, with or without
14 modification, are permitted provided that the following conditions are met:
15 * Redistributions of source code must retain the above copyright
16 notice, this list of conditions and the following disclaimer.
17 * Redistributions in binary form must reproduce the above copyright
18 notice, this list of conditions and the following disclaimer in the
19 documentation and/or other materials provided with the distribution.
20 * Neither the name of GOODIX nor the names of its contributors may be used
21 to endorse or promote products derived from this software without
22 specific prior written permission.
23
24 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
25 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27 ARE DISCLAIMED. IN NO EVENT SHALL COPYRIGHT HOLDERS AND CONTRIBUTORS BE
28 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
29 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
30 SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
31 INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
32 CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
33 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
34 POSSIBILITY OF SUCH DAMAGE.
35 ****************************************************************************************
36 */
37
38 /** @addtogroup PERIPHERAL Peripheral Driver
39 * @{
40 */
41
42 /** @addtogroup LL_DRIVER LL Driver
43 * @{
44 */
45
46 /** @defgroup LL_COMP COMP
47 * @brief COMP LL module driver.
48 * @{
49 */
50
51 /* Define to prevent recursive inclusion -------------------------------------*/
52 #ifndef __GR55XX_LL_COMP_H__
53 #define __GR55XX_LL_COMP_H__
54
55 /* Includes ------------------------------------------------------------------*/
56 #include "gr55xx.h"
57
58 #ifdef __cplusplus
59 extern "C" {
60 #endif
61
62 #if defined(AON)
63
64 /** @defgroup COMP_LL_STRUCTURES Structures
65 * @{
66 */
67
68 /* Exported types ------------------------------------------------------------*/
69 /** @defgroup COMP_LL_ES_INIT COMP Exported init structures
70 * @{
71 */
72
73 /**
74 * @brief LL COMP init Structure definition
75 */
76 typedef struct _ll_comp_init {
77 uint32_t input_source; /**< Specifies the input source for the comparator.
78 This parameter can be any value of @ref COMP_LL_EC_INPUT_SRC.
79 This parameter can be modified afterwards using unitary function
80 @ref ll_comp_set_input_src(). */
81
82 uint32_t ref_source; /**< Specifies the reference source for the comparator.
83 This parameter can be any value of @ref COMP_LL_EC_INPUT_SRC.
84 This parameter can be modified afterwards using unitary function
85 @ref ll_comp_set_ref_src(). */
86 uint32_t ref_value; /*!< Specifies the value of the COMP buffered reference.
87 If ref_source select to LL_COMP_REF_SRC_VBAT, this parameter can be a value
88 between: 0 ~ 7.
89 This parameter can be modified afterwards using unitary function
90 @ref ll_comp_set_vbatt_lvl().
91 If ref_source select to LL_COMP_REF_SRC_VREF, this parameter can be a value
92 between: 0 ~ 63.
93 This parameter can be modified afterwards using unitary function
94 @ref ll_comp_set_vref_lvl(). */
95 } ll_comp_init_t;
96
97 /** @} */
98
99 /** @} */
100
101 /**
102 * @defgroup COMP_LL_MACRO Defines
103 * @{
104 */
105
106 /* Exported constants --------------------------------------------------------*/
107 /** @defgroup COMP_LL_Exported_Constants COMP Exported Constants
108 * @{
109 */
110
111 /** @defgroup COMP_LL_EC_INPUT_SRC COMP INPUT SOURCE
112 * @{
113 */
114 #define LL_COMP_INPUT_SRC_IO0 (0UL << AON_RF_REG_10_CHANNEL_SEL_P_Pos) /**< Set MSIO_0 as inputs for
115 the comparator */
116 #define LL_COMP_INPUT_SRC_IO1 (1UL << AON_RF_REG_10_CHANNEL_SEL_P_Pos) /**< Set MSIO_1 as inputs for
117 the comparator */
118 #define LL_COMP_INPUT_SRC_IO2 (2UL << AON_RF_REG_10_CHANNEL_SEL_P_Pos) /**< Set MSIO_2 as inputs for
119 the comparator */
120 #define LL_COMP_INPUT_SRC_IO3 (3UL << AON_RF_REG_10_CHANNEL_SEL_P_Pos) /**< Set MSIO_3 as inputs for
121 the comparator */
122 #define LL_COMP_INPUT_SRC_IO4 (4UL << AON_RF_REG_10_CHANNEL_SEL_P_Pos) /**< Set MSIO_4 as inputs for
123 the comparator */
124 /** @} */
125
126 /** @defgroup COMP_LL_EC_REF_SRC COMP REF SOURCE
127 * @{
128 */
129 #define LL_COMP_REF_SRC_IO0 (0UL << AON_RF_REG_10_CHANNEL_SEL_N_Pos) /**< Set MSIO_0 as references for
130 the comparator */
131 #define LL_COMP_REF_SRC_IO1 (1UL << AON_RF_REG_10_CHANNEL_SEL_N_Pos) /**< Set MSIO_1 as references for
132 the comparator */
133 #define LL_COMP_REF_SRC_IO2 (2UL << AON_RF_REG_10_CHANNEL_SEL_N_Pos) /**< Set MSIO_2 as references for
134 the comparator */
135 #define LL_COMP_REF_SRC_IO3 (3UL << AON_RF_REG_10_CHANNEL_SEL_N_Pos) /**< Set MSIO_3 as references for
136 the comparator */
137 #define LL_COMP_REF_SRC_IO4 (4UL << AON_RF_REG_10_CHANNEL_SEL_N_Pos) /**< Set MSIO_4 as references for
138 the comparator */
139 #define LL_COMP_REF_SRC_VBAT (6UL << AON_RF_REG_10_CHANNEL_SEL_N_Pos) /**< Set VBATT as references for
140 the comparator */
141 #define LL_COMP_REF_SRC_VREF (7UL << AON_RF_REG_10_CHANNEL_SEL_N_Pos) /**< Set VREF as references for
142 the comparator */
143 /** @} */
144
145 /** @} */
146
147 /* Exported macro ------------------------------------------------------------*/
148 /** @defgroup COMP_LL_Exported_Macros COMP Exported Macros
149 * @{
150 */
151
152 /** @defgroup COMP_LL_EM_WRITE_READ Common Write and read registers Macros
153 * @{
154 */
155
156 /**
157 * @brief Write a value in COMP register
158 * @param __instance__ COMP instance
159 * @param __REG__ Register to be written
160 * @param __VALUE__ Value to be written in the register
161 * @retval None
162 */
163 #define LL_COMP_WriteReg(__instance__, __REG__, __VALUE__) WRITE_REG((__instance__)->__REG__, (__VALUE__))
164
165 /**
166 * @brief Read a value in COMP register
167 * @param __instance__ COMP instance
168 * @param __REG__ Register to be read
169 * @retval Register value
170 */
171 #define LL_COMP_ReadReg(__instance__, __REG__) READ_REG((__instance__)->__REG__)
172
173 /** @} */
174
175 /** @} */
176
177 /* Private types -------------------------------------------------------------*/
178 /* Private variables ---------------------------------------------------------*/
179 /* Private constants ---------------------------------------------------------*/
180 /* Private macros ------------------------------------------------------------*/
181 /** @defgroup COMP_LL_Private_Macros COMP Private Macros
182 * @{
183 */
184
185 /** @defgroup COMP_LL_EC_DEFAULT_CONFIG InitStruct default configuartion
186 * @{
187 */
188
189 /**
190 * @brief Default configuartion for initializing structure
191 */
192 #define LL_COMP_DEFAULT_CONFIG \
193 { \
194 .channel_p = LL_COMP_CHANNEL_IO0, \
195 .channel_n = LL_COMP_CHANNEL_IO1, \
196 }
197 /** @} */
198
199 /** @} */
200
201 /** @} */
202
203 /* Exported functions --------------------------------------------------------*/
204 /** @defgroup COMP_LL_DRIVER_FUNCTIONS Functions
205 * @{
206 */
207
208 /** @defgroup COMP_LL_EF_Configuration Basic Configuration
209 * @{
210 */
211
212 /**
213 * @brief Enable COMP module.
214 *
215 * Register|BitsName
216 * --------|--------
217 * RF_REG_10 | COMP_EN
218 *
219 * @retval None
220 */
ll_comp_enable(void)221 __STATIC_INLINE void ll_comp_enable(void)
222 {
223 SET_BITS(AON->PWR_RET01, AON_PWR_REG01_WAKE_UP_SEL_MSIO_COMP);
224 SET_BITS(AON->RF_REG_10, AON_RF_REG_10_WAKE_COMP_EN_Msk);
225 }
226
227 /**
228 * @brief Disable COMP module.
229 *
230 * Register|BitsName
231 * --------|--------
232 * RF_REG_10 | COMP_EN
233 *
234 * @retval None
235 */
ll_comp_disable(void)236 __STATIC_INLINE void ll_comp_disable(void)
237 {
238 CLEAR_BITS(AON->RF_REG_10, AON_RF_REG_10_WAKE_COMP_EN_Msk);
239 CLEAR_BITS(AON->PWR_RET01, AON_PWR_REG01_WAKE_UP_SEL_MSIO_COMP);
240 }
241
242 /**
243 * @brief Set channel of COMP input source.
244 *
245 * Register|BitsName
246 * --------|--------
247 * RF_REG_10 | AON_RF_REG_10_CHANNEL_SEL_P
248 *
249 * @param source This parameter can be one of the following values:
250 * @arg @ref LL_COMP_INPUT_SRC_IO0
251 * @arg @ref LL_COMP_INPUT_SRC_IO1
252 * @arg @ref LL_COMP_INPUT_SRC_IO2
253 * @arg @ref LL_COMP_INPUT_SRC_IO3
254 * @arg @ref LL_COMP_INPUT_SRC_IO4
255 * @retval None
256 */
ll_comp_set_input_src(uint32_t source)257 __STATIC_INLINE void ll_comp_set_input_src(uint32_t source)
258 {
259 MODIFY_REG(AON->RF_REG_10, AON_RF_REG_10_CHANNEL_SEL_P_Msk, source);
260 }
261
262 /**
263 * @brief Set channel of COMP reference source.
264 *
265 * Register|BitsName
266 * --------|--------
267 * RF_REG_10 | AON_RF_REG_10_CHANNEL_SEL_N
268 *
269 * @param source This parameter can be one of the following values:
270 * @arg @ref LL_COMP_REF_SRC_IO0
271 * @arg @ref LL_COMP_REF_SRC_IO1
272 * @arg @ref LL_COMP_REF_SRC_IO2
273 * @arg @ref LL_COMP_REF_SRC_IO3
274 * @arg @ref LL_COMP_REF_SRC_IO4
275 * @arg @ref LL_COMP_REF_SRC_VBAT
276 * @arg @ref LL_COMP_REF_SRC_VREF
277 * @retval None
278 */
ll_comp_set_ref_src(uint32_t source)279 __STATIC_INLINE void ll_comp_set_ref_src(uint32_t source)
280 {
281 MODIFY_REG(AON->RF_REG_10, AON_RF_REG_10_CHANNEL_SEL_N_Msk, source);
282 }
283
284 /**
285 * @brief Set VBATT control level.
286 *
287 * Register|BitsName
288 * --------|--------
289 * RF_REG_10 | BATT_LVL_CTRL_LV
290 *
291 * @param level This parameter can be a value between: 0 ~ 7
292 * Vbatt_ref = ((level+1)/10) * VBATT
293 * @retval None
294 */
ll_comp_set_vbatt_lvl(uint32_t level)295 __STATIC_INLINE void ll_comp_set_vbatt_lvl(uint32_t level)
296 {
297 MODIFY_REG(AON->RF_REG_10, AON_RF_REG_10_COMP_BATT_LVL_CTRL_LV_Msk, \
298 level << AON_RF_REG_10_COMP_BATT_LVL_CTRL_LV_Pos);
299 }
300
301 /**
302 * @brief Set VREF control level.
303 *
304 * Register|BitsName
305 * --------|--------
306 * RF_REG_10 | COMP_REF_CTRL_LV
307 *
308 * @param level This parameter can be a value between: 0 ~ 63
309 * Vref = 30mv * level
310 * @retval None
311 */
ll_comp_set_vref_lvl(uint32_t level)312 __STATIC_INLINE void ll_comp_set_vref_lvl(uint32_t level)
313 {
314 MODIFY_REG(AON->RF_REG_10, AON_RF_REG_10_COMP_REF_CTRL_LV_Msk, level << AON_RF_REG_10_COMP_REF_CTRL_LV_Pos);
315 }
316
317 /**
318 * @brief Indicate if the COMP Interrupt Flag is set or not.
319 *
320 * Register|BitsName
321 * --------|--------
322 * SLP_EVENT | MSIO_COMP
323 *
324 * @retval State of bit (1 or o).
325 */
ll_comp_is_active_flag_it(void)326 SECTION_RAM_CODE __STATIC_INLINE uint32_t ll_comp_is_active_flag_it(void)
327 {
328 return (READ_BITS(AON->SLP_EVENT, AON_SLP_EVENT_PMU_MSIO_COMP) == AON_SLP_EVENT_PMU_MSIO_COMP);
329 }
330
331 /**
332 * @brief Clear Interrupt Status flag for COMP.
333 *
334 * Register|BitsName
335 * --------|--------
336 * SLP_EVENT | MSIO_COMP
337 *
338 * @retval None.
339 */
ll_comp_clear_flag_it(void)340 SECTION_RAM_CODE __STATIC_INLINE void ll_comp_clear_flag_it(void)
341 {
342 GLOBAL_EXCEPTION_DISABLE();
343 CLEAR_BITS(AON->SLP_EVENT, AON_SLP_EVENT_PMU_MSIO_COMP);
344 GLOBAL_EXCEPTION_ENABLE();
345 }
346
347 /** @} */
348
349 /** @defgroup COMP_LL_EF_Init Initialization and de-initialization functions
350 * @{
351 */
352
353 /**
354 * @brief De-initialize COMP registers (Registers restored to their default values).
355 * @retval An error_status_t enumeration value:
356 * - SUCCESS: COMP registers are de-initialized
357 * - ERROR: COMP registers are not de-initialized
358 */
359 error_status_t ll_comp_deinit(void);
360
361 /**
362 * @brief Initialize COMP registers according to the specified.
363 * parameters in p_comp_init.
364 * @param p_comp_init Pointer to a ll_comp_init_t structure that contains the configuration
365 * information for the specified COMP peripheral.
366 * @retval An error_status_t enumeration value:
367 * - SUCCESS: COMP registers are initialized according to p_comp_init content
368 * - ERROR: Problem occurred during COMP Registers initialization
369 */
370 error_status_t ll_comp_init(ll_comp_init_t *p_comp_init);
371
372 /**
373 * @brief Set each field of a @ref ll_comp_init_t type structure to default value.
374 * @param p_comp_init Pointer to a @ref ll_comp_init_t structure
375 * whose fields will be set to default values.
376 * @retval None
377 */
378 void ll_comp_struct_init(ll_comp_init_t *p_comp_init);
379
380 /** @} */
381
382 /** @} */
383
384 #endif /* AON */
385
386 #ifdef __cplusplus
387 }
388 #endif
389
390 #endif /* __GR55XX_LL_COMP_H__ */
391
392 /** @} */
393
394 /** @} */
395
396 /** @} */
397