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