ft32f0xx_gpio.h 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370
  1. /**
  2. ******************************************************************************
  3. * @file ft32f0xx_gpio.h
  4. * @author FMD AE
  5. * @brief This file contains all the functions prototypes for the GPIO
  6. * firmware library.
  7. * @version V1.0.0
  8. * @data 2021-07-01
  9. ******************************************************************************
  10. */
  11. /* Define to prevent recursive inclusion -------------------------------------*/
  12. #ifndef __FT32F030X8_GPIO_H
  13. #define __FT32F030X8_GPIO_H
  14. #ifdef __cplusplus
  15. extern "C" {
  16. #endif
  17. /* Includes ------------------------------------------------------------------*/
  18. #include "ft32f0xx.h"
  19. /** @addtogroup GPIO
  20. * @{
  21. */
  22. /* Exported types ------------------------------------------------------------*/
  23. #define IS_GPIO_ALL_PERIPH(PERIPH) (((PERIPH) == GPIOA) || \
  24. ((PERIPH) == GPIOB) || \
  25. ((PERIPH) == GPIOC) || \
  26. ((PERIPH) == GPIOD) || \
  27. ((PERIPH) == GPIOE) || \
  28. ((PERIPH) == GPIOF))
  29. #define IS_GPIO_LIST_PERIPH(PERIPH) (((PERIPH) == GPIOA) || \
  30. ((PERIPH) == GPIOB))
  31. /** @defgroup Configuration_Mode_enumeration
  32. * @{
  33. */
  34. typedef enum
  35. {
  36. GPIO_Mode_IN = 0x00, /*!< GPIO Input Mode */
  37. GPIO_Mode_OUT = 0x01, /*!< GPIO Output Mode */
  38. GPIO_Mode_AF = 0x02, /*!< GPIO Alternate function Mode */
  39. GPIO_Mode_AN = 0x03 /*!< GPIO Analog In/Out Mode */
  40. }GPIOMode_TypeDef;
  41. #define IS_GPIO_MODE(MODE) (((MODE) == GPIO_Mode_IN)|| ((MODE) == GPIO_Mode_OUT) || \
  42. ((MODE) == GPIO_Mode_AF)|| ((MODE) == GPIO_Mode_AN))
  43. /**
  44. * @}
  45. */
  46. /** @defgroup Output_type_enumeration
  47. * @{
  48. */
  49. typedef enum
  50. {
  51. GPIO_OType_PP = 0x00,
  52. GPIO_OType_OD = 0x01
  53. }GPIOOType_TypeDef;
  54. #define IS_GPIO_OTYPE(OTYPE) (((OTYPE) == GPIO_OType_PP) || ((OTYPE) == GPIO_OType_OD))
  55. /**
  56. * @}
  57. */
  58. /** @defgroup Output_Maximum_frequency_enumeration
  59. * @{
  60. */
  61. typedef enum
  62. {
  63. GPIO_Speed_Level_1 = 0x00, /*!< I/O output speed: Low 2 MHz */
  64. GPIO_Speed_Level_2 = 0x01, /*!< I/O output speed: Medium 10 MHz */
  65. GPIO_Speed_Level_3 = 0x03 /*!< I/O output speed: High 50 MHz */
  66. }GPIOSpeed_TypeDef;
  67. #define IS_GPIO_SPEED(SPEED) (((SPEED) == GPIO_Speed_Level_1) || ((SPEED) == GPIO_Speed_Level_2) || \
  68. ((SPEED) == GPIO_Speed_Level_3))
  69. /**
  70. * @}
  71. */
  72. /** @defgroup Configuration_Pull-Up_Pull-Down_enumeration
  73. * @{
  74. */
  75. typedef enum
  76. {
  77. GPIO_PuPd_NOPULL = 0x00,
  78. GPIO_PuPd_UP = 0x01,
  79. GPIO_PuPd_DOWN = 0x02
  80. }GPIOPuPd_TypeDef;
  81. #define IS_GPIO_PUPD(PUPD) (((PUPD) == GPIO_PuPd_NOPULL) || ((PUPD) == GPIO_PuPd_UP) || \
  82. ((PUPD) == GPIO_PuPd_DOWN))
  83. /**
  84. * @}
  85. */
  86. /** @defgroup Bit_SET_and_Bit_RESET_enumeration
  87. * @{
  88. */
  89. typedef enum
  90. {
  91. Bit_RESET = 0,
  92. Bit_SET
  93. }BitAction;
  94. #define IS_GPIO_BIT_ACTION(ACTION) (((ACTION) == Bit_RESET) || ((ACTION) == Bit_SET))
  95. /**
  96. * @}
  97. */
  98. /**
  99. * @brief GPIO Init structure definition
  100. */
  101. typedef struct
  102. {
  103. uint32_t GPIO_Pin; /*!< Specifies the GPIO pins to be configured.
  104. This parameter can be any value of @ref GPIO_pins_define */
  105. GPIOMode_TypeDef GPIO_Mode; /*!< Specifies the operating mode for the selected pins.
  106. This parameter can be a value of @ref GPIOMode_TypeDef */
  107. GPIOSpeed_TypeDef GPIO_Speed; /*!< Specifies the speed for the selected pins.
  108. This parameter can be a value of @ref GPIOSpeed_TypeDef */
  109. GPIOOType_TypeDef GPIO_OType; /*!< Specifies the operating output type for the selected pins.
  110. This parameter can be a value of @ref GPIOOType_TypeDef */
  111. GPIOPuPd_TypeDef GPIO_PuPd; /*!< Specifies the operating Pull-up/Pull down for the selected pins.
  112. This parameter can be a value of @ref GPIOPuPd_TypeDef */
  113. }GPIO_InitTypeDef;
  114. /* Exported constants --------------------------------------------------------*/
  115. /** @defgroup GPIO_Exported_Constants
  116. * @{
  117. */
  118. /** @defgroup GPIO_pins_define
  119. * @{
  120. */
  121. #define GPIO_Pin_0 ((uint16_t)0x0001) /*!< Pin 0 selected */
  122. #define GPIO_Pin_1 ((uint16_t)0x0002) /*!< Pin 1 selected */
  123. #define GPIO_Pin_2 ((uint16_t)0x0004) /*!< Pin 2 selected */
  124. #define GPIO_Pin_3 ((uint16_t)0x0008) /*!< Pin 3 selected */
  125. #define GPIO_Pin_4 ((uint16_t)0x0010) /*!< Pin 4 selected */
  126. #define GPIO_Pin_5 ((uint16_t)0x0020) /*!< Pin 5 selected */
  127. #define GPIO_Pin_6 ((uint16_t)0x0040) /*!< Pin 6 selected */
  128. #define GPIO_Pin_7 ((uint16_t)0x0080) /*!< Pin 7 selected */
  129. #define GPIO_Pin_8 ((uint16_t)0x0100) /*!< Pin 8 selected */
  130. #define GPIO_Pin_9 ((uint16_t)0x0200) /*!< Pin 9 selected */
  131. #define GPIO_Pin_10 ((uint16_t)0x0400) /*!< Pin 10 selected */
  132. #define GPIO_Pin_11 ((uint16_t)0x0800) /*!< Pin 11 selected */
  133. #define GPIO_Pin_12 ((uint16_t)0x1000) /*!< Pin 12 selected */
  134. #define GPIO_Pin_13 ((uint16_t)0x2000) /*!< Pin 13 selected */
  135. #define GPIO_Pin_14 ((uint16_t)0x4000) /*!< Pin 14 selected */
  136. #define GPIO_Pin_15 ((uint16_t)0x8000) /*!< Pin 15 selected */
  137. #define GPIO_Pin_All ((uint16_t)0xFFFF) /*!< All pins selected */
  138. #define IS_GPIO_PIN(PIN) ((PIN) != (uint16_t)0x00)
  139. #define IS_GET_GPIO_PIN(PIN) (((PIN) == GPIO_Pin_0) || \
  140. ((PIN) == GPIO_Pin_1) || \
  141. ((PIN) == GPIO_Pin_2) || \
  142. ((PIN) == GPIO_Pin_3) || \
  143. ((PIN) == GPIO_Pin_4) || \
  144. ((PIN) == GPIO_Pin_5) || \
  145. ((PIN) == GPIO_Pin_6) || \
  146. ((PIN) == GPIO_Pin_7) || \
  147. ((PIN) == GPIO_Pin_8) || \
  148. ((PIN) == GPIO_Pin_9) || \
  149. ((PIN) == GPIO_Pin_10) || \
  150. ((PIN) == GPIO_Pin_11) || \
  151. ((PIN) == GPIO_Pin_12) || \
  152. ((PIN) == GPIO_Pin_13) || \
  153. ((PIN) == GPIO_Pin_14) || \
  154. ((PIN) == GPIO_Pin_15))
  155. /**
  156. * @}
  157. */
  158. /** @defgroup GPIO_Pin_sources
  159. * @{
  160. */
  161. #define GPIO_PinSource0 ((uint8_t)0x00)
  162. #define GPIO_PinSource1 ((uint8_t)0x01)
  163. #define GPIO_PinSource2 ((uint8_t)0x02)
  164. #define GPIO_PinSource3 ((uint8_t)0x03)
  165. #define GPIO_PinSource4 ((uint8_t)0x04)
  166. #define GPIO_PinSource5 ((uint8_t)0x05)
  167. #define GPIO_PinSource6 ((uint8_t)0x06)
  168. #define GPIO_PinSource7 ((uint8_t)0x07)
  169. #define GPIO_PinSource8 ((uint8_t)0x08)
  170. #define GPIO_PinSource9 ((uint8_t)0x09)
  171. #define GPIO_PinSource10 ((uint8_t)0x0A)
  172. #define GPIO_PinSource11 ((uint8_t)0x0B)
  173. #define GPIO_PinSource12 ((uint8_t)0x0C)
  174. #define GPIO_PinSource13 ((uint8_t)0x0D)
  175. #define GPIO_PinSource14 ((uint8_t)0x0E)
  176. #define GPIO_PinSource15 ((uint8_t)0x0F)
  177. #define IS_GPIO_PIN_SOURCE(PINSOURCE) (((PINSOURCE) == GPIO_PinSource0) || \
  178. ((PINSOURCE) == GPIO_PinSource1) || \
  179. ((PINSOURCE) == GPIO_PinSource2) || \
  180. ((PINSOURCE) == GPIO_PinSource3) || \
  181. ((PINSOURCE) == GPIO_PinSource4) || \
  182. ((PINSOURCE) == GPIO_PinSource5) || \
  183. ((PINSOURCE) == GPIO_PinSource6) || \
  184. ((PINSOURCE) == GPIO_PinSource7) || \
  185. ((PINSOURCE) == GPIO_PinSource8) || \
  186. ((PINSOURCE) == GPIO_PinSource9) || \
  187. ((PINSOURCE) == GPIO_PinSource10) || \
  188. ((PINSOURCE) == GPIO_PinSource11) || \
  189. ((PINSOURCE) == GPIO_PinSource12) || \
  190. ((PINSOURCE) == GPIO_PinSource13) || \
  191. ((PINSOURCE) == GPIO_PinSource14) || \
  192. ((PINSOURCE) == GPIO_PinSource15))
  193. /**
  194. * @}
  195. */
  196. /** @defgroup GPIO_Alternate_function_selection_define
  197. * @{
  198. */
  199. /**
  200. * @brief AF 0 selection
  201. */
  202. #define GPIO_AF_0 ((uint8_t)0x00) /* WKUP, EVENTOUT, TIM15, SPI1, TIM17,
  203. MCO, SWDAT, SWCLK, TIM14, BOOT,
  204. USART1, CEC, IR_OUT, SPI2, TS, TIM3,
  205. USART4, CAN, TIM3, USART2, USART3,
  206. CRS, TIM16, TIM1 */
  207. /**
  208. * @brief AF 1 selection
  209. */
  210. #define GPIO_AF_1 ((uint8_t)0x01) /* USART2, CEC, TIM3, USART1, IR,
  211. EVENTOUT, I2C1, I2C2, TIM15, SPI2,
  212. USART3, TS, SPI1 */
  213. /**
  214. * @brief AF 2 selection
  215. */
  216. #define GPIO_AF_2 ((uint8_t)0x02) /* TIM2, TIM1, EVENTOUT, TIM16, TIM17,
  217. USB */
  218. /**
  219. * @brief AF 3 selection
  220. */
  221. #define GPIO_AF_3 ((uint8_t)0x03) /* TS, I2C1, TIM15, EVENTOUT */
  222. /**
  223. * @brief AF 4 selection
  224. */
  225. #define GPIO_AF_4 ((uint8_t)0x04) /* TIM14, USART4, USART3, CRS, CAN,
  226. I2C1 */
  227. /**
  228. * @brief AF 5 selection
  229. */
  230. #define GPIO_AF_5 ((uint8_t)0x05) /* TIM16, TIM17, TIM15, SPI2, I2C2,
  231. MCO, I2C1, USB */
  232. /**
  233. * @brief AF 6 selection
  234. */
  235. #define GPIO_AF_6 ((uint8_t)0x06) /* EVENTOUT */
  236. /**
  237. * @brief AF 7 selection
  238. */
  239. #define GPIO_AF_7 ((uint8_t)0x07) /* COMP1 OUT and COMP2 OUT */
  240. #define IS_GPIO_AF(AF) (((AF) == GPIO_AF_0) || ((AF) == GPIO_AF_1) || \
  241. ((AF) == GPIO_AF_2) || ((AF) == GPIO_AF_3) || \
  242. ((AF) == GPIO_AF_4) || ((AF) == GPIO_AF_5) || \
  243. ((AF) == GPIO_AF_6) || ((AF) == GPIO_AF_7))
  244. /**
  245. * @}
  246. */
  247. /** @defgroup GPIO_Speed_Legacy
  248. * @{
  249. */
  250. #define GPIO_Speed_2MHz GPIO_Speed_Level_1 /*!< I/O output speed: Low 2 MHz */
  251. #define GPIO_Speed_10MHz GPIO_Speed_Level_2 /*!< I/O output speed: Medium 10 MHz */
  252. #define GPIO_Speed_50MHz GPIO_Speed_Level_3 /*!< I/O output speed: High 50 MHz */
  253. /** @defgroup GPIO_LEDM Only Use in GPIOA and GPIOB
  254. * @}
  255. */
  256. #define GPIO_LEDM_0 ((uint32_t)(0x00000001))
  257. #define GPIO_LEDM_1 ((uint32_t)(0x00000002))
  258. #define GPIO_LEDM_3 ((uint32_t)(0x00000008))
  259. #define GPIO_LEDM_4 ((uint32_t)(0x00000010))
  260. #define GPIO_LEDM_5 ((uint32_t)(0x00000020))
  261. #define GPIO_LEDM_6 ((uint32_t)(0x00000040))
  262. #define GPIO_LEDM_7 ((uint32_t)(0x00000080))
  263. #define GPIO_LEDM_8 ((uint32_t)(0x00000100))
  264. #define GPIO_LEDM_9 ((uint32_t)(0x00000200))
  265. #define GPIO_LEDM_10 ((uint32_t)(0x00000400))
  266. #define GPIO_LEDM_13 ((uint32_t)(0x00002000))
  267. #define GPIO_LEDM_14 ((uint32_t)(0x00004000))
  268. #define GPIO_LEDM_15 ((uint32_t)(0x00008000))
  269. #define IS_GPIO_LEDM(LEDM) (((LEDM) == GPIO_LEDM_0) ||\
  270. ((LEDM) == GPIO_LEDM_1) ||\
  271. ((LEDM) == GPIO_LEDM_3) ||\
  272. ((LEDM) == GPIO_LEDM_4) ||\
  273. ((LEDM) == GPIO_LEDM_5) ||\
  274. ((LEDM) == GPIO_LEDM_6) ||\
  275. ((LEDM) == GPIO_LEDM_7) ||\
  276. ((LEDM) == GPIO_LEDM_8) ||\
  277. ((LEDM) == GPIO_LEDM_9) ||\
  278. ((LEDM) == GPIO_LEDM_10) ||\
  279. ((LEDM) == GPIO_LEDM_13) ||\
  280. ((LEDM) == GPIO_LEDM_14) ||\
  281. ((LEDM) == GPIO_LEDM_15))
  282. /**
  283. * @}
  284. */
  285. /* Exported macro ------------------------------------------------------------*/
  286. /* Exported functions ------------------------------------------------------- */
  287. /* Function used to set the GPIO configuration to the default reset state *****/
  288. void GPIO_DeInit(GPIO_TypeDef* GPIOx);
  289. /* Initialization and Configuration functions *********************************/
  290. void GPIO_Init(GPIO_TypeDef* GPIOx, GPIO_InitTypeDef* GPIO_InitStruct);
  291. void GPIO_StructInit(GPIO_InitTypeDef* GPIO_InitStruct);
  292. void GPIO_PinLockConfig(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin);
  293. /* GPIO Read and Write functions **********************************************/
  294. uint8_t GPIO_ReadInputDataBit(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin);
  295. uint16_t GPIO_ReadInputData(GPIO_TypeDef* GPIOx);
  296. uint8_t GPIO_ReadOutputDataBit(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin);
  297. uint16_t GPIO_ReadOutputData(GPIO_TypeDef* GPIOx);
  298. void GPIO_SetBits(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin);
  299. void GPIO_ResetBits(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin);
  300. void GPIO_WriteBit(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin, BitAction BitVal);
  301. void GPIO_Write(GPIO_TypeDef* GPIOx, uint16_t PortVal);
  302. /* GPIO Alternate functions configuration functions ***************************/
  303. void GPIO_PinAFConfig(GPIO_TypeDef* GPIOx, uint16_t GPIO_PinSource, uint8_t GPIO_AF);
  304. /*GPIO LED*/
  305. void GPIO_LedmConfig(GPIO_TypeDef* GPIOx, uint16_t GPIO_LEDMx);
  306. #ifdef __cplusplus
  307. }
  308. #endif
  309. #endif /* __FT32F0XX_GPIO_H */
  310. /**
  311. * @}
  312. */
  313. /**
  314. * @}
  315. */
  316. /************************ (C) COPYRIGHT FMD *****END OF FILE****/