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