HAL_GPIO.h 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  1. /*
  2. ******************************************************************************
  3. * @file HAL_GPIO.h
  4. * @version V1.0.0
  5. * @date 2020
  6. * @brief Header file of GPIO HAL module.
  7. ******************************************************************************
  8. */
  9. #ifndef __HAL_GPIO_H__
  10. #define __HAL_GPIO_H__
  11. #include "ACM32Fxx_HAL.h"
  12. /** @defgroup GPIO_pins GPIO pins
  13. * @{
  14. */
  15. #define GPIO_PIN_0 ((uint16_t)0x0001) /* Pin 0 selected */
  16. #define GPIO_PIN_1 ((uint16_t)0x0002) /* Pin 1 selected */
  17. #define GPIO_PIN_2 ((uint16_t)0x0004) /* Pin 2 selected */
  18. #define GPIO_PIN_3 ((uint16_t)0x0008) /* Pin 3 selected */
  19. #define GPIO_PIN_4 ((uint16_t)0x0010) /* Pin 4 selected */
  20. #define GPIO_PIN_5 ((uint16_t)0x0020) /* Pin 5 selected */
  21. #define GPIO_PIN_6 ((uint16_t)0x0040) /* Pin 6 selected */
  22. #define GPIO_PIN_7 ((uint16_t)0x0080) /* Pin 7 selected */
  23. #define GPIO_PIN_8 ((uint16_t)0x0100) /* Pin 8 selected */
  24. #define GPIO_PIN_9 ((uint16_t)0x0200) /* Pin 9 selected */
  25. #define GPIO_PIN_10 ((uint16_t)0x0400) /* Pin 10 selected */
  26. #define GPIO_PIN_11 ((uint16_t)0x0800) /* Pin 11 selected */
  27. #define GPIO_PIN_12 ((uint16_t)0x1000) /* Pin 12 selected */
  28. #define GPIO_PIN_13 ((uint16_t)0x2000) /* Pin 13 selected */
  29. #define GPIO_PIN_14 ((uint16_t)0x4000) /* Pin 14 selected */
  30. #define GPIO_PIN_15 ((uint16_t)0x8000) /* Pin 15 selected */
  31. #define GPIO_PIN_MASK (0x0000FFFFu) /* PIN mask for assert test */
  32. /**
  33. * @}
  34. */
  35. /** @defgroup GPIO_mode GPIO mode
  36. * @{
  37. */
  38. #define GPIO_MODE_INPUT (0x00010000u) /*!< Input Floating Mode */
  39. #define GPIO_MODE_OUTPUT_PP (0x00010001u) /*!< Output Push Pull Mode */
  40. #define GPIO_MODE_OUTPUT_OD (0x00011002u) /*!< Output Open Drain Mode */
  41. #define GPIO_MODE_AF_PP (0x00000003u) /*!< Alternate Function Push Pull Mode */
  42. #define GPIO_MODE_AF_OD (0x00001004u) /*!< Alternate Function Open Drain Mode */
  43. #define GPIO_MODE_ANALOG (0x00000005u) /*!< Analog Mode */
  44. #define GPIO_MODE_IT_RISING (0x10010000u) /*!< External Interrupt Mode with Rising edge trigger detection */
  45. #define GPIO_MODE_IT_FALLING (0x10010001u) /*!< External Interrupt Mode with Falling edge trigger detection */
  46. #define GPIO_MODE_IT_RISING_FALLING (0x10010002u) /*!< External Interrupt Mode with Rising/Falling edge trigger detection */
  47. #define GPIO_MODE_IT_HIGH_LEVEL (0x10010003u) /*!< External Interrupt Mode with high level trigger detection */
  48. #define GPIO_MODE_IT_LOW_LEVEL (0x10010004u) /*!< External Interrupt Mode with low level trigger detection */
  49. #define GPIO_MODE_OD_MASK (0x00001000u) /*!< OD Mode Mask */
  50. #define GPIO_MODE_IO_MASK (0x00010000u) /*!< Use GPIO Function Mask */
  51. #define GPIO_MODE_IT_MASK (0x10000000u) /*!< GPIO interrupt Mask */
  52. /**
  53. * @}
  54. */
  55. /** @defgroup GPIO_pull GPIO pull
  56. * @{
  57. */
  58. #define GPIO_NOPULL (0x00000000u) /*!< No Pull-up or Pull-down activation */
  59. #define GPIO_PULLUP (0x00000001u) /*!< Pull-up activation */
  60. #define GPIO_PULLDOWN (0x00000002u) /*!< Pull-down activation */
  61. /**
  62. * @}
  63. */
  64. /** @defgroup GPIOEx_function_selection GPIO pull
  65. * @{
  66. */
  67. #define GPIO_FUNCTION_0 (0x00000000u)
  68. #define GPIO_FUNCTION_1 (0x00000001u)
  69. #define GPIO_FUNCTION_2 (0x00000002u)
  70. #define GPIO_FUNCTION_3 (0x00000003u)
  71. #define GPIO_FUNCTION_4 (0x00000004u)
  72. #define GPIO_FUNCTION_5 (0x00000005u)
  73. #define GPIO_FUNCTION_6 (0x00000006u)
  74. #define GPIO_FUNCTION_7 (0x00000007u)
  75. #define GPIO_FUNCTION_8 (0x00000008u)
  76. #define GPIO_FUNCTION_9 (0x00000009u)
  77. /**
  78. * @}
  79. */
  80. /** @defgroup GPIOx Index
  81. * @{
  82. */
  83. typedef enum
  84. {
  85. GPIOA,
  86. GPIOB,
  87. GPIOC,
  88. GPIOD,
  89. }enum_GPIOx_t;
  90. /**
  91. * @}
  92. */
  93. /** @defgroup GPIO Bit SET and Bit RESET enumeration
  94. * @{
  95. */
  96. typedef enum
  97. {
  98. GPIO_PIN_CLEAR = 0u,
  99. GPIO_PIN_SET = 1u,
  100. }enum_PinState_t;
  101. /**
  102. * @}
  103. */
  104. /*
  105. * @brief GPIO Init structure definition
  106. */
  107. typedef struct
  108. {
  109. uint32_t Pin; /*!< Specifies the GPIO pins to be configured.
  110. This parameter can be any value of @ref GPIO_pins */
  111. uint32_t Mode; /*!< Specifies the operating mode for the selected pins.
  112. This parameter can be a value of @ref GPIO_mode */
  113. uint32_t Pull; /*!< Specifies the Pull-up or Pull-Down activation for the selected pins.
  114. This parameter can be a value of @ref GPIO_pull */
  115. uint32_t Alternate; /*!< Peripheral to be connected to the selected pins
  116. This parameter can be a value of @ref GPIOEx_function_selection */
  117. } GPIO_InitTypeDef;
  118. /** @defgroup GPIO Private Macros
  119. * @{
  120. */
  121. #define IS_GPIO_ALL_INSTANCE(INSTANCE) (((INSTANCE) == GPIOA) || \
  122. ((INSTANCE) == GPIOB) || \
  123. ((INSTANCE) == GPIOC) || \
  124. ((INSTANCE) == GPIOD) )
  125. #define IS_GPIO_PIN(__PIN__) ((((uint32_t)(__PIN__) & GPIO_PIN_MASK) != 0x00u) &&\
  126. (((uint32_t)(__PIN__) & ~GPIO_PIN_MASK) == 0x00u))
  127. #define IS_GPIO_MODE(__MODE__) (((__MODE__) == GPIO_MODE_INPUT) ||\
  128. ((__MODE__) == GPIO_MODE_OUTPUT_PP) ||\
  129. ((__MODE__) == GPIO_MODE_OUTPUT_OD) ||\
  130. ((__MODE__) == GPIO_MODE_AF_PP) ||\
  131. ((__MODE__) == GPIO_MODE_AF_OD) ||\
  132. ((__MODE__) == GPIO_MODE_IT_RISING) ||\
  133. ((__MODE__) == GPIO_MODE_IT_FALLING) ||\
  134. ((__MODE__) == GPIO_MODE_IT_RISING_FALLING) ||\
  135. ((__MODE__) == GPIO_MODE_IT_HIGH_LEVEL) ||\
  136. ((__MODE__) == GPIO_MODE_IT_LOW_LEVEL) ||\
  137. ((__MODE__) == GPIO_MODE_ANALOG))
  138. #define IS_GPIO_PULL(__PULL__) (((__PULL__) == GPIO_NOPULL) ||\
  139. ((__PULL__) == GPIO_PULLUP) ||\
  140. ((__PULL__) == GPIO_PULLDOWN))
  141. #define IS_GPIO_PIN_ACTION(ACTION) (((ACTION) == GPIO_PIN_CLEAR) || ((ACTION) == GPIO_PIN_SET))
  142. #define IS_GPIO_FUNCTION(__FUNCTION__) (((__FUNCTION__) == GPIO_FUNCTION_0) ||\
  143. ((__FUNCTION__) == GPIO_FUNCTION_1) ||\
  144. ((__FUNCTION__) == GPIO_FUNCTION_2) ||\
  145. ((__FUNCTION__) == GPIO_FUNCTION_3) ||\
  146. ((__FUNCTION__) == GPIO_FUNCTION_4) ||\
  147. ((__FUNCTION__) == GPIO_FUNCTION_5) ||\
  148. ((__FUNCTION__) == GPIO_FUNCTION_6) ||\
  149. ((__FUNCTION__) == GPIO_FUNCTION_7) ||\
  150. ((__FUNCTION__) == GPIO_FUNCTION_8) ||\
  151. ((__FUNCTION__) == GPIO_FUNCTION_9))
  152. /**
  153. * @}
  154. */
  155. /* Exported functions --------------------------------------------------------*/
  156. /* HAL_GPIO_IRQHandler */
  157. void HAL_GPIO_IRQHandler(enum_GPIOx_t fe_GPIO, uint32_t fu32_GPIO_Pin);
  158. /* HAL_GPIO_Init */
  159. void HAL_GPIO_Init(enum_GPIOx_t fe_GPIO, GPIO_InitTypeDef *GPIO_Init);
  160. /* HAL_GPIO_DeInit */
  161. void HAL_GPIO_DeInit(enum_GPIOx_t fe_GPIO, uint32_t fu32_Pin);
  162. /* HAL_GPIO_AnalogEnable */
  163. void HAL_GPIO_AnalogEnable(enum_GPIOx_t fe_GPIO, uint32_t fu32_Pin);
  164. /* HAL_GPIO_WritePin */
  165. void HAL_GPIO_WritePin(enum_GPIOx_t fe_GPIO, uint32_t fu32_GPIO_Pin, enum_PinState_t fe_PinState);
  166. /* HAL_GPIO_ReadPin */
  167. enum_PinState_t HAL_GPIO_ReadPin(enum_GPIOx_t fe_GPIO, uint32_t fu32_GPIO_Pin);
  168. #endif