gr55xx_ll_comp.h
Go to the documentation of this file.
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 #ifdef __cplusplus
56 extern "C" {
57 #endif
58
59 /* Includes ------------------------------------------------------------------*/
60 #include "gr55xx.h"
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 {
78 uint32_t input_source; /**< Specifies the input source for the comparator.
79 This parameter can be any value of @ref COMP_LL_EC_INPUT_SRC.
80
81 This parameter can be modified afterwards using unitary function @ref ll_comp_set_input_src(). */
82
83 uint32_t ref_source; /**< Specifies the reference source for the comparator.
84 This parameter can be any value of @ref COMP_LL_EC_INPUT_SRC.
85
86 This parameter can be modified afterwards using unitary function @ref ll_comp_set_ref_src(). */
87 uint32_t ref_value; /*!< Specifies the value of the COMP buffered reference.
88 If ref_source select to LL_COMP_REF_SRC_VBAT, this parameter can be a value between: 0 ~ 7.
89 This parameter can be modified afterwards using unitary function @ref ll_comp_set_vbatt_lvl().
90
91 If ref_source select to LL_COMP_REF_SRC_VREF, this parameter can be a value between: 0 ~ 63.
92 This parameter can be modified afterwards using unitary function @ref ll_comp_set_vref_lvl(). */
93 } ll_comp_init_t;
94
95 /** @} */
96
97 /** @} */
98
99 /**
100 * @defgroup COMP_LL_MACRO Defines
101 * @{
102 */
103
104 /* Exported constants --------------------------------------------------------*/
105 /** @defgroup COMP_LL_Exported_Constants COMP Exported Constants
106 * @{
107 */
108
109 /** @defgroup COMP_LL_EC_INPUT_SRC COMP INPUT SOURCE
110 * @{
111 */
112 #define LL_COMP_INPUT_SRC_IO0 (0UL << AON_RF_REG_10_CHANNEL_SEL_P_Pos) /**< Set MSIO_0 as inputs for the comparator */
113 #define LL_COMP_INPUT_SRC_IO1 (1UL << AON_RF_REG_10_CHANNEL_SEL_P_Pos) /**< Set MSIO_1 as inputs for the comparator */
114 #define LL_COMP_INPUT_SRC_IO2 (2UL << AON_RF_REG_10_CHANNEL_SEL_P_Pos) /**< Set MSIO_2 as inputs for the comparator */
115 #define LL_COMP_INPUT_SRC_IO3 (3UL << AON_RF_REG_10_CHANNEL_SEL_P_Pos) /**< Set MSIO_3 as inputs for the comparator */
116 #define LL_COMP_INPUT_SRC_IO4 (4UL << AON_RF_REG_10_CHANNEL_SEL_P_Pos) /**< Set MSIO_4 as inputs for the comparator */
117 /** @} */
118
119 /** @defgroup COMP_LL_EC_REF_SRC COMP REF SOURCE
120 * @{
121 */
122 #define LL_COMP_REF_SRC_IO0 (0UL << AON_RF_REG_10_CHANNEL_SEL_N_Pos) /**< Set MSIO_0 as references for the comparator */
123 #define LL_COMP_REF_SRC_IO1 (1UL << AON_RF_REG_10_CHANNEL_SEL_N_Pos) /**< Set MSIO_1 as references for the comparator */
124 #define LL_COMP_REF_SRC_IO2 (2UL << AON_RF_REG_10_CHANNEL_SEL_N_Pos) /**< Set MSIO_2 as references for the comparator */
125 #define LL_COMP_REF_SRC_IO3 (3UL << AON_RF_REG_10_CHANNEL_SEL_N_Pos) /**< Set MSIO_3 as references for the comparator */
126 #define LL_COMP_REF_SRC_IO4 (4UL << AON_RF_REG_10_CHANNEL_SEL_N_Pos) /**< Set MSIO_4 as references for the comparator */
127 #define LL_COMP_REF_SRC_VBAT (6UL << AON_RF_REG_10_CHANNEL_SEL_N_Pos) /**< Set VBATT as references for the comparator */
128 #define LL_COMP_REF_SRC_VREF (7UL << AON_RF_REG_10_CHANNEL_SEL_N_Pos) /**< Set VREF as references for the comparator */
129 /** @} */
130
131 /** @} */
132
133 /* Exported macro ------------------------------------------------------------*/
134 /** @defgroup COMP_LL_Exported_Macros COMP Exported Macros
135 * @{
136 */
137
138 /** @defgroup COMP_LL_EM_WRITE_READ Common Write and read registers Macros
139 * @{
140 */
141
142 /**
143 * @brief Write a value in COMP register
144 * @param __instance__ COMP instance
145 * @param __REG__ Register to be written
146 * @param __VALUE__ Value to be written in the register
147 * @retval None
148 */
149 #define LL_COMP_WriteReg(__instance__, __REG__, __VALUE__) WRITE_REG((__instance__)->__REG__, (__VALUE__))
150
151 /**
152 * @brief Read a value in COMP register
153 * @param __instance__ COMP instance
154 * @param __REG__ Register to be read
155 * @retval Register value
156 */
157 #define LL_COMP_ReadReg(__instance__, __REG__) READ_REG((__instance__)->__REG__)
158
159 /** @} */
160
161 /** @} */
162
163 /* Private types -------------------------------------------------------------*/
164 /* Private variables ---------------------------------------------------------*/
165 /* Private constants ---------------------------------------------------------*/
166 /* Private macros ------------------------------------------------------------*/
167 /** @defgroup COMP_LL_Private_Macros COMP Private Macros
168 * @{
169 */
170
171 /** @defgroup COMP_LL_EC_DEFAULT_CONFIG InitStruct default configuartion
172 * @{
173 */
174
175 /**
176 * @brief Default configuartion for initializing structure
177 */
178 #define LL_COMP_DEFAULT_CONFIG \
179 { \
180 .channel_p = LL_COMP_CHANNEL_IO0, \
181 .channel_n = LL_COMP_CHANNEL_IO1, \
182 }
183 /** @} */
184
185 /** @} */
186
187 /** @} */
188
189 /* Exported functions --------------------------------------------------------*/
190 /** @defgroup COMP_LL_DRIVER_FUNCTIONS Functions
191 * @{
192 */
193
194 /** @defgroup COMP_LL_EF_Configuration Basic Configuration
195 * @{
196 */
197
198 /**
199 * @brief Enable COMP module.
200 *
201 * \rst
202 * +----------------------+-----------------------------------+
203 * | Register | BitsName |
204 * +======================+===================================+
205 * | RF_REG_10 | COMP_EN |
206 * +----------------------+-----------------------------------+
207 * \endrst
208 *
209 * @retval None
210 */
211 __STATIC_INLINE void ll_comp_enable(void)
212 {
213 SET_BITS(AON->PWR_RET01, AON_PWR_REG01_WAKE_UP_SEL_MSIO_COMP);
214 SET_BITS(AON->RF_REG_10, AON_RF_REG_10_WAKE_COMP_EN_Msk);
215 }
216
217 /**
218 * @brief Disable COMP module.
219 *
220 * \rst
221 * +----------------------+-----------------------------------+
222 * | Register | BitsName |
223 * +======================+===================================+
224 * | RF_REG_10 | COMP_EN |
225 * +----------------------+-----------------------------------+
226 * \endrst
227 *
228 * @retval None
229 */
230 __STATIC_INLINE void ll_comp_disable(void)
231 {
232 CLEAR_BITS(AON->RF_REG_10, AON_RF_REG_10_WAKE_COMP_EN_Msk);
233 CLEAR_BITS(AON->PWR_RET01, AON_PWR_REG01_WAKE_UP_SEL_MSIO_COMP);
234 }
235
236 /**
237 * @brief Set channel of COMP input source.
238 *
239 * \rst
240 * +----------------------+-----------------------------------+
241 * | Register | BitsName |
242 * +======================+===================================+
243 * | RF_REG_10 | AON_RF_REG_10_CHANNEL_SEL_P |
244 * +----------------------+-----------------------------------+
245 * \endrst
246 *
247 * @param source This parameter can be one of the following values:
248 * @arg @ref LL_COMP_INPUT_SRC_IO0
249 * @arg @ref LL_COMP_INPUT_SRC_IO1
250 * @arg @ref LL_COMP_INPUT_SRC_IO2
251 * @arg @ref LL_COMP_INPUT_SRC_IO3
252 * @arg @ref LL_COMP_INPUT_SRC_IO4
253 * @retval None
254 */
255 __STATIC_INLINE void ll_comp_set_input_src(uint32_t source)
256 {
257 MODIFY_REG(AON->RF_REG_10, AON_RF_REG_10_CHANNEL_SEL_P_Msk, source);
258 }
259
260 /**
261 * @brief Set channel of COMP reference source.
262 *
263 * \rst
264 * +----------------------+-----------------------------------+
265 * | Register | BitsName |
266 * +======================+===================================+
267 * | RF_REG_10 | AON_RF_REG_10_CHANNEL_SEL_N |
268 * +----------------------+-----------------------------------+
269 * \endrst
270 *
271 * @param source This parameter can be one of the following values:
272 * @arg @ref LL_COMP_REF_SRC_IO0
273 * @arg @ref LL_COMP_REF_SRC_IO1
274 * @arg @ref LL_COMP_REF_SRC_IO2
275 * @arg @ref LL_COMP_REF_SRC_IO3
276 * @arg @ref LL_COMP_REF_SRC_IO4
277 * @arg @ref LL_COMP_REF_SRC_VBAT
278 * @arg @ref LL_COMP_REF_SRC_VREF
279 * @retval None
280 */
281 __STATIC_INLINE void ll_comp_set_ref_src(uint32_t source)
282 {
283 MODIFY_REG(AON->RF_REG_10, AON_RF_REG_10_CHANNEL_SEL_N_Msk, source);
284 }
285
286 /**
287 * @brief Set VBATT control level.
288 *
289 * \rst
290 * +----------------------+-----------------------------------+
291 * | Register | BitsName |
292 * +======================+===================================+
293 * | RF_REG_10 | BATT_LVL_CTRL_LV |
294 * +----------------------+-----------------------------------+
295 * \endrst
296 *
297 * @param level This parameter can be a value between: 0 ~ 7
298 * Vbatt_ref = ((level+1)/10) * VBATT
299 * @retval None
300 */
301 __STATIC_INLINE void ll_comp_set_vbatt_lvl(uint32_t level)
302 {
303 MODIFY_REG(AON->RF_REG_10, AON_RF_REG_10_COMP_BATT_LVL_CTRL_LV_Msk, level << AON_RF_REG_10_COMP_BATT_LVL_CTRL_LV_Pos);
304 }
305
306 /**
307 * @brief Set VREF control level.
308 *
309 * \rst
310 * +----------------------+-----------------------------------+
311 * | Register | BitsName |
312 * +======================+===================================+
313 * | RF_REG_10 | COMP_REF_CTRL_LV |
314 * +----------------------+-----------------------------------+
315 * \endrst
316 *
317 * @param level This parameter can be a value between: 0 ~ 63
318 * Vref = 30mv * level
319 * @retval None
320 */
321 __STATIC_INLINE void ll_comp_set_vref_lvl(uint32_t level)
322 {
323 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);
324 }
325
326 /**
327 * @brief Indicate if the COMP Interrupt Flag is set or not.
328 *
329 * \rst
330 * +----------------------+-----------------------------------+
331 * | Register | BitsName |
332 * +======================+===================================+
333 * | SLP_EVENT | MSIO_COMP |
334 * +----------------------+-----------------------------------+
335 * \endrst
336 *
337 * @retval State of bit (1 or o).
338 */
339 SECTION_RAM_CODE __STATIC_INLINE uint32_t ll_comp_is_active_flag_it(void)
340 {
341 return (READ_BITS(AON->SLP_EVENT, AON_SLP_EVENT_PMU_MSIO_COMP) == AON_SLP_EVENT_PMU_MSIO_COMP);
342 }
343
344 /**
345 * @brief Clear Interrupt Status flag for COMP.
346 *
347 * \rst
348 * +----------------------+-----------------------------------+
349 * | Register | BitsName |
350 * +======================+===================================+
351 * | SLP_EVENT | MSIO_COMP |
352 * +----------------------+-----------------------------------+
353 * \endrst
354 *
355 * @retval None.
356 */
357 SECTION_RAM_CODE __STATIC_INLINE void ll_comp_clear_flag_it(void)
358 {
359 GLOBAL_EXCEPTION_DISABLE();
360 CLEAR_BITS(AON->SLP_EVENT, AON_SLP_EVENT_PMU_MSIO_COMP);
361 GLOBAL_EXCEPTION_ENABLE();
362 }
363
364 /** @} */
365
366 /** @defgroup COMP_LL_EF_Init Initialization and de-initialization functions
367 * @{
368 */
369
370 /**
371 * @brief De-initialize COMP registers (Registers restored to their default values).
372 * @retval An error_status_t enumeration value:
373 * - SUCCESS: COMP registers are de-initialized
374 * - ERROR: COMP registers are not de-initialized
375 */
376 error_status_t ll_comp_deinit(void);
377
378 /**
379 * @brief Initialize COMP registers according to the specified.
380 * parameters in p_comp_init.
381 * @param p_comp_init Pointer to a ll_comp_init_t structure that contains the configuration
382 * information for the specified COMP peripheral.
383 * @retval An error_status_t enumeration value:
384 * - SUCCESS: COMP registers are initialized according to p_comp_init content
385 * - ERROR: Problem occurred during COMP Registers initialization
386 */
387 error_status_t ll_comp_init(ll_comp_init_t *p_comp_init);
388
389 /**
390 * @brief Set each field of a @ref ll_comp_init_t type structure to default value.
391 * @param p_comp_init Pointer to a @ref ll_comp_init_t structure
392 * whose fields will be set to default values.
393 * @retval None
394 */
395 void ll_comp_struct_init(ll_comp_init_t *p_comp_init);
396
397 /** @} */
398
399 /** @} */
400
401 #endif /* AON */
402
403 #ifdef __cplusplus
404 }
405 #endif
406
407 #endif /* __GR55XX_LL_COMP_H__ */
408
409 /** @} */
410
411 /** @} */
412
413 /** @} */
_ll_comp_init::ref_source
uint32_t ref_source
Specifies the reference source for the comparator.
Definition: gr55xx_ll_comp.h:83
ll_comp_is_active_flag_it
SECTION_RAM_CODE __STATIC_INLINE uint32_t ll_comp_is_active_flag_it(void)
Indicate if the COMP Interrupt Flag is set or not.
Definition: gr55xx_ll_comp.h:339
ll_comp_init_t
struct _ll_comp_init ll_comp_init_t
LL COMP init Structure definition.
_ll_comp_init::input_source
uint32_t input_source
Specifies the input source for the comparator.
Definition: gr55xx_ll_comp.h:78
_ll_comp_init
LL COMP init Structure definition.
Definition: gr55xx_ll_comp.h:77
ll_comp_set_vref_lvl
__STATIC_INLINE void ll_comp_set_vref_lvl(uint32_t level)
Set VREF control level.
Definition: gr55xx_ll_comp.h:321
ll_comp_disable
__STATIC_INLINE void ll_comp_disable(void)
Disable COMP module.
Definition: gr55xx_ll_comp.h:230
ll_comp_deinit
error_status_t ll_comp_deinit(void)
De-initialize COMP registers (Registers restored to their default values).
ll_comp_init
error_status_t ll_comp_init(ll_comp_init_t *p_comp_init)
Initialize COMP registers according to the specified.
ll_comp_enable
__STATIC_INLINE void ll_comp_enable(void)
Enable COMP module.
Definition: gr55xx_ll_comp.h:211
ll_comp_struct_init
void ll_comp_struct_init(ll_comp_init_t *p_comp_init)
Set each field of a ll_comp_init_t type structure to default value.
ll_comp_set_vbatt_lvl
__STATIC_INLINE void ll_comp_set_vbatt_lvl(uint32_t level)
Set VBATT control level.
Definition: gr55xx_ll_comp.h:301
ll_comp_set_ref_src
__STATIC_INLINE void ll_comp_set_ref_src(uint32_t source)
Set channel of COMP reference source.
Definition: gr55xx_ll_comp.h:281
ll_comp_clear_flag_it
SECTION_RAM_CODE __STATIC_INLINE void ll_comp_clear_flag_it(void)
Clear Interrupt Status flag for COMP.
Definition: gr55xx_ll_comp.h:357
_ll_comp_init::ref_value
uint32_t ref_value
Definition: gr55xx_ll_comp.h:87
ll_comp_set_input_src
__STATIC_INLINE void ll_comp_set_input_src(uint32_t source)
Set channel of COMP input source.
Definition: gr55xx_ll_comp.h:255