gd32f10x_gpio.h 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281
  1. /**
  2. ******************************************************************************
  3. * @brief GPIO header file of the firmware library.
  4. ******************************************************************************
  5. */
  6. /* Define to prevent recursive inclusion -------------------------------------*/
  7. #ifndef __GD32F10x_GPIO_H
  8. #define __GD32F10x_GPIO_H
  9. #ifdef __cplusplus
  10. extern "C" {
  11. #endif
  12. /* Includes ------------------------------------------------------------------*/
  13. #include "gd32f10x.h"
  14. /** @addtogroup GD32F10x_Firmware
  15. * @{
  16. */
  17. /** @addtogroup GPIO
  18. * @{
  19. */
  20. /** @defgroup GPIO_Exported_Types
  21. * @{
  22. */
  23. /**
  24. * @brief Output_Maximum_frequency_enumeration
  25. */
  26. typedef enum {
  27. GPIO_SPEED_10MHZ = 1,
  28. GPIO_SPEED_2MHZ,
  29. GPIO_SPEED_50MHZ
  30. } GPIO_SpeedPara;
  31. /**
  32. * @brief GPIO_Mode_enumeration
  33. */
  34. typedef enum {
  35. GPIO_MODE_AIN = 0x0,
  36. GPIO_MODE_IN_FLOATING = 0x04,
  37. GPIO_MODE_IPD = 0x28,
  38. GPIO_MODE_IPU = 0x48,
  39. GPIO_MODE_OUT_OD = 0x14,
  40. GPIO_MODE_OUT_PP = 0X10,
  41. GPIO_MODE_AF_OD = 0X1C,
  42. GPIO_MODE_AF_PP = 0X18
  43. } GPIO_ModePara;
  44. /**
  45. * @brief GPIO Initial Parameters
  46. */
  47. typedef struct {
  48. uint16_t GPIO_Pin; /*!< The GPIO pins to be configured. choose several from @ref GPIO_pins_define */
  49. GPIO_SpeedPara GPIO_Speed; /*!< The speed for This parameter can be a value of @ref GPIOSpeed_TypeDef */
  50. GPIO_ModePara GPIO_Mode; /*!< The operating mode for the selected pins. choose one from @ref GPIO_ModePara */
  51. } GPIO_InitPara;
  52. /**
  53. * @brief Bit_State_enumeration
  54. */
  55. typedef enum {
  56. Bit_RESET = 0,
  57. Bit_SET
  58. } BitState;
  59. /**
  60. * @}
  61. */
  62. /** @defgroup GPIO_Exported_Constants
  63. * @{
  64. */
  65. /** @defgroup GPIO_pins_define
  66. * @{
  67. */
  68. #define GPIO_PIN_0 ((uint16_t)0x0001)
  69. #define GPIO_PIN_1 ((uint16_t)0x0002)
  70. #define GPIO_PIN_2 ((uint16_t)0x0004)
  71. #define GPIO_PIN_3 ((uint16_t)0x0008)
  72. #define GPIO_PIN_4 ((uint16_t)0x0010)
  73. #define GPIO_PIN_5 ((uint16_t)0x0020)
  74. #define GPIO_PIN_6 ((uint16_t)0x0040)
  75. #define GPIO_PIN_7 ((uint16_t)0x0080)
  76. #define GPIO_PIN_8 ((uint16_t)0x0100)
  77. #define GPIO_PIN_9 ((uint16_t)0x0200)
  78. #define GPIO_PIN_10 ((uint16_t)0x0400)
  79. #define GPIO_PIN_11 ((uint16_t)0x0800)
  80. #define GPIO_PIN_12 ((uint16_t)0x1000)
  81. #define GPIO_PIN_13 ((uint16_t)0x2000)
  82. #define GPIO_PIN_14 ((uint16_t)0x4000)
  83. #define GPIO_PIN_15 ((uint16_t)0x8000)
  84. #define GPIO_PIN_ALL ((uint16_t)0xFFFF)
  85. /**
  86. * @}
  87. */
  88. /** @defgroup GPIO_Remap_define
  89. * @{
  90. */
  91. #define GPIO_REMAP_SPI1 ((uint32_t)0x00000001)
  92. #define GPIO_REMAP_I2C1 ((uint32_t)0x00000002)
  93. #define GPIO_REMAP_USART1 ((uint32_t)0x00000004)
  94. #define GPIO_REMAP_USART2 ((uint32_t)0x00000008)
  95. #define GPIO_PARTIAL_REMAP_USART3 ((uint32_t)0x00140010)
  96. #define GPIO_FULL_REMAP_USART3 ((uint32_t)0x00140030)
  97. #define GPIO_PARTIAL_REMAP_TIMER1 ((uint32_t)0x00160040)
  98. #define GPIO_FULL_REMAP_TIMER1 ((uint32_t)0x001600C0)
  99. #define GPIO_PARTIAL_REMAP1_TIMER2 ((uint32_t)0x00180100)
  100. #define GPIO_PARTIAL_REMAP2_TIMER2 ((uint32_t)0x00180200)
  101. #define GPIO_FULL_REMAP_TIMER2 ((uint32_t)0x00180300)
  102. #define GPIO_PARTIAL_REMAP_TIMER3 ((uint32_t)0x001A0800)
  103. #define GPIO_FULL_REMAP_TIMER3 ((uint32_t)0x001A0C00)
  104. #define GPIO_REMAP_TIMER4 ((uint32_t)0x00001000)
  105. #define GPIO_REMAP1_CAN1 ((uint32_t)0x001D4000)
  106. #define GPIO_REMAP2_CAN1 ((uint32_t)0x001D6000)
  107. #define GPIO_REMAP_PD01 ((uint32_t)0x00008000)
  108. #define GPIO_REMAP_TIMER5CH4_LSI ((uint32_t)0x00200001)
  109. #define GPIO_REMAP_ADC1_ETRGINJ ((uint32_t)0x00200002)
  110. #define GPIO_REMAP_ADC1_ETRGREG ((uint32_t)0x00200004)
  111. #define GPIO_REMAP_ADC2_ETRGINJ ((uint32_t)0x00200008)
  112. #define GPIO_REMAP_ADC2_ETRGREG ((uint32_t)0x00200010)
  113. #define GPIO_REMAP_ETH ((uint32_t)0x00200020)
  114. #define GPIO_REMAP_CAN2 ((uint32_t)0x00200040)
  115. #define GPIO_REMAP_SWJ_NOJTRST ((uint32_t)0x00300100)
  116. #define GPIO_REMAP_SWJ_JTAGDISABLE ((uint32_t)0x00300200)
  117. #define GPIO_REMAP_SWJ_DISABLE ((uint32_t)0x00300400)
  118. #define GPIO_REMAP_SPI3 ((uint32_t)0x00201100)
  119. #define GPIO_REMAP_TIMER2ITR1_PTP_SOF ((uint32_t)0x00202000)
  120. #define GPIO_REMAP_PTP_PPS ((uint32_t)0x00204000)
  121. #define GPIO_REMAP_TIMER15 ((uint32_t)0x80000001)
  122. #define GPIO_REMAP_TIMER16 ((uint32_t)0x80000002)
  123. #define GPIO_REMAP_TIMER17 ((uint32_t)0x80000004)
  124. #define GPIO_REMAP_CEC ((uint32_t)0x80000008)
  125. #define GPIO_REMAP_TIMER1_DMA ((uint32_t)0x80000010)
  126. #define GPIO_REMAP_TIMER9 ((uint32_t)0x80000020)
  127. #define GPIO_REMAP_TIMER10 ((uint32_t)0x80000040)
  128. #define GPIO_REMAP_TIMER11 ((uint32_t)0x80000080)
  129. #define GPIO_REMAP_TIMER13 ((uint32_t)0x80000100)
  130. #define GPIO_REMAP_TIMER14 ((uint32_t)0x80000200)
  131. #define GPIO_REMAP_EXMC_NADV ((uint32_t)0x80000400)
  132. #define GPIO_REMAP_TIMER67_DAC_DMA ((uint32_t)0x80000800)
  133. #define GPIO_REMAP_TIMER12 ((uint32_t)0x80001000)
  134. #define GPIO_REMAP_MISC ((uint32_t)0x80002000)
  135. /**
  136. * @}
  137. */
  138. /** @defgroup GPIO_Port_Sources
  139. * @{
  140. */
  141. #define GPIO_PORT_SOURCE_GPIOA ((uint8_t)0x00)
  142. #define GPIO_PORT_SOURCE_GPIOB ((uint8_t)0x01)
  143. #define GPIO_PORT_SOURCE_GPIOC ((uint8_t)0x02)
  144. #define GPIO_PORT_SOURCE_GPIOD ((uint8_t)0x03)
  145. #define GPIO_PORT_SOURCE_GPIOE ((uint8_t)0x04)
  146. #define GPIO_PORT_SOURCE_GPIOF ((uint8_t)0x05)
  147. #define GPIO_PORT_SOURCE_GPIOG ((uint8_t)0x06)
  148. /**
  149. * @}
  150. */
  151. /** @defgroup GPIO_Pin_sources
  152. * @{
  153. */
  154. #define GPIO_PINSOURCE0 ((uint8_t)0x00)
  155. #define GPIO_PINSOURCE1 ((uint8_t)0x01)
  156. #define GPIO_PINSOURCE2 ((uint8_t)0x02)
  157. #define GPIO_PINSOURCE3 ((uint8_t)0x03)
  158. #define GPIO_PINSOURCE4 ((uint8_t)0x04)
  159. #define GPIO_PINSOURCE5 ((uint8_t)0x05)
  160. #define GPIO_PINSOURCE6 ((uint8_t)0x06)
  161. #define GPIO_PINSOURCE7 ((uint8_t)0x07)
  162. #define GPIO_PINSOURCE8 ((uint8_t)0x08)
  163. #define GPIO_PINSOURCE9 ((uint8_t)0x09)
  164. #define GPIO_PINSOURCE10 ((uint8_t)0x0A)
  165. #define GPIO_PINSOURCE11 ((uint8_t)0x0B)
  166. #define GPIO_PINSOURCE12 ((uint8_t)0x0C)
  167. #define GPIO_PINSOURCE13 ((uint8_t)0x0D)
  168. #define GPIO_PINSOURCE14 ((uint8_t)0x0E)
  169. #define GPIO_PINSOURCE15 ((uint8_t)0x0F)
  170. /**
  171. * @}
  172. */
  173. /** @defgroup Ethernet_Media_Interface
  174. * @{
  175. */
  176. #define GPIO_ETH_MEDIAINTERFACE_MII ((uint32_t)0x00000000)
  177. #define GPIO_ETH_MEDIAINTERFACE_RMII ((uint32_t)0x00800000)
  178. /**
  179. * @}
  180. */
  181. /* output mode definitions */
  182. #define CTL_CLTR(regval) (BITS(0,1) & ((uint32_t)(regval) << 0))
  183. #define GPIO_MODE_INPUT CTL_CLTR(0) /*!< input mode */
  184. #define GPIO_MODE_OUTPUT CTL_CLTR(1) /*!< output mode */
  185. #define GPIO_MODE_AF CTL_CLTR(2) /*!< alternate function mode */
  186. #define GPIO_MODE_ANALOG CTL_CLTR(3) /*!< analog mode */
  187. /** @defgroup AFIO_Event_Output
  188. * @{
  189. */
  190. #define AFIO_ECR_EVOE_SET ((uint32_t)0x00000080)
  191. #define AFIO_ECR_EVOE_RESET ((uint32_t)0xffffff7f)
  192. /* gpio alternate function */
  193. #define AF(regval) (BITS(0,3) & ((uint32_t)(regval) << 0))
  194. #define GPIO_AF_0 AF(0) /*!< alternate function selected 0 */
  195. #define GPIO_AF_1 AF(1) /*!< alternate function selected 1 */
  196. #define GPIO_AF_2 AF(2) /*!< alternate function selected 2 */
  197. #define GPIO_AF_3 AF(3) /*!< alternate function selected 3 */
  198. #define GPIO_AF_4 AF(4) /*!< alternate function selected 4 */
  199. #define GPIO_AF_5 AF(5) /*!< alternate function selected 5 */
  200. #define GPIO_AF_6 AF(6) /*!< alternate function selected 6 */
  201. #define GPIO_AF_7 AF(7) /*!< alternate function selected 7 */
  202. #define GPIO_AF_8 AF(8) /*!< alternate function selected 8 */
  203. #define GPIO_AF_9 AF(9) /*!< alternate function selected 9 */
  204. #define GPIO_AF_10 AF(10) /*!< alternate function selected 10 */
  205. #define GPIO_AF_11 AF(11) /*!< alternate function selected 11 */
  206. #define GPIO_AF_12 AF(12) /*!< alternate function selected 12 */
  207. #define GPIO_AF_13 AF(13) /*!< alternate function selected 13 */
  208. #define GPIO_AF_14 AF(14) /*!< alternate function selected 14 */
  209. #define GPIO_AF_15 AF(15) /*!< alternate function selected 15 */
  210. /**
  211. * @}
  212. */
  213. /**
  214. * @}
  215. */
  216. /** @defgroup GPIO_Exported_Functions
  217. * @{
  218. */
  219. void GPIO_DeInit(GPIO_TypeDef *GPIOx);
  220. void GPIO_AFDeInit(void);
  221. void GPIO_Init(GPIO_TypeDef *GPIOx, GPIO_InitPara *GPIO_InitStruct);
  222. void GPIO_ParaInit(GPIO_InitPara *GPIO_InitStruct);
  223. uint8_t GPIO_ReadInputBit(GPIO_TypeDef *GPIOx, uint16_t GPIO_Pin);
  224. uint16_t GPIO_ReadInputData(GPIO_TypeDef *GPIOx);
  225. uint8_t GPIO_ReadOutputBit(GPIO_TypeDef *GPIOx, uint16_t GPIO_Pin);
  226. uint16_t GPIO_ReadOutputData(GPIO_TypeDef *GPIOx);
  227. void GPIO_SetBits(GPIO_TypeDef *GPIOx, uint16_t GPIO_Pin);
  228. void GPIO_ResetBits(GPIO_TypeDef *GPIOx, uint16_t GPIO_Pin);
  229. void GPIO_WriteBit(GPIO_TypeDef *GPIOx, uint16_t GPIO_Pin, BitState BitVal);
  230. void GPIO_Write(GPIO_TypeDef *GPIOx, uint16_t PortVal);
  231. void GPIO_PinLockConfig(GPIO_TypeDef *GPIOx, uint16_t GPIO_Pin);
  232. void GPIO_EventOutputConfig(uint8_t GPIO_PortSource, uint8_t GPIO_PinSource);
  233. void GPIO_EventOutputEnable(TypeState NewState);
  234. void GPIO_PinRemapConfig(uint32_t GPIO_Remap, TypeState NewState);
  235. void GPIO_EXTILineConfig(uint8_t GPIO_PortSource, uint8_t GPIO_PinSource);
  236. void GPIO_ETH_MediaInterfaceConfig(uint32_t GPIO_ETH_MediaInterface);
  237. #ifdef __cplusplus
  238. }
  239. #endif
  240. #endif /* __GD32F10X_GPIO_H */
  241. /**
  242. * @}
  243. */
  244. /**
  245. * @}
  246. */
  247. /**
  248. * @}
  249. */