• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 /* Includes ------------------------------------------------------------------*/
56 #include "gr55xx_ll_msio.h"
57 #include "gr55xx_hal_def.h"
58 /* Include MSIO HAL Extended module */
59 #include "gr55xx_hal_msio_ex.h"
60 
61 #ifdef __cplusplus
62 extern "C" {
63 #endif
64 
65 /* Exported types ------------------------------------------------------------*/
66 /** @addtogroup HAL_MSIO_ENUMERATIONS Enumerations
67   * @{
68   */
69 
70 /**
71   * @brief  MSIO Bit SET and Bit RESET enumerations
72   */
73 typedef enum {
74     MSIO_PIN_RESET = 0U,          /**< MSIO pin low level. */
75     MSIO_PIN_SET                  /**< MSIO pin high level.*/
76 } msio_pin_state_t;
77 
78 /** @} */
79 
80 /** @addtogroup HAL_MSIO_STRUCTURES Structures
81   * @{
82   */
83 
84 /**
85   * @brief   MSIO init structure definition
86   */
87 typedef struct _msio_init {
88     uint32_t pin;       /**< Specifies the MSIO pins to be configured.
89                             This parameter can be any value of @ref MSIO_pins */
90 
91     uint32_t direction; /**< Specifies the direction for the selected pins.
92                              This parameter can be a value of @ref MSIO_direction */
93 
94     uint32_t mode;      /**< Specifies the operating mode for the selected pins.
95                              This parameter can be a value of @ref MSIO_mode */
96 
97     uint32_t pull;      /**< Specifies the Pull-up or Pull-Down activation for the selected pins.
98                              This parameter can be a value of @ref MSIO_pull */
99 
100     uint32_t mux;       /**< Specifies the Peripheral to be connected to the selected pins.
101                              This parameter can be a value of @ref GPIOEx_Mux_Function_Selection. */
102 } msio_init_t;
103 
104 /** @} */
105 
106 /**
107   * @defgroup  HAL_MSIO_MACRO Defines
108   * @{
109   */
110 
111 /* Exported constants --------------------------------------------------------*/
112 /** @defgroup MSIO_Exported_Constants MSIO Exported Constants
113   * @{
114   */
115 
116 /** @defgroup MSIO_pins MSIO pins
117   * @{
118   */
119 #define MSIO_PIN_0                  ((uint16_t)0x0001U)  /**< Pin 0 selected    */
120 #define MSIO_PIN_1                  ((uint16_t)0x0002U)  /**< Pin 1 selected    */
121 #define MSIO_PIN_2                  ((uint16_t)0x0004U)  /**< Pin 2 selected    */
122 #define MSIO_PIN_3                  ((uint16_t)0x0008U)  /**< Pin 3 selected    */
123 #define MSIO_PIN_4                  ((uint16_t)0x0010U)  /**< Pin 4 selected    */
124 
125 #define MSIO_PIN_ALL                ((uint16_t)0x001FU)  /**< All pins selected */
126 
127 #define MSIO_PIN_MASK               (0x0000001FU)        /**< PIN mask for assert test */
128 /** @} */
129 
130 /** @defgroup MSIO_direction MSIO direction
131   * @{
132   */
133 #define MSIO_DIRECTION_NONE         LL_MSIO_DIRECTION_NONE      /**< Disable input & output */
134 #define MSIO_DIRECTION_INPUT        LL_MSIO_DIRECTION_INPUT     /**< Only Input             */
135 #define MSIO_DIRECTION_OUTPUT       LL_MSIO_DIRECTION_OUTPUT    /**< Only Output            */
136 #define MSIO_DIRECTION_INOUT        LL_MSIO_DIRECTION_INOUT     /**< Input & Output         */
137 /** @} */
138 
139 /** @defgroup MSIO_mode MSIO mode
140    * @brief MSIO Analog or Digital mode
141   * @{
142   */
143 #define MSIO_MODE_ANALOG            LL_MSIO_MODE_ANALOG         /**< Analog  IO */
144 #define MSIO_MODE_DIGITAL           LL_MSIO_MODE_DIGITAL        /**< Digital IO */
145 /** @} */
146 
147 /** @defgroup MSIO_pull MSIO pull
148   * @brief MSIO Pull-Up or Pull-Down Activation
149   * @{
150   */
151 #define  MSIO_NOPULL                LL_MSIO_PULL_NO             /**< No Pull-up or Pull-down activation  */
152 #define  MSIO_PULLUP                LL_MSIO_PULL_UP             /**< Pull-up activation                  */
153 #define  MSIO_PULLDOWN              LL_MSIO_PULL_DOWN           /**< Pull-down activation                */
154 /** @} */
155 
156 /**
157   * @brief MSIO_default_config initStruct default configuartion
158   */
159 #define MSIO_DEFAULT_CONFIG                      \
160 {                                                \
161     .pin        = MSIO_PIN_ALL,                  \
162     .direction  = MSIO_DIRECTION_INPUT,          \
163     .mode       = MSIO_MODE_DIGITAL,             \
164     .pull       = MSIO_PULLDOWN,                 \
165     .mux        = GPIO_MUX_7,                    \
166 }
167 /** @} */
168 
169 /* Exported macro ------------------------------------------------------------*/
170 /** @defgroup MSIO_Exported_Macros MSIO Exported Macros
171   * @{
172   */
173 
174 /** @} */
175 
176 /* Private macros ------------------------------------------------------------*/
177 /** @addtogroup MSIO_Private_Macros MSIO Private Macros
178   * @{
179   */
180 
181 /**
182   * @brief Check if MSIO pin action is valid.
183   * @param __ACTION__ MSIO pin action.
184   * @retval SET (__ACTION__ is valid) or RESET (__ACTION__ is invalid)
185   */
186 #define IS_MSIO_PIN_ACTION(__ACTION__)  (((__ACTION__) == MSIO_PIN_RESET) || ((__ACTION__) == MSIO_PIN_SET))
187 
188 /**
189   * @brief Check if MSIO pins are valid.
190   * @param __PIN__ MSIO pins.
191   * @retval SET (__PIN__ is valid) or RESET (__PIN__ is invalid)
192   */
193 #define IS_MSIO_PIN(__PIN__)            ((((__PIN__) &  MSIO_PIN_MASK) != 0x00U) && \
194                                          (((__PIN__) & ~MSIO_PIN_MASK) == 0x00U))
195 
196 /**
197   * @brief Check if MSIO direction is valid.
198   * @param __DIR__ MSIO direction.
199   * @retval SET (__DIR__ is valid) or RESET (__DIR__ is invalid)
200   */
201 #define IS_MSIO_DIRECTION(__DIR__)      (((__DIR__) == MSIO_DIRECTION_NONE)   || \
202                                          ((__DIR__) == MSIO_DIRECTION_INPUT)  || \
203                                          ((__DIR__) == MSIO_DIRECTION_OUTPUT) || \
204                                          ((__DIR__) == MSIO_DIRECTION_INOUT))
205 
206 /**
207   * @brief Check if MSIO mode is valid.
208   * @param __MODE__ MSIO mode.
209   * @retval SET (__MODE__ is valid) or RESET (__MODE__ is invalid)
210   */
211 #define IS_MSIO_MODE(__MODE__)          (((__MODE__) == MSIO_MODE_ANALOG) || \
212                                          ((__MODE__) == MSIO_MODE_DIGITAL))
213 
214 /**
215   * @brief Check if MSIO pull type is valid.
216   * @param __PULL__ MSIO pull type.
217   * @retval SET (__PULL__ is valid) or RESET (__PULL__ is invalid)
218   */
219 #define IS_MSIO_PULL(__PULL__)          (((__PULL__) == MSIO_NOPULL)   || \
220                                          ((__PULL__) == MSIO_PULLUP)   || \
221                                          ((__PULL__) == MSIO_PULLDOWN))
222 
223 /** @} */
224 
225 /** @} */
226 
227 /* Exported functions --------------------------------------------------------*/
228 /** @addtogroup HAL_MSIO_DRIVER_FUNCTIONS Functions
229   * @{
230   */
231 
232 /** @addtogroup MSIO_Exported_Functions_Group1 Initialization and de-initialization functions
233   *  @brief    Initialization and Configuration functions
234   * @{
235   */
236 
237 /**
238  ****************************************************************************************
239  * @brief  Initialize the MSIOx peripheral according to the specified parameters in the @ref msio_init_t.
240  * @param[in]  p_msio_init: Pointer to an @ref msio_init_t structure that contains
241  *                         the configuration information for the specified MSIO peripheral port.
242  ****************************************************************************************
243  */
244 void hal_msio_init(msio_init_t *p_msio_init);
245 
246 /**
247  ****************************************************************************************
248  * @brief  De-initialize the MSIOx peripheral registers to their default reset values.
249  * @param[in]  msio_pin: Specifies the port bit to be written.
250  *         This parameter can be a combination of the following values:
251  *         @arg @ref MSIO_PIN_0
252  *         @arg @ref MSIO_PIN_1
253  *         @arg @ref MSIO_PIN_2
254  *         @arg @ref MSIO_PIN_3
255  *         @arg @ref MSIO_PIN_4
256  *         @arg @ref MSIO_PIN_ALL
257  ****************************************************************************************
258  */
259 void hal_msio_deinit(uint32_t msio_pin);
260 
261 /** @} */
262 
263 /** @addtogroup MSIO_Exported_Functions_Group2 IO operation functions
264   *  @brief MSIO Read, Write, and Toggle management functions.
265   * @{
266   */
267 
268 /**
269  ****************************************************************************************
270  * @brief  Read the specified input port pin.
271  * @param[in]  msio_pin: Specifies the port bit to be read.
272  *         This parameter can be one of the following values:
273  *         @arg @ref MSIO_PIN_0
274  *         @arg @ref MSIO_PIN_1
275  *         @arg @ref MSIO_PIN_2
276  *         @arg @ref MSIO_PIN_3
277  *         @arg @ref MSIO_PIN_4
278  * @retval ::MSIO_PIN_RESET: MSIO pin low level.
279  * @retval ::MSIO_PIN_SET: MSIO pin high level.
280  ****************************************************************************************
281  */
282 msio_pin_state_t hal_msio_read_pin(uint16_t msio_pin);
283 
284 /**
285  ****************************************************************************************
286  * @brief  Set or clear the selected data port bit.
287  * @param[in]  msio_pin: Specifies the port bit to be written.
288  *         This parameter can be a combination of the following values:
289  *         @arg @ref MSIO_PIN_0
290  *         @arg @ref MSIO_PIN_1
291  *         @arg @ref MSIO_PIN_2
292  *         @arg @ref MSIO_PIN_3
293  *         @arg @ref MSIO_PIN_4
294  *         @arg @ref MSIO_PIN_ALL
295  * @param[in]  pin_state: Specifies the value to be written to the selected bit.
296  *         This parameter can be one of the MSIO_PinState enum values:
297  *            @arg MSIO_PIN_RESET: to clear the port pin
298  *            @arg MSIO_PIN_SET: to set the port pin
299  ****************************************************************************************
300  */
301 void hal_msio_write_pin(uint16_t msio_pin, msio_pin_state_t pin_state);
302 
303 /**
304  ****************************************************************************************
305  * @brief  Toggle the specified MSIO pin.
306  * @param[in]  msio_pin: Specifies the pin to be toggled.
307  *         This parameter can be a combination of the following values:
308  *         @arg @ref MSIO_PIN_0
309  *         @arg @ref MSIO_PIN_1
310  *         @arg @ref MSIO_PIN_2
311  *         @arg @ref MSIO_PIN_3
312  *         @arg @ref MSIO_PIN_4
313  *         @arg @ref MSIO_PIN_ALL
314  ****************************************************************************************
315  */
316 void hal_msio_toggle_pin(uint16_t msio_pin);
317 
318 /** @} */
319 
320 /** @} */
321 
322 #ifdef __cplusplus
323 }
324 #endif
325 
326 #endif /* __GR55xx_HAL_MSIO_H__ */
327 
328 /** @} */
329 
330 /** @} */
331 
332 /** @} */
333