com_gpio.h 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. #ifndef __COM_GPIO_H__
  2. #define __COM_GPIO_H__
  3. #ifndef uint8_t
  4. #define uint8_t unsigned char
  5. #endif
  6. #ifndef uint16_t
  7. #define uint16_t unsigned short
  8. #endif
  9. #ifndef uint32_t
  10. #define uint32_t unsigned long
  11. #endif
  12. /* Exported types ------------------------------------------------------------*/
  13. /** @defgroup GPIO_Exported_Types GPIO Exported Types
  14. * @{
  15. */
  16. /**
  17. * @brief GPIO Init structure definition
  18. */
  19. typedef struct
  20. {
  21. uint32_t Pin; /*!< Specifies the GPIO pins to be configured.
  22. This parameter can be any value of @ref GPIO_pins_define */
  23. uint32_t Mode; /*!< Specifies the operating mode for the selected pins.
  24. This parameter can be a value of @ref GPIO_mode_define */
  25. uint32_t Pull; /*!< Specifies the Pull-up or Pull-Down activation for the selected pins.
  26. This parameter can be a value of @ref GPIO_pull_define */
  27. uint32_t Speed; /*!< Specifies the speed for the selected pins.
  28. This parameter can be a value of @ref GPIO_speed_define */
  29. uint32_t Alternate; /*!< Peripheral to be connected to the selected pins.
  30. This parameter can be a value of @ref GPIO_Alternate_function_selection */
  31. }GPIO_InitTypeDef;
  32. /**
  33. * @brief GPIO Bit SET and Bit RESET enumeration
  34. */
  35. typedef enum
  36. {
  37. GPIO_PIN_RESET = 0,
  38. GPIO_PIN_SET
  39. }GPIO_PinState;
  40. /**
  41. * @}
  42. */
  43. /* Exported constants --------------------------------------------------------*/
  44. /** @defgroup GPIO_Exported_Constants GPIO Exported Constants
  45. * @{
  46. */
  47. /** @defgroup GPIO_pins_define GPIO pins define
  48. * @{
  49. */
  50. #define GPIO_PIN_0 ((uint16_t)0x0001) /* Pin 0 selected */
  51. #define GPIO_PIN_1 ((uint16_t)0x0002) /* Pin 1 selected */
  52. #define GPIO_PIN_2 ((uint16_t)0x0004) /* Pin 2 selected */
  53. #define GPIO_PIN_3 ((uint16_t)0x0008) /* Pin 3 selected */
  54. #define GPIO_PIN_4 ((uint16_t)0x0010) /* Pin 4 selected */
  55. #define GPIO_PIN_5 ((uint16_t)0x0020) /* Pin 5 selected */
  56. #define GPIO_PIN_6 ((uint16_t)0x0040) /* Pin 6 selected */
  57. #define GPIO_PIN_7 ((uint16_t)0x0080) /* Pin 7 selected */
  58. #define GPIO_PIN_8 ((uint16_t)0x0100) /* Pin 8 selected */
  59. #define GPIO_PIN_9 ((uint16_t)0x0200) /* Pin 9 selected */
  60. #define GPIO_PIN_10 ((uint16_t)0x0400) /* Pin 10 selected */
  61. #define GPIO_PIN_11 ((uint16_t)0x0800) /* Pin 11 selected */
  62. #define GPIO_PIN_12 ((uint16_t)0x1000) /* Pin 12 selected */
  63. #define GPIO_PIN_13 ((uint16_t)0x2000) /* Pin 13 selected */
  64. #define GPIO_PIN_14 ((uint16_t)0x4000) /* Pin 14 selected */
  65. #define GPIO_PIN_15 ((uint16_t)0x8000) /* Pin 15 selected */
  66. #define GPIO_PIN_All ((uint16_t)0xFFFF) /* All pins selected */
  67. #define GPIO_PIN_MASK 0x0000FFFFU /* PIN mask for assert test */
  68. /**
  69. * @}
  70. */
  71. /** @defgroup GPIO_mode_define GPIO mode define
  72. * @brief GPIO Configuration Mode
  73. * Elements values convention: 0xX0yz00YZ
  74. * - X : GPIO mode or EXTI Mode
  75. * - y : External IT or Event trigger detection
  76. * - z : IO configuration on External IT or Event
  77. * - Y : Output type (Push Pull or Open Drain)
  78. * - Z : IO Direction mode (Input, Output, Alternate or Analog)
  79. * @{
  80. */
  81. #define GPIO_MODE_INPUT 0x00000000U /*!< Input Floating Mode */
  82. #define GPIO_MODE_OUTPUT_PP 0x00000001U /*!< Output Push Pull Mode */
  83. #define GPIO_MODE_OUTPUT_OD 0x00000011U /*!< Output Open Drain Mode */
  84. #define GPIO_MODE_AF_PP 0x00000002U /*!< Alternate Function Push Pull Mode */
  85. #define GPIO_MODE_AF_OD 0x00000012U /*!< Alternate Function Open Drain Mode */
  86. #define GPIO_MODE_ANALOG 0x00000003U /*!< Analog Mode */
  87. #define GPIO_MODE_IT_RISING 0x10110000U /*!< External Interrupt Mode with Rising edge trigger detection */
  88. #define GPIO_MODE_IT_FALLING 0x10210000U /*!< External Interrupt Mode with Falling edge trigger detection */
  89. #define GPIO_MODE_IT_RISING_FALLING 0x10310000U /*!< External Interrupt Mode with Rising/Falling edge trigger detection */
  90. #define GPIO_MODE_EVT_RISING 0x10120000U /*!< External Event Mode with Rising edge trigger detection */
  91. #define GPIO_MODE_EVT_FALLING 0x10220000U /*!< External Event Mode with Falling edge trigger detection */
  92. #define GPIO_MODE_EVT_RISING_FALLING 0x10320000U /*!< External Event Mode with Rising/Falling edge trigger detection */
  93. /**
  94. * @}
  95. */
  96. /** @defgroup GPIO_speed_define GPIO speed define
  97. * @brief GPIO Output Maximum frequency
  98. * @{
  99. */
  100. #define GPIO_SPEED_FREQ_LOW 0x00000000U /*!< IO works at 2 MHz, please refer to the product datasheet */
  101. #define GPIO_SPEED_FREQ_MEDIUM 0x00000001U /*!< range 12,5 MHz to 50 MHz, please refer to the product datasheet */
  102. #define GPIO_SPEED_FREQ_HIGH 0x00000002U /*!< range 25 MHz to 100 MHz, please refer to the product datasheet */
  103. #define GPIO_SPEED_FREQ_VERY_HIGH 0x00000003U /*!< range 50 MHz to 200 MHz, please refer to the product datasheet */
  104. /**
  105. * @}
  106. */
  107. /** @defgroup GPIO_pull_define GPIO pull define
  108. * @brief GPIO Pull-Up or Pull-Down Activation
  109. * @{
  110. */
  111. #define GPIO_NOPULL 0x00000000U /*!< No Pull-up or Pull-down activation */
  112. #define GPIO_PULLUP 0x00000001U /*!< Pull-up activation */
  113. #define GPIO_PULLDOWN 0x00000002U /*!< Pull-down activation */
  114. #endif /* __COM_GPIO_H__ */