stm32f0xx_gpio.h 13 KB

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