apm32f10x_gpio.h 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295
  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.4
  7. *
  8. * @date 2022-12-01
  9. *
  10. * @attention
  11. *
  12. * Copyright (C) 2020-2022 Geehy Semiconductor
  13. *
  14. * You may not use this file except in compliance with the
  15. * GEEHY COPYRIGHT NOTICE (GEEHY SOFTWARE PACKAGE LICENSE).
  16. *
  17. * The program is only for reference, which is distributed in the hope
  18. * that it will be useful and instructional for customers to develop
  19. * their software. Unless required by applicable law or agreed to in
  20. * writing, the program is distributed on an "AS IS" BASIS, WITHOUT
  21. * ANY WARRANTY OR CONDITIONS OF ANY KIND, either express or implied.
  22. * See the GEEHY SOFTWARE PACKAGE LICENSE for the governing permissions
  23. * and limitations under the License.
  24. */
  25. /* Define to prevent recursive inclusion */
  26. #ifndef __APM32F10X_GPIO_H
  27. #define __APM32F10X_GPIO_H
  28. /* Includes */
  29. #include "apm32f10x.h"
  30. #ifdef __cplusplus
  31. extern "C" {
  32. #endif
  33. /** @addtogroup APM32F10x_StdPeriphDriver
  34. @{
  35. */
  36. /** @addtogroup GPIO_Driver GPIO Driver
  37. @{
  38. */
  39. /** @defgroup GPIO_Enumerations Enumerations
  40. @{
  41. */
  42. /**
  43. * @brief GPIO Output Maximum frequency selection
  44. */
  45. typedef enum
  46. {
  47. GPIO_SPEED_10MHz = 1,
  48. GPIO_SPEED_2MHz,
  49. GPIO_SPEED_50MHz
  50. } GPIO_SPEED_T;
  51. /**
  52. * @brief Configuration Mode enumeration
  53. */
  54. typedef enum
  55. {
  56. GPIO_MODE_ANALOG = 0x0, /*!< Analog mode */
  57. GPIO_MODE_IN_FLOATING = 0x04, /*!< Floating input */
  58. GPIO_MODE_IN_PD = 0x28, /*!< Input with pull-down */
  59. GPIO_MODE_IN_PU = 0x48, /*!< Input with pull-up */
  60. GPIO_MODE_OUT_PP = 0x80, /*!< General purpose output push-pull */
  61. GPIO_MODE_OUT_OD = 0x84, /*!< General purpose output Open-drain */
  62. GPIO_MODE_AF_PP = 0x88, /*!< Alternate function output Push-pull */
  63. GPIO_MODE_AF_OD = 0x8C, /*!< Alternate function output Open-drain */
  64. } GPIO_MODE_T;
  65. /**
  66. * @brief Definition of the GPIO pins
  67. */
  68. typedef enum
  69. {
  70. GPIO_PIN_0 = ((uint16_t)BIT0),
  71. GPIO_PIN_1 = ((uint16_t)BIT1),
  72. GPIO_PIN_2 = ((uint16_t)BIT2),
  73. GPIO_PIN_3 = ((uint16_t)BIT3),
  74. GPIO_PIN_4 = ((uint16_t)BIT4),
  75. GPIO_PIN_5 = ((uint16_t)BIT5),
  76. GPIO_PIN_6 = ((uint16_t)BIT6),
  77. GPIO_PIN_7 = ((uint16_t)BIT7),
  78. GPIO_PIN_8 = ((uint16_t)BIT8),
  79. GPIO_PIN_9 = ((uint16_t)BIT9),
  80. GPIO_PIN_10 = ((uint16_t)BIT10),
  81. GPIO_PIN_11 = ((uint16_t)BIT11),
  82. GPIO_PIN_12 = ((uint16_t)BIT12),
  83. GPIO_PIN_13 = ((uint16_t)BIT13),
  84. GPIO_PIN_14 = ((uint16_t)BIT14),
  85. GPIO_PIN_15 = ((uint16_t)BIT15),
  86. GPIO_PIN_ALL = ((uint32_t)0XFFFF),
  87. } GPIO_PIN_T;
  88. /**
  89. * @brief GPIO remap type define
  90. */
  91. typedef enum
  92. {
  93. GPIO_NO_REMAP_SPI1 = 0x00000010,
  94. GPIO_REMAP_SPI1 = 0x00000011,
  95. GPIO_NO_REMAP_I2C1 = 0x00000110,
  96. GPIO_REMAP_I2C1 = 0x00000111,
  97. GPIO_NO_REMAP_USART1 = 0x00000210,
  98. GPIO_REMAP_USART1 = 0x00000211,
  99. GPIO_NO_REMAP_USART2 = 0x00000310,
  100. GPIO_REMAP_USART2 = 0x00000311,
  101. GPIO_NO_REMAP_USART3 = 0x00000430,
  102. GPIO_PARTIAL_REMAP_USART3 = 0x00000431,
  103. GPIO_FULL_REMAP_USART3 = 0x00000433,
  104. GPIO_NO_REMAP_TMR1 = 0x00000630,
  105. GPIO_PARTIAL_REMAP_TMR1 = 0x00000631,
  106. GPIO_FULL_REMAP_TMR1 = 0x00000633,
  107. GPIO_NO_REMAP_TMR2 = 0x00000830,
  108. GPIO_PARTIAL_REMAP1_TMR2 = 0x00000831,
  109. GPIO_PARTIAL_REMAP2_TMR2 = 0x00000832,
  110. GPIO_FULL_REMAP_TMR2 = 0x00000833,
  111. GPIO_NO_REMAP_TMR3 = 0x00000A30,
  112. GPIO_PARTIAL_REMAP_TMR3 = 0x00000A32,
  113. GPIO_FULL_REMAP_TMR3 = 0x00000A33,
  114. GPIO_NO_REMAP_TMR4 = 0x00000C10,
  115. GPIO_REMAP_TMR4 = 0x00000C11,
  116. GPIO_NO_REMAP_CAN1 = 0x00000D30,
  117. GPIO_REMAP1_CAN1 = 0x00000D32,
  118. GPIO_REMAP2_CAN1 = 0x00000D33,
  119. GPIO_NO_REMAP_PD01 = 0x00000F10,
  120. GPIO_REMAP_PD01 = 0x00000F11,
  121. GPIO_NO_REMAP_TMR5CH4_LSI = 0x00001010,
  122. GPIO_REMAP_TMR5CH4_LSI = 0x00001011,
  123. #if !defined(APM32F10X_CL)
  124. GPIO_NO_REMAP_ADC1_ETRGINJ = 0x00001110,
  125. GPIO_REMAP_ADC1_ETRGINJ = 0x00001111,
  126. GPIO_NO_REMAP_ADC1_ETRGREG = 0x00001210,
  127. GPIO_REMAP_ADC1_ETRGREG = 0x00001211,
  128. GPIO_NO_REMAP_ADC2_ETRGINJ = 0x00001310,
  129. GPIO_REMAP_ADC2_ETRGINJ = 0x00001311,
  130. GPIO_NO_REMAP_ADC2_ETRGREG = 0x00001410,
  131. GPIO_REMAP_ADC2_ETRGREG = 0x00001411,
  132. GPIO_NO_REMAP_ETH = 0x00001510,
  133. GPIO_REMAP_ETH = 0x00001511,
  134. GPIO_NO_REMAP_CAN2 = 0x00001610,
  135. GPIO_REMAP_CAN2 = 0x00001611,
  136. GPIO_REMAP_MII = 0x00001710,
  137. GPIO_REMAP_RMII = 0x00001711,
  138. GPIO_NO_REMAP_SWJ = 0x00001870,
  139. GPIO_REMAP_SWJ_NOJTRST = 0x00001871,
  140. GPIO_REMAP_SWJ_JTAGDISABLE = 0x00001872,
  141. GPIO_REMAP_SWJ_DISABLE = 0x00001874,
  142. GPIO_NO_REMAP_EMMC_NADV = 0x00010A10,
  143. GPIO_REMAP_EMMC_NADV = 0x00010A11,
  144. #else /* APM32F10X_CL */
  145. GPIO_NO_REMAP_ETH_MAC = 0x00001510,
  146. GPIO_REMAP_ETH_MAC = 0x00001511,
  147. GPIO_NO_REMAP_CAN2 = 0x00001610,
  148. GPIO_REMAP_CAN2 = 0x00001611,
  149. GPIO_REMAP_MACEISEL_MII = 0x00001710,
  150. GPIO_REMAP_MACEISEL_RMII = 0x00001711,
  151. GPIO_NO_REMAP_SWJ = 0x00001870,
  152. GPIO_REMAP_SWJ_NOJTRST = 0x00001871,
  153. GPIO_REMAP_SWJ_JTAGDISABLE = 0x00001872,
  154. GPIO_REMAP_SWJ_DISABLE = 0x00001874,
  155. GPIO_NO_REMAP_SPI3 = 0x00001C10,
  156. GPIO_REMAP_SPI3 = 0x00001C11,
  157. GPIO_NO_REMAP_TMR2ITR1 = 0x00001D10,
  158. GPIO_REMAP_TMR2ITR1 = 0x00001D11,
  159. GPIO_NO_REMAP_PTP_PPS = 0x00001E10,
  160. GPIO_REMAP_PTP_PPS = 0x00001E11,
  161. #endif
  162. } GPIO_REMAP_T;
  163. /**
  164. * @brief gpio port source define
  165. */
  166. typedef enum
  167. {
  168. GPIO_PORT_SOURCE_A,
  169. GPIO_PORT_SOURCE_B,
  170. GPIO_PORT_SOURCE_C,
  171. GPIO_PORT_SOURCE_D,
  172. GPIO_PORT_SOURCE_E,
  173. GPIO_PORT_SOURCE_F,
  174. GPIO_PORT_SOURCE_G,
  175. } GPIO_PORT_SOURCE_T;
  176. /**
  177. * @brief gpio pin source define
  178. */
  179. typedef enum
  180. {
  181. GPIO_PIN_SOURCE_0,
  182. GPIO_PIN_SOURCE_1,
  183. GPIO_PIN_SOURCE_2,
  184. GPIO_PIN_SOURCE_3,
  185. GPIO_PIN_SOURCE_4,
  186. GPIO_PIN_SOURCE_5,
  187. GPIO_PIN_SOURCE_6,
  188. GPIO_PIN_SOURCE_7,
  189. GPIO_PIN_SOURCE_8,
  190. GPIO_PIN_SOURCE_9,
  191. GPIO_PIN_SOURCE_10,
  192. GPIO_PIN_SOURCE_11,
  193. GPIO_PIN_SOURCE_12,
  194. GPIO_PIN_SOURCE_13,
  195. GPIO_PIN_SOURCE_14,
  196. GPIO_PIN_SOURCE_15,
  197. } GPIO_PIN_SOURCE_T;
  198. /**@} end of group GPIO_Enumerations*/
  199. /** @defgroup GPIO_Structures Structures
  200. @{
  201. */
  202. /**
  203. * @brief GPIO Config structure definition
  204. */
  205. typedef struct
  206. {
  207. uint16_t pin;
  208. GPIO_SPEED_T speed;
  209. GPIO_MODE_T mode;
  210. } GPIO_Config_T;
  211. /**@} end of group GPIO_Structures*/
  212. /** @defgroup GPIO_Functions Functions
  213. @{
  214. */
  215. /* Reset and common Configuration */
  216. void GPIO_Reset(GPIO_T* port);
  217. void GPIO_AFIOReset(void);
  218. void GPIO_Config(GPIO_T* port, GPIO_Config_T* gpioConfig);
  219. void GPIO_ConfigStructInit(GPIO_Config_T* gpioConfig);
  220. /* Read */
  221. uint8_t GPIO_ReadInputBit(GPIO_T* port, uint16_t pin);
  222. uint16_t GPIO_ReadInputPort(GPIO_T* port);
  223. uint8_t GPIO_ReadOutputBit(GPIO_T* port, uint16_t pin);
  224. uint16_t GPIO_ReadOutputPort(GPIO_T* port);
  225. /* Write */
  226. void GPIO_SetBit(GPIO_T* port, uint16_t pin);
  227. void GPIO_ResetBit(GPIO_T* port, uint16_t pin);
  228. void GPIO_WriteOutputPort(GPIO_T* port, uint16_t portValue);
  229. void GPIO_WriteBitValue(GPIO_T* port, uint16_t pin, uint8_t bitVal);
  230. /* GPIO Configuration */
  231. void GPIO_ConfigPinLock(GPIO_T* port, uint16_t pin);
  232. void GPIO_ConfigEventOutput(GPIO_PORT_SOURCE_T portSource, GPIO_PIN_SOURCE_T pinSource);
  233. void GPIO_EnableEventOutput(void);
  234. void GPIO_DisableEventOutput(void);
  235. void GPIO_ConfigPinRemap(GPIO_REMAP_T remap);
  236. void GPIO_ConfigEINTLine(GPIO_PORT_SOURCE_T portSource, GPIO_PIN_SOURCE_T pinSource);
  237. /**@} end of group GPIO_Functions*/
  238. /**@} end of group GPIO_Driver */
  239. /**@} end of group APM32F10x_StdPeriphDriver*/
  240. #ifdef __cplusplus
  241. }
  242. #endif
  243. #endif /* __APM32F10X_GPIO_H */