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