You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

347 lines
13 KiB

  1. /**
  2. ******************************************************************************
  3. * @file stm32h7xx_hal_gpio.h
  4. * @author MCD Application Team
  5. * @brief Header file of GPIO HAL module.
  6. ******************************************************************************
  7. * @attention
  8. *
  9. * <h2><center>&copy; COPYRIGHT(c) 2017 STMicroelectronics.
  10. * All rights reserved.</center></h2>
  11. *
  12. * This software component is licensed by ST under BSD 3-Clause license,
  13. * the "License"; You may not use this file except in compliance with the
  14. * License. You may obtain a copy of the License at:
  15. * opensource.org/licenses/BSD-3-Clause
  16. *
  17. ******************************************************************************
  18. */
  19. /* Define to prevent recursive inclusion -------------------------------------*/
  20. #ifndef STM32H7xx_HAL_GPIO_H
  21. #define STM32H7xx_HAL_GPIO_H
  22. #ifdef __cplusplus
  23. extern "C" {
  24. #endif
  25. /* Includes ------------------------------------------------------------------*/
  26. #include "stm32h7xx_hal_def.h"
  27. /** @addtogroup STM32H7xx_HAL_Driver
  28. * @{
  29. */
  30. /** @addtogroup GPIO
  31. * @{
  32. */
  33. /* Exported types ------------------------------------------------------------*/
  34. /** @defgroup GPIO_Exported_Types GPIO Exported Types
  35. * @{
  36. */
  37. /**
  38. * @brief GPIO Init structure definition
  39. */
  40. typedef struct
  41. {
  42. uint32_t Pin; /*!< Specifies the GPIO pins to be configured.
  43. This parameter can be any value of @ref GPIO_pins_define */
  44. uint32_t Mode; /*!< Specifies the operating mode for the selected pins.
  45. This parameter can be a value of @ref GPIO_mode_define */
  46. uint32_t Pull; /*!< Specifies the Pull-up or Pull-Down activation for the selected pins.
  47. This parameter can be a value of @ref GPIO_pull_define */
  48. uint32_t Speed; /*!< Specifies the speed for the selected pins.
  49. This parameter can be a value of @ref GPIO_speed_define */
  50. uint32_t Alternate; /*!< Peripheral to be connected to the selected pins.
  51. This parameter can be a value of @ref GPIO_Alternate_function_selection */
  52. } GPIO_InitTypeDef;
  53. /**
  54. * @brief GPIO Bit SET and Bit RESET enumeration
  55. */
  56. typedef enum
  57. {
  58. GPIO_PIN_RESET = 0U,
  59. GPIO_PIN_SET
  60. } GPIO_PinState;
  61. /**
  62. * @}
  63. */
  64. /* Exported constants --------------------------------------------------------*/
  65. /** @defgroup GPIO_Exported_Constants GPIO Exported Constants
  66. * @{
  67. */
  68. /** @defgroup GPIO_pins_define GPIO pins define
  69. * @{
  70. */
  71. #define GPIO_PIN_0 ((uint16_t)0x0001) /* Pin 0 selected */
  72. #define GPIO_PIN_1 ((uint16_t)0x0002) /* Pin 1 selected */
  73. #define GPIO_PIN_2 ((uint16_t)0x0004) /* Pin 2 selected */
  74. #define GPIO_PIN_3 ((uint16_t)0x0008) /* Pin 3 selected */
  75. #define GPIO_PIN_4 ((uint16_t)0x0010) /* Pin 4 selected */
  76. #define GPIO_PIN_5 ((uint16_t)0x0020) /* Pin 5 selected */
  77. #define GPIO_PIN_6 ((uint16_t)0x0040) /* Pin 6 selected */
  78. #define GPIO_PIN_7 ((uint16_t)0x0080) /* Pin 7 selected */
  79. #define GPIO_PIN_8 ((uint16_t)0x0100) /* Pin 8 selected */
  80. #define GPIO_PIN_9 ((uint16_t)0x0200) /* Pin 9 selected */
  81. #define GPIO_PIN_10 ((uint16_t)0x0400) /* Pin 10 selected */
  82. #define GPIO_PIN_11 ((uint16_t)0x0800) /* Pin 11 selected */
  83. #define GPIO_PIN_12 ((uint16_t)0x1000) /* Pin 12 selected */
  84. #define GPIO_PIN_13 ((uint16_t)0x2000) /* Pin 13 selected */
  85. #define GPIO_PIN_14 ((uint16_t)0x4000) /* Pin 14 selected */
  86. #define GPIO_PIN_15 ((uint16_t)0x8000) /* Pin 15 selected */
  87. #define GPIO_PIN_All ((uint16_t)0xFFFF) /* All pins selected */
  88. #define GPIO_PIN_MASK (0x0000FFFFU) /* PIN mask for assert test */
  89. /**
  90. * @}
  91. */
  92. /** @defgroup GPIO_mode_define GPIO mode define
  93. * @brief GPIO Configuration Mode
  94. * Elements values convention: 0xX0yz00YZ
  95. * - X : GPIO mode or EXTI Mode
  96. * - y : External IT or Event trigger detection
  97. * - z : IO configuration on External IT or Event
  98. * - Y : Output type (Push Pull or Open Drain)
  99. * - Z : IO Direction mode (Input, Output, Alternate or Analog)
  100. * @{
  101. */
  102. #define GPIO_MODE_INPUT (0x00000000U) /*!< Input Floating Mode */
  103. #define GPIO_MODE_OUTPUT_PP (0x00000001U) /*!< Output Push Pull Mode */
  104. #define GPIO_MODE_OUTPUT_OD (0x00000011U) /*!< Output Open Drain Mode */
  105. #define GPIO_MODE_AF_PP (0x00000002U) /*!< Alternate Function Push Pull Mode */
  106. #define GPIO_MODE_AF_OD (0x00000012U) /*!< Alternate Function Open Drain Mode */
  107. #define GPIO_MODE_ANALOG (0x00000003U) /*!< Analog Mode */
  108. #define GPIO_MODE_IT_RISING (0x11110000U) /*!< External Interrupt Mode with Rising edge trigger detection */
  109. #define GPIO_MODE_IT_FALLING (0x11210000U) /*!< External Interrupt Mode with Falling edge trigger detection */
  110. #define GPIO_MODE_IT_RISING_FALLING (0x11310000U) /*!< External Interrupt Mode with Rising/Falling edge trigger detection */
  111. #define GPIO_MODE_EVT_RISING (0x11120000U) /*!< External Event Mode with Rising edge trigger detection */
  112. #define GPIO_MODE_EVT_FALLING (0x11220000U) /*!< External Event Mode with Falling edge trigger detection */
  113. #define GPIO_MODE_EVT_RISING_FALLING (0x11320000U) /*!< External Event Mode with Rising/Falling edge trigger detection */
  114. /**
  115. * @}
  116. */
  117. /** @defgroup GPIO_speed_define GPIO speed define
  118. * @brief GPIO Output Maximum frequency
  119. * @{
  120. */
  121. #define GPIO_SPEED_FREQ_LOW (0x00000000U) /*!< Low speed */
  122. #define GPIO_SPEED_FREQ_MEDIUM (0x00000001U) /*!< Medium speed */
  123. #define GPIO_SPEED_FREQ_HIGH (0x00000002U) /*!< Fast speed */
  124. #define GPIO_SPEED_FREQ_VERY_HIGH (0x00000003U) /*!< High speed */
  125. /**
  126. * @}
  127. */
  128. /** @defgroup GPIO_pull_define GPIO pull define
  129. * @brief GPIO Pull-Up or Pull-Down Activation
  130. * @{
  131. */
  132. #define GPIO_NOPULL (0x00000000U) /*!< No Pull-up or Pull-down activation */
  133. #define GPIO_PULLUP (0x00000001U) /*!< Pull-up activation */
  134. #define GPIO_PULLDOWN (0x00000002U) /*!< Pull-down activation */
  135. /**
  136. * @}
  137. */
  138. /**
  139. * @}
  140. */
  141. /* Exported macro ------------------------------------------------------------*/
  142. /** @defgroup GPIO_Exported_Macros GPIO Exported Macros
  143. * @{
  144. */
  145. /**
  146. * @brief Checks whether the specified EXTI line flag is set or not.
  147. * @param __EXTI_LINE__: specifies the EXTI line flag to check.
  148. * This parameter can be GPIO_PIN_x where x can be(0..15)
  149. * @retval The new state of __EXTI_LINE__ (SET or RESET).
  150. */
  151. #define __HAL_GPIO_EXTI_GET_FLAG(__EXTI_LINE__) (EXTI_D1->PR1 & (__EXTI_LINE__))
  152. /**
  153. * @brief Clears the EXTI's line pending flags.
  154. * @param __EXTI_LINE__: specifies the EXTI lines flags to clear.
  155. * This parameter can be any combination of GPIO_PIN_x where x can be (0..15)
  156. * @retval None
  157. */
  158. #define __HAL_GPIO_EXTI_CLEAR_FLAG(__EXTI_LINE__) (EXTI_D1->PR1 = (__EXTI_LINE__))
  159. /**
  160. * @brief Checks whether the specified EXTI line is asserted or not.
  161. * @param __EXTI_LINE__: specifies the EXTI line to check.
  162. * This parameter can be GPIO_PIN_x where x can be(0..15)
  163. * @retval The new state of __EXTI_LINE__ (SET or RESET).
  164. */
  165. #define __HAL_GPIO_EXTI_GET_IT(__EXTI_LINE__) (EXTI_D1->PR1 & (__EXTI_LINE__))
  166. /**
  167. * @brief Clears the EXTI's line pending bits.
  168. * @param __EXTI_LINE__: specifies the EXTI lines to clear.
  169. * This parameter can be any combination of GPIO_PIN_x where x can be (0..15)
  170. * @retval None
  171. */
  172. #define __HAL_GPIO_EXTI_CLEAR_IT(__EXTI_LINE__) (EXTI_D1->PR1 = (__EXTI_LINE__))
  173. #if defined(DUAL_CORE)
  174. /**
  175. * @brief Checks whether the specified EXTI line flag is set or not.
  176. * @param __EXTI_LINE__: specifies the EXTI line flag to check.
  177. * This parameter can be GPIO_PIN_x where x can be(0..15)
  178. * @retval The new state of __EXTI_LINE__ (SET or RESET).
  179. */
  180. #define __HAL_GPIO_EXTID2_GET_FLAG(__EXTI_LINE__) (EXTI_D2->PR1 & (__EXTI_LINE__))
  181. /**
  182. * @brief Clears the EXTI's line pending flags.
  183. * @param __EXTI_LINE__: specifies the EXTI lines flags to clear.
  184. * This parameter can be any combination of GPIO_PIN_x where x can be (0..15)
  185. * @retval None
  186. */
  187. #define __HAL_GPIO_EXTID2_CLEAR_FLAG(__EXTI_LINE__) (EXTI_D2->PR1 = (__EXTI_LINE__))
  188. /**
  189. * @brief Checks whether the specified EXTI line is asserted or not.
  190. * @param __EXTI_LINE__: specifies the EXTI line to check.
  191. * This parameter can be GPIO_PIN_x where x can be(0..15)
  192. * @retval The new state of __EXTI_LINE__ (SET or RESET).
  193. */
  194. #define __HAL_GPIO_EXTID2_GET_IT(__EXTI_LINE__) (EXTI_D2->PR1 & (__EXTI_LINE__))
  195. /**
  196. * @brief Clears the EXTI's line pending bits.
  197. * @param __EXTI_LINE__: specifies the EXTI lines to clear.
  198. * This parameter can be any combination of GPIO_PIN_x where x can be (0..15)
  199. * @retval None
  200. */
  201. #define __HAL_GPIO_EXTID2_CLEAR_IT(__EXTI_LINE__) (EXTI_D2->PR1 = (__EXTI_LINE__))
  202. #endif
  203. /**
  204. * @brief Generates a Software interrupt on selected EXTI line.
  205. * @param __EXTI_LINE__: specifies the EXTI line to check.
  206. * This parameter can be GPIO_PIN_x where x can be(0..15)
  207. * @retval None
  208. */
  209. #define __HAL_GPIO_EXTI_GENERATE_SWIT(__EXTI_LINE__) (EXTI->SWIER1 |= (__EXTI_LINE__))
  210. /**
  211. * @}
  212. */
  213. /* Include GPIO HAL Extension module */
  214. #include "stm32h7xx_hal_gpio_ex.h"
  215. /* Exported functions --------------------------------------------------------*/
  216. /** @addtogroup GPIO_Exported_Functions
  217. * @{
  218. */
  219. /** @addtogroup GPIO_Exported_Functions_Group1
  220. * @{
  221. */
  222. /* Initialization and de-initialization functions *****************************/
  223. void HAL_GPIO_Init(GPIO_TypeDef *GPIOx, GPIO_InitTypeDef *GPIO_Init);
  224. void HAL_GPIO_DeInit(GPIO_TypeDef *GPIOx, uint32_t GPIO_Pin);
  225. /**
  226. * @}
  227. */
  228. /** @addtogroup GPIO_Exported_Functions_Group2
  229. * @{
  230. */
  231. /* IO operation functions *****************************************************/
  232. GPIO_PinState HAL_GPIO_ReadPin(GPIO_TypeDef *GPIOx, uint16_t GPIO_Pin);
  233. void HAL_GPIO_WritePin(GPIO_TypeDef *GPIOx, uint16_t GPIO_Pin, GPIO_PinState PinState);
  234. void HAL_GPIO_TogglePin(GPIO_TypeDef *GPIOx, uint16_t GPIO_Pin);
  235. HAL_StatusTypeDef HAL_GPIO_LockPin(GPIO_TypeDef *GPIOx, uint16_t GPIO_Pin);
  236. void HAL_GPIO_EXTI_IRQHandler(uint16_t GPIO_Pin);
  237. void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin);
  238. /**
  239. * @}
  240. */
  241. /**
  242. * @}
  243. */
  244. /* Private types -------------------------------------------------------------*/
  245. /* Private variables ---------------------------------------------------------*/
  246. /* Private constants ---------------------------------------------------------*/
  247. /** @defgroup GPIO_Private_Constants GPIO Private Constants
  248. * @{
  249. */
  250. /**
  251. * @}
  252. */
  253. /* Private macros ------------------------------------------------------------*/
  254. /** @defgroup GPIO_Private_Macros GPIO Private Macros
  255. * @{
  256. */
  257. #define IS_GPIO_PIN_ACTION(ACTION) (((ACTION) == GPIO_PIN_RESET) || ((ACTION) == GPIO_PIN_SET))
  258. #define IS_GPIO_PIN(__PIN__) ((((__PIN__) & GPIO_PIN_MASK) != 0x00U) &&\
  259. (((__PIN__) & ~GPIO_PIN_MASK) == 0x00U))
  260. #define IS_GPIO_MODE(MODE) (((MODE) == GPIO_MODE_INPUT) ||\
  261. ((MODE) == GPIO_MODE_OUTPUT_PP) ||\
  262. ((MODE) == GPIO_MODE_OUTPUT_OD) ||\
  263. ((MODE) == GPIO_MODE_AF_PP) ||\
  264. ((MODE) == GPIO_MODE_AF_OD) ||\
  265. ((MODE) == GPIO_MODE_IT_RISING) ||\
  266. ((MODE) == GPIO_MODE_IT_FALLING) ||\
  267. ((MODE) == GPIO_MODE_IT_RISING_FALLING) ||\
  268. ((MODE) == GPIO_MODE_EVT_RISING) ||\
  269. ((MODE) == GPIO_MODE_EVT_FALLING) ||\
  270. ((MODE) == GPIO_MODE_EVT_RISING_FALLING) ||\
  271. ((MODE) == GPIO_MODE_ANALOG))
  272. #define IS_GPIO_SPEED(SPEED) (((SPEED) == GPIO_SPEED_FREQ_LOW) || ((SPEED) == GPIO_SPEED_FREQ_MEDIUM) || \
  273. ((SPEED) == GPIO_SPEED_FREQ_HIGH) || ((SPEED) == GPIO_SPEED_FREQ_VERY_HIGH))
  274. #define IS_GPIO_PULL(PULL) (((PULL) == GPIO_NOPULL) || ((PULL) == GPIO_PULLUP) || \
  275. ((PULL) == GPIO_PULLDOWN))
  276. /**
  277. * @}
  278. */
  279. /* Private functions ---------------------------------------------------------*/
  280. /** @defgroup GPIO_Private_Functions GPIO Private Functions
  281. * @{
  282. */
  283. /**
  284. * @}
  285. */
  286. /**
  287. * @}
  288. */
  289. /**
  290. * @}
  291. */
  292. #ifdef __cplusplus
  293. }
  294. #endif
  295. #endif /* STM32H7xx_HAL_GPIO_H */
  296. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/