py32f002b_hal_gpio.h 12 KB

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