hal_gpio.h 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  1. ////////////////////////////////////////////////////////////////////////////////
  2. /// @file hal_gpio.h
  3. /// @author AE TEAM
  4. /// @brief THIS FILE CONTAINS ALL THE FUNCTIONS PROTOTYPES FOR THE GPIO
  5. /// FIRMWARE LIBRARY.
  6. ////////////////////////////////////////////////////////////////////////////////
  7. /// @attention
  8. ///
  9. /// THE EXISTING FIRMWARE IS ONLY FOR REFERENCE, WHICH IS DESIGNED TO PROVIDE
  10. /// CUSTOMERS WITH CODING INFORMATION ABOUT THEIR PRODUCTS SO THEY CAN SAVE
  11. /// TIME. THEREFORE, MINDMOTION SHALL NOT BE LIABLE FOR ANY DIRECT, INDIRECT OR
  12. /// CONSEQUENTIAL DAMAGES ABOUT ANY CLAIMS ARISING OUT OF THE CONTENT OF SUCH
  13. /// HARDWARE AND/OR THE USE OF THE CODING INFORMATION CONTAINED HEREIN IN
  14. /// CONNECTION WITH PRODUCTS MADE BY CUSTOMERS.
  15. ///
  16. /// <H2><CENTER>&COPY; COPYRIGHT MINDMOTION </CENTER></H2>
  17. ////////////////////////////////////////////////////////////////////////////////
  18. // Define to prevent recursive inclusion
  19. #ifndef __HAL_GPIO_H
  20. #define __HAL_GPIO_H
  21. // Files includes
  22. #include "types.h"
  23. #include "reg_gpio.h"
  24. ////////////////////////////////////////////////////////////////////////////////
  25. /// @addtogroup MM32_Hardware_Abstract_Layer
  26. /// @{
  27. ////////////////////////////////////////////////////////////////////////////////
  28. /// @defgroup GPIO_HAL
  29. /// @brief GPIO HAL modules
  30. /// @{
  31. ////////////////////////////////////////////////////////////////////////////////
  32. /// @defgroup GPIO_Exported_Types
  33. /// @{
  34. ////////////////////////////////////////////////////////////////////////////////
  35. /// @brief Output Maximum frequency selection
  36. ////////////////////////////////////////////////////////////////////////////////
  37. typedef enum {
  38. GPIO_Speed_50MHz = 1, ///< Maximum speed is 50MHz
  39. GPIO_Speed_20MHz, ///< Maximum speed is 20MHz
  40. GPIO_Speed_10MHz ///< Maximum speed is 10MHz
  41. } GPIOSpeed_TypeDef;
  42. ////////////////////////////////////////////////////////////////////////////////
  43. /// @brief Configuration Mode enumeration
  44. ////////////////////////////////////////////////////////////////////////////////
  45. typedef enum {
  46. GPIO_Mode_AIN = 0x00, ///< Analog input
  47. GPIO_Mode_FLOATING = 0x04, ///< Floating input
  48. GPIO_Mode_IPD = 0x28, ///< Pull down input
  49. GPIO_Mode_IPU = 0x48, ///< Pull up input
  50. GPIO_Mode_Out_OD = 0x14, ///< Universal open drain output
  51. GPIO_Mode_Out_PP = 0x10, ///< Universal push-pull output
  52. GPIO_Mode_AF_OD = 0x1C, ///< Multiplex open drain output
  53. GPIO_Mode_AF_PP = 0x18 ///< Multiplexed push-pull output
  54. } GPIOMode_TypeDef;
  55. ////////////////////////////////////////////////////////////////////////////////
  56. /// @brief Bit_SET and Bit_RESET enumeration
  57. ////////////////////////////////////////////////////////////////////////////////
  58. typedef enum {
  59. Bit_RESET = 0, ///< bit reset
  60. Bit_SET ///< bit set
  61. } BitAction;
  62. ////////////////////////////////////////////////////////////////////////////////
  63. /// @brief GPIO Init structure definition
  64. ////////////////////////////////////////////////////////////////////////////////
  65. typedef struct {
  66. u16 GPIO_Pin; ///< GPIO_Pin
  67. GPIOSpeed_TypeDef GPIO_Speed; ///< GPIO_Speed
  68. GPIOMode_TypeDef GPIO_Mode; ///< GPIO_Mode
  69. } GPIO_InitTypeDef;
  70. /// @}
  71. ////////////////////////////////////////////////////////////////////////////////
  72. /// @defgroup GPIO_Exported_Constants
  73. /// @{
  74. #define GPIO_Speed_2MHz GPIO_Speed_20MHz
  75. #define GPIO_Pin_0 (0x0001U) ///< Pin 0 selected
  76. #define GPIO_Pin_1 (0x0002U) ///< Pin 1 selected
  77. #define GPIO_Pin_2 (0x0004U) ///< Pin 2 selected
  78. #define GPIO_Pin_3 (0x0008U) ///< Pin 3 selected
  79. #define GPIO_Pin_4 (0x0010U) ///< Pin 4 selected
  80. #define GPIO_Pin_5 (0x0020U) ///< Pin 5 selected
  81. #define GPIO_Pin_6 (0x0040U) ///< Pin 6 selected
  82. #define GPIO_Pin_7 (0x0080U) ///< Pin 7 selected
  83. #define GPIO_Pin_8 (0x0100U) ///< Pin 8 selected
  84. #define GPIO_Pin_9 (0x0200U) ///< Pin 9 selected
  85. #define GPIO_Pin_10 (0x0400U) ///< Pin 10 selected
  86. #define GPIO_Pin_11 (0x0800U) ///< Pin 11 selected
  87. #define GPIO_Pin_12 (0x1000U) ///< Pin 12 selected
  88. #define GPIO_Pin_13 (0x2000U) ///< Pin 13 selected
  89. #define GPIO_Pin_14 (0x4000U) ///< Pin 14 selected
  90. #define GPIO_Pin_15 (0x8000U) ///< Pin 15 selected
  91. #define GPIO_Pin_All (0xFFFFU) ///< All pins selected
  92. #define GPIO_AF_0 (0x00U) ///< Alternative function 0
  93. #define GPIO_AF_1 (0x01U) ///< Alternative function 1
  94. #define GPIO_AF_2 (0x02U) ///< Alternative function 2
  95. #define GPIO_AF_3 (0x03U) ///< Alternative function 3
  96. #define GPIO_AF_4 (0x04U) ///< Alternative function 4
  97. #define GPIO_AF_5 (0x05U) ///< Alternative function 5
  98. #define GPIO_AF_6 (0x06U) ///< Alternative function 6
  99. #define GPIO_AF_7 (0x07U) ///< Alternative function 7
  100. #define GPIO_AF_8 (0x08U) ///< Alternative function 8
  101. #define GPIO_AF_9 (0x09U) ///< Alternative function 9
  102. #define GPIO_AF_10 (0x0AU) ///< Alternative function 10
  103. #define GPIO_AF_11 (0x0BU) ///< Alternative function 11
  104. #define GPIO_AF_12 (0x0CU) ///< Alternative function 12
  105. #define GPIO_AF_13 (0x0DU) ///< Alternative function 13
  106. #define GPIO_AF_14 (0x0EU) ///< Alternative function 14
  107. #define GPIO_AF_15 (0x0FU) ///< Alternative function 15
  108. #define GPIO_PortSourceGPIOA (0x00U)
  109. #define GPIO_PortSourceGPIOB (0x01U)
  110. #define GPIO_PortSourceGPIOC (0x02U)
  111. #define GPIO_PortSourceGPIOD (0x03U)
  112. #define GPIO_PinSource0 (0x00U)
  113. #define GPIO_PinSource1 (0x01U)
  114. #define GPIO_PinSource2 (0x02U)
  115. #define GPIO_PinSource3 (0x03U)
  116. #define GPIO_PinSource4 (0x04U)
  117. #define GPIO_PinSource5 (0x05U)
  118. #define GPIO_PinSource6 (0x06U)
  119. #define GPIO_PinSource7 (0x07U)
  120. #define GPIO_PinSource8 (0x08U)
  121. #define GPIO_PinSource9 (0x09U)
  122. #define GPIO_PinSource10 (0x0AU)
  123. #define GPIO_PinSource11 (0x0BU)
  124. #define GPIO_PinSource12 (0x0CU)
  125. #define GPIO_PinSource13 (0x0DU)
  126. #define GPIO_PinSource14 (0x0EU)
  127. #define GPIO_PinSource15 (0x0FU)
  128. /// @}
  129. ////////////////////////////////////////////////////////////////////////////////
  130. /// @defgroup GPIO_Exported_Variables
  131. /// @{
  132. #ifdef _HAL_GPIO_C_
  133. #define GLOBAL
  134. #else
  135. #define GLOBAL extern
  136. #endif
  137. #undef GLOBAL
  138. /// @}
  139. ////////////////////////////////////////////////////////////////////////////////
  140. /// @defgroup GPIO_Exported_Functions
  141. /// @{
  142. void GPIO_DeInit(GPIO_TypeDef* gpio);
  143. void GPIO_AFIODeInit(void);
  144. void GPIO_Init(GPIO_TypeDef* gpio, GPIO_InitTypeDef* init_struct);
  145. void GPIO_StructInit(GPIO_InitTypeDef* init_struct);
  146. void GPIO_SetBits(GPIO_TypeDef* gpio, u16 pin);
  147. void GPIO_ResetBits(GPIO_TypeDef* gpio, u16 pin);
  148. void GPIO_WriteBit(GPIO_TypeDef* gpio, u16 pin, BitAction value);
  149. void GPIO_Write(GPIO_TypeDef* gpio, u16 value);
  150. void GPIO_PinLock(GPIO_TypeDef* gpio, u16 pin, FunctionalState state);
  151. void GPIO_PinLockConfig(GPIO_TypeDef* gpio, u16 pin);
  152. bool GPIO_ReadInputDataBit(GPIO_TypeDef* gpio, u16 pin);
  153. bool GPIO_ReadOutputDataBit(GPIO_TypeDef* gpio, u16 pin);
  154. u16 GPIO_ReadInputData(GPIO_TypeDef* gpio);
  155. u16 GPIO_ReadOutputData(GPIO_TypeDef* gpio);
  156. void GPIO_PinAFConfig(GPIO_TypeDef* gpio, u8 pin, u8 alternate_function);
  157. void exGPIO_PinAFConfig(GPIO_TypeDef* gpio, u16 pin, s32 remap, s8 alternate_function);
  158. /// @}
  159. /// @}
  160. /// @}
  161. ////////////////////////////////////////////////////////////////////////////////
  162. #endif // __HAL_GPIO_H
  163. ////////////////////////////////////////////////////////////////////////////////