apm32s10x_gpio.h 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254
  1. /*!
  2. * @file apm32s10x_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 2022-12-31
  9. *
  10. * @attention
  11. *
  12. * Copyright (C) 2022-2023 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. /* Define to prevent recursive inclusion */
  26. #ifndef __APM32S10X_GPIO_H
  27. #define __APM32S10X_GPIO_H
  28. #ifdef __cplusplus
  29. extern "C" {
  30. #endif
  31. /* Includes */
  32. #include "apm32s10x.h"
  33. /** @addtogroup APM32S10x_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_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_REMAP_T;
  136. /**
  137. * @brief gpio port source define
  138. */
  139. typedef enum
  140. {
  141. GPIO_PORT_SOURCE_A,
  142. GPIO_PORT_SOURCE_B,
  143. GPIO_PORT_SOURCE_C,
  144. GPIO_PORT_SOURCE_D,
  145. GPIO_PORT_SOURCE_E
  146. } GPIO_PORT_SOURCE_T;
  147. /**
  148. * @brief gpio pin source define
  149. */
  150. typedef enum
  151. {
  152. GPIO_PIN_SOURCE_0,
  153. GPIO_PIN_SOURCE_1,
  154. GPIO_PIN_SOURCE_2,
  155. GPIO_PIN_SOURCE_3,
  156. GPIO_PIN_SOURCE_4,
  157. GPIO_PIN_SOURCE_5,
  158. GPIO_PIN_SOURCE_6,
  159. GPIO_PIN_SOURCE_7,
  160. GPIO_PIN_SOURCE_8,
  161. GPIO_PIN_SOURCE_9,
  162. GPIO_PIN_SOURCE_10,
  163. GPIO_PIN_SOURCE_11,
  164. GPIO_PIN_SOURCE_12,
  165. GPIO_PIN_SOURCE_13,
  166. GPIO_PIN_SOURCE_14,
  167. GPIO_PIN_SOURCE_15
  168. } GPIO_PIN_SOURCE_T;
  169. /**@} end of group GPIO_Enumerations */
  170. /** @defgroup GPIO_Structures Structures
  171. @{
  172. */
  173. /**
  174. * @brief GPIO Config structure definition
  175. */
  176. typedef struct
  177. {
  178. uint16_t pin;
  179. GPIO_SPEED_T speed;
  180. GPIO_MODE_T mode;
  181. } GPIO_Config_T;
  182. /**@} end of group GPIO_Structures */
  183. /** @defgroup GPIO_Functions Functions
  184. @{
  185. */
  186. /* Reset and common Configuration */
  187. void GPIO_Reset(GPIO_T* port);
  188. void GPIO_AFIOReset(void);
  189. void GPIO_Config(GPIO_T* port, GPIO_Config_T* gpioConfig);
  190. void GPIO_ConfigStructInit(GPIO_Config_T* gpioConfig);
  191. /* Read */
  192. uint8_t GPIO_ReadInputBit(GPIO_T* port, uint16_t pin);
  193. uint16_t GPIO_ReadInputPort(GPIO_T* port);
  194. uint8_t GPIO_ReadOutputBit(GPIO_T* port, uint16_t pin);
  195. uint16_t GPIO_ReadOutputPort(GPIO_T* port);
  196. /* Write */
  197. void GPIO_SetBit(GPIO_T* port, uint16_t pin);
  198. void GPIO_ResetBit(GPIO_T* port, uint16_t pin);
  199. void GPIO_WriteOutputPort(GPIO_T* port, uint16_t portValue);
  200. void GPIO_WriteBitValue(GPIO_T* port, uint16_t pin, uint8_t bitVal);
  201. /* GPIO Configuration */
  202. void GPIO_ConfigPinLock(GPIO_T* port, uint16_t pin);
  203. void GPIO_ConfigEventOutput(GPIO_PORT_SOURCE_T portSource, GPIO_PIN_SOURCE_T pinSource);
  204. void GPIO_EnableEventOutput(void);
  205. void GPIO_DisableEventOutput(void);
  206. void GPIO_ConfigPinRemap(GPIO_REMAP_T remap);
  207. void GPIO_ConfigEINTLine(GPIO_PORT_SOURCE_T portSource, GPIO_PIN_SOURCE_T pinSource);
  208. /**@} end of group GPIO_Functions */
  209. /**@} end of group GPIO_Driver */
  210. /**@} end of group APM32S10x_StdPeriphDriver */
  211. #ifdef __cplusplus
  212. }
  213. #endif
  214. #endif /* __APM32S10X_GPIO_H */