gr533x_hal_aon_gpio.h
Go to the documentation of this file.
1 /**
2 ****************************************************************************************
3 *
4 * @file gr533x_hal_aon_gpio.h
5 * @author BLE Driver Team
6 * @brief Header file containing functions prototypes of AON GPIO HAL 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 HAL_DRIVER HAL Driver
43 * @{
44 */
45
46 /** @defgroup HAL_AON_GPIO AON_GPIO
47 * @brief AON_GPIO HAL module driver.
48 * @{
49 */
50
51 /* Define to prevent recursive inclusion -------------------------------------*/
52 #ifndef __GR533x_HAL_AON_GPIO_H__
53 #define __GR533x_HAL_AON_GPIO_H__
54
55 #ifdef __cplusplus
56 extern "C" {
57 #endif
58
59 /* Includes ------------------------------------------------------------------*/
60 #include "gr533x_ll_aon_gpio.h"
61 #include "gr533x_hal_def.h"
62
63 /* Exported types ------------------------------------------------------------*/
64 /** @addtogroup HAL_AON_GPIO_ENUMERATIONS Enumerations
65 * @{
66 */
67
68 /**
69 * @brief AON_GPIO Bit SET and Bit RESET enumerations
70 */
71 typedef enum
72 {
73 AON_GPIO_PIN_RESET = 0U, /**< AON GPIO pin low level.*/
74 AON_GPIO_PIN_SET /**< AON GPIO pin high level.*/
75 } aon_gpio_pin_state_t;
76
77 /** @} */
78
79 /** @addtogroup HAL_AON_GPIO_STRUCTURES Structures
80 * @{
81 */
82
83 /**
84 * @brief AON_GPIO init structure definition
85 */
86 typedef struct _aon_gpio_init
87 {
88 uint32_t pin; /**< Specifies the AON_GPIO pins to be configured.
89 This parameter can be any value of @ref AON_GPIO_Pins */
90
91 uint32_t mode; /**< Specifies the operating mode for the selected pins.
92 This parameter can be a value of @ref AON_GPIO_Mode */
93
94 uint32_t pull; /**< Specifies the Pull-up or Pull-Down activation for the selected pins.
95 This parameter can be a value of @ref AON_GPIO_Pull */
96
97 uint32_t mux; /**< Specifies the Peripheral to be connected to the selected pins.
98 This parameter can be a value of GPIOEx_Mux_Function_Selection. */
99
100 uint32_t speed; /**< Specifies the Speed for the selected pins.
101 This parameter can be a value of @ref AON_GPIO_SPEED */
102
103 uint32_t strength; /**< Specifies the Speed for the selected pins.
104 This parameter can be a value of @ref AON_GPIO_STRENGTH */
105
106 uint32_t input_type; /**< Specifies the Speed for the selected pins.
107 This parameter can be a value of @ref AON_GPIO_INPUT_TYPE*/
108 } aon_gpio_init_t;
109
110 /** @} */
111
112 /** @addtogroup HAL_AON_GPIO_CALLBACK_STRUCTURES Callback Structures
113 * @{
114 */
115
116 /** @defgroup AON_GPIO_Callback AON_GPIO Callback
117 * @{
118 */
119
120 /**
121 * @brief HAL AON_GPIO Callback function definition
122 */
123 typedef struct _hal_aon_gpio_callback
124 {
125 void (*aon_gpio_callback)(uint16_t aon_gpio_pin); /**< AON GPIO pin detection callback */
126 } hal_aon_gpio_callback_t;
127
128 /** @} */
129
130 /** @} */
131
132 /**
133 * @defgroup HAL_AON_GPIO_MACRO Defines
134 * @{
135 */
136
137 /* Exported constants --------------------------------------------------------*/
138 /** @defgroup AON_GPIO_Exported_Constants AON_GPIO Exported Constants
139 * @{
140 */
141
142 /** @defgroup AON_GPIO_Pins AON_GPIO pins
143 * @{
144 */
145 #define AON_GPIO_PIN_0 ((uint16_t)0x0001U) /**< Pin 0 selected */
146 #define AON_GPIO_PIN_1 ((uint16_t)0x0002U) /**< Pin 1 selected */
147 #define AON_GPIO_PIN_2 ((uint16_t)0x0004U) /**< Pin 2 selected */
148 #define AON_GPIO_PIN_3 ((uint16_t)0x0008U) /**< Pin 3 selected */
149 #define AON_GPIO_PIN_4 ((uint16_t)0x0010U) /**< Pin 4 selected */
150 #define AON_GPIO_PIN_5 ((uint16_t)0x0020U) /**< Pin 5 selected */
151 #define AON_GPIO_PIN_6 ((uint16_t)0x0040U) /**< Pin 6 selected */
152 #define AON_GPIO_PIN_7 ((uint16_t)0x0080U) /**< Pin 7 selected */
153
154 #define AON_GPIO_PIN_ALL ((uint16_t)0x00FFU) /**< All pins selected */
155
156 #define AON_GPIO_PIN_MASK (0x000000FFU) /**< PIN mask for assert test */
157 /** @} */
158
159 /** @defgroup AON_GPIO_Mode AON_GPIO mode
160 * @brief AON_GPIO Configuration Mode
161 * Elements values convention: 0x000000YX
162 * - X : IO Direction mode (Input, Output, Mux)
163 * - Y : IT trigger detection
164 * @{
165 */
166 #define AON_GPIO_MODE_NONE (LL_AON_GPIO_MODE_NONE << 0) /**< Disable input and output */
167 #define AON_GPIO_MODE_INPUT (LL_AON_GPIO_MODE_INPUT << 0) /**< Input Mode */
168 #define AON_GPIO_MODE_OUTPUT (LL_AON_GPIO_MODE_OUTPUT << 0) /**< Output Mode */
169 #define AON_GPIO_MODE_INOUT (LL_AON_GPIO_MODE_INOUT << 0) /**< Input andoutput Mode */
170 #define AON_GPIO_MODE_MUX (LL_AON_GPIO_MODE_INOUT << 0) /**< Mux Mode */
171 #define AON_GPIO_MODE_IT_RISING (LL_AON_GPIO_TRIGGER_RISING << 4 | AON_GPIO_MODE_INPUT) /**< Interrupt Mode with Rising edge trigger detection */
172 #define AON_GPIO_MODE_IT_FALLING (LL_AON_GPIO_TRIGGER_FALLING << 4 | AON_GPIO_MODE_INPUT) /**< Interrupt Mode with Falling edge trigger detection */
173 #define AON_GPIO_MODE_IT_HIGH (LL_AON_GPIO_TRIGGER_HIGH << 4 | AON_GPIO_MODE_INPUT) /**< Interrupt Mode with High-level trigger detection */
174 #define AON_GPIO_MODE_IT_LOW (LL_AON_GPIO_TRIGGER_LOW << 4 | AON_GPIO_MODE_INPUT) /**< Interrupt Mode with Low-level trigger detection */
175 #define AON_GPIO_MODE_IT_BOTH_EDGE (LL_AON_GPIO_TRIGGER_BOTH_EDGE << 4 | AON_GPIO_MODE_INPUT) /**< Interrupt Mode with Rising and Falling edge trigger detection */
176 /** @} */
177
178
179 /** @defgroup AON_GPIO_Pull AON_GPIO pull
180 * @brief AON_GPIO Pull-Up or Pull-Down activation
181 * @{
182 */
183 #define AON_GPIO_NOPULL LL_AON_GPIO_PULL_NO /**< No Pull-up or Pull-down activation */
184 #define AON_GPIO_PULLUP LL_AON_GPIO_PULL_UP /**< Pull-up activation */
185 #define AON_GPIO_PULLDOWN LL_AON_GPIO_PULL_DOWN /**< Pull-down activation */
186 /** @} */
187
188 /** @defgroup AON_GPIO_SPEED IO speed
189 * @{
190 */
191 #define AON_GPIO_SPEED_MEDIUM LL_AON_GPIO_SPEED_MEDIUM /*!< Select medium speed */
192 #define AON_GPIO_SPEED_HIGH LL_AON_GPIO_SPEED_HIGH /*!< Select high speed */
193 /** @} */
194
195 /** @defgroup AON_GPIO_STRENGTH IO strength
196 * @{
197 */
198 #define AON_GPIO_STRENGTH_LOW LL_AON_GPIO_STRENGTH_LOW /*!< Select low output driver strength */
199 #define AON_GPIO_STRENGTH_MEDIUM LL_AON_GPIO_STRENGTH_MEDIUM /*!< Select medium output driver strength */
200 #define AON_GPIO_STRENGTH_HIGH LL_AON_GPIO_STRENGTH_HIGH /*!< Select high output driver strength */
201 #define AON_GPIO_STRENGTH_ULTRA LL_AON_GPIO_STRENGTH_ULTRA /*!< Select high output driver strength */
202 /** @} */
203
204 /** @defgroup AON_GPIO_INPUT_TYPE Input type
205 * @{
206 */
207 #define AON_GPIO_INPUT_TYPE_CMOS LL_AON_GPIO_INPUT_TYPE_CMOS /**< CMOS input */
208 #define AON_GPIO_INPUT_TYPE_SCHMITT LL_AON_GPIO_INPUT_TYPE_SCHMITT /**< Schmitt input */
209 /** @} */
210
211 /**
212 * @brief AON_GPIO_default_config initStruct default configuration
213 */
214 #define AON_GPIO_DEFAULT_CONFIG \
215 { \
216 .pin = AON_GPIO_PIN_ALL, \
217 .mode = AON_GPIO_MODE_INPUT, \
218 .pull = AON_GPIO_PULLDOWN, \
219 .mux = IO_MUX_GPIO, \
220 .speed = AON_GPIO_SPEED_MEDIUM, \
221 .strength = AON_GPIO_STRENGTH_MEDIUM, \
222 .input_type = AON_GPIO_INPUT_TYPE_CMOS, \
223 }
224 /** @} */
225
226 /* Exported macro ------------------------------------------------------------*/
227 /** @defgroup AON_GPIO_Exported_Macros AON_GPIO Exported Macros
228 * @{
229 */
230
231 /**
232 * @brief Check whether the specified AON_GPIO pin is asserted or not.
233 * @param __AON_GPIO_PIN__ specifies the AON_GPIO pin to be checked.
234 * This parameter can be AON_GPIO_PIN_x where x can be (0..15).
235 * @retval The new state of __AON_GPIO_PIN__ (SET or RESET).
236 */
237 #define __HAL_AON_GPIO_IT_GET_IT(__AON_GPIO_PIN__) ll_aon_gpio_read_flag_it(__AON_GPIO_PIN__)
238
239 /**
240 * @brief Clear the AON_GPIO pin pending bits.
241 * @param __AON_GPIO_PIN__ specifies the AON_GPIO pins to be cleared.
242 * This parameter can be any combination of AON_GPIO_PIN_x where x can be (0..15).
243 * @retval None
244 */
245 #define __HAL_AON_GPIO_IT_CLEAR_IT(__AON_GPIO_PIN__) ll_aon_gpio_clear_flag_it(__AON_GPIO_PIN__)
246
247 /** @} */
248
249 /* Private macros ------------------------------------------------------------*/
250 /** @addtogroup AON_GPIO_Private_Macros AON_GPIO Private Macros
251 * @{
252 */
253
254 /**
255 * @brief Check if AON GPIO pin action is valid.
256 * @param __ACTION__ AON GPIO pin action.
257 * @retval SET (__ACTION__ is valid) or RESET (__ACTION__ is invalid)
258 */
259 #define IS_AON_GPIO_PIN_ACTION(__ACTION__) (((__ACTION__) == AON_GPIO_PIN_RESET) || ((__ACTION__) == AON_GPIO_PIN_SET))
260
261 /**
262 * @brief Check if AON GPIO pins are valid.
263 * @param __PIN__ AON GPIO pins.
264 * @retval SET (__PIN__ is valid) or RESET (__PIN__ is invalid)
265 */
266 #define IS_AON_GPIO_PIN(__PIN__) ((((__PIN__) & AON_GPIO_PIN_MASK) != 0x00U) &&\
267 (((__PIN__) & ~AON_GPIO_PIN_MASK) == 0x00U))
268
269 /**
270 * @brief Check if AON GPIO mode is valid.
271 * @param __MODE__ AON GPIO mode.
272 * @retval SET (__MODE__ is valid) or RESET (__MODE__ is invalid)
273 */
274 #define IS_AON_GPIO_MODE(__MODE__) (((__MODE__) == AON_GPIO_MODE_INPUT) ||\
275 ((__MODE__) == AON_GPIO_MODE_OUTPUT) ||\
276 ((__MODE__) == AON_GPIO_MODE_MUX) ||\
277 ((__MODE__) == AON_GPIO_MODE_IT_RISING) ||\
278 ((__MODE__) == AON_GPIO_MODE_IT_FALLING) ||\
279 ((__MODE__) == AON_GPIO_MODE_IT_HIGH) ||\
280 ((__MODE__) == AON_GPIO_MODE_IT_LOW))
281
282 /**
283 * @brief Check if AON GPIO pull type is valid.
284 * @param __PULL__ AON GPIO pull type.
285 * @retval SET (__PULL__ is valid) or RESET (__PULL__ is invalid)
286 */
287 #define IS_AON_GPIO_PULL(__PULL__) (((__PULL__) == AON_GPIO_NOPULL) ||\
288 ((__PULL__) == AON_GPIO_PULLUP) || \
289 ((__PULL__) == AON_GPIO_PULLDOWN))
290
291 /** @} */
292
293 /** @} */
294
295 /* Exported functions --------------------------------------------------------*/
296 /** @addtogroup HAL_AON_GPIO_DRIVER_FUNCTIONS Functions
297 * @{
298 */
299
300 /** @addtogroup AON_GPIO_Exported_Functions_Group1 Initialization and de-initialization functions
301 * @brief Initialization and Configuration functions
302 * @{
303 */
304
305 /**
306 ****************************************************************************************
307 * @brief Initialize the AON_GPIOx peripheral according to the specified parameters in the @ref aon_gpio_init_t.
308 *
309 * @param[in] p_aon_gpio_init: Pointer to an @ref aon_gpio_init_t structure that contains
310 * the configuration information for the specified AON_GPIO peripheral port.
311 ****************************************************************************************
312 */
313 void hal_aon_gpio_init(aon_gpio_init_t *p_aon_gpio_init);
314
315 /**
316 ****************************************************************************************
317 * @brief De-initialize the AON_GPIOx peripheral registers to their default reset values.
318 *
319 * @param[in] aon_gpio_pin: Specifies the port bit to be written.
320 * This parameter can be a combination of the following values:
321 * @arg @ref AON_GPIO_PIN_0
322 * @arg @ref AON_GPIO_PIN_1
323 * @arg @ref AON_GPIO_PIN_2
324 * @arg @ref AON_GPIO_PIN_3
325 * @arg @ref AON_GPIO_PIN_4
326 * @arg @ref AON_GPIO_PIN_5
327 * @arg @ref AON_GPIO_PIN_ALL
328 ****************************************************************************************
329 */
330 void hal_aon_gpio_deinit(uint32_t aon_gpio_pin);
331
332 /** @} */
333
334 /** @addtogroup AON_GPIO_Exported_Functions_Group2 IO operation functions
335 * @brief AON_GPIO Read, Write, Toggle, Lock and EXTI management functions.
336 * @{
337 */
338
339 /**
340 ****************************************************************************************
341 * @brief Read the specified input port pin.
342 *
343 * @param[in] aon_gpio_pin: Specifies the port bit to be read.
344 * This parameter can be one of the following values:
345 * @arg @ref AON_GPIO_PIN_0
346 * @arg @ref AON_GPIO_PIN_1
347 * @arg @ref AON_GPIO_PIN_2
348 * @arg @ref AON_GPIO_PIN_3
349 * @arg @ref AON_GPIO_PIN_4
350 * @arg @ref AON_GPIO_PIN_5
351 *
352 * @return The input port pin value.
353 ****************************************************************************************
354 */
355 aon_gpio_pin_state_t hal_aon_gpio_read_pin(uint16_t aon_gpio_pin);
356
357 /**
358 ****************************************************************************************
359 * @brief Set or clear the selected data port bit.
360 *
361 * @param[in] aon_gpio_pin: Specifies the port bit to be written.
362 * This parameter can be a combination of the following values:
363 * @arg @ref AON_GPIO_PIN_0
364 * @arg @ref AON_GPIO_PIN_1
365 * @arg @ref AON_GPIO_PIN_2
366 * @arg @ref AON_GPIO_PIN_3
367 * @arg @ref AON_GPIO_PIN_4
368 * @arg @ref AON_GPIO_PIN_5
369 * @arg @ref AON_GPIO_PIN_ALL
370 * @param[in] pin_state: Specifies the value to be written to the selected bit.
371 * This parameter can be one of the AON_GPIO_PinState enum values:
372 * @arg AON_GPIO_PIN_RESET: to clear the port pin
373 * @arg AON_GPIO_PIN_SET: to set the port pin
374 ****************************************************************************************
375 */
376 void hal_aon_gpio_write_pin(uint16_t aon_gpio_pin, aon_gpio_pin_state_t pin_state);
377
378 /**
379 ****************************************************************************************
380 * @brief Toggle the specified AON_GPIO pin.
381 *
382 * @param[in] aon_gpio_pin: Specifies the pin to be toggled.
383 * This parameter can be a combination of the following values:
384 * @arg @ref AON_GPIO_PIN_0
385 * @arg @ref AON_GPIO_PIN_1
386 * @arg @ref AON_GPIO_PIN_2
387 * @arg @ref AON_GPIO_PIN_3
388 * @arg @ref AON_GPIO_PIN_4
389 * @arg @ref AON_GPIO_PIN_5
390 * @arg @ref AON_GPIO_PIN_ALL
391 ****************************************************************************************
392 */
393 void hal_aon_gpio_toggle_pin(uint16_t aon_gpio_pin);
394
395 /** @} */
396
397 /** @addtogroup AON_GPIO_IRQ_Handler_and_Callbacks IRQ Handler and Callbacks
398 * @brief IRQ Handler and Callbacks functions
399 * @{
400 */
401
402 /**
403 ****************************************************************************************
404 * @brief Handle AON_GPIO interrupt request.
405 ****************************************************************************************
406 */
407 void hal_aon_gpio_irq_handler(void);
408
409 /**
410 ****************************************************************************************
411 * @brief AON GPIO pin detection callback.
412 *
413 * @note This function should not be modified. When the callback is needed,
414 * the hal_aon_gpio_callback can be implemented in the user file.
415 *
416 * @param[in] aon_gpio_pin: Indicate the port pin whose interrupt was triggered.
417 * This parameter can be a combination of the following values:
418 * @arg @ref AON_GPIO_PIN_0
419 * @arg @ref AON_GPIO_PIN_1
420 * @arg @ref AON_GPIO_PIN_2
421 * @arg @ref AON_GPIO_PIN_3
422 * @arg @ref AON_GPIO_PIN_4
423 * @arg @ref AON_GPIO_PIN_5
424 * @arg @ref AON_GPIO_PIN_ALL
425 ****************************************************************************************
426 */
427 void hal_aon_gpio_callback(uint16_t aon_gpio_pin);
428
429 /** @} */
430
431 /** @} */
432
433
434 #ifdef __cplusplus
435 }
436 #endif
437
438 #endif /* __GR533x_HAL_AON_GPIO_H__ */
439
440 /** @} */
441
442 /** @} */
443
444 /** @} */
aon_gpio_init_t
struct _aon_gpio_init aon_gpio_init_t
AON_GPIO init structure definition.
hal_aon_gpio_toggle_pin
void hal_aon_gpio_toggle_pin(uint16_t aon_gpio_pin)
Toggle the specified AON_GPIO pin.
_aon_gpio_init::strength
uint32_t strength
Definition: gr533x_hal_aon_gpio.h:103
hal_aon_gpio_deinit
void hal_aon_gpio_deinit(uint32_t aon_gpio_pin)
De-initialize the AON_GPIOx peripheral registers to their default reset values.
_aon_gpio_init::speed
uint32_t speed
Definition: gr533x_hal_aon_gpio.h:100
aon_gpio_pin_state_t
aon_gpio_pin_state_t
AON_GPIO Bit SET and Bit RESET enumerations.
Definition: gr533x_hal_aon_gpio.h:72
AON_GPIO_PIN_RESET
@ AON_GPIO_PIN_RESET
Definition: gr533x_hal_aon_gpio.h:73
_aon_gpio_init::input_type
uint32_t input_type
Definition: gr533x_hal_aon_gpio.h:106
hal_aon_gpio_write_pin
void hal_aon_gpio_write_pin(uint16_t aon_gpio_pin, aon_gpio_pin_state_t pin_state)
Set or clear the selected data port bit.
_hal_aon_gpio_callback::aon_gpio_callback
void(* aon_gpio_callback)(uint16_t aon_gpio_pin)
Definition: gr533x_hal_aon_gpio.h:125
_aon_gpio_init::pin
uint32_t pin
Definition: gr533x_hal_aon_gpio.h:88
gr533x_ll_aon_gpio.h
Header file containing functions prototypes of AON GPIO LL library.
_hal_aon_gpio_callback
HAL AON_GPIO Callback function definition.
Definition: gr533x_hal_aon_gpio.h:124
hal_aon_gpio_callback_t
struct _hal_aon_gpio_callback hal_aon_gpio_callback_t
HAL AON_GPIO Callback function definition.
hal_aon_gpio_callback
void hal_aon_gpio_callback(uint16_t aon_gpio_pin)
AON GPIO pin detection callback.
AON_GPIO_PIN_SET
@ AON_GPIO_PIN_SET
Definition: gr533x_hal_aon_gpio.h:74
_aon_gpio_init::mux
uint32_t mux
Definition: gr533x_hal_aon_gpio.h:97
_aon_gpio_init::pull
uint32_t pull
Definition: gr533x_hal_aon_gpio.h:94
_aon_gpio_init::mode
uint32_t mode
Definition: gr533x_hal_aon_gpio.h:91
hal_aon_gpio_init
void hal_aon_gpio_init(aon_gpio_init_t *p_aon_gpio_init)
Initialize the AON_GPIOx peripheral according to the specified parameters in the aon_gpio_init_t.
_aon_gpio_init
AON_GPIO init structure definition.
Definition: gr533x_hal_aon_gpio.h:87
gr533x_hal_def.h
This file contains HAL common definitions, enumeration, macros and structures definitions.
hal_aon_gpio_irq_handler
void hal_aon_gpio_irq_handler(void)
Handle AON_GPIO interrupt request.
hal_aon_gpio_read_pin
aon_gpio_pin_state_t hal_aon_gpio_read_pin(uint16_t aon_gpio_pin)
Read the specified input port pin.