gr55xx_hal_msio.h
Go to the documentation of this file.
1 /**
2  ****************************************************************************************
3  *
4  * @file gr55xx_hal_msio.h
5  * @author BLE Driver Team
6  * @brief Header file containing functions prototypes of MSIO 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_MSIO MSIO
47  * @brief MSIO HAL module driver.
48  * @{
49  */
50 
51 /* Define to prevent recursive inclusion -------------------------------------*/
52 #ifndef __GR55xx_HAL_MSIO_H__
53 #define __GR55xx_HAL_MSIO_H__
54 
55 #ifdef __cplusplus
56 extern "C" {
57 #endif
58 
59 /* Includes ------------------------------------------------------------------*/
60 #include "gr55xx_ll_msio.h"
61 #include "gr55xx_hal_def.h"
62 
63 /* Exported types ------------------------------------------------------------*/
64 
65 /** @addtogroup HAL_MSIO_CALLBACK_STRUCTURES Callback Structures
66  * @{
67  */
68 
69 /**
70  * @brief HAL_MSIO Callback function definition
71  */
72 typedef struct _msio_callback
73 {
74  void (*msio_callback)(msio_pad_t MSIOx, uint16_t msio_pin); /**< MSIO pin detection callback */
76 
77 /** @} */
78 
79 /** @addtogroup HAL_MSIO_ENUMERATIONS Enumerations
80  * @{
81  */
82 
83 /**
84  * @brief MSIO Bit SET and Bit RESET enumerations
85  */
86 typedef enum
87 {
88  MSIO_PIN_RESET = 0U, /**< MSIO pin low level. */
89  MSIO_PIN_SET /**< MSIO pin high level.*/
91 
92 /** @} */
93 
94 /** @addtogroup HAL_MSIO_STRUCTURES Structures
95  * @{
96  */
97 
98 /**
99  * @brief MSIO init structure definition
100  */
101 typedef struct _msio_init
102 {
103  uint32_t pin; /**< Specifies the MSIO pins to be configured.
104  This parameter can be any value of @ref MSIO_pins */
105 
106  uint32_t direction; /**< Specifies the direction for the selected pins.
107  This parameter can be a value of @ref MSIO_direction */
108 
109  uint32_t mode; /**< Specifies the operating mode for the selected pins.
110  This parameter can be a value of @ref MSIO_mode */
111 
112  uint32_t pull; /**< Specifies the Pull-up or Pull-Down activation for the selected pins.
113  This parameter can be a value of @ref MSIO_pull */
114 
115  uint32_t mux; /**< Specifies the Peripheral to be connected to the selected pins.
116  This parameter can be a value of @ref MSIOEx_Mux_Function_Selection. */
118 
119 /** @} */
120 
121 /**
122  * @defgroup HAL_MSIO_MACRO Defines
123  * @{
124  */
125 
126 /* Exported constants --------------------------------------------------------*/
127 /** @defgroup MSIO_Exported_Constants MSIO Exported Constants
128  * @{
129  */
130 
131 /** @defgroup MSIO_pins MSIO pins
132  * @{
133  */
134 #define MSIO_PIN_0 ((uint16_t)0x0001U) /**< Pin 0 selected */
135 #define MSIO_PIN_1 ((uint16_t)0x0002U) /**< Pin 1 selected */
136 #define MSIO_PIN_2 ((uint16_t)0x0004U) /**< Pin 2 selected */
137 #define MSIO_PIN_3 ((uint16_t)0x0008U) /**< Pin 3 selected */
138 #define MSIO_PIN_4 ((uint16_t)0x0010U) /**< Pin 4 selected */
139 #define MSIO_PIN_5 ((uint16_t)0x0020U) /**< Pin 5 selected */
140 #define MSIO_PIN_6 ((uint16_t)0x0040U) /**< Pin 6 selected */
141 #define MSIO_PIN_7 ((uint16_t)0x0080U) /**< Pin 7 selected */
142 #define MSIO_PIN_ALL ((uint16_t)0x00FFU) /**< All pins selected */
143 #define MSIO_PIN_MASK (0x000000FFU) /**< PIN mask for assert test */
144 
145 /** @} */
146 
147 /** @defgroup MSIO_direction MSIO direction
148  * @{
149  */
150 #define MSIO_DIRECTION_NONE LL_MSIO_DIRECTION_NONE /**< Disable input & output */
151 #define MSIO_DIRECTION_INPUT LL_MSIO_DIRECTION_INPUT /**< Only Input */
152 #define MSIO_DIRECTION_OUTPUT LL_MSIO_DIRECTION_OUTPUT /**< Only Output */
153 #define MSIO_DIRECTION_INOUT LL_MSIO_DIRECTION_INOUT /**< Input & Output */
154 /** @} */
155 
156 /** @defgroup MSIO_mode MSIO mode
157  * @brief MSIO Analog or Digital mode
158  * Elements values convention: 0x000000YX
159  * - X : IO Direction mode (Input, Output, Mux)
160  * - Y : IT trigger detection
161  * @{
162  */
163 #define MSIO_MODE_ANALOG LL_MSIO_MODE_ANALOG /**< Analog IO */
164 #define MSIO_MODE_DIGITAL LL_MSIO_MODE_DIGITAL /**< Digital IO */
165 #define MSIO_MODE_IT_RISING (LL_MSIO_TRIGGER_IT_RISING << 4) /**< Interrupt Mode with Rising edge trigger detection */
166 #define MSIO_MODE_IT_FALLING (LL_MSIO_TRIGGER_IT_FALLING << 4) /**< Interrupt Mode with Falling edge trigger detection */
167 #define MSIO_MODE_IT_HIGH (LL_MSIO_TRIGGER_IT_HIGH << 4) /**< Interrupt Mode with High-level trigger detection */
168 #define MSIO_MODE_IT_LOW (LL_MSIO_TRIGGER_IT_LOW << 4) /**< Interrupt Mode with Low-level trigger detection */
169 #define MSIO_MODE_IT_BOTH_EDGE (LL_MSIO_TRIGGER_IT_BOTH_EDGE << 4) /**< Interrupt Mode with Rising and Falling edge trigger detection */
170 /** @} */
171 
172 /** @defgroup MSIO_pull MSIO pull
173  * @brief MSIO Pull-Up or Pull-Down Activation
174  * @{
175  */
176 #define MSIO_NOPULL LL_MSIO_PULL_NO /**< No Pull-up or Pull-down activation */
177 #define MSIO_PULLUP LL_MSIO_PULL_UP /**< Pull-up activation */
178 #define MSIO_PULLDOWN LL_MSIO_PULL_DOWN /**< Pull-down activation */
179 /** @} */
180 
181 /**
182  * @brief MSIO_default_config initStruct default configuartion
183  */
184 #define MSIO_DEFAULT_CONFIG \
185 { \
186  .pin = MSIO_PIN_ALL, \
187  .direction = MSIO_DIRECTION_INPUT, \
188  .mode = MSIO_MODE_DIGITAL, \
189  .pull = MSIO_PULLDOWN, \
190  .mux = MSIO_MUX_7, \
191 }
192 
193 /** @} */
194 
195 /* Exported macro ------------------------------------------------------------*/
196 /** @defgroup MSIO_Exported_Macros MSIO Exported Macros
197  * @{
198  */
199 
200 /**
201  * @brief Check whether the specified MSIO pin is asserted or not.
202  * @param __MSIOX__ MSIOX: Must select the MSIOA port
203  * @param __MSIO_PIN__ Specifies the MSIO pin to check.
204  * This parameter can be MSIO_PIN_x where x can be (0..7)
205  * @retval The new state of __MSIO_PIN__ (SET or RESET).
206  */
207 #define __HAL_MSIO_IT_GET_IT(__MSIOX__, __MSIO_PIN__) ll_msio_read_flag_it(__MSIOX__, __MSIO_PIN__)
208 
209 /**
210  * @brief Clear the MSIO pin pending bits.
211  * @param __MSIOX__ MSIOX: Must select the MSIOA port
212  * @param __MSIO_PIN__ Specifies the MSIO pins to clear.
213  * This parameter can be any combination of MSIO_PIN_x where x can be (0..7)
214  * @retval None
215  */
216 #define __HAL_MSIO_IT_CLEAR_IT(__MSIOX__, __MSIO_PIN__) ll_msio_clear_flag_it(__MSIOX__, __MSIO_PIN__)
217 
218 
219 /** @} */
220 
221 /* Private macros ------------------------------------------------------------*/
222 /** @addtogroup MSIO_Private_Macros MSIO Private Macros
223  * @{
224  */
225 
226 /**
227  * @brief Check if MSIO pin action is valid.
228  * @param __ACTION__ MSIO pin action.
229  * @retval SET (__ACTION__ is valid) or RESET (__ACTION__ is invalid)
230  */
231 #define IS_MSIO_PIN_ACTION(__ACTION__) (((__ACTION__) == MSIO_PIN_RESET) || ((__ACTION__) == MSIO_PIN_SET))
232 
233 /**
234  * @brief Check if MSIO pins are valid.
235  * @param __PIN__ MSIO pins.
236  * @retval SET (__PIN__ is valid) or RESET (__PIN__ is invalid)
237  */
238 #define IS_MSIO_PIN(__PIN__) ((((__PIN__) & MSIO_PIN_MASK) != 0x00U) && \
239  (((__PIN__) & ~MSIO_PIN_MASK) == 0x00U))
240 
241 /**
242  * @brief Check if MSIO direction is valid.
243  * @param __DIR__ MSIO direction.
244  * @retval SET (__DIR__ is valid) or RESET (__DIR__ is invalid)
245  */
246 #define IS_MSIO_DIRECTION(__DIR__) (((__DIR__) == MSIO_DIRECTION_NONE) || \
247  ((__DIR__) == MSIO_DIRECTION_INPUT) || \
248  ((__DIR__) == MSIO_DIRECTION_OUTPUT) || \
249  ((__DIR__) == MSIO_DIRECTION_INOUT))
250 
251 /**
252  * @brief Check if MSIO mode is valid.
253  * @param __MODE__ MSIO mode.
254  * @retval SET (__MODE__ is valid) or RESET (__MODE__ is invalid)
255  */
256 #define IS_MSIO_MODE(__MODE__) (((__MODE__) == MSIO_MODE_ANALOG) || \
257  ((__MODE__) == MSIO_MODE_DIGITAL))
258 
259 /**
260  * @brief Check if MSIO pull type is valid.
261  * @param __PULL__ MSIO pull type.
262  * @retval SET (__PULL__ is valid) or RESET (__PULL__ is invalid)
263  */
264 #define IS_MSIO_PULL(__PULL__) (((__PULL__) == MSIO_NOPULL) || \
265  ((__PULL__) == MSIO_PULLUP) || \
266  ((__PULL__) == MSIO_PULLDOWN))
267 
268 /** @} */
269 
270 /** @} */
271 
272 /* Include MSIO HAL Extended module */
273 #include "gr55xx_hal_msio_ex.h"
274 
275 /* Exported functions --------------------------------------------------------*/
276 /** @addtogroup HAL_MSIO_DRIVER_FUNCTIONS Functions
277  * @{
278  */
279 
280 /** @addtogroup MSIO_Exported_Functions_Group1 Initialization and de-initialization functions
281  * @brief Initialization and Configuration functions
282  * @{
283  */
284 
285 /**
286  ****************************************************************************************
287  * @brief Initialize the MSIOx peripheral according to the specified parameters in the @ref msio_init_t.
288  * @param[in] MSIOx: MSIO peripheral port.
289  * @param[in] p_msio_init: Pointer to an @ref msio_init_t structure that contains
290  * the configuration information for the specified MSIO peripheral port.
291  ****************************************************************************************
292  */
293 void hal_msio_init(msio_pad_t MSIOx, msio_init_t *p_msio_init);
294 
295 /**
296  ****************************************************************************************
297  * @brief De-initialize the MSIOx peripheral registers to their default reset values.
298  * @param[in] MSIOx: MSIO peripheral port.
299  * @param[in] msio_pin: Specifies the port bit to be written.
300  * This parameter can be a combination of the following values:
301  * @arg @ref MSIO_PIN_0
302  * @arg @ref MSIO_PIN_1
303  * @arg @ref MSIO_PIN_2
304  * @arg @ref MSIO_PIN_3
305  * @arg @ref MSIO_PIN_4
306  * @arg @ref MSIO_PIN_5
307  * @arg @ref MSIO_PIN_6
308  * @arg @ref MSIO_PIN_7
309  * @arg @ref MSIO_PIN_ALL
310  ****************************************************************************************
311  */
312 void hal_msio_deinit(msio_pad_t MSIOx, uint32_t msio_pin);
313 
314 /** @} */
315 
316 /** @addtogroup MSIO_Exported_Functions_Group2 IO operation functions
317  * @brief MSIO Read, Write, and Toggle management functions.
318  * @{
319  */
320 
321 /**
322  ****************************************************************************************
323  * @brief Read the specified input port pin.
324  * @param[in] MSIOx: MSIO peripheral port.
325  * @param[in] msio_pin: Specifies the port bit to be read.
326  * This parameter can be one of the following values:
327  * @arg @ref MSIO_PIN_0
328  * @arg @ref MSIO_PIN_1
329  * @arg @ref MSIO_PIN_2
330  * @arg @ref MSIO_PIN_3
331  * @arg @ref MSIO_PIN_4
332  * @arg @ref MSIO_PIN_5
333  * @arg @ref MSIO_PIN_6
334  * @arg @ref MSIO_PIN_7
335  * @retval ::MSIO_PIN_RESET: MSIO pin low level.
336  * @retval ::MSIO_PIN_SET: MSIO pin high level.
337  ****************************************************************************************
338  */
340 
341 /**
342  ****************************************************************************************
343  * @brief Set or clear the selected data port bit.
344  * @param[in] MSIOx: MSIO peripheral port.
345  * @param[in] msio_pin: Specifies the port bit to be written.
346  * This parameter can be a combination of the following values:
347  * @arg @ref MSIO_PIN_0
348  * @arg @ref MSIO_PIN_1
349  * @arg @ref MSIO_PIN_2
350  * @arg @ref MSIO_PIN_3
351  * @arg @ref MSIO_PIN_4
352  * @arg @ref MSIO_PIN_5
353  * @arg @ref MSIO_PIN_6
354  * @arg @ref MSIO_PIN_7
355  * @arg @ref MSIO_PIN_ALL
356  * @param[in] pin_state: Specifies the value to be written to the selected bit.
357  * This parameter can be one of the MSIO_PinState enum values:
358  * @arg MSIO_PIN_RESET: to clear the port pin
359  * @arg MSIO_PIN_SET: to set the port pin
360  ****************************************************************************************
361  */
362 void hal_msio_write_pin(msio_pad_t MSIOx, uint16_t msio_pin, msio_pin_state_t pin_state);
363 
364 /**
365  ****************************************************************************************
366  * @brief Toggle the specified MSIO pin.
367  * @param[in] MSIOx: MSIO peripheral port.
368  * @param[in] msio_pin: Specifies the pin to be toggled.
369  * This parameter can be a combination of the following values:
370  * @arg @ref MSIO_PIN_0
371  * @arg @ref MSIO_PIN_1
372  * @arg @ref MSIO_PIN_2
373  * @arg @ref MSIO_PIN_3
374  * @arg @ref MSIO_PIN_4
375  * @arg @ref MSIO_PIN_5
376  * @arg @ref MSIO_PIN_6
377  * @arg @ref MSIO_PIN_7
378  * @arg @ref MSIO_PIN_ALL
379  ****************************************************************************************
380  */
381 void hal_msio_toggle_pin(msio_pad_t MSIOx, uint16_t msio_pin);
382 /** @} */
383 
384  /** @addtogroup MSIO_Exported_Functions_Group3 MSIO_A_IRQHandler and Callbacks
385  * @brief IRQ Handler and Callbacks functions
386  * @{
387  */
388 
389 /**
390  ****************************************************************************************
391  * @brief Handle MSIOA interrupt request.
392  *
393  * @param[in] MSIOx: Must select the MSIOA port.
394  ****************************************************************************************
395  */
397 
398 /**
399  ****************************************************************************************
400  * @brief MSIOA pin detection callback.
401  *
402  * @note This function should not be modified. When the callback is needed,
403  * the hal_msio_exti_callback can be implemented in the user file.
404  *
405  * @param[in] MSIOx: Must select the MSIOA port.
406  * @param[in] msio_pin: Indicate the port pin whose interrupt was triggered.
407  * This parameter can be a combination of the following values:
408  * @arg @ref MSIO_PIN_0
409  * @arg @ref MSIO_PIN_1
410  * @arg @ref MSIO_PIN_2
411  * @arg @ref MSIO_PIN_3
412  * @arg @ref MSIO_PIN_4
413  * @arg @ref MSIO_PIN_5
414  * @arg @ref MSIO_PIN_6
415  * @arg @ref MSIO_PIN_7
416  * @arg @ref MSIO_PIN_ALL
417  ****************************************************************************************
418  */
419 void hal_msio_exti_callback(msio_pad_t MSIOx, uint16_t msio_pin);
420 
421 
422 /** @} */
423 
424 /** @} */
425 
426 
427 #ifdef __cplusplus
428 }
429 #endif
430 
431 #endif /* __GR55xx_HAL_MSIO_H__ */
432 
433 /** @} */
434 
435 /** @} */
436 
437 /** @} */
_msio_init::direction
uint32_t direction
Definition: gr55xx_hal_msio.h:106
MSIO_PIN_RESET
@ MSIO_PIN_RESET
Definition: gr55xx_hal_msio.h:88
_msio_init
MSIO init structure definition.
Definition: gr55xx_hal_msio.h:102
gr55xx_ll_msio.h
Header file containing functions prototypes of MSIO LL library.
hal_msio_write_pin
void hal_msio_write_pin(msio_pad_t MSIOx, uint16_t msio_pin, msio_pin_state_t pin_state)
Set or clear the selected data port bit.
_msio_callback::msio_callback
void(* msio_callback)(msio_pad_t MSIOx, uint16_t msio_pin)
Definition: gr55xx_hal_msio.h:74
msio_callback_t
struct _msio_callback msio_callback_t
HAL_MSIO Callback function definition.
msio_init_t
struct _msio_init msio_init_t
MSIO init structure definition.
_msio_init::mode
uint32_t mode
Definition: gr55xx_hal_msio.h:109
hal_msio_exti_callback
void hal_msio_exti_callback(msio_pad_t MSIOx, uint16_t msio_pin)
MSIOA pin detection callback.
hal_msio_init
void hal_msio_init(msio_pad_t MSIOx, msio_init_t *p_msio_init)
Initialize the MSIOx peripheral according to the specified parameters in the msio_init_t.
hal_msio_deinit
void hal_msio_deinit(msio_pad_t MSIOx, uint32_t msio_pin)
De-initialize the MSIOx peripheral registers to their default reset values.
msio_pad_t
msio_pad_t
MSIO pad Enumerations definition.
Definition: gr55xx_ll_msio.h:77
hal_msio_toggle_pin
void hal_msio_toggle_pin(msio_pad_t MSIOx, uint16_t msio_pin)
Toggle the specified MSIO pin.
_msio_init::mux
uint32_t mux
Definition: gr55xx_hal_msio.h:115
hal_msio_read_pin
msio_pin_state_t hal_msio_read_pin(msio_pad_t MSIOx, uint16_t msio_pin)
Read the specified input port pin.
_msio_callback
HAL_MSIO Callback function definition.
Definition: gr55xx_hal_msio.h:73
msio_pin_state_t
msio_pin_state_t
MSIO Bit SET and Bit RESET enumerations.
Definition: gr55xx_hal_msio.h:87
MSIO_PIN_SET
@ MSIO_PIN_SET
Definition: gr55xx_hal_msio.h:89
_msio_init::pull
uint32_t pull
Definition: gr55xx_hal_msio.h:112
hal_msio_exti_irq_handler
void hal_msio_exti_irq_handler(msio_pad_t MSIOx)
Handle MSIOA interrupt request.
_msio_init::pin
uint32_t pin
Definition: gr55xx_hal_msio.h:103
gr55xx_hal_def.h
This file contains HAL common definitions, enumeration, macros and structures definitions.
gr55xx_hal_msio_ex.h
Header file containing extended macro of MSIO HAL library.