1 /*********************************************************************************************************//**
2  * @file    ht32f5xxxx_gpio.h
3  * @version $Rev:: 8260         $
4  * @date    $Date:: 2024-11-05 #$
5  * @brief   The header file of the GPIO and AFIO library.
6  *************************************************************************************************************
7  * @attention
8  *
9  * Firmware Disclaimer Information
10  *
11  * 1. The customer hereby acknowledges and agrees that the program technical documentation, including the
12  *    code, which is supplied by Holtek Semiconductor Inc., (hereinafter referred to as "HOLTEK") is the
13  *    proprietary and confidential intellectual property of HOLTEK, and is protected by copyright law and
14  *    other intellectual property laws.
15  *
16  * 2. The customer hereby acknowledges and agrees that the program technical documentation, including the
17  *    code, is confidential information belonging to HOLTEK, and must not be disclosed to any third parties
18  *    other than HOLTEK and the customer.
19  *
20  * 3. The program technical documentation, including the code, is provided "as is" and for customer reference
21  *    only. After delivery by HOLTEK, the customer shall use the program technical documentation, including
22  *    the code, at their own risk. HOLTEK disclaims any expressed, implied or statutory warranties, including
23  *    the warranties of merchantability, satisfactory quality and fitness for a particular purpose.
24  *
25  * <h2><center>Copyright (C) Holtek Semiconductor Inc. All rights reserved</center></h2>
26  ************************************************************************************************************/
27 
28 /* Define to prevent recursive inclusion -------------------------------------------------------------------*/
29 #ifndef __HT32F5XXXX_GPIO_H
30 #define __HT32F5XXXX_GPIO_H
31 
32 #ifdef __cplusplus
33  extern "C" {
34 #endif
35 
36 /* Includes ------------------------------------------------------------------------------------------------*/
37 #include "ht32.h"
38 
39 /** @addtogroup HT32F5xxxx_Peripheral_Driver HT32F5xxxx Peripheral Driver
40   * @{
41   */
42 
43 /** @addtogroup GPIO
44   * @{
45   */
46 
47 
48 /* Settings ------------------------------------------------------------------------------------------------*/
49 /** @defgroup GPIO_Settings GPIO settings
50   * @{
51   */
52 #ifndef AUTO_CK_CONTROL
53 #define AUTO_CK_CONTROL      (0)
54 #endif
55 /**
56   * @}
57   */
58 
59 /* Exported types ------------------------------------------------------------------------------------------*/
60 /** @defgroup GPIO_Exported_Types GPIO exported types
61   * @{
62   */
63 
64 /**
65  * @brief  Enumeration of GPIO pull resistor.
66  */
67 typedef enum
68 {
69   GPIO_PR_UP = 0,        /*!< weak pull-up resistor                                                         */
70   GPIO_PR_DOWN,          /*!< weak pull-down resistor                                                       */
71   GPIO_PR_DISABLE,       /*!< Tri-state                                                                     */
72   #if (LIBCFG_GPIO_PR_STRONG_UP)
73   GPIO_PR_STRONG_UP,     /*!< strong pull-up resistor                                                       */
74   GPIO_PR_STRONGEST_UP   /*!< strongest pull-up resistor                                                    */
75   #endif
76 } GPIO_PR_Enum;
77 /**
78  * @brief  Enumeration of GPIO output drive current.
79  */
80 typedef enum
81 {
82   GPIO_DV_4MA = 0,   /*!<  4mA source/sink current                                                          */
83   GPIO_DV_8MA,       /*!<  8mA source/sink current                                                          */
84   GPIO_DV_12MA,      /*!< 12mA source/sink current                                                          */
85   GPIO_DV_16MA       /*!< 16mA source/sink current                                                          */
86 } GPIO_DV_Enum;
87 /**
88  * @brief  Enumeration of GPIO direction.
89  */
90 typedef enum
91 {
92   GPIO_DIR_IN = 0,    /*!< input mode                                                                       */
93   GPIO_DIR_OUT        /*!< output mode                                                                      */
94 } GPIO_DIR_Enum;
95 /**
96  * @brief  Enumeration of AFIO for EXTI channel.
97  */
98 typedef enum
99 {
100   AFIO_EXTI_CH_0 = 0,     /*!< GPIO pin 0                                                                   */
101   AFIO_EXTI_CH_1,         /*!< GPIO pin 1                                                                   */
102   AFIO_EXTI_CH_2,         /*!< GPIO pin 2                                                                   */
103   AFIO_EXTI_CH_3,         /*!< GPIO pin 3                                                                   */
104   AFIO_EXTI_CH_4,         /*!< GPIO pin 4                                                                   */
105   AFIO_EXTI_CH_5,         /*!< GPIO pin 5                                                                   */
106   AFIO_EXTI_CH_6,         /*!< GPIO pin 6                                                                   */
107   AFIO_EXTI_CH_7,         /*!< GPIO pin 7                                                                   */
108   AFIO_EXTI_CH_8,         /*!< GPIO pin 8                                                                   */
109   AFIO_EXTI_CH_9,         /*!< GPIO pin 9                                                                   */
110   AFIO_EXTI_CH_10,        /*!< GPIO pin 10                                                                  */
111   AFIO_EXTI_CH_11,        /*!< GPIO pin 11                                                                  */
112   AFIO_EXTI_CH_12,        /*!< GPIO pin 12                                                                  */
113   AFIO_EXTI_CH_13,        /*!< GPIO pin 13                                                                  */
114   AFIO_EXTI_CH_14,        /*!< GPIO pin 14                                                                  */
115   AFIO_EXTI_CH_15         /*!< GPIO pin 15                                                                  */
116 } AFIO_EXTI_CH_Enum;
117 /**
118  * @brief Enumeration of AFIO_MODE.
119  */
120 typedef enum
121 {
122  AFIO_MODE_DEFAULT = 0,   /*!< Default AFIO mode                                                            */
123  AFIO_MODE_1,             /*!< AFIO mode 1                                                                  */
124  AFIO_MODE_2,             /*!< AFIO mode 2                                                                  */
125  AFIO_MODE_3,             /*!< AFIO mode 3                                                                  */
126  AFIO_MODE_4,             /*!< AFIO mode 4                                                                  */
127  AFIO_MODE_5,             /*!< AFIO mode 5                                                                  */
128  AFIO_MODE_6,             /*!< AFIO mode 6                                                                  */
129  AFIO_MODE_7,             /*!< AFIO mode 7                                                                  */
130  AFIO_MODE_8,             /*!< AFIO mode 8                                                                  */
131  AFIO_MODE_9,             /*!< AFIO mode 9                                                                  */
132  AFIO_MODE_10,            /*!< AFIO mode 10                                                                 */
133  AFIO_MODE_11,            /*!< AFIO mode 11                                                                 */
134  AFIO_MODE_12,            /*!< AFIO mode 12                                                                 */
135  AFIO_MODE_13,            /*!< AFIO mode 13                                                                 */
136  AFIO_MODE_14,            /*!< AFIO mode 14                                                                 */
137  AFIO_MODE_15             /*!< AFIO mode 15                                                                 */
138 } AFIO_MODE_Enum;
139 /**
140   * @}
141   */
142 
143 /* Exported constants --------------------------------------------------------------------------------------*/
144 /** @defgroup GPIO_Exported_Constants GPIO exported constants
145   * @{
146   */
147 
148 /* Definitions of AFIO_FUN                                                                                  */
149 #define AFIO_FUN_DEFAULT    AFIO_MODE_DEFAULT  /*!< Default AFIO mode                                       */
150 #define AFIO_FUN_GPIO       AFIO_MODE_1        /*!< AFIO mode GPIO                                          */
151 #if (LIBCFG_AFIO_SYSTEM_MODE1)
152 #define AFIO_FUN_SYSTEM     AFIO_MODE_1        /*!< AFIO mode System                                        */
153 #else
154 #define AFIO_FUN_SYSTEM     AFIO_MODE_15       /*!< AFIO mode System                                        */
155 #endif
156 #if (LIBCFG_AFIO_DAC_MODE3)
157 #define AFIO_FUN_DAC0       AFIO_MODE_3        /*!< AFIO mode DAC0                                          */
158 #define AFIO_FUN_DAC1       AFIO_MODE_3        /*!< AFIO mode DAC1                                          */
159 #else
160 #define AFIO_FUN_DAC0       AFIO_MODE_2        /*!< AFIO mode DAC0                                          */
161 #endif
162 #define AFIO_FUN_ADC0       AFIO_MODE_2        /*!< AFIO mode ADC0                                          */
163 #define AFIO_FUN_ADC1       AFIO_MODE_3        /*!< AFIO mode ADC1                                          */
164 #if (LIBCFG_AFIO_LEDC_MODE3)
165 #define AFIO_FUN_LEDC       AFIO_MODE_3        /*!< AFIO mode LEDC                                          */
166 #else
167 #define AFIO_FUN_LEDC       AFIO_MODE_14       /*!< AFIO mode LEDC                                          */
168 #endif
169 #if ((LIBCFG_CMP) && (LIBCFG_OPA))
170 #define AFIO_FUN_CMP        AFIO_FUN_CMP_OPA   /*!< AFIO mode CMP                                           */
171 #define AFIO_FUN_OPA        AFIO_FUN_CMP_OPA   /*!< AFIO mode OPA                                           */
172 #elif ((LIBCFG_CMP) && (LIBCFG_PGA))
173 #define AFIO_FUN_CMP        AFIO_FUN_CMP_PGA   /*!< AFIO mode CMP                                           */
174 #define AFIO_FUN_PGA        AFIO_FUN_CMP_PGA   /*!< AFIO mode PGA                                           */
175 #elif (LIBCFG_CMP)
176 #define AFIO_FUN_CMP        AFIO_MODE_3        /*!< AFIO mode CMP                                           */
177 #endif
178 #define AFIO_FUN_MCTM_GPTM  AFIO_MODE_4        /*!< AFIO mode MCTM/GPTM                                     */
179 #if (LIBCFG_AFIO_SCTM_MODE4)
180 #define AFIO_FUN_SCTM       AFIO_MODE_4        /*!< AFIO mode SCTM                                          */
181 #elif (LIBCFG_AFIO_SCTM_MODE9)
182 #define AFIO_FUN_SCTM       AFIO_MODE_9        /*!< AFIO mode SCTM                                          */
183 #else
184 #define AFIO_FUN_SCTM       AFIO_MODE_13       /*!< AFIO mode SCTM                                          */
185 #endif
186 #if (LIBCFG_AFIO_PWM_MODE4)
187 #define AFIO_FUN_PWM        AFIO_MODE_4        /*!< AFIO mode PWM                                           */
188 #else
189 #define AFIO_FUN_PWM        AFIO_MODE_13       /*!< AFIO mode PWM                                           */
190 #endif
191 #define AFIO_FUN_SPI        AFIO_MODE_5        /*!< AFIO mode SPI                                           */
192 #define AFIO_FUN_USART_UART AFIO_MODE_6        /*!< AFIO mode USART/UART                                    */
193 #define AFIO_FUN_I2C        AFIO_MODE_7        /*!< AFIO mode I2C                                           */
194 #define AFIO_FUN_SCI        AFIO_MODE_8        /*!< AFIO mode SCI                                           */
195 #if ((LIBCFG_CMP) && (LIBCFG_OPA))
196 #define AFIO_FUN_CMP_OPA    AFIO_MODE_8        /*!< AFIO mode CMP/OPA                                       */
197 #elif ((LIBCFG_CMP) && (LIBCFG_PGA))
198 #define AFIO_FUN_CMP_PGA    AFIO_MODE_8        /*!< AFIO mode CMP/PGA                                       */
199 #endif
200 #define AFIO_FUN_EBI        AFIO_MODE_9        /*!< AFIO mode EBI                                           */
201 #define AFIO_FUN_I2S        AFIO_MODE_10       /*!< AFIO mode I2S                                           */
202 #define AFIO_FUN_CAN        AFIO_MODE_12       /*!< AFIO mode CAN                                           */
203 #define AFIO_FUN_TEKY       AFIO_MODE_12       /*!< AFIO mode TKEY                                          */
204 #define AFIO_FUN_LCD        AFIO_MODE_14       /*!< AFIO mode LCD                                           */
205 #define AFIO_FUN_SLED       AFIO_MODE_14       /*!< AFIO mode SLED                                          */
206 
207 /* Definitions of AFIO_FUN alias                                                                            */
208 #define AFIO_FUN_MCTM0      AFIO_FUN_MCTM_GPTM
209 
210 #define AFIO_FUN_GPTM0      AFIO_FUN_MCTM_GPTM
211 #define AFIO_FUN_GPTM1      AFIO_FUN_MCTM_GPTM
212 #define AFIO_FUN_GPTM2      AFIO_FUN_MCTM_GPTM
213 #define AFIO_FUN_GPTM3      AFIO_FUN_MCTM_GPTM
214 
215 #define AFIO_FUN_PWM0       AFIO_FUN_PWM
216 #define AFIO_FUN_PWM1       AFIO_FUN_PWM
217 #define AFIO_FUN_PWM2       AFIO_FUN_PWM
218 #define AFIO_FUN_PWM3       AFIO_FUN_PWM
219 
220 #define AFIO_FUN_SCTM0      AFIO_FUN_SCTM
221 #define AFIO_FUN_SCTM1      AFIO_FUN_SCTM
222 #define AFIO_FUN_SCTM2      AFIO_FUN_SCTM
223 #define AFIO_FUN_SCTM3      AFIO_FUN_SCTM
224 
225 #define AFIO_FUN_ADC        AFIO_FUN_ADC0
226 
227 /* Definitions of GPIO_Px                                                                                   */
228 #define GPIO_PORT_NUM   (6)
229 #define GPIO_PIN_NUM    (16)
230 #define GPIO_PA         (0)
231 #define GPIO_PB         (1)
232 #if (LIBCFG_GPIOC)
233 #define GPIO_PC         (2)
234 #endif
235 #if (LIBCFG_GPIOD)
236 #define GPIO_PD         (3)
237 #endif
238 #if (LIBCFG_GPIOE)
239 #define GPIO_PE         (4)
240 #endif
241 #if (LIBCFG_GPIOF)
242 #define GPIO_PF         (5)
243 #endif
244 
245 /* Definitions of GPIO port source for EXTI channel                                                         */
246 #define AFIO_ESS_PA GPIO_PA  /*!< EXTI channel x source come from GPIO Port A                               */
247 #define AFIO_ESS_PB GPIO_PB  /*!< EXTI channel x source come from GPIO Port B                               */
248 #if (LIBCFG_GPIOC)
249 #define AFIO_ESS_PC GPIO_PC  /*!< EXTI channel x source come from GPIO Port C                               */
250 #endif
251 #if (LIBCFG_GPIOD)
252 #define AFIO_ESS_PD GPIO_PD  /*!< EXTI channel x source come from GPIO Port D                               */
253 #endif
254 #if (LIBCFG_GPIOE)
255 #define AFIO_ESS_PE GPIO_PE  /*!< EXTI channel x source come from GPIO Port E                               */
256 #endif
257 #if (LIBCFG_GPIOF)
258 #define AFIO_ESS_PF GPIO_PF  /*!< EXTI channel x source come from GPIO Port F                               */
259 #endif
260 
261 /* Definitions of GPIO_PIN                                                                                  */
262 #define GPIO_PIN_0    0x0001   /*!< GPIO pin 0 selected                                                     */
263 #define GPIO_PIN_1    0x0002   /*!< GPIO pin 1 selected                                                     */
264 #define GPIO_PIN_2    0x0004   /*!< GPIO pin 2 selected                                                     */
265 #define GPIO_PIN_3    0x0008   /*!< GPIO pin 3 selected                                                     */
266 #define GPIO_PIN_4    0x0010   /*!< GPIO pin 4 selected                                                     */
267 #define GPIO_PIN_5    0x0020   /*!< GPIO pin 5 selected                                                     */
268 #define GPIO_PIN_6    0x0040   /*!< GPIO pin 6 selected                                                     */
269 #define GPIO_PIN_7    0x0080   /*!< GPIO pin 7 selected                                                     */
270 #define GPIO_PIN_8    0x0100   /*!< GPIO pin 8 selected                                                     */
271 #define GPIO_PIN_9    0x0200   /*!< GPIO pin 9 selected                                                     */
272 #define GPIO_PIN_10   0x0400   /*!< GPIO pin 10 selected                                                    */
273 #define GPIO_PIN_11   0x0800   /*!< GPIO pin 11 selected                                                    */
274 #define GPIO_PIN_12   0x1000   /*!< GPIO pin 12 selected                                                    */
275 #define GPIO_PIN_13   0x2000   /*!< GPIO pin 13 selected                                                    */
276 #define GPIO_PIN_14   0x4000   /*!< GPIO pin 14 selected                                                    */
277 #define GPIO_PIN_15   0x8000   /*!< GPIO pin 15 selected                                                    */
278 #define GPIO_PIN_ALL  0xFFFF   /*!< GPIO all pins selected                                                  */
279 
280 /* Definitions of AFIO_PIN                                                                                  */
281 #define AFIO_PIN_0    0x0001   /*!< AFIO pin 0 selected                                                     */
282 #define AFIO_PIN_1    0x0002   /*!< AFIO pin 1 selected                                                     */
283 #define AFIO_PIN_2    0x0004   /*!< AFIO pin 2 selected                                                     */
284 #define AFIO_PIN_3    0x0008   /*!< AFIO pin 3 selected                                                     */
285 #define AFIO_PIN_4    0x0010   /*!< AFIO pin 4 selected                                                     */
286 #define AFIO_PIN_5    0x0020   /*!< AFIO pin 5 selected                                                     */
287 #define AFIO_PIN_6    0x0040   /*!< AFIO pin 6 selected                                                     */
288 #define AFIO_PIN_7    0x0080   /*!< AFIO pin 7 selected                                                     */
289 #define AFIO_PIN_8    0x0100   /*!< AFIO pin 8 selected                                                     */
290 #define AFIO_PIN_9    0x0200   /*!< AFIO pin 9 selected                                                     */
291 #define AFIO_PIN_10   0x0400   /*!< AFIO pin 10 selected                                                    */
292 #define AFIO_PIN_11   0x0800   /*!< AFIO pin 11 selected                                                    */
293 #define AFIO_PIN_12   0x1000   /*!< AFIO pin 12 selected                                                    */
294 #define AFIO_PIN_13   0x2000   /*!< AFIO pin 13 selected                                                    */
295 #define AFIO_PIN_14   0x4000   /*!< AFIO pin 14 selected                                                    */
296 #define AFIO_PIN_15   0x8000   /*!< AFIO pin 15 selected                                                    */
297 #define AFIO_PIN_ALL  0xFFFF   /*!< All AFIO pins selected                                                  */
298 
299 /* Definitions of GPIO_PIN_NUM                                                                              */
300 #define GPIO_PIN_NUM_0    0x00   /*!< GPIO pin number 0 selected                                            */
301 #define GPIO_PIN_NUM_1    0x01   /*!< GPIO pin number 1 selected                                            */
302 #define GPIO_PIN_NUM_2    0x02   /*!< GPIO pin number 2 selected                                            */
303 #define GPIO_PIN_NUM_3    0x03   /*!< GPIO pin number 3 selected                                            */
304 #define GPIO_PIN_NUM_4    0x04   /*!< GPIO pin number 4 selected                                            */
305 #define GPIO_PIN_NUM_5    0x05   /*!< GPIO pin number 5 selected                                            */
306 #define GPIO_PIN_NUM_6    0x06   /*!< GPIO pin number 6 selected                                            */
307 #define GPIO_PIN_NUM_7    0x07   /*!< GPIO pin number 7 selected                                            */
308 #define GPIO_PIN_NUM_8    0x08   /*!< GPIO pin number 8 selected                                            */
309 #define GPIO_PIN_NUM_9    0x09   /*!< GPIO pin number 9 selected                                            */
310 #define GPIO_PIN_NUM_10   0x0A   /*!< GPIO pin number 10 selected                                           */
311 #define GPIO_PIN_NUM_11   0x0B   /*!< GPIO pin number 11 selected                                           */
312 #define GPIO_PIN_NUM_12   0x0C   /*!< GPIO pin number 12 selected                                           */
313 #define GPIO_PIN_NUM_13   0x0D   /*!< GPIO pin number 13 selected                                           */
314 #define GPIO_PIN_NUM_14   0x0E   /*!< GPIO pin number 14 selected                                           */
315 #define GPIO_PIN_NUM_15   0x0F   /*!< GPIO pin number 15 selected                                           */
316 
317 /**
318   * @}
319   */
320 
321 /* Exported macro ------------------------------------------------------------------------------------------*/
322 /** @defgroup GPIO_Exported_Macro GPIO exported macro
323   * @{
324   */
325 /* check parameter of the GPIOx                                                                             */
326 #define IS_GPIO(x)           (IS_GPIO1(x) || IS_GPIO2(x) || IS_GPIO3(x) || IS_GPIO4(x) || IS_GPIO5(x))
327 
328 #define IS_GPIO1(x)          ((x == HT_GPIOA) || (x == HT_GPIOB) )
329 
330 #if (LIBCFG_GPIOC)
331 #define IS_GPIO2(x)          (x == HT_GPIOC)
332 #else
333 #define IS_GPIO2(x)          (0)
334 #endif
335 #if (LIBCFG_GPIOD)
336 #define IS_GPIO3(x)          (x == HT_GPIOD)
337 #else
338 #define IS_GPIO3(x)          (0)
339 #endif
340 #if (LIBCFG_GPIOE)
341 #define IS_GPIO4(x)          (x == HT_GPIOE)
342 #else
343 #define IS_GPIO4(x)          (0)
344   #endif
345 #if (LIBCFG_GPIOF)
346 #define IS_GPIO5(x)          (x == HT_GPIOF)
347 #else
348 #define IS_GPIO5(x)          (0)
349 #endif
350 
351 /* check parameter of the GPIO_Px                                                                           */
352 #define IS_GPIO_PORT(x)           (IS_GPIO_PORT1(x) || IS_GPIO_PORT2(x) || IS_GPIO_PORT3(x) || IS_GPIO_PORT4(x) || IS_GPIO_PORT5(x))
353 
354 #define IS_GPIO_PORT1(x)          ((x == GPIO_PA) || (x == GPIO_PB))
355 
356 #if (LIBCFG_GPIOC)
357 #define IS_GPIO_PORT2(x)          (x == GPIO_PC)
358 #else
359 #define IS_GPIO_PORT2(x)          (0)
360 #endif
361 #if (LIBCFG_GPIOD)
362 #define IS_GPIO_PORT3(x)          (x == GPIO_PD)
363 #else
364 #define IS_GPIO_PORT3(x)          (0)
365 #endif
366 #if (LIBCFG_GPIOE)
367 #define IS_GPIO_PORT4(x)          (x == GPIO_PE)
368 #else
369 #define IS_GPIO_PORT4(x)          (0)
370 #endif
371 #if (LIBCFG_GPIOF)
372 #define IS_GPIO_PORT5(x)          (x == GPIO_PF)
373 #else
374 #define IS_GPIO_PORT5(x)          (0)
375 #endif
376 
377 /* check parameter of the GPIO_PIN_NUM                                                                      */
378 #define IS_GPIO_PIN_NUM(x)        (x < 16)
379 
380 
381 #define IS_GPIO_PR_UP(x)           (x == GPIO_PR_UP)
382 #define IS_GPIO_PR_DOWN(x)         (x == GPIO_PR_DOWN)
383 #define IS_GPIO_PR_DISABLE(x)      (x == GPIO_PR_DISABLE)
384 
385 #if (LIBCFG_GPIO_PR_STRONG_UP)
386 #define IS_GPIO_PR_STRONG_UP(x)    (x == GPIO_PR_STRONG_UP)
387 #define IS_GPIO_PR_STRONGEST_UP(x) (x == GPIO_PR_STRONGEST_UP)
388 #else
389 #define IS_GPIO_PR_STRONG_UP(x)    (0)
390 #define IS_GPIO_PR_STRONGEST_UP(x) (0)
391 #endif
392 
393 /* check parameter of the GPIOx pull resistor                                                               */
394 #define IS_GPIO_PR(x)        (IS_GPIO_PR_UP(x)        || \
395                               IS_GPIO_PR_DOWN(x)      || \
396                               IS_GPIO_PR_DISABLE(x)   || \
397                               IS_GPIO_PR_STRONG_UP(x) || \
398                               IS_GPIO_PR_STRONGEST_UP(x))
399 
400 /* check parameter of the GPIOx driving current                                                             */
401 #define IS_GPIO_DV(x)        (((x) == GPIO_DV_4MA) || ((x) == GPIO_DV_8MA) || ((x) == GPIO_DV_12MA) || ((x) == GPIO_DV_16MA) )
402 
403 /* check parameter of the GPIOx input/output direction                                                      */
404 #define IS_GPIO_DIR(x)       (((x) == GPIO_DIR_IN) || ((x) == GPIO_DIR_OUT))
405 
406 /* check parameter of the EXTI source port                                                                  */
407 #define IS_AFIO_ESS(x)       (IS_AFIO_ESS1(x) || IS_AFIO_ESS2(x) || IS_AFIO_ESS3(x) || IS_AFIO_ESS4(x) || IS_AFIO_ESS5(x))
408 
409 #define IS_AFIO_ESS1(x)      ((x == AFIO_ESS_PA) || (x == AFIO_ESS_PB))
410 #if (LIBCFG_GPIOC)
411 #define IS_AFIO_ESS2(x)      (x == AFIO_ESS_PC)
412 #else
413 #define IS_AFIO_ESS2(x)      (0)
414 #endif
415 #if (LIBCFG_GPIOD)
416 #define IS_AFIO_ESS3(x)      (x == AFIO_ESS_PD)
417 #else
418 #define IS_AFIO_ESS3(x)      (0)
419 #endif
420 #if (LIBCFG_GPIOE)
421 #define IS_AFIO_ESS4(x)      (x == AFIO_ESS_PE)
422 #else
423 #define IS_AFIO_ESS4(x)      (0)
424 #endif
425 #if (LIBCFG_GPIOF)
426 #define IS_AFIO_ESS5(x)      (x == AFIO_ESS_PF)
427 #else
428 #define IS_AFIO_ESS5(x)      (0)
429 #endif
430 
431 /* check parameter of the EXTI channel                                                                      */
432 #if (LIBCFG_EXTI_8CH)
433 #define IS_AFIO_EXTI_CH(x)   ((x == AFIO_EXTI_CH_0)  || (x == AFIO_EXTI_CH_1)  || \
434                               (x == AFIO_EXTI_CH_2)  || (x == AFIO_EXTI_CH_3)  || \
435                               (x == AFIO_EXTI_CH_4)  || (x == AFIO_EXTI_CH_5)  || \
436                               (x == AFIO_EXTI_CH_6)  || (x == AFIO_EXTI_CH_7))
437 #else
438 #define IS_AFIO_EXTI_CH(x)   ((x == AFIO_EXTI_CH_0)  || (x == AFIO_EXTI_CH_1)  || \
439                               (x == AFIO_EXTI_CH_2)  || (x == AFIO_EXTI_CH_3)  || \
440                               (x == AFIO_EXTI_CH_4)  || (x == AFIO_EXTI_CH_5)  || \
441                               (x == AFIO_EXTI_CH_6)  || (x == AFIO_EXTI_CH_7)  || \
442                               (x == AFIO_EXTI_CH_8)  || (x == AFIO_EXTI_CH_9)  || \
443                               (x == AFIO_EXTI_CH_10) || (x == AFIO_EXTI_CH_11) || \
444                               (x == AFIO_EXTI_CH_12) || (x == AFIO_EXTI_CH_13) || \
445                               (x == AFIO_EXTI_CH_14) || (x == AFIO_EXTI_CH_15))
446 #endif
447 
448 /* check parameter of the AFIO mode                                                                         */
449 #if (LIBCFG_AFIO_MODE_0_7)
450 #define IS_AFIO_MODE(x)      ((x == AFIO_MODE_DEFAULT) || (x == AFIO_MODE_1)  || \
451                               (x == AFIO_MODE_2)       || (x == AFIO_MODE_3)  || \
452                               (x == AFIO_MODE_4)       || (x == AFIO_MODE_5)  || \
453                               (x == AFIO_MODE_6)       || (x == AFIO_MODE_7))
454 #else
455 #define IS_AFIO_MODE(x)      ((x == AFIO_MODE_DEFAULT) || (x == AFIO_MODE_1)  || \
456                               (x == AFIO_MODE_2)       || (x == AFIO_MODE_3)  || \
457                               (x == AFIO_MODE_4)       || (x == AFIO_MODE_5)  || \
458                               (x == AFIO_MODE_6)       || (x == AFIO_MODE_7)  || \
459                               (x == AFIO_MODE_8)       || (x == AFIO_MODE_9)  || \
460                               (x == AFIO_MODE_10)      || (x == AFIO_MODE_11) || \
461                               (x == AFIO_MODE_12)      || (x == AFIO_MODE_13) || \
462                               (x == AFIO_MODE_14)      || (x == AFIO_MODE_15))
463 #endif
464 /**
465   * @}
466   */
467 
468 /* Exported functions --------------------------------------------------------------------------------------*/
469 /** @defgroup GPIO_Exported_Functions GPIO exported functions
470   * @{
471   */
472 
473 /* Prototype of related GPIO function                                                                       */
474 void GPIO_DeInit(HT_GPIO_TypeDef* HT_GPIOx);
475 void GPIO_DirectionConfig(HT_GPIO_TypeDef* HT_GPIOx, u16 GPIO_PIN_nBITMAP, GPIO_DIR_Enum GPIO_DIR_INorOUT);
476 void GPIO_PullResistorConfig(HT_GPIO_TypeDef* HT_GPIOx, u16 GPIO_PIN_nBITMAP, GPIO_PR_Enum GPIO_PR_x);
477 void GPIO_InputConfig(HT_GPIO_TypeDef* HT_GPIOx, u16 GPIO_PIN_nBITMAP, ControlStatus Cmd);
478 void GPIO_DriveConfig(HT_GPIO_TypeDef* HT_GPIOx, u16 GPIO_PIN_nBITMAP, GPIO_DV_Enum GPIO_DV_nMA);
479 void GPIO_OpenDrainConfig(HT_GPIO_TypeDef* HT_GPIOx, u16 GPIO_PIN_nBITMAP, ControlStatus Cmd);
480 #if (LIBCFG_GPIO_SINK_CURRENT_ENHANCED)
481 void GPIO_SinkConfig(HT_GPIO_TypeDef* HT_GPIOx, u16 GPIO_PIN_n, ControlStatus Cmd);
482 #endif
483 FlagStatus GPIO_ReadInBit(HT_GPIO_TypeDef* HT_GPIOx, u16 GPIO_PIN_n);
484 FlagStatus GPIO_ReadOutBit(HT_GPIO_TypeDef* HT_GPIOx, u16 GPIO_PIN_n);
485 u16 GPIO_ReadInData(HT_GPIO_TypeDef* HT_GPIOx);
486 u16 GPIO_ReadOutData(HT_GPIO_TypeDef* HT_GPIOx);
487 void GPIO_SetOutBits(HT_GPIO_TypeDef* HT_GPIOx, u16 GPIO_PIN_nBITMAP);
488 void GPIO_ClearOutBits(HT_GPIO_TypeDef* HT_GPIOx, u16 GPIO_PIN_nBITMAP);
489 void GPIO_WriteOutBits(HT_GPIO_TypeDef* HT_GPIOx, u16 GPIO_PIN_nBITMAP, FlagStatus Status);
490 void GPIO_WriteOutData(HT_GPIO_TypeDef* HT_GPIOx, u16 Data);
491 void GPIO_PinLock(HT_GPIO_TypeDef* HT_GPIOx, u16 GPIO_PIN_nBITMAP);
492 bool GPIO_IsPortLocked(HT_GPIO_TypeDef* HT_GPIOx);
493 bool GPIO_IsPinLocked(HT_GPIO_TypeDef* HT_GPIOx, u16 GPIO_PIN_n);
494 #if (LIBCFG_GPIO_DISABLE_DEBUG_PORT)
495 void GPIO_DisableDebugPort(void);
496 #endif
497 u32 GPIO_GetID(HT_GPIO_TypeDef* HT_GPIOx);
498 
499 /* Prototype of related AFIO function                                                                       */
500 void AFIO_DeInit(void);
501 void AFIO_GPxConfig(u32 GPIO_Px, u32 AFIO_PIN_n, AFIO_MODE_Enum AFIO_MODE_n);
502 void AFIO_EXTISourceConfig(u32 GPIO_PIN_NUM_n, u32 GPIO_Px);
503 /**
504   * @}
505   */
506 
507 
508 /**
509   * @}
510   */
511 
512 /**
513   * @}
514   */
515 
516 #ifdef __cplusplus
517 }
518 #endif
519 
520 #endif
521