PageRenderTime 45ms CodeModel.GetById 15ms RepoModel.GetById 0ms app.codeStats 0ms

/SYS_V1.34/FWLib/inc/stm32f10x_gpio.h

https://github.com/fredcooke/DSOQuad_SourceCode
C Header | 237 lines | 184 code | 23 blank | 30 comment | 169 complexity | 2ffaa740aaf5e97229e7b889cc1de9fc MD5 | raw file
  1. /******************** (C) COPYRIGHT 2008 STMicroelectronics ********************
  2. * File Name : stm32f10x_gpio.h
  3. * Author : MCD Application Team
  4. * Version : V2.0.3
  5. * Date : 09/22/2008
  6. * Description : This file contains all the functions prototypes for the
  7. * GPIO firmware library.
  8. ********************************************************************************
  9. * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
  10. * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE TIME.
  11. * AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY DIRECT,
  12. * INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING FROM THE
  13. * CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING
  14. * INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
  15. *******************************************************************************/
  16. /* Define to prevent recursive inclusion -------------------------------------*/
  17. #ifndef __STM32F10x_GPIO_H
  18. #define __STM32F10x_GPIO_H
  19. /* Includes ------------------------------------------------------------------*/
  20. #include "stm32f10x_map.h"
  21. /* Exported types ------------------------------------------------------------*/
  22. #define IS_GPIO_ALL_PERIPH(PERIPH) (((*(u32*)&(PERIPH)) == GPIOA_BASE) || \
  23. ((*(u32*)&(PERIPH)) == GPIOB_BASE) || \
  24. ((*(u32*)&(PERIPH)) == GPIOC_BASE) || \
  25. ((*(u32*)&(PERIPH)) == GPIOD_BASE) || \
  26. ((*(u32*)&(PERIPH)) == GPIOE_BASE) || \
  27. ((*(u32*)&(PERIPH)) == GPIOF_BASE) || \
  28. ((*(u32*)&(PERIPH)) == GPIOG_BASE))
  29. /* Output Maximum frequency selection ----------------------------------------*/
  30. typedef enum
  31. {
  32. GPIO_Speed_10MHz = 1,
  33. GPIO_Speed_2MHz,
  34. GPIO_Speed_50MHz
  35. }GPIOSpeed_TypeDef;
  36. #define IS_GPIO_SPEED(SPEED) (((SPEED) == GPIO_Speed_10MHz) || ((SPEED) == GPIO_Speed_2MHz) || \
  37. ((SPEED) == GPIO_Speed_50MHz))
  38. /* Configuration Mode enumeration --------------------------------------------*/
  39. typedef enum
  40. { GPIO_Mode_AIN = 0x0,
  41. GPIO_Mode_IN_FLOATING = 0x04,
  42. GPIO_Mode_IPD = 0x28,
  43. GPIO_Mode_IPU = 0x48,
  44. GPIO_Mode_Out_OD = 0x14,
  45. GPIO_Mode_Out_PP = 0x10,
  46. GPIO_Mode_AF_OD = 0x1C,
  47. GPIO_Mode_AF_PP = 0x18
  48. }GPIOMode_TypeDef;
  49. #define IS_GPIO_MODE(MODE) (((MODE) == GPIO_Mode_AIN) || ((MODE) == GPIO_Mode_IN_FLOATING) || \
  50. ((MODE) == GPIO_Mode_IPD) || ((MODE) == GPIO_Mode_IPU) || \
  51. ((MODE) == GPIO_Mode_Out_OD) || ((MODE) == GPIO_Mode_Out_PP) || \
  52. ((MODE) == GPIO_Mode_AF_OD) || ((MODE) == GPIO_Mode_AF_PP))
  53. /* GPIO Init structure definition */
  54. typedef struct
  55. {
  56. u16 GPIO_Pin;
  57. GPIOSpeed_TypeDef GPIO_Speed;
  58. GPIOMode_TypeDef GPIO_Mode;
  59. }GPIO_InitTypeDef;
  60. /* Bit_SET and Bit_RESET enumeration -----------------------------------------*/
  61. typedef enum
  62. { Bit_RESET = 0,
  63. Bit_SET
  64. }BitAction;
  65. #define IS_GPIO_BIT_ACTION(ACTION) (((ACTION) == Bit_RESET) || ((ACTION) == Bit_SET))
  66. /* Exported constants --------------------------------------------------------*/
  67. /* GPIO pins define ----------------------------------------------------------*/
  68. #define GPIO_Pin_0 ((u16)0x0001) /* Pin 0 selected */
  69. #define GPIO_Pin_1 ((u16)0x0002) /* Pin 1 selected */
  70. #define GPIO_Pin_2 ((u16)0x0004) /* Pin 2 selected */
  71. #define GPIO_Pin_3 ((u16)0x0008) /* Pin 3 selected */
  72. #define GPIO_Pin_4 ((u16)0x0010) /* Pin 4 selected */
  73. #define GPIO_Pin_5 ((u16)0x0020) /* Pin 5 selected */
  74. #define GPIO_Pin_6 ((u16)0x0040) /* Pin 6 selected */
  75. #define GPIO_Pin_7 ((u16)0x0080) /* Pin 7 selected */
  76. #define GPIO_Pin_8 ((u16)0x0100) /* Pin 8 selected */
  77. #define GPIO_Pin_9 ((u16)0x0200) /* Pin 9 selected */
  78. #define GPIO_Pin_10 ((u16)0x0400) /* Pin 10 selected */
  79. #define GPIO_Pin_11 ((u16)0x0800) /* Pin 11 selected */
  80. #define GPIO_Pin_12 ((u16)0x1000) /* Pin 12 selected */
  81. #define GPIO_Pin_13 ((u16)0x2000) /* Pin 13 selected */
  82. #define GPIO_Pin_14 ((u16)0x4000) /* Pin 14 selected */
  83. #define GPIO_Pin_15 ((u16)0x8000) /* Pin 15 selected */
  84. #define GPIO_Pin_All ((u16)0xFFFF) /* All pins selected */
  85. #define IS_GPIO_PIN(PIN) ((((PIN) & (u16)0x00) == 0x00) && ((PIN) != (u16)0x00))
  86. #define IS_GET_GPIO_PIN(PIN) (((PIN) == GPIO_Pin_0) || \
  87. ((PIN) == GPIO_Pin_1) || \
  88. ((PIN) == GPIO_Pin_2) || \
  89. ((PIN) == GPIO_Pin_3) || \
  90. ((PIN) == GPIO_Pin_4) || \
  91. ((PIN) == GPIO_Pin_5) || \
  92. ((PIN) == GPIO_Pin_6) || \
  93. ((PIN) == GPIO_Pin_7) || \
  94. ((PIN) == GPIO_Pin_8) || \
  95. ((PIN) == GPIO_Pin_9) || \
  96. ((PIN) == GPIO_Pin_10) || \
  97. ((PIN) == GPIO_Pin_11) || \
  98. ((PIN) == GPIO_Pin_12) || \
  99. ((PIN) == GPIO_Pin_13) || \
  100. ((PIN) == GPIO_Pin_14) || \
  101. ((PIN) == GPIO_Pin_15))
  102. /* GPIO Remap define ---------------------------------------------------------*/
  103. #define GPIO_Remap_SPI1 ((u32)0x00000001) /* SPI1 Alternate Function mapping */
  104. #define GPIO_Remap_I2C1 ((u32)0x00000002) /* I2C1 Alternate Function mapping */
  105. #define GPIO_Remap_USART1 ((u32)0x00000004) /* USART1 Alternate Function mapping */
  106. #define GPIO_Remap_USART2 ((u32)0x00000008) /* USART2 Alternate Function mapping */
  107. #define GPIO_PartialRemap_USART3 ((u32)0x00140010) /* USART3 Partial Alternate Function mapping */
  108. #define GPIO_FullRemap_USART3 ((u32)0x00140030) /* USART3 Full Alternate Function mapping */
  109. #define GPIO_PartialRemap_TIM1 ((u32)0x00160040) /* TIM1 Partial Alternate Function mapping */
  110. #define GPIO_FullRemap_TIM1 ((u32)0x001600C0) /* TIM1 Full Alternate Function mapping */
  111. #define GPIO_PartialRemap1_TIM2 ((u32)0x00180100) /* TIM2 Partial1 Alternate Function mapping */
  112. #define GPIO_PartialRemap2_TIM2 ((u32)0x00180200) /* TIM2 Partial2 Alternate Function mapping */
  113. #define GPIO_FullRemap_TIM2 ((u32)0x00180300) /* TIM2 Full Alternate Function mapping */
  114. #define GPIO_PartialRemap_TIM3 ((u32)0x001A0800) /* TIM3 Partial Alternate Function mapping */
  115. #define GPIO_FullRemap_TIM3 ((u32)0x001A0C00) /* TIM3 Full Alternate Function mapping */
  116. #define GPIO_Remap_TIM4 ((u32)0x00001000) /* TIM4 Alternate Function mapping */
  117. #define GPIO_Remap1_CAN ((u32)0x001D4000) /* CAN Alternate Function mapping */
  118. #define GPIO_Remap2_CAN ((u32)0x001D6000) /* CAN Alternate Function mapping */
  119. #define GPIO_Remap_PD01 ((u32)0x00008000) /* PD01 Alternate Function mapping */
  120. #define GPIO_Remap_TIM5CH4_LSI ((u32)0x00200001) /* LSI connected to TIM5 Channel4 input capture for calibration */
  121. #define GPIO_Remap_ADC1_ETRGINJ ((u32)0x00200002) /* ADC1 External Trigger Injected Conversion remapping */
  122. #define GPIO_Remap_ADC1_ETRGREG ((u32)0x00200004) /* ADC1 External Trigger Regular Conversion remapping */
  123. #define GPIO_Remap_ADC2_ETRGINJ ((u32)0x00200008) /* ADC2 External Trigger Injected Conversion remapping */
  124. #define GPIO_Remap_ADC2_ETRGREG ((u32)0x00200010) /* ADC2 External Trigger Regular Conversion remapping */
  125. #define GPIO_Remap_SWJ_NoJTRST ((u32)0x00300100) /* Full SWJ Enabled (JTAG-DP + SW-DP) but without JTRST */
  126. #define GPIO_Remap_SWJ_JTAGDisable ((u32)0x00300200) /* JTAG-DP Disabled and SW-DP Enabled */
  127. #define GPIO_Remap_SWJ_Disable ((u32)0x00300400) /* Full SWJ Disabled (JTAG-DP + SW-DP) */
  128. #define IS_GPIO_REMAP(REMAP) (((REMAP) == GPIO_Remap_SPI1) || ((REMAP) == GPIO_Remap_I2C1) || \
  129. ((REMAP) == GPIO_Remap_USART1) || ((REMAP) == GPIO_Remap_USART2) || \
  130. ((REMAP) == GPIO_PartialRemap_USART3) || ((REMAP) == GPIO_FullRemap_USART3) || \
  131. ((REMAP) == GPIO_PartialRemap_TIM1) || ((REMAP) == GPIO_FullRemap_TIM1) || \
  132. ((REMAP) == GPIO_PartialRemap1_TIM2) || ((REMAP) == GPIO_PartialRemap2_TIM2) || \
  133. ((REMAP) == GPIO_FullRemap_TIM2) || ((REMAP) == GPIO_PartialRemap_TIM3) || \
  134. ((REMAP) == GPIO_FullRemap_TIM3) || ((REMAP) == GPIO_Remap_TIM4) || \
  135. ((REMAP) == GPIO_Remap1_CAN) || ((REMAP) == GPIO_Remap2_CAN) || \
  136. ((REMAP) == GPIO_Remap_PD01) || ((REMAP) == GPIO_Remap_TIM5CH4_LSI) || \
  137. ((REMAP) == GPIO_Remap_ADC1_ETRGINJ) ||((REMAP) == GPIO_Remap_ADC1_ETRGREG) || \
  138. ((REMAP) == GPIO_Remap_ADC2_ETRGINJ) ||((REMAP) == GPIO_Remap_ADC2_ETRGREG) || \
  139. ((REMAP) == GPIO_Remap_SWJ_NoJTRST) || ((REMAP) == GPIO_Remap_SWJ_JTAGDisable)|| \
  140. ((REMAP) == GPIO_Remap_SWJ_Disable))
  141. /* GPIO Port Sources ---------------------------------------------------------*/
  142. #define GPIO_PortSourceGPIOA ((u8)0x00)
  143. #define GPIO_PortSourceGPIOB ((u8)0x01)
  144. #define GPIO_PortSourceGPIOC ((u8)0x02)
  145. #define GPIO_PortSourceGPIOD ((u8)0x03)
  146. #define GPIO_PortSourceGPIOE ((u8)0x04)
  147. #define GPIO_PortSourceGPIOF ((u8)0x05)
  148. #define GPIO_PortSourceGPIOG ((u8)0x06)
  149. #define IS_GPIO_EVENTOUT_PORT_SOURCE(PORTSOURCE) (((PORTSOURCE) == GPIO_PortSourceGPIOA) || \
  150. ((PORTSOURCE) == GPIO_PortSourceGPIOB) || \
  151. ((PORTSOURCE) == GPIO_PortSourceGPIOC) || \
  152. ((PORTSOURCE) == GPIO_PortSourceGPIOD) || \
  153. ((PORTSOURCE) == GPIO_PortSourceGPIOE))
  154. #define IS_GPIO_EXTI_PORT_SOURCE(PORTSOURCE) (((PORTSOURCE) == GPIO_PortSourceGPIOA) || \
  155. ((PORTSOURCE) == GPIO_PortSourceGPIOB) || \
  156. ((PORTSOURCE) == GPIO_PortSourceGPIOC) || \
  157. ((PORTSOURCE) == GPIO_PortSourceGPIOD) || \
  158. ((PORTSOURCE) == GPIO_PortSourceGPIOE) || \
  159. ((PORTSOURCE) == GPIO_PortSourceGPIOF) || \
  160. ((PORTSOURCE) == GPIO_PortSourceGPIOG))
  161. /* GPIO Pin sources ----------------------------------------------------------*/
  162. #define GPIO_PinSource0 ((u8)0x00)
  163. #define GPIO_PinSource1 ((u8)0x01)
  164. #define GPIO_PinSource2 ((u8)0x02)
  165. #define GPIO_PinSource3 ((u8)0x03)
  166. #define GPIO_PinSource4 ((u8)0x04)
  167. #define GPIO_PinSource5 ((u8)0x05)
  168. #define GPIO_PinSource6 ((u8)0x06)
  169. #define GPIO_PinSource7 ((u8)0x07)
  170. #define GPIO_PinSource8 ((u8)0x08)
  171. #define GPIO_PinSource9 ((u8)0x09)
  172. #define GPIO_PinSource10 ((u8)0x0A)
  173. #define GPIO_PinSource11 ((u8)0x0B)
  174. #define GPIO_PinSource12 ((u8)0x0C)
  175. #define GPIO_PinSource13 ((u8)0x0D)
  176. #define GPIO_PinSource14 ((u8)0x0E)
  177. #define GPIO_PinSource15 ((u8)0x0F)
  178. #define IS_GPIO_PIN_SOURCE(PINSOURCE) (((PINSOURCE) == GPIO_PinSource0) || \
  179. ((PINSOURCE) == GPIO_PinSource1) || \
  180. ((PINSOURCE) == GPIO_PinSource2) || \
  181. ((PINSOURCE) == GPIO_PinSource3) || \
  182. ((PINSOURCE) == GPIO_PinSource4) || \
  183. ((PINSOURCE) == GPIO_PinSource5) || \
  184. ((PINSOURCE) == GPIO_PinSource6) || \
  185. ((PINSOURCE) == GPIO_PinSource7) || \
  186. ((PINSOURCE) == GPIO_PinSource8) || \
  187. ((PINSOURCE) == GPIO_PinSource9) || \
  188. ((PINSOURCE) == GPIO_PinSource10) || \
  189. ((PINSOURCE) == GPIO_PinSource11) || \
  190. ((PINSOURCE) == GPIO_PinSource12) || \
  191. ((PINSOURCE) == GPIO_PinSource13) || \
  192. ((PINSOURCE) == GPIO_PinSource14) || \
  193. ((PINSOURCE) == GPIO_PinSource15))
  194. /* Exported macro ------------------------------------------------------------*/
  195. /* Exported functions ------------------------------------------------------- */
  196. void GPIO_DeInit(GPIO_TypeDef* GPIOx);
  197. void GPIO_AFIODeInit(void);
  198. void GPIO_Init(GPIO_TypeDef* GPIOx, GPIO_InitTypeDef* GPIO_InitStruct);
  199. void GPIO_StructInit(GPIO_InitTypeDef* GPIO_InitStruct);
  200. u8 GPIO_ReadInputDataBit(GPIO_TypeDef* GPIOx, u16 GPIO_Pin);
  201. u16 GPIO_ReadInputData(GPIO_TypeDef* GPIOx);
  202. u8 GPIO_ReadOutputDataBit(GPIO_TypeDef* GPIOx, u16 GPIO_Pin);
  203. u16 GPIO_ReadOutputData(GPIO_TypeDef* GPIOx);
  204. void GPIO_SetBits(GPIO_TypeDef* GPIOx, u16 GPIO_Pin);
  205. void GPIO_ResetBits(GPIO_TypeDef* GPIOx, u16 GPIO_Pin);
  206. void GPIO_WriteBit(GPIO_TypeDef* GPIOx, u16 GPIO_Pin, BitAction BitVal);
  207. void GPIO_Write(GPIO_TypeDef* GPIOx, u16 PortVal);
  208. void GPIO_PinLockConfig(GPIO_TypeDef* GPIOx, u16 GPIO_Pin);
  209. void GPIO_EventOutputConfig(u8 GPIO_PortSource, u8 GPIO_PinSource);
  210. void GPIO_EventOutputCmd(FunctionalState NewState);
  211. void GPIO_PinRemapConfig(u32 GPIO_Remap, FunctionalState NewState);
  212. void GPIO_EXTILineConfig(u8 GPIO_PortSource, u8 GPIO_PinSource);
  213. #endif /* __STM32F10x_GPIO_H */
  214. /******************* (C) COPYRIGHT 2008 STMicroelectronics *****END OF FILE****/