apm32f10x_gpio.h 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247
  1. /*!
  2. * @file apm32f10x_gpio.h
  3. *
  4. * @brief This file contains all the functions prototypes for the GPIO firmware library
  5. *
  6. * @version V1.0.1
  7. *
  8. * @date 2021-03-23
  9. *
  10. */
  11. #ifndef __APM32F10X_GPIO_H
  12. #define __APM32F10X_GPIO_H
  13. #include "apm32f10x.h"
  14. #ifdef __cplusplus
  15. extern "C" {
  16. #endif
  17. /** @addtogroup Peripherals_Library Standard Peripheral Library
  18. @{
  19. */
  20. /** @addtogroup GPIO_Driver GPIO Driver
  21. @{
  22. */
  23. /** @addtogroup GPIO_Enumerations Enumerations
  24. @{
  25. */
  26. /**
  27. * @brief GPIO Output Maximum frequency selection
  28. */
  29. typedef enum
  30. {
  31. GPIO_SPEED_10MHz = 1,
  32. GPIO_SPEED_2MHz,
  33. GPIO_SPEED_50MHz
  34. }GPIO_SPEED_T;
  35. /**
  36. * @brief Configuration Mode enumeration
  37. */
  38. typedef enum
  39. {
  40. GPIO_MODE_ANALOG = 0x0, //!< Analog mode
  41. GPIO_MODE_IN_FLOATING = 0x04, //!< Floating input
  42. GPIO_MODE_IN_PD = 0x28, //!< Input with pull-down
  43. GPIO_MODE_IN_PU = 0x48, //!< Input with pull-up
  44. GPIO_MODE_OUT_PP = 0x80, //!< General purpose output push-pull
  45. GPIO_MODE_OUT_OD = 0x84, //!< General purpose output Open-drain
  46. GPIO_MODE_AF_PP = 0x88, //!< Alternate function output Push-pull
  47. GPIO_MODE_AF_OD = 0x8C, //!< Alternate function output Open-drain
  48. }GPIO_MODE_T;
  49. /**
  50. * @brief Definition of the GPIO pins
  51. */
  52. typedef enum
  53. {
  54. GPIO_PIN_0 = ((uint16_t)BIT0),
  55. GPIO_PIN_1 = ((uint16_t)BIT1),
  56. GPIO_PIN_2 = ((uint16_t)BIT2),
  57. GPIO_PIN_3 = ((uint16_t)BIT3),
  58. GPIO_PIN_4 = ((uint16_t)BIT4),
  59. GPIO_PIN_5 = ((uint16_t)BIT5),
  60. GPIO_PIN_6 = ((uint16_t)BIT6),
  61. GPIO_PIN_7 = ((uint16_t)BIT7),
  62. GPIO_PIN_8 = ((uint16_t)BIT8),
  63. GPIO_PIN_9 = ((uint16_t)BIT9),
  64. GPIO_PIN_10 = ((uint16_t)BIT10),
  65. GPIO_PIN_11 = ((uint16_t)BIT11),
  66. GPIO_PIN_12 = ((uint16_t)BIT12),
  67. GPIO_PIN_13 = ((uint16_t)BIT13),
  68. GPIO_PIN_14 = ((uint16_t)BIT14),
  69. GPIO_PIN_15 = ((uint16_t)BIT15),
  70. GPIO_PIN_ALL = ((uint32_t)0XFFFF),
  71. } GPIO_PIN_T;
  72. /**
  73. * @brief GPIO remap type define
  74. */
  75. typedef enum
  76. {
  77. GPIO_NO_REMAP_SPI1 = 0x00000010,
  78. GPIO_REMAP_SPI1 = 0x00000011,
  79. GPIO_NO_REMAP_I2C1 = 0x00000110,
  80. GPIO_REMAP_I2C1 = 0x00000111,
  81. GPIO_NO_REMAP_USART1 = 0x00000210,
  82. GPIO_REMAP_USART1 = 0x00000211,
  83. GPIO_NO_REMAP_USART2 = 0x00000310,
  84. GPIO_REMAP_USART2 = 0x00000311,
  85. GPIO_NO_REMAP_USART3 = 0x00000430,
  86. GPIO_PARTIAL_REMAP_USART3 = 0x00000431,
  87. GPIO_FULL_REMAP_USART3 = 0x00000433,
  88. GPIO_NO_REMAP_TMR1 = 0x00000630,
  89. GPIO_PARTIAL_REMAP_TMR1 = 0x00000631,
  90. GPIO_FULL_REMAP_TMR1 = 0x00000633,
  91. GPIO_NO_REMAP_TMR2 = 0x00000830,
  92. GPIO_PARTIAL_REMAP1_TMR2 = 0x00000831,
  93. GPIO_PARTIAL_REMAP2_TMR2 = 0x00000832,
  94. GPIO_FULL_REMAP_TMR2 = 0x00000833,
  95. GPIO_NO_REMAP_TMR3 = 0x00000A30,
  96. GPIO_PARTIAL_REMAP_TMR3 = 0x00000A32,
  97. GPIO_FULL_REMAP_TMR3 = 0x00000A33,
  98. GPIO_NO_REMAP_TMR4 = 0x00000C10,
  99. GPIO_REMAP_TMR4 = 0x00000C11,
  100. GPIO_NO_REMAP_CAN1 = 0x00000D30,
  101. GPIO_REMAP1_CAN1 = 0x00000D32,
  102. GPIO_REMAP2_CAN1 = 0x00000D33,
  103. GPIO_NO_REMAP_PD01 = 0x00000F10,
  104. GPIO_REMAP_PD01 = 0x00000F11,
  105. GPIO_NO_REMAP_TMR5CH4_LSI = 0x00001010,
  106. GPIO_REMAP_TMR5CH4_LSI = 0x00001011,
  107. GPIO_NO_REMAP_ADC1_ETRGINJ = 0x00001110,
  108. GPIO_REMAP_ADC1_ETRGINJ = 0x00001111,
  109. GPIO_NO_REMAP_ADC1_ETRGREG = 0x00001210,
  110. GPIO_REMAP_ADC1_ETRGREG = 0x00001211,
  111. GPIO_NO_REMAP_ADC2_ETRGINJ = 0x00001310,
  112. GPIO_REMAP_ADC2_ETRGINJ = 0x00001311,
  113. GPIO_NO_REMAP_ADC2_ETRGREG = 0x00001410,
  114. GPIO_REMAP_ADC2_ETRGREG = 0x00001411,
  115. GPIO_NO_REMAP_CAN2 = 0x00001610,
  116. GPIO_REMAP_CAN2 = 0x00001611,
  117. GPIO_NO_REMAP_SWJ = 0x00001870,
  118. GPIO_REMAP_SWJ_NOJTRST = 0x00001871,
  119. GPIO_REMAP_SWJ_JTAGDISABLE = 0x00001872,
  120. GPIO_REMAP_SWJ_DISABLE = 0x00001874,
  121. GPIO_NO_REMAP_EMMC_NADV = 0x00010A10,
  122. GPIO_REMAP_EMMC_NADV = 0x00010A11,
  123. }GPIO_REMAP_T;
  124. /**
  125. * @brief gpio port source define
  126. */
  127. typedef enum
  128. {
  129. GPIO_PORT_SOURCE_A,
  130. GPIO_PORT_SOURCE_B,
  131. GPIO_PORT_SOURCE_C,
  132. GPIO_PORT_SOURCE_D,
  133. GPIO_PORT_SOURCE_E,
  134. GPIO_PORT_SOURCE_F,
  135. GPIO_PORT_SOURCE_G,
  136. }GPIO_PORT_SOURCE_T;
  137. /**
  138. * @brief gpio pin source define
  139. */
  140. typedef enum
  141. {
  142. GPIO_PIN_SOURCE_0,
  143. GPIO_PIN_SOURCE_1,
  144. GPIO_PIN_SOURCE_2,
  145. GPIO_PIN_SOURCE_3,
  146. GPIO_PIN_SOURCE_4,
  147. GPIO_PIN_SOURCE_5,
  148. GPIO_PIN_SOURCE_6,
  149. GPIO_PIN_SOURCE_7,
  150. GPIO_PIN_SOURCE_8,
  151. GPIO_PIN_SOURCE_9,
  152. GPIO_PIN_SOURCE_10,
  153. GPIO_PIN_SOURCE_11,
  154. GPIO_PIN_SOURCE_12,
  155. GPIO_PIN_SOURCE_13,
  156. GPIO_PIN_SOURCE_14,
  157. GPIO_PIN_SOURCE_15,
  158. }GPIO_PIN_SOURCE_T;
  159. /**@} end of group GPIO_Enumerations*/
  160. /** @addtogroup GPIO_Structure Data Structure
  161. @{
  162. */
  163. /**
  164. * @brief GPIO Config structure definition
  165. */
  166. typedef struct
  167. {
  168. uint16_t pin;
  169. GPIO_SPEED_T speed;
  170. GPIO_MODE_T mode;
  171. }GPIO_Config_T;
  172. /**@} end of group GPIO_Structure*/
  173. /** @addtogroup GPIO_Fuctions Fuctions
  174. @{
  175. */
  176. /** Reset and common Configuration */
  177. void GPIO_Reset(GPIO_T* port);
  178. void GPIO_AFIOReset(void);
  179. void GPIO_Config(GPIO_T* port, GPIO_Config_T* gpioConfig);
  180. void GPIO_StructInit(GPIO_Config_T* gpioConfig);
  181. /** Read */
  182. uint8_t GPIO_ReadInputBit(GPIO_T* port, uint16_t pin);
  183. uint16_t GPIO_ReadInputPort(GPIO_T* port);
  184. uint8_t GPIO_ReadOutputBit(GPIO_T* port, uint16_t pin);
  185. uint16_t GPIO_ReadOutputPort(GPIO_T* port);
  186. /** Write */
  187. void GPIO_SetBits(GPIO_T* port, uint16_t pin);
  188. void GPIO_ResetBits(GPIO_T* port, uint16_t pin);
  189. void GPIO_WriteOutputPort(GPIO_T* port, uint16_t portValue);
  190. void GPIO_WriteBitValue(GPIO_T* port, uint16_t pin, uint8_t bitVal);
  191. /** GPIO Configuration */
  192. void GPIO_ConfigPinLock(GPIO_T* port, uint16_t pin);
  193. void GPIO_ConfigEventOutput(GPIO_PORT_SOURCE_T portSource, GPIO_PIN_SOURCE_T pinSource);
  194. void GPIO_EnableEventOutput(void);
  195. void GPIO_DisableEventOutput(void);
  196. void GPIO_ConfigPinRemap(GPIO_REMAP_T remap);
  197. void GPIO_ConfigEINTLine(GPIO_PORT_SOURCE_T portSource, GPIO_PIN_SOURCE_T pinSource);
  198. /**@} end of group GPIO_Fuctions*/
  199. /**@} end of group GPIO_Driver */
  200. /**@} end of group Peripherals_Library*/
  201. #ifdef __cplusplus
  202. }
  203. #endif
  204. #endif /* __APM32F10X_GPIO_H */