yc_gpio.h 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243
  1. /*
  2. * Copyright (c) 2006-2020, YICHIP Development Team
  3. * @file yc_gpio.h
  4. * @brief source file for setting gpio
  5. *
  6. * Change Logs:
  7. * Date Author Version Notes
  8. * 2020-12-23 yangzhengfeng V1.1.0 Modify the register module configuration
  9. */
  10. #ifndef __YC_GPIO_H__
  11. #define __YC_GPIO_H__
  12. #include "yc3122.h"
  13. #include "system.h"
  14. #ifdef __cplusplus
  15. extern "C" {
  16. #endif
  17. uint8_t UnMap(uint16_t x);
  18. #define GPIO_CONFIG(x) *((volatile uint8_t*)(MGPIO_BASE + x))
  19. #define GPIO_GetNum(port, pin) ((port * GPIO_PIN_NUM) + UnMap(pin))
  20. #define GPIO_OD_TypeDef uint8_t
  21. #define GPIO_FUN_TYPEDEF uint8_t
  22. #define GPIO_PORT_NUM 5
  23. #define GPIO_PIN_NUM 16
  24. #define GPIO_OD_PORTA_10 ((GPIO_OD_TypeDef)0x00) /*!< Pin 10 selected */
  25. #define GPIO_OD_PORTB_06 ((GPIO_OD_TypeDef)0x01) /*!< Pin 20 selected */
  26. #define GPIO_OD_PORTC_01 ((GPIO_OD_TypeDef)0x02) /*!< Pin 33 selected */
  27. #define GPIO_OD_PORTC_08 ((GPIO_OD_TypeDef)0x03) /*!< Pin 40 selected */
  28. #define GPIO_OD_PORTD_00 ((GPIO_OD_TypeDef)0x04) /*!< Pin 48 selected */
  29. #define GPIO_OD_PORTD_12 ((GPIO_OD_TypeDef)0x05) /*!< Pin 60 selected */
  30. #define GPIO_OD_PORTE_06 ((GPIO_OD_TypeDef)0x06) /*!< Pin 76 selected */
  31. #define GPIO_OD_PORTE_12 ((GPIO_OD_TypeDef)0x07) /*!< Pin 70 selected */
  32. #define IS_GPIO_OD(port_od) ((port_od == GPIO_OD_PORTA_10) || \
  33. (port_od == GPIO_OD_PORTB_06) || \
  34. (port_od == GPIO_OD_PORTC_01) || \
  35. (port_od == GPIO_OD_PORTC_08) || \
  36. (port_od == GPIO_OD_PORTD_00) || \
  37. (port_od == GPIO_OD_PORTD_12) || \
  38. (port_od == GPIO_OD_PORTE_06) || \
  39. (port_od == GPIO_OD_PORTE_12))
  40. typedef enum
  41. {
  42. GPIO_Pin_0 = BIT0,
  43. GPIO_Pin_1 = BIT1,
  44. GPIO_Pin_2 = BIT2,
  45. GPIO_Pin_3 = BIT3,
  46. GPIO_Pin_4 = BIT4,
  47. GPIO_Pin_5 = BIT5,
  48. GPIO_Pin_6 = BIT6,
  49. GPIO_Pin_7 = BIT7,
  50. GPIO_Pin_8 = BIT8,
  51. GPIO_Pin_9 = BIT9,
  52. GPIO_Pin_10 = BIT10,
  53. GPIO_Pin_11 = BIT11,
  54. GPIO_Pin_12 = BIT12,
  55. GPIO_Pin_13 = BIT13,
  56. GPIO_Pin_14 = BIT14,
  57. GPIO_Pin_15 = BIT15
  58. } GPIO_Pin_TypeDef;
  59. #define IS_GPIO_PIN(PIN) (((((PIN) & ~(uint16_t)0xFFFF)) == 0x00) && ((PIN) != (uint16_t)0x00))
  60. #define IS_GPIO_PIN_SINGLE(PIN) ((PIN == GPIO_Pin_0) || \
  61. (PIN == GPIO_Pin_1) || \
  62. (PIN == GPIO_Pin_2) || \
  63. (PIN == GPIO_Pin_3) || \
  64. (PIN == GPIO_Pin_4) || \
  65. (PIN == GPIO_Pin_5) || \
  66. (PIN == GPIO_Pin_6) || \
  67. (PIN == GPIO_Pin_7) || \
  68. (PIN == GPIO_Pin_8) || \
  69. (PIN == GPIO_Pin_9) || \
  70. (PIN == GPIO_Pin_10) || \
  71. (PIN == GPIO_Pin_11) || \
  72. (PIN == GPIO_Pin_12) || \
  73. (PIN == GPIO_Pin_13) || \
  74. (PIN == GPIO_Pin_14) || \
  75. (PIN == GPIO_Pin_15))
  76. typedef enum
  77. {
  78. GPIOA = 0,
  79. GPIOB,
  80. GPIOC,
  81. GPIOD,
  82. GPIOE
  83. } GPIO_TypeDef;
  84. #define IS_GPIO_PORT(port) (port <= GPIOE)
  85. /******************* Bit definition for gpio funaction **********************/
  86. #define INPUT ((GPIO_FUN_TYPEDEF) 0)
  87. #define QSPI_NCS ((GPIO_FUN_TYPEDEF) 2) /*Mapping the scope GPIO[32:0] and GPIO[76:56]*/
  88. #define QSPI_SCK ((GPIO_FUN_TYPEDEF) 3) /*Mapping the scope GPIO[32:0] and GPIO[76:56]*/
  89. #define QSPI_IO0 ((GPIO_FUN_TYPEDEF) 4) /*Mapping the scope GPIO[32:0] and GPIO[76:56]*/
  90. #define QSPI_IO1 ((GPIO_FUN_TYPEDEF) 5) /*Mapping the scope GPIO[32:0] and GPIO[76:56]*/
  91. #define QSPI_IO2 ((GPIO_FUN_TYPEDEF) 6) /*Mapping the scope GPIO[32:0] and GPIO[76:56]*/
  92. #define QSPI_IO3 ((GPIO_FUN_TYPEDEF) 7) /*Mapping the scope GPIO[32:0] and GPIO[76:56]*/
  93. #define UART0_TXD ((GPIO_FUN_TYPEDEF) 8)
  94. #define UART0_RXD ((GPIO_FUN_TYPEDEF) 9)
  95. #define UART0_RTS ((GPIO_FUN_TYPEDEF)10)
  96. #define UART0_CTS ((GPIO_FUN_TYPEDEF)11)
  97. #define UART1_TXD ((GPIO_FUN_TYPEDEF)12) /*Mapping the scope GPIO[47:0]*/
  98. #define UART1_RXD ((GPIO_FUN_TYPEDEF)13) /*Mapping the scope GPIO[47:0]*/
  99. #define UART1_RTS ((GPIO_FUN_TYPEDEF)14) /*Mapping the scope GPIO[47:0]*/
  100. #define UART1_CTS ((GPIO_FUN_TYPEDEF)15) /*Mapping the scope GPIO[47:0]*/
  101. #define UART2_TXD ((GPIO_FUN_TYPEDEF)36) /*Mapping the scope GPIO[79:40]*/
  102. #define UART2_RXD ((GPIO_FUN_TYPEDEF)37) /*Mapping the scope GPIO[79:40]*/
  103. #define UART2_RTS ((GPIO_FUN_TYPEDEF)38) /*Mapping the scope GPIO[79:40]*/
  104. #define UART2_CTS ((GPIO_FUN_TYPEDEF)39) /*Mapping the scope GPIO[79:40]*/
  105. #define UART3_TXD ((GPIO_FUN_TYPEDEF)53) /*Each group of 4 GPIOs is mapped to CTS/TXD/RXD/RTS,mapping the scope GPIO[60:20]*/
  106. #define UART3_RXD ((GPIO_FUN_TYPEDEF)53) /*Each group of 4 GPIOs is mapped to CTS/TXD/RXD/RTS,mapping the scope GPIO[60:20]*/
  107. #define UART3_RTS ((GPIO_FUN_TYPEDEF)53) /*Each group of 4 GPIOs is mapped to CTS/TXD/RXD/RTS,mapping the scope GPIO[60:20]*/
  108. #define UART3_CTS ((GPIO_FUN_TYPEDEF)53) /*Each group of 4 GPIOs is mapped to CTS/TXD/RXD/RTS,mapping the scope GPIO[60:20]*/
  109. #define PWM_OUT ((GPIO_FUN_TYPEDEF)16) /*Each group of 8 GPIOs is mapped to PWM0~7*/
  110. #define PWM_OUT8 ((GPIO_FUN_TYPEDEF)17) /*Mapping the scope GPIO[79:48]*/
  111. #define PWM_OUT01 ((GPIO_FUN_TYPEDEF)40) /*GPIO_INDEX%8 is not a 0 and 1 pin, each two is a group, respectively mapped to PWM0/PWM1*/
  112. #define PWM_OUT23 ((GPIO_FUN_TYPEDEF)41) /*GPIO_INDEX%8 is not a 2 and 3 pin, each two is a group, respectively mapped to PWM2/PWM3*/
  113. #define DCMI_PCLK ((GPIO_FUN_TYPEDEF)18)
  114. #define DCMI_VSYNC ((GPIO_FUN_TYPEDEF)19)
  115. #define DCMI_HSYNC ((GPIO_FUN_TYPEDEF)20)
  116. #define DCMI_D0 ((GPIO_FUN_TYPEDEF)21)
  117. #define DCMI_D1 ((GPIO_FUN_TYPEDEF)22)
  118. #define DCMI_D0_D13 ((GPIO_FUN_TYPEDEF)23) /*GPIO[7] to GPIO[76] is a group of 14, which are mapped to D13 to D0 respectively*/
  119. #define SPID_SDIO ((GPIO_FUN_TYPEDEF)27) /*Every 3 GPIOs are a group, which are respectively mapped to SPI0_SDIO/SPI1_SDIO/SPI2_SDIO*/
  120. #define SPID0_NCS ((GPIO_FUN_TYPEDEF)24) /*Mapping the scope GPIO[79:0]*/
  121. #define SPID0_SCK ((GPIO_FUN_TYPEDEF)25) /*Mapping the scope GPIO[79:0]*/
  122. #define SPID0_MOSI ((GPIO_FUN_TYPEDEF)26) /*Mapping the scope GPIO[79:0]*/
  123. #define SPID0_MISO ((GPIO_FUN_TYPEDEF)28) /*Mapping the scope GPIO[79:0]*/
  124. #define SPID1_NCS ((GPIO_FUN_TYPEDEF)48) /*Mapping the scope GPIO[79:0]*/
  125. #define SPID1_SCK ((GPIO_FUN_TYPEDEF)49) /*Mapping the scope GPIO[79:0]*/
  126. #define SPID1_MOSI ((GPIO_FUN_TYPEDEF)50) /*Mapping the scope GPIO[79:0]*/
  127. #define SPID1_MISO ((GPIO_FUN_TYPEDEF)52) /*Mapping the scope GPIO[79:0]*/
  128. #define SPID_SLV_IN ((GPIO_FUN_TYPEDEF)29) /*Each of 6 GPIOs is a group, which are mapped to MSPI0~2 NCS_IN/SCK_IN respectively*/
  129. #define XTAL32K ((GPIO_FUN_TYPEDEF)30) /*Mapping the scope GPIO[15:0] and [74:48]*/
  130. #define HSPI_NCS ((GPIO_FUN_TYPEDEF)31) /*Map to all pins*/
  131. #define HSPI_SCK ((GPIO_FUN_TYPEDEF)32) /*Map to all pins*/
  132. #define HSPI_MOSI ((GPIO_FUN_TYPEDEF)33) /*Map to all pins*/
  133. #define HSPI_MISO ((GPIO_FUN_TYPEDEF)34) /*Map to all pins*/
  134. #define DAC_OUT ((GPIO_FUN_TYPEDEF)35) /*Each group of 2 GPIOs is mapped to Out P/Out N respectively*/
  135. #define SDIO ((GPIO_FUN_TYPEDEF)42) /*Each of 6 GPIOs is a group mapped to SDIO_CLK/SDIO_CMD/DAT0/DAT1/DAT2/DAT3*/
  136. #define PSRAM_NCS ((GPIO_FUN_TYPEDEF)43)
  137. #define PSRAM_SCK ((GPIO_FUN_TYPEDEF)44)
  138. #define PSRAM_DATA_0 ((GPIO_FUN_TYPEDEF)45) /*Each group of 4 GPIOs is mapped to D0/D1/D2/D3 respectively*/
  139. #define PSRAM_DATA_1 ((GPIO_FUN_TYPEDEF)45) /*Each group of 4 GPIOs is mapped to D0/D1/D2/D3 respectively*/
  140. #define PSRAM_DATA_2 ((GPIO_FUN_TYPEDEF)45) /*Each group of 4 GPIOs is mapped to D0/D1/D2/D3 respectively*/
  141. #define PSRAM_DATA_3 ((GPIO_FUN_TYPEDEF)45) /*Each group of 4 GPIOs is mapped to D0/D1/D2/D3 respectively*/
  142. #define JTAG_RV_TCK ((GPIO_FUN_TYPEDEF)46) /*Each group of 4 GPIOs is mapped to TCK/TMS/TDI/TDO*/
  143. #define JTAG_RV_TMS ((GPIO_FUN_TYPEDEF)46) /*Each group of 4 GPIOs is mapped to TCK/TMS/TDI/TDO*/
  144. #define JTAG_RV_TDI ((GPIO_FUN_TYPEDEF)46) /*Each group of 4 GPIOs is mapped to TCK/TMS/TDI/TDO*/
  145. #define JTAG_RV_TDO ((GPIO_FUN_TYPEDEF)46) /*Each group of 4 GPIOs is mapped to TCK/TMS/TDI/TDO*/
  146. #define I2C0_SCL ((GPIO_FUN_TYPEDEF)58)
  147. #define I2C0_SDA ((GPIO_FUN_TYPEDEF)59)
  148. #define I2C1_SCL ((GPIO_FUN_TYPEDEF)47)
  149. #define I2C1_SDA ((GPIO_FUN_TYPEDEF)47)
  150. #define SCI7816_IO ((GPIO_FUN_TYPEDEF)56)
  151. #define SCI7816_IO2 ((GPIO_FUN_TYPEDEF)51)
  152. #define NFC_CLK_OUT ((GPIO_FUN_TYPEDEF)55)
  153. #define ICE ((GPIO_FUN_TYPEDEF)57)
  154. #define JTAG_SWCLK ((GPIO_FUN_TYPEDEF)60) /*The first 16 pins are mapped to SWCLK, and the latter pins are mapped to SWCLK/SWDIO for a group of 2 GPIOs*/
  155. #define JTAG_SWDIO ((GPIO_FUN_TYPEDEF)61) /*The first 16 pins are mapped to SWDIO*/
  156. #define OUTPUT_LOW ((GPIO_FUN_TYPEDEF)62)
  157. #define OUTPUT_HIGH ((GPIO_FUN_TYPEDEF)63)
  158. #define PULL_PU ((GPIO_FUN_TYPEDEF)64)
  159. #define PULL_PD ((GPIO_FUN_TYPEDEF)128)
  160. #define ANALOG ((GPIO_FUN_TYPEDEF)192)
  161. #define IS_GPIO_FUN(fun) (fun <= 0xff)
  162. #define IS_GPIO_MODE(mode) (((mode) == GPIO_Mode_IN_FLOATING) || \
  163. ((mode) == GPIO_Mode_IPU) || \
  164. ((mode) == GPIO_Mode_IPD) || \
  165. ((mode) == GPIO_Mode_AIN) || \
  166. ((mode) == GPIO_Mode_Out_PP))
  167. /**
  168. * @brief Bit_SET and Bit_RESET enumeration
  169. */
  170. typedef enum
  171. {
  172. Bit_RESET = 0,
  173. Bit_SET = 1
  174. } BitAction;
  175. /**
  176. * @brief Configuration Mode enumeration
  177. */
  178. typedef enum
  179. {
  180. GPIO_Mode_IN_FLOATING = 0x00,
  181. GPIO_Mode_IPU = 0x01,
  182. GPIO_Mode_IPD = 0x02,
  183. GPIO_Mode_AIN = 0x03,
  184. GPIO_Mode_Out_PP = 0x3E /*!< analog signal mode */
  185. } GPIO_ModeTypeDef;
  186. /**
  187. * @brief Configuration GPIO OD enumeration
  188. */
  189. typedef enum
  190. {
  191. GPIO_Mode_OD_RESET = 0x0,
  192. GPIO_Mode_OD_SET = 0x1
  193. } GPIO_ODTypeDef;
  194. #define IS_GPIO_MODE_OUT(mode) (((mode) == GPIO_Mode_OD_RESET) || \
  195. ((mode) == GPIO_Mode_OD_SET))
  196. /**
  197. * @brief GPIO Init structure definition
  198. */
  199. typedef struct
  200. {
  201. GPIO_Pin_TypeDef GPIO_Pin;
  202. GPIO_ModeTypeDef GPIO_Mode;
  203. } GPIO_InitTypeDef;
  204. uint32_t GPIO_GetGPIONum(GPIO_TypeDef GPIOx);
  205. void GPIO_Config(GPIO_TypeDef GPIOx, GPIO_Pin_TypeDef GPIO_Pin, GPIO_FUN_TYPEDEF function);
  206. void GPIO_Init(GPIO_TypeDef GPIOx, GPIO_InitTypeDef* GPIO_InitStruct);
  207. void GPIO_PullUpCmd(GPIO_TypeDef GPIOx, GPIO_Pin_TypeDef GPIO_Pin, FunctionalState NewState);
  208. uint16_t GPIO_ReadInputData(GPIO_TypeDef GPIOx);
  209. uint8_t GPIO_ReadInputDataBit(GPIO_TypeDef GPIOx, GPIO_Pin_TypeDef GPIO_Pin);
  210. uint16_t GPIO_ReadOutputData(GPIO_TypeDef GPIOx);
  211. uint8_t GPIO_ReadOutputDataBit(GPIO_TypeDef GPIOx, GPIO_Pin_TypeDef GPIO_Pin);
  212. void GPIO_ResetBit(GPIO_TypeDef GPIOx, GPIO_Pin_TypeDef GPIO_Pin);
  213. void GPIO_ResetBits(GPIO_TypeDef GPIOx, uint16_t GPIO_Pin);
  214. void GPIO_SetBit(GPIO_TypeDef GPIOx, GPIO_Pin_TypeDef GPIO_Pin);
  215. void GPIO_SetBits(GPIO_TypeDef GPIOx, uint16_t GPIO_Pin);
  216. void GPIO_Write(GPIO_TypeDef GPIOx, GPIO_Pin_TypeDef GPIO_Pin);
  217. void GPIO_WriteBit(GPIO_TypeDef GPIOx, GPIO_Pin_TypeDef GPIO_Pin, BitAction BitVal);
  218. void GPIO_ODSet(uint8_t GPIOx_OD, GPIO_ODTypeDef GPIO_OD_Set);
  219. #ifdef __cplusplus
  220. }
  221. #endif
  222. #endif /* __YC_GPIO_H__ */
  223. /************************ (C) COPYRIGHT Yichip Microelectronics *****END OF FILE****/