stm32f0xx_gpio.h 13 KB

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