com_gpio.h 6.1 KB

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