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 /** @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 @ref 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_ALL ((uint16_t)0x00FFU) /**< All pins selected */
158 #define MSIO_PIN_MASK (0x000000FFU) /**< PIN mask for assert test */
159
160 /** @} */
161
162 /** @defgroup MSIO_direction MSIO direction
163 * @{
164 */
165 #define MSIO_DIRECTION_NONE LL_MSIO_DIRECTION_NONE /**< Disable input & output */
166 #define MSIO_DIRECTION_INPUT LL_MSIO_DIRECTION_INPUT /**< Only Input */
167 #define MSIO_DIRECTION_OUTPUT LL_MSIO_DIRECTION_OUTPUT /**< Only Output */
168 #define MSIO_DIRECTION_INOUT LL_MSIO_DIRECTION_INOUT /**< Input & Output */
169 /** @} */
170
171 /** @defgroup MSIO_mode MSIO mode
172 * @brief MSIO Analog or Digital mode
173 * Elements values convention: 0x000000YX
174 * - X : IO Direction mode (Input, Output, Mux)
175 * - Y : IT trigger detection
176 * @{
177 */
178 #define MSIO_MODE_ANALOG LL_MSIO_MODE_ANALOG /**< Analog IO */
179 #define MSIO_MODE_DIGITAL LL_MSIO_MODE_DIGITAL /**< Digital IO */
180 /** @} */
181
182 /** @defgroup MSIO_pull MSIO pull
183 * @brief MSIO Pull-Up or Pull-Down Activation
184 * @{
185 */
186 #define MSIO_NOPULL LL_MSIO_PULL_NO /**< No Pull-up or Pull-down activation */
187 #define MSIO_PULLUP LL_MSIO_PULL_UP /**< Pull-up activation */
188 #define MSIO_PULLDOWN LL_MSIO_PULL_DOWN /**< Pull-down activation */
189 /** @} */
190
191 /** @defgroup MSIO_speed MSIO IO speed
192 * @brief MSIO IO speed
193 * @{
194 */
195 #define MSIO_SPEED_MEDIUM LL_MSIO_SPEED_MEDIUM /*!< Select medium speed */
196 #define MSIO_SPEED_HIGH LL_MSIO_SPEED_HIGH /*!< Select high speed */
197 /** @} */
198
199 /** @defgroup MSIO_strength MSIO IO strength
200 * @brief MSIO IO strength
201 * @{
202 */
203 #define MSIO_STRENGTH_LOW LL_MSIO_STRENGTH_LOW /*!< Select low output driver strength */
204 #define MSIO_STRENGTH_MEDIUM LL_MSIO_STRENGTH_MEDIUM /*!< Select medium output driver strength */
205 #define MSIO_STRENGTH_HIGH LL_MSIO_STRENGTH_HIGH /*!< Select high output driver strength */
206 #define MSIO_STRENGTH_ULTRA LL_MSIO_STRENGTH_ULTRA /*!< Select high output driver strength */
207 /** @} */
208
209 /** @defgroup MSIO_input_type MSIO IO strength
210 * @brief MSIO IO strength
211 * @{
212 */
213 #define MSIO_INPUT_TYPE_CMOS LL_MSIO_INPUT_TYPE_CMOS /**< CMOS input */
214 #define MSIO_INPUT_TYPE_SCHMITT LL_MSIO_INPUT_TYPE_SCHMITT /**< Schmitt input */
215 /** @} */
216
217 /**
218 * @brief MSIO_default_config initStruct default configuartion
219 */
220 #define MSIO_DEFAULT_CONFIG \
221 { \
222 .pin = MSIO_PIN_ALL, \
223 .direction = MSIO_DIRECTION_INPUT, \
224 .mode = MSIO_MODE_DIGITAL, \
225 .pull = MSIO_PULLDOWN, \
226 .speed = MSIO_SPEED_MEDIUM, \
227 .strength = MSIO_STRENGTH_MEDIUM, \
228 .input_type = MSIO_INPUT_TYPE_CMOS, \
229 .mux = MSIO_MUX_8, \
230 }
231
232 /** @} */
233
234 /* Exported macro ------------------------------------------------------------*/
235 /** @defgroup MSIO_Exported_Macros MSIO Exported Macros
236 * @{
237 */
238
239 /**
240 * @brief Check whether the specified MSIO pin is asserted or not.
241 * @param __MSIOX__ MSIOX: Must select the MSIOB port
242 * @param __MSIO_PIN__ Specifies the MSIO pin to check.
243 * This parameter can be MSIO_PIN_x where x can be (0..7)
244 * @retval The new state of __MSIO_PIN__ (SET or RESET).
245 */
246 #define __HAL_MSIO_IT_GET_IT(__MSIOX__, __MSIO_PIN__) ll_msio_read_flag_it(__MSIOX__, __MSIO_PIN__)
247
248 /**
249 * @brief Clear the MSIO pin pending bits.
250 * @param __MSIOX__ MSIOX: Must select the MSIOB port
251 * @param __MSIO_PIN__ Specifies the MSIO pins to clear.
252 * This parameter can be any combination of MSIO_PIN_x where x can be (0..7)
253 * @retval None
254 */
255 #define __HAL_MSIO_IT_CLEAR_IT(__MSIOX__, __MSIO_PIN__) ll_msio_clear_flag_it(__MSIOX__, __MSIO_PIN__)
256
257
258 /** @} */
259
260 /* Private macros ------------------------------------------------------------*/
261 /** @addtogroup MSIO_Private_Macros MSIO Private Macros
262 * @{
263 */
264
265 /**
266 * @brief Check if MSIO pin action is valid.
267 * @param __ACTION__ MSIO pin action.
268 * @retval SET (__ACTION__ is valid) or RESET (__ACTION__ is invalid)
269 */
270 #define IS_MSIO_PIN_ACTION(__ACTION__) (((__ACTION__) == MSIO_PIN_RESET) || ((__ACTION__) == MSIO_PIN_SET))
271
272 /**
273 * @brief Check if MSIO pins are valid.
274 * @param __PIN__ MSIO pins.
275 * @retval SET (__PIN__ is valid) or RESET (__PIN__ is invalid)
276 */
277 #define IS_MSIO_PIN(__PIN__) ((((__PIN__) & MSIO_PIN_MASK) != 0x00U) && \
278 (((__PIN__) & ~MSIO_PIN_MASK) == 0x00U))
279
280 /**
281 * @brief Check if MSIO direction is valid.
282 * @param __DIR__ MSIO direction.
283 * @retval SET (__DIR__ is valid) or RESET (__DIR__ is invalid)
284 */
285 #define IS_MSIO_DIRECTION(__DIR__) (((__DIR__) == MSIO_DIRECTION_NONE) || \
286 ((__DIR__) == MSIO_DIRECTION_INPUT) || \
287 ((__DIR__) == MSIO_DIRECTION_OUTPUT) || \
288 ((__DIR__) == MSIO_DIRECTION_INOUT))
289
290 /**
291 * @brief Check if MSIO mode is valid.
292 * @param __MODE__ MSIO mode.
293 * @retval SET (__MODE__ is valid) or RESET (__MODE__ is invalid)
294 */
295 #define IS_MSIO_MODE(__MODE__) (((__MODE__) == MSIO_MODE_ANALOG) || \
296 ((__MODE__) == MSIO_MODE_DIGITAL))
297
298 /**
299 * @brief Check if MSIO pull type is valid.
300 * @param __PULL__ MSIO pull type.
301 * @retval SET (__PULL__ is valid) or RESET (__PULL__ is invalid)
302 */
303 #define IS_MSIO_PULL(__PULL__) (((__PULL__) == MSIO_NOPULL) || \
304 ((__PULL__) == MSIO_PULLUP) || \
305 ((__PULL__) == MSIO_PULLDOWN))
306
307 /** @} */
308
309 /** @} */
310
311 /* Include MSIO HAL Extended module */
312 #include "gr55xx_hal_msio_ex.h"
313
314 /* Exported functions --------------------------------------------------------*/
315 /** @addtogroup HAL_MSIO_DRIVER_FUNCTIONS Functions
316 * @{
317 */
318
319 /** @addtogroup MSIO_Exported_Functions_Group1 Initialization and de-initialization functions
320 * @brief Initialization and Configuration functions
321 * @{
322 */
323
324 /**
325 ****************************************************************************************
326 * @brief Initialize the MSIOx peripheral according to the specified parameters in the @ref msio_init_t.
327 * @param[in] MSIOx: MSIO peripheral port.
328 * @param[in] p_msio_init: Pointer to an @ref msio_init_t structure that contains
329 * the configuration information for the specified MSIO peripheral port.
330 ****************************************************************************************
331 */
332 void hal_msio_init(msio_pad_t MSIOx, msio_init_t *p_msio_init);
333
334 /**
335 ****************************************************************************************
336 * @brief De-initialize the MSIOx peripheral registers to their default reset values.
337 * @param[in] MSIOx: MSIO peripheral port.
338 * @param[in] msio_pin: Specifies the port bit to be written.
339 * This parameter can be a combination of the following values:
340 * @arg @ref MSIO_PIN_0
341 * @arg @ref MSIO_PIN_1
342 * @arg @ref MSIO_PIN_2
343 * @arg @ref MSIO_PIN_3
344 * @arg @ref MSIO_PIN_4
345 * @arg @ref MSIO_PIN_ALL
346 ****************************************************************************************
347 */
348 void hal_msio_deinit(msio_pad_t MSIOx, uint32_t msio_pin);
349
350 /** @} */
351
352 /** @addtogroup MSIO_Exported_Functions_Group2 IO operation functions
353 * @brief MSIO Read, Write, and Toggle management functions.
354 * @{
355 */
356
357 /**
358 ****************************************************************************************
359 * @brief Read the specified input port pin.
360 * @param[in] MSIOx: MSIO peripheral port.
361 * @param[in] msio_pin: Specifies the port bit to be read.
362 * This parameter can be one of the following values:
363 * @arg @ref MSIO_PIN_0
364 * @arg @ref MSIO_PIN_1
365 * @arg @ref MSIO_PIN_2
366 * @arg @ref MSIO_PIN_3
367 * @arg @ref MSIO_PIN_4
368 * @arg @ref MSIO_PIN_5
369 * @arg @ref MSIO_PIN_6
370 * @arg @ref MSIO_PIN_7
371 * @retval ::MSIO_PIN_RESET: MSIO pin low level.
372 * @retval ::MSIO_PIN_SET: MSIO pin high level.
373 ****************************************************************************************
374 */
375 msio_pin_state_t hal_msio_read_pin(msio_pad_t MSIOx, uint16_t msio_pin);
376
377 /**
378 ****************************************************************************************
379 * @brief Set or clear the selected data port bit.
380 * @param[in] MSIOx: MSIO peripheral port.
381 * @param[in] msio_pin: Specifies the port bit to be written.
382 * This parameter can be a combination of the following values:
383 * @arg @ref MSIO_PIN_0
384 * @arg @ref MSIO_PIN_1
385 * @arg @ref MSIO_PIN_2
386 * @arg @ref MSIO_PIN_3
387 * @arg @ref MSIO_PIN_4
388 * @arg @ref MSIO_PIN_5
389 * @arg @ref MSIO_PIN_6
390 * @arg @ref MSIO_PIN_7
391 * @arg @ref MSIO_PIN_ALL
392 * @param[in] pin_state: Specifies the value to be written to the selected bit.
393 * This parameter can be one of the MSIO_PinState enum values:
394 * @arg MSIO_PIN_RESET: to clear the port pin
395 * @arg MSIO_PIN_SET: to set the port pin
396 ****************************************************************************************
397 */
398 void hal_msio_write_pin(msio_pad_t MSIOx, uint16_t msio_pin, msio_pin_state_t pin_state);
399
400 /**
401 ****************************************************************************************
402 * @brief Toggle the specified MSIO pin.
403 * @param[in] MSIOx: MSIO peripheral port.
404 * @param[in] msio_pin: Specifies the pin to be toggled.
405 * This parameter can be a combination of the following values:
406 * @arg @ref MSIO_PIN_0
407 * @arg @ref MSIO_PIN_1
408 * @arg @ref MSIO_PIN_2
409 * @arg @ref MSIO_PIN_3
410 * @arg @ref MSIO_PIN_4
411 * @arg @ref MSIO_PIN_5
412 * @arg @ref MSIO_PIN_6
413 * @arg @ref MSIO_PIN_7
414 * @arg @ref MSIO_PIN_ALL
415 ****************************************************************************************
416 */
417 void hal_msio_toggle_pin(msio_pad_t MSIOx, uint16_t msio_pin);
418 /** @} */
419
420 /** @addtogroup MSIO_Exported_Functions_Group3 MSIO_B_IRQHandler and Callbacks
421 * @brief IRQ Handler and Callbacks functions
422 * @{
423 */
424
425 /**
426 ****************************************************************************************
427 * @brief Handle MSIOB interrupt request.
428 *
429 * @param[in] MSIOx: Must select the MSIOB port.
430 ****************************************************************************************
431 */
432 void hal_msio_exti_irq_handler(msio_pad_t MSIOx);
433
434 /**
435 ****************************************************************************************
436 * @brief MSIOB pin detection callback.
437 *
438 * @note This function should not be modified. When the callback is needed,
439 * the hal_msio_exti_callback can be implemented in the user file.
440 *
441 * @param[in] MSIOx: Must select the MSIOB port.
442 * @param[in] msio_pin: Indicate the port pin whose interrupt was triggered.
443 * This parameter can be a combination of the following values:
444 * @arg @ref MSIO_PIN_0
445 * @arg @ref MSIO_PIN_1
446 * @arg @ref MSIO_PIN_2
447 * @arg @ref MSIO_PIN_3
448 * @arg @ref MSIO_PIN_4
449 * @arg @ref MSIO_PIN_5
450 * @arg @ref MSIO_PIN_6
451 * @arg @ref MSIO_PIN_7
452 * @arg @ref MSIO_PIN_ALL
453 ****************************************************************************************
454 */
455 void hal_msio_exti_callback(msio_pad_t MSIOx, uint16_t msio_pin);
456
457
458 /** @} */
459
460 /** @} */
461
462
463 #ifdef __cplusplus
464 }
465 #endif
466
467 #endif /* __GR55xx_HAL_MSIO_H__ */
468
469 /** @} */
470
471 /** @} */
472
473 /** @} */
_msio_init::direction
uint32_t direction
Definition: gr55xx_hal_msio.h:112
_hal_msio_callback
HAL_MSIO Callback function definition.
Definition: gr55xx_hal_msio.h:77
MSIO_PIN_RESET
@ MSIO_PIN_RESET
Definition: gr55xx_hal_msio.h:94
_msio_init
MSIO init structure definition.
Definition: gr55xx_hal_msio.h:108
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_init::input_type
uint32_t input_type
Definition: gr55xx_hal_msio.h:130
msio_init_t
struct _msio_init msio_init_t
MSIO init structure definition.
_msio_init::mode
uint32_t mode
Definition: gr55xx_hal_msio.h:115
_msio_init::strength
uint32_t strength
Definition: gr55xx_hal_msio.h:127
hal_msio_exti_callback
void hal_msio_exti_callback(msio_pad_t MSIOx, uint16_t msio_pin)
MSIOB 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.
_msio_init::speed
uint32_t speed
Definition: gr55xx_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: gr55xx_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: gr55xx_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: gr55xx_hal_msio.h:95
_hal_msio_callback::msio_callback
void(* msio_callback)(msio_pad_t MSIOx, uint16_t msio_pin)
Definition: gr55xx_hal_msio.h:78
_msio_init::pull
uint32_t pull
Definition: gr55xx_hal_msio.h:118
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: gr55xx_hal_msio.h:109
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.