HAL_gpio.h 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325
  1. /**
  2. ******************************************************************************
  3. * @file HAL_gpio.h
  4. * @author AE Team
  5. * @version V1.1.0
  6. * @date 28/08/2019
  7. * @brief This file contains all the functions prototypes for the GPIO
  8. * firmware library.
  9. ******************************************************************************
  10. * @copy
  11. *
  12. * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
  13. * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE
  14. * TIME. AS A RESULT, MindMotion SHALL NOT BE HELD LIABLE FOR ANY
  15. * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING
  16. * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE
  17. * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
  18. *
  19. * <h2><center>&copy; COPYRIGHT 2019 MindMotion</center></h2>
  20. */
  21. /* Define to prevent recursive inclusion -------------------------------------*/
  22. #ifndef __HAL_GPIO_H
  23. #define __HAL_GPIO_H
  24. /* Includes ------------------------------------------------------------------*/
  25. #include "HAL_device.h"
  26. /** @addtogroup StdPeriph_Driver
  27. * @{
  28. */
  29. /** @addtogroup GPIO
  30. * @{
  31. */
  32. /** @defgroup GPIO_Exported_Types
  33. * @{
  34. */
  35. #define IS_GPIO_ALL_PERIPH(PERIPH) (((*(uint32_t*)&(PERIPH)) == GPIOA_BASE) || \
  36. ((*(uint32_t*)&(PERIPH)) == GPIOB_BASE) || \
  37. ((*(uint32_t*)&(PERIPH)) == GPIOC_BASE) || \
  38. ((*(uint32_t*)&(PERIPH)) == GPIOD_BASE) || \
  39. ((*(uint32_t*)&(PERIPH)) == GPIOE_BASE) || \
  40. ((*(uint32_t*)&(PERIPH)) == GPIOF_BASE) || \
  41. ((*(uint32_t*)&(PERIPH)) == GPIOG_BASE))
  42. /**
  43. * @brief Output Maximum frequency selection
  44. */
  45. typedef enum
  46. {
  47. GPIO_Speed_10MHz = 1,
  48. GPIO_Speed_2MHz,
  49. GPIO_Speed_50MHz
  50. } GPIOSpeed_TypeDef;
  51. #define IS_GPIO_SPEED(SPEED) (((SPEED) == GPIO_Speed_10MHz) || ((SPEED) == GPIO_Speed_2MHz) || \
  52. ((SPEED) == GPIO_Speed_50MHz))
  53. /**
  54. * @brief Configuration Mode enumeration
  55. */
  56. typedef enum
  57. {
  58. GPIO_Mode_AIN = 0x0, //模拟输入
  59. GPIO_Mode_IN_FLOATING = 0x04, //浮空输入
  60. GPIO_Mode_IPD = 0x28, //下拉输入
  61. GPIO_Mode_IPU = 0x48, //上拉输入
  62. GPIO_Mode_Out_OD = 0x14,//通用开漏输出
  63. GPIO_Mode_Out_PP = 0x10,//通用推免输出
  64. GPIO_Mode_AF_OD = 0x1C, // 复用开漏输出
  65. GPIO_Mode_AF_PP = 0x18 //复用推免输出
  66. } GPIOMode_TypeDef;
  67. #define IS_GPIO_MODE(MODE) (((MODE) == GPIO_Mode_AIN) || ((MODE) == GPIO_Mode_IN_FLOATING) || \
  68. ((MODE) == GPIO_Mode_IPD) || ((MODE) == GPIO_Mode_IPU) || \
  69. ((MODE) == GPIO_Mode_Out_OD) || ((MODE) == GPIO_Mode_Out_PP) || \
  70. ((MODE) == GPIO_Mode_AF_OD) || ((MODE) == GPIO_Mode_AF_PP))
  71. /**
  72. * @brief GPIO Init structure definition
  73. */
  74. typedef struct
  75. {
  76. uint16_t GPIO_Pin;
  77. GPIOSpeed_TypeDef GPIO_Speed;
  78. GPIOMode_TypeDef GPIO_Mode;
  79. } GPIO_InitTypeDef;
  80. /**
  81. * @brief Bit_SET and Bit_RESET enumeration
  82. */
  83. typedef enum
  84. {
  85. Bit_RESET = 0,
  86. Bit_SET
  87. } BitAction;
  88. #define IS_GPIO_BIT_ACTION(ACTION) (((ACTION) == Bit_RESET) || ((ACTION) == Bit_SET))
  89. /**
  90. * @}
  91. */
  92. /** @defgroup GPIO_Exported_Constants
  93. * @{
  94. */
  95. /** @defgroup GPIO_pins_define
  96. * @{
  97. */
  98. #define GPIO_Pin_0 ((uint16_t)0x0001) /* Pin 0 selected */
  99. #define GPIO_Pin_1 ((uint16_t)0x0002) /* Pin 1 selected */
  100. #define GPIO_Pin_2 ((uint16_t)0x0004) /* Pin 2 selected */
  101. #define GPIO_Pin_3 ((uint16_t)0x0008) /* Pin 3 selected */
  102. #define GPIO_Pin_4 ((uint16_t)0x0010) /* Pin 4 selected */
  103. #define GPIO_Pin_5 ((uint16_t)0x0020) /* Pin 5 selected */
  104. #define GPIO_Pin_6 ((uint16_t)0x0040) /* Pin 6 selected */
  105. #define GPIO_Pin_7 ((uint16_t)0x0080) /* Pin 7 selected */
  106. #define GPIO_Pin_8 ((uint16_t)0x0100) /* Pin 8 selected */
  107. #define GPIO_Pin_9 ((uint16_t)0x0200) /* Pin 9 selected */
  108. #define GPIO_Pin_10 ((uint16_t)0x0400) /* Pin 10 selected */
  109. #define GPIO_Pin_11 ((uint16_t)0x0800) /* Pin 11 selected */
  110. #define GPIO_Pin_12 ((uint16_t)0x1000) /* Pin 12 selected */
  111. #define GPIO_Pin_13 ((uint16_t)0x2000) /* Pin 13 selected */
  112. #define GPIO_Pin_14 ((uint16_t)0x4000) /* Pin 14 selected */
  113. #define GPIO_Pin_15 ((uint16_t)0x8000) /* Pin 15 selected */
  114. #define GPIO_Pin_All ((uint16_t)0xFFFF) /* All pins selected */
  115. #define IS_GPIO_PIN(PIN) ((((PIN) & (uint16_t)0x00) == 0x00) && ((PIN) != (uint16_t)0x00))
  116. #define IS_GET_GPIO_PIN(PIN) (((PIN) == GPIO_Pin_0) || \
  117. ((PIN) == GPIO_Pin_1) || \
  118. ((PIN) == GPIO_Pin_2) || \
  119. ((PIN) == GPIO_Pin_3) || \
  120. ((PIN) == GPIO_Pin_4) || \
  121. ((PIN) == GPIO_Pin_5) || \
  122. ((PIN) == GPIO_Pin_6) || \
  123. ((PIN) == GPIO_Pin_7) || \
  124. ((PIN) == GPIO_Pin_8) || \
  125. ((PIN) == GPIO_Pin_9) || \
  126. ((PIN) == GPIO_Pin_10) || \
  127. ((PIN) == GPIO_Pin_11) || \
  128. ((PIN) == GPIO_Pin_12) || \
  129. ((PIN) == GPIO_Pin_13) || \
  130. ((PIN) == GPIO_Pin_14) || \
  131. ((PIN) == GPIO_Pin_15))
  132. /**
  133. * @}
  134. */
  135. /** @defgroup GPIO_Remap_define
  136. * @{
  137. */
  138. #define GPIO_Remap_SPI1 ((uint32_t)0x00000001) /* SPI1 Alternate Function mapping */
  139. #define GPIO_Remap_I2C1 ((uint32_t)0x00000002) /* I2C1 Alternate Function mapping */
  140. #define GPIO_Remap_UART1 ((uint32_t)0x00000004) /* UART1 Alternate Function mapping */
  141. #define GPIO_Remap_UART2 ((uint32_t)0x00000008) /* UART2 Alternate Function mapping */
  142. #define GPIO_PartialRemap_UART3 ((uint32_t)0x00140010) /* UART3 Partial Alternate Function mapping */
  143. #define GPIO_FullRemap_UART3 ((uint32_t)0x00140030) /* UART3 Full Alternate Function mapping */
  144. #define GPIO_PartialRemap_TIM1 ((uint32_t)0x00160040) /* TIM1 Partial Alternate Function mapping */
  145. #define GPIO_FullRemap_TIM1 ((uint32_t)0x001600C0) /* TIM1 Full Alternate Function mapping */
  146. #define GPIO_PartialRemap1_TIM2 ((uint32_t)0x00180100) /* TIM2 Partial1 Alternate Function mapping */
  147. #define GPIO_PartialRemap2_TIM2 ((uint32_t)0x00180200) /* TIM2 Partial2 Alternate Function mapping */
  148. #define GPIO_FullRemap_TIM2 ((uint32_t)0x00180300) /* TIM2 Full Alternate Function mapping */
  149. #define GPIO_PartialRemap_TIM3 ((uint32_t)0x001A0800) /* TIM3 Partial Alternate Function mapping */
  150. #define GPIO_FullRemap_TIM3 ((uint32_t)0x001A0C00) /* TIM3 Full Alternate Function mapping */
  151. #define GPIO_Remap_TIM4 ((uint32_t)0x00001000) /* TIM4 Alternate Function mapping */
  152. #define GPIO_Remap1_CAN1 ((uint32_t)0x001D4000) /* CAN Alternate Function mapping */
  153. #define GPIO_Remap2_CAN1 ((uint32_t)0x001D0000) /* CAN Alternate Function mapping */
  154. #define GPIO_Remap_PD01 ((uint32_t)0x00008000) /* PD01 Alternate Function mapping */
  155. #define GPIO_Remap_TIM5CH4_LSI ((uint32_t)0x00200001) /* LSI connected to TIM5 Channel4 input capture for calibration */
  156. #define GPIO_Remap_ADC1_ETRGINJ ((uint32_t)0x00200002) /* ADC1 External Trigger Injected Conversion remapping */
  157. #define GPIO_Remap_ADC1_ETRGREG ((uint32_t)0x00200004) /* ADC1 External Trigger Regular Conversion remapping */
  158. #define GPIO_Remap_ADC2_ETRGINJ ((uint32_t)0x00200008) /* ADC2 External Trigger Injected Conversion remapping */
  159. #define GPIO_Remap_ADC2_ETRGREG ((uint32_t)0x00200010) /* ADC2 External Trigger Regular Conversion remapping */
  160. #define GPIO_Remap_SWJ_NoJTRST ((uint32_t)0x00300100) /* Full SWJ Enabled (JTAG-DP + SW-DP) but without JTRST */
  161. #define GPIO_Remap_SWJ_JTAGDisable ((uint32_t)0x00300200) /* JTAG-DP Disabled and SW-DP Enabled */
  162. #define GPIO_Remap_SWJ_Disable ((uint32_t)0x00300400) /* Full SWJ Disabled (JTAG-DP + SW-DP) */
  163. #define IS_GPIO_REMAP(REMAP) (((REMAP) == GPIO_Remap_SPI1) || ((REMAP) == GPIO_Remap_I2C1) || \
  164. ((REMAP) == GPIO_Remap_UART1) || ((REMAP) == GPIO_Remap_UART2) || \
  165. ((REMAP) == GPIO_PartialRemap_UART3) || ((REMAP) == GPIO_FullRemap_UART3) || \
  166. ((REMAP) == GPIO_PartialRemap_TIM1) || ((REMAP) == GPIO_FullRemap_TIM1) || \
  167. ((REMAP) == GPIO_PartialRemap1_TIM2) || ((REMAP) == GPIO_PartialRemap2_TIM2) || \
  168. ((REMAP) == GPIO_FullRemap_TIM2) || ((REMAP) == GPIO_PartialRemap_TIM3) || \
  169. ((REMAP) == GPIO_FullRemap_TIM3) || ((REMAP) == GPIO_Remap_TIM4) || \
  170. ((REMAP) == GPIO_Remap1_CAN1) || ((REMAP) == GPIO_Remap2_CAN1) || \
  171. ((REMAP) == GPIO_Remap_PD01) || ((REMAP) == GPIO_Remap_TIM5CH4_LSI) || \
  172. ((REMAP) == GPIO_Remap_ADC1_ETRGINJ) ||((REMAP) == GPIO_Remap_ADC1_ETRGREG) || \
  173. ((REMAP) == GPIO_Remap_ADC2_ETRGINJ) ||((REMAP) == GPIO_Remap_ADC2_ETRGREG) || \
  174. ((REMAP) == GPIO_Remap_SWJ_NoJTRST) || ((REMAP) == GPIO_Remap_SWJ_JTAGDisable)|| \
  175. ((REMAP) == GPIO_Remap_SWJ_Disable))
  176. /**
  177. * @}
  178. */
  179. /** @defgroup GPIO_Port_Sources
  180. * @{
  181. */
  182. #define GPIO_PortSourceGPIOA ((uint8_t)0x00)
  183. #define GPIO_PortSourceGPIOB ((uint8_t)0x01)
  184. #define GPIO_PortSourceGPIOC ((uint8_t)0x02)
  185. #define GPIO_PortSourceGPIOD ((uint8_t)0x03)
  186. #define GPIO_PortSourceGPIOE ((uint8_t)0x04)
  187. #define GPIO_PortSourceGPIOF ((uint8_t)0x05)
  188. #define GPIO_PortSourceGPIOG ((uint8_t)0x06)
  189. #define IS_GPIO_EVENTOUT_PORT_SOURCE(PORTSOURCE) (((PORTSOURCE) == GPIO_PortSourceGPIOA) || \
  190. ((PORTSOURCE) == GPIO_PortSourceGPIOB) || \
  191. ((PORTSOURCE) == GPIO_PortSourceGPIOC) || \
  192. ((PORTSOURCE) == GPIO_PortSourceGPIOD) || \
  193. ((PORTSOURCE) == GPIO_PortSourceGPIOE))
  194. #define IS_GPIO_EXTI_PORT_SOURCE(PORTSOURCE) (((PORTSOURCE) == GPIO_PortSourceGPIOA) || \
  195. ((PORTSOURCE) == GPIO_PortSourceGPIOB) || \
  196. ((PORTSOURCE) == GPIO_PortSourceGPIOC) || \
  197. ((PORTSOURCE) == GPIO_PortSourceGPIOD) || \
  198. ((PORTSOURCE) == GPIO_PortSourceGPIOE) || \
  199. ((PORTSOURCE) == GPIO_PortSourceGPIOF) || \
  200. ((PORTSOURCE) == GPIO_PortSourceGPIOG))
  201. /**
  202. * @}
  203. */
  204. /** @defgroup GPIO_Pin_sources
  205. * @{
  206. */
  207. #define GPIO_PinSource0 ((uint8_t)0x00)
  208. #define GPIO_PinSource1 ((uint8_t)0x01)
  209. #define GPIO_PinSource2 ((uint8_t)0x02)
  210. #define GPIO_PinSource3 ((uint8_t)0x03)
  211. #define GPIO_PinSource4 ((uint8_t)0x04)
  212. #define GPIO_PinSource5 ((uint8_t)0x05)
  213. #define GPIO_PinSource6 ((uint8_t)0x06)
  214. #define GPIO_PinSource7 ((uint8_t)0x07)
  215. #define GPIO_PinSource8 ((uint8_t)0x08)
  216. #define GPIO_PinSource9 ((uint8_t)0x09)
  217. #define GPIO_PinSource10 ((uint8_t)0x0A)
  218. #define GPIO_PinSource11 ((uint8_t)0x0B)
  219. #define GPIO_PinSource12 ((uint8_t)0x0C)
  220. #define GPIO_PinSource13 ((uint8_t)0x0D)
  221. #define GPIO_PinSource14 ((uint8_t)0x0E)
  222. #define GPIO_PinSource15 ((uint8_t)0x0F)
  223. #define IS_GPIO_PIN_SOURCE(PINSOURCE) (((PINSOURCE) == GPIO_PinSource0) || \
  224. ((PINSOURCE) == GPIO_PinSource1) || \
  225. ((PINSOURCE) == GPIO_PinSource2) || \
  226. ((PINSOURCE) == GPIO_PinSource3) || \
  227. ((PINSOURCE) == GPIO_PinSource4) || \
  228. ((PINSOURCE) == GPIO_PinSource5) || \
  229. ((PINSOURCE) == GPIO_PinSource6) || \
  230. ((PINSOURCE) == GPIO_PinSource7) || \
  231. ((PINSOURCE) == GPIO_PinSource8) || \
  232. ((PINSOURCE) == GPIO_PinSource9) || \
  233. ((PINSOURCE) == GPIO_PinSource10) || \
  234. ((PINSOURCE) == GPIO_PinSource11) || \
  235. ((PINSOURCE) == GPIO_PinSource12) || \
  236. ((PINSOURCE) == GPIO_PinSource13) || \
  237. ((PINSOURCE) == GPIO_PinSource14) || \
  238. ((PINSOURCE) == GPIO_PinSource15))
  239. /**
  240. * @}
  241. */
  242. /**
  243. * @}
  244. */
  245. /** @defgroup GPIO_Exported_Macros
  246. * @{
  247. */
  248. /**
  249. * @}
  250. */
  251. /** @defgroup GPIO_Exported_Functions
  252. * @{
  253. */
  254. void GPIO_DeInit(GPIO_TypeDef* GPIOx);
  255. void GPIO_AFIODeInit(void);
  256. void GPIO_Init(GPIO_TypeDef* GPIOx, GPIO_InitTypeDef* GPIO_InitStruct);
  257. void GPIO_StructInit(GPIO_InitTypeDef* GPIO_InitStruct);
  258. uint8_t GPIO_ReadInputDataBit(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin);
  259. uint16_t GPIO_ReadInputData(GPIO_TypeDef* GPIOx);
  260. uint8_t GPIO_ReadOutputDataBit(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin);
  261. uint16_t GPIO_ReadOutputData(GPIO_TypeDef* GPIOx);
  262. void GPIO_SetBits(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin);
  263. void GPIO_ResetBits(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin);
  264. void GPIO_WriteBit(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin, BitAction BitVal);
  265. void GPIO_Write(GPIO_TypeDef* GPIOx, uint16_t PortVal);
  266. void GPIO_PinLockConfig(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin);
  267. void GPIO_EventOutputConfig(uint8_t GPIO_PortSource, uint8_t GPIO_PinSource);
  268. void GPIO_EventOutputCmd(FunctionalState NewState);
  269. void GPIO_PinRemapConfig(uint32_t GPIO_Remap, FunctionalState NewState);
  270. void GPIO_EXTILineConfig(uint8_t GPIO_PortSource, uint8_t GPIO_PinSource);
  271. #endif /* __HAL_GPIO_H */
  272. /**
  273. * @}
  274. */
  275. /**
  276. * @}
  277. */
  278. /**
  279. * @}
  280. */
  281. /*-------------------------(C) COPYRIGHT 2019 MindMotion ----------------------*/