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 * Register|BitsName
202 * --------|--------
203 * RF_REG_10 | COMP_EN
204 *
205 * @retval None
206 */
207 __STATIC_INLINE void ll_comp_enable(void)
208 {
209 SET_BITS(AON->PWR_RET01, AON_PWR_REG01_WAKE_UP_SEL_MSIO_COMP);
210 SET_BITS(AON->RF_REG_10, AON_RF_REG_10_WAKE_COMP_EN_Msk);
211 }
212
213 /**
214 * @brief Disable COMP module.
215 *
216 * Register|BitsName
217 * --------|--------
218 * RF_REG_10 | COMP_EN
219 *
220 * @retval None
221 */
222 __STATIC_INLINE void ll_comp_disable(void)
223 {
224 CLEAR_BITS(AON->RF_REG_10, AON_RF_REG_10_WAKE_COMP_EN_Msk);
225 CLEAR_BITS(AON->PWR_RET01, AON_PWR_REG01_WAKE_UP_SEL_MSIO_COMP);
226 }
227
228 /**
229 * @brief Set channel of COMP input source.
230 *
231 * Register|BitsName
232 * --------|--------
233 * RF_REG_10 | AON_RF_REG_10_CHANNEL_SEL_P
234 *
235 * @param source This parameter can be one of the following values:
236 * @arg @ref LL_COMP_INPUT_SRC_IO0
237 * @arg @ref LL_COMP_INPUT_SRC_IO1
238 * @arg @ref LL_COMP_INPUT_SRC_IO2
239 * @arg @ref LL_COMP_INPUT_SRC_IO3
240 * @arg @ref LL_COMP_INPUT_SRC_IO4
241 * @retval None
242 */
243 __STATIC_INLINE void ll_comp_set_input_src(uint32_t source)
244 {
245 MODIFY_REG(AON->RF_REG_10, AON_RF_REG_10_CHANNEL_SEL_P_Msk, source);
246 }
247
248 /**
249 * @brief Set channel of COMP reference source.
250 *
251 * Register|BitsName
252 * --------|--------
253 * RF_REG_10 | AON_RF_REG_10_CHANNEL_SEL_N
254 *
255 * @param source This parameter can be one of the following values:
256 * @arg @ref LL_COMP_REF_SRC_IO0
257 * @arg @ref LL_COMP_REF_SRC_IO1
258 * @arg @ref LL_COMP_REF_SRC_IO2
259 * @arg @ref LL_COMP_REF_SRC_IO3
260 * @arg @ref LL_COMP_REF_SRC_IO4
261 * @arg @ref LL_COMP_REF_SRC_VBAT
262 * @arg @ref LL_COMP_REF_SRC_VREF
263 * @retval None
264 */
265 __STATIC_INLINE void ll_comp_set_ref_src(uint32_t source)
266 {
267 MODIFY_REG(AON->RF_REG_10, AON_RF_REG_10_CHANNEL_SEL_N_Msk, source);
268 }
269
270 /**
271 * @brief Set VBATT control level.
272 *
273 * Register|BitsName
274 * --------|--------
275 * RF_REG_10 | BATT_LVL_CTRL_LV
276 *
277 * @param level This parameter can be a value between: 0 ~ 7
278 * Vbatt_ref = ((level+1)/10) * VBATT
279 * @retval None
280 */
281 __STATIC_INLINE void ll_comp_set_vbatt_lvl(uint32_t level)
282 {
283 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);
284 }
285
286 /**
287 * @brief Set VREF control level.
288 *
289 * Register|BitsName
290 * --------|--------
291 * RF_REG_10 | COMP_REF_CTRL_LV
292 *
293 * @param level This parameter can be a value between: 0 ~ 63
294 * Vref = 30mv * level
295 * @retval None
296 */
297 __STATIC_INLINE void ll_comp_set_vref_lvl(uint32_t level)
298 {
299 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);
300 }
301
302 /**
303 * @brief Indicate if the COMP Interrupt Flag is set or not.
304 *
305 * Register|BitsName
306 * --------|--------
307 * SLP_EVENT | MSIO_COMP
308 *
309 * @retval State of bit (1 or o).
310 */
311 SECTION_RAM_CODE __STATIC_INLINE uint32_t ll_comp_is_active_flag_it(void)
312 {
313 return (READ_BITS(AON->SLP_EVENT, AON_SLP_EVENT_PMU_MSIO_COMP) == AON_SLP_EVENT_PMU_MSIO_COMP);
314 }
315
316 /**
317 * @brief Clear Interrupt Status flag for COMP.
318 *
319 * Register|BitsName
320 * --------|--------
321 * SLP_EVENT | MSIO_COMP
322 *
323 * @retval None.
324 */
325 SECTION_RAM_CODE __STATIC_INLINE void ll_comp_clear_flag_it(void)
326 {
327 GLOBAL_EXCEPTION_DISABLE();
328 CLEAR_BITS(AON->SLP_EVENT, AON_SLP_EVENT_PMU_MSIO_COMP);
329 GLOBAL_EXCEPTION_ENABLE();
330 }
331
332 /** @} */
333
334 /** @defgroup COMP_LL_EF_Init Initialization and de-initialization functions
335 * @{
336 */
337
338 /**
339 * @brief De-initialize COMP registers (Registers restored to their default values).
340 * @retval An error_status_t enumeration value:
341 * - SUCCESS: COMP registers are de-initialized
342 * - ERROR: COMP registers are not de-initialized
343 */
344 error_status_t ll_comp_deinit(void);
345
346 /**
347 * @brief Initialize COMP registers according to the specified.
348 * parameters in p_comp_init.
349 * @param p_comp_init Pointer to a ll_comp_init_t structure that contains the configuration
350 * information for the specified COMP peripheral.
351 * @retval An error_status_t enumeration value:
352 * - SUCCESS: COMP registers are initialized according to p_comp_init content
353 * - ERROR: Problem occurred during COMP Registers initialization
354 */
355 error_status_t ll_comp_init(ll_comp_init_t *p_comp_init);
356
357 /**
358 * @brief Set each field of a @ref ll_comp_init_t type structure to default value.
359 * @param p_comp_init Pointer to a @ref ll_comp_init_t structure
360 * whose fields will be set to default values.
361 * @retval None
362 */
363 void ll_comp_struct_init(ll_comp_init_t *p_comp_init);
364
365 /** @} */
366
367 /** @} */
368
369 #endif /* AON */
370
371 #ifdef __cplusplus
372 }
373 #endif
374
375 #endif /* __GR55XX_LL_COMP_H__ */
376
377 /** @} */
378
379 /** @} */
380
381 /** @} */
_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:311
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:297
ll_comp_disable
__STATIC_INLINE void ll_comp_disable(void)
Disable COMP module.
Definition: gr55xx_ll_comp.h:222
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:207
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:281
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:265
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:325
_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:243