apm32f10x_gpio.h 6.9 KB

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