liubin | 281ac46 | 2023-07-19 14:22:54 +0800 | [diff] [blame] | 1 | /***************************************************************************** |
| 2 | * Copyright Statement: |
| 3 | * -------------------- |
| 4 | * This software is protected by Copyright and the information contained |
| 5 | * herein is confidential. The software may not be copied and the information |
| 6 | * contained herein may not be used or disclosed except with the written |
| 7 | * permission of Quectel Co., Ltd. 2019 |
| 8 | * |
| 9 | *****************************************************************************/ |
| 10 | /***************************************************************************** |
| 11 | * |
| 12 | * Filename: |
| 13 | * --------- |
| 14 | * ql_gpio.h |
| 15 | * |
| 16 | * Project: |
| 17 | * -------- |
| 18 | * OpenLinux |
| 19 | * |
| 20 | * Description: |
| 21 | * ------------ |
| 22 | * GPIO API defines. |
| 23 | * |
| 24 | * |
| 25 | *============================================================================ |
| 26 | * HISTORY |
| 27 | *---------------------------------------------------------------------------- |
| 28 | * WHO WHEN WHAT |
| 29 | *---------------------------------------------------------------------------- |
| 30 | * Carola.Zhang 16/07/2019 Create. |
| 31 | ****************************************************************************/ |
| 32 | |
| 33 | #ifndef __QL_GPIO_H__ |
| 34 | #define __QL_GPIO_H__ |
| 35 | |
| 36 | typedef enum{ |
| 37 | /*Invalid*/ PINNAME_BEGIN = -1, |
| 38 | /*PIN-1*/ PINNAME_GPIO1 = 1, |
| 39 | /*PIN-2*/ PINNAME_GPIO2 = 2, |
| 40 | /*PIN-3*/ PINNAME_GPIO3 = 3, |
| 41 | /*PIN-4*/ PINNAME_GPIO4 = 4, |
| 42 | /*PIN-5*/ PINNAME_GPIO5 = 5, |
| 43 | /*PIN-6*/ PINNAME_NET_STATUS = 6, |
| 44 | /*PIN-11*/ PINNAME_DBG_RXD = 11, |
| 45 | /*PIN-12*/ PINNAME_DBG_TXD = 12, |
| 46 | /*PIN-13*/ PINNAME_USIM_PRESENCE = 13, |
| 47 | /*PIN-23*/ PINNAME_SD_INT_DET = 23, |
| 48 | /*PIN-24*/ PINNAME_PCM_IN = 24, |
| 49 | /*PIN-25*/ PINNAME_PCM_OUT = 25, |
| 50 | /*PIN-26*/ PINNAME_PCM_SYNC = 26, |
| 51 | /*PIN-27*/ PINNAME_PCM_CLK = 27, |
| 52 | /*PIN-28*/ PINNAME_SDC2_DATA3 = 28, |
| 53 | /*PIN-29*/ PINNAME_SDC2_DATA2 = 29, |
| 54 | /*PIN-30*/ PINNAME_SDC2_DATA1 = 30, |
| 55 | /*PIN-31*/ PINNAME_SDC2_DATA0 = 31, |
| 56 | /*PIN-32*/ PINNAME_SDC2_CLK = 32, |
| 57 | /*PIN-33*/ PINNAME_SDC2_CMD = 33, |
| 58 | /*PIN-37*/ PINNAME_SPI_CS_N = 37, |
| 59 | /*PIN-38*/ PINNAME_SPI_MOSI = 38, |
| 60 | /*PIN-39*/ PINNAME_SPI_MISO = 39, |
| 61 | /*PIN-40*/ PINNAME_SPI_CLK = 40, |
| 62 | /*PIN-41*/ PINNAME_I2C_SCL = 41, |
| 63 | /*PIN-42*/ PINNAME_I2C_SDA = 42, |
b.liu | 4baa0a7 | 2023-11-22 14:51:52 +0800 | [diff] [blame] | 64 | /*PIN-45*/ PINNAME_GPIO20 = 45, |
| 65 | /*PIN-49*/ PINNAME_STATUS = 49, |
| 66 | /*PIN-51*/ PINNAME_NETLIGHT = 51, |
liubin | 281ac46 | 2023-07-19 14:22:54 +0800 | [diff] [blame] | 67 | /*PIN-62*/ PINNAME_GPIO6 = 62, |
| 68 | /*PIN-63*/ PINNAME_DCD = 63, |
| 69 | /*PIN-66*/ PINNAME_DTR = 66, |
| 70 | /*PIN-64*/ PINNAME_MAIN_CTS = 64, |
| 71 | /*PIN-65*/ PINNAME_MAIN_RTS = 65, |
| 72 | /*PIN-67*/ PINNAME_MAIN_TXD = 67, |
| 73 | /*PIN-68*/ PINNAME_MAIN_RXD = 68, |
| 74 | /*PIN-73*/ PINNAME_RMII_RXD1 = 73, |
| 75 | /*PIN-74*/ PINNAME_RMII_RXCL = 74, |
| 76 | /*PIN-75*/ PINNAME_RMII_CLK = 75, |
| 77 | /*PIN-76*/ PINNAME_RMII_RXD0 = 76, |
| 78 | /*PIN-77*/ PINNAME_RMII_TXD0 = 77, |
| 79 | /*PIN-78*/ PINNAME_RMII_TXD1 = 78, |
| 80 | /*PIN-79*/ PINNAME_RMII_RXD2 = 79, |
| 81 | /*PIN-80*/ PINNAME_RMII_TXD2 = 80, |
| 82 | /*PIN-81*/ PINNAME_RMII_TX_CTRL = 81, |
| 83 | /*PIN-82*/ PINNAME_RMII_RXD3 = 82, |
| 84 | /*PIN-83*/ PINNAME_RMII_TXCL = 83, |
| 85 | /*PIN-84*/ PINNAME_RMII_TXD3 = 84, |
| 86 | /*PIN-118*/ PINNAME_WLAN_SLP_CLK = 118, |
| 87 | /*PIN-119*/ PINNAME_RMII_RST = 119, |
| 88 | /*PIN-120*/ PINNAME_RMII_INT = 120, |
| 89 | /*PIN-121*/ PINNAME_RMII_MDIO = 121, |
| 90 | /*PIN-122*/ PINNAME_RMII_MDC = 122, |
b.liu | 4baa0a7 | 2023-11-22 14:51:52 +0800 | [diff] [blame] | 91 | /*PIN-123*/ PINNAME_PRI_TDI = 123, |
liubin | 281ac46 | 2023-07-19 14:22:54 +0800 | [diff] [blame] | 92 | /*PIN-127*/ PINNAME_WLAN_PER_EN = 127, |
| 93 | /*PIN-135*/ PINNAME_WLAN_WAKE = 135, |
| 94 | /*PIN-136*/ PINNAME_WLAN_EN = 136, |
| 95 | /*PIN-139*/ PINNAME_GPIO8 = 139, |
| 96 | PINNAME_END |
| 97 | }Enum_PinName; |
| 98 | |
| 99 | /**************************************************************************** |
| 100 | * Error Code Definition |
| 101 | ***************************************************************************/ |
| 102 | enum { |
| 103 | RES_OK = 0, |
| 104 | RES_BAD_PARAMETER = -1, ///< Parameter is invalid. |
| 105 | RES_IO_NOT_SUPPORT = -2, |
| 106 | RES_IO_ERROR = -3, |
| 107 | RES_NOT_IMPLEMENTED = -4 |
| 108 | }; |
| 109 | |
| 110 | typedef enum{ |
| 111 | PINDIRECTION_IN = 0, |
| 112 | PINDIRECTION_OUT = 1 |
| 113 | }Enum_PinDirection; |
| 114 | |
| 115 | typedef enum{ |
| 116 | PINLEVEL_LOW = 0, |
| 117 | PINLEVEL_HIGH = 1 |
| 118 | }Enum_PinLevel; |
| 119 | |
| 120 | typedef enum{ |
| 121 | PINPULLSEL_DISABLE = (0<<13), // Disable pull selection |
| 122 | PINPULLSEL_PULLDOWN = (5<<13), // Pull-down |
| 123 | PINPULLSEL_PULLUP = (6<<13) // Pull-up |
| 124 | }Enum_PinPullSel; |
| 125 | |
| 126 | /**************************************************************************** |
| 127 | * GPIO Config Items |
| 128 | ***************************************************************************/ |
| 129 | typedef struct{ |
| 130 | Enum_PinName pin_name; |
| 131 | Enum_PinDirection pinDirection; |
| 132 | Enum_PinLevel pinLevel; |
| 133 | Enum_PinPullSel pinPullSel; |
| 134 | }ST_GPIOConfig; |
| 135 | |
| 136 | //------------------------------------------------------------------------------ |
| 137 | /** |
| 138 | * The type of GPIO Edge Sensivity. |
| 139 | */ |
| 140 | //------------------------------------------------------------------------------ |
| 141 | typedef enum { |
| 142 | EINT_SENSE_NONE, // pin is input, but no an interrupt pin. |
| 143 | EINT_SENSE_RISING, |
| 144 | EINT_SENSE_FALLING, |
| 145 | EINT_SENSE_BOTH |
| 146 | }Enum_EintType; |
| 147 | |
| 148 | /***************************************************************** |
| 149 | * Function: Ql_GPIO_Init |
| 150 | * |
| 151 | * Description: |
| 152 | * This function enables the GPIO function of the specified pin, |
| 153 | * and initialize the configurations, including direction, |
| 154 | * level and pull selection. |
| 155 | * |
| 156 | * Parameters: |
| 157 | * pin_name: |
| 158 | * Pin name, one value of Enum_PinName. |
| 159 | * dir: |
| 160 | * The initial direction of GPIO, one value of Enum_PinDirection. |
| 161 | * level: |
| 162 | * The initial level of GPIO, one value of Enum_PinLevel. |
| 163 | * pull_sel: |
| 164 | * Pull selection, one value of Enum_PinPullSel. |
| 165 | * Return: |
| 166 | * RES_OK, this function succeeds. |
| 167 | * RES_IO_NOT_SUPPORT, the input GPIO is invalid. |
| 168 | * RES_IO_ERR, the function failed |
| 169 | * other place. For example this GPIO has been using as EINT. |
| 170 | *****************************************************************/ |
| 171 | int Ql_GPIO_Init(Enum_PinName pin_name, |
| 172 | Enum_PinDirection dir, |
| 173 | Enum_PinLevel level, |
| 174 | Enum_PinPullSel pull_sel |
| 175 | ); |
| 176 | |
| 177 | /***************************************************************** |
| 178 | * Function: Ql_GPIO_Base_Init |
| 179 | * |
| 180 | * Description: |
| 181 | * This function enables the GPIO function of the specified pin. |
| 182 | * |
| 183 | * Parameters: |
| 184 | * pin_name: |
| 185 | * Pin name, one value of Enum_PinName. |
| 186 | * |
| 187 | * Return: |
| 188 | * RES_OK, this function succeeds. |
| 189 | * RES_IO_NOT_SUPPORT, the input GPIO is invalid. |
| 190 | * RES_IO_ERR, the function failed |
| 191 | *****************************************************************/ |
| 192 | int Ql_GPIO_Base_Init(Enum_PinName pin_name ); |
| 193 | |
| 194 | /***************************************************************** |
| 195 | * Function: Ql_GPIO_SetLevel |
| 196 | * |
| 197 | * Description: |
| 198 | * This function sets the level of the specified GPIO. |
| 199 | * |
| 200 | * Parameters: |
| 201 | * pin_name: |
| 202 | * Pin name, one value of Enum_PinName. |
| 203 | * level: |
| 204 | * The initial level of GPIO, one value of Enum_PinLevel. |
| 205 | * Return: |
| 206 | * RES_OK, this function succeeds. |
| 207 | * RES_IO_NOT_SUPPORT, the input GPIO is invalid. |
| 208 | * RES_IO_ERR, the function failed |
| 209 | * other place. For example this GPIO has been using as EINT. |
| 210 | *****************************************************************/ |
| 211 | int Ql_GPIO_SetLevel(Enum_PinName pin_name, Enum_PinLevel level); |
| 212 | |
| 213 | /***************************************************************** |
| 214 | * Function: Ql_GPIO_GetLevel |
| 215 | * |
| 216 | * Description: |
| 217 | * This function gets the level of the specified GPIO. |
| 218 | * |
| 219 | * Parameters: |
| 220 | * pin_name: |
| 221 | * Pin name, one value of Enum_PinName. |
| 222 | * Return: |
| 223 | * The level value of the specified GPIO, which is |
| 224 | * nonnegative integer. |
| 225 | * RES_IO_NOT_SUPPORT, the input GPIO is invalid. |
| 226 | *****************************************************************/ |
| 227 | int Ql_GPIO_GetLevel(Enum_PinName pin_name); |
| 228 | |
| 229 | /***************************************************************** |
| 230 | * Function: Ql_GPIO_SetDirection |
| 231 | * |
| 232 | * Description: |
| 233 | * This function sets the direction of the specified GPIO. |
| 234 | * |
| 235 | * Parameters: |
| 236 | * pin_name: |
| 237 | * Pin name, one value of Enum_PinName. |
| 238 | * dir: |
| 239 | * The initial direction of GPIO, one value of Enum_PinDirection. |
| 240 | * Return: |
| 241 | * RES_OK, this function succeeds. |
| 242 | * RES_IO_NOT_SUPPORT, the input GPIO is invalid. |
| 243 | * RES_IO_ERR, the function failed |
| 244 | * other place. For example this GPIO has been using as EINT. |
| 245 | *****************************************************************/ |
| 246 | int Ql_GPIO_SetDirection(Enum_PinName pin_name, Enum_PinDirection dir); |
| 247 | |
| 248 | /***************************************************************** |
| 249 | * Function: Ql_GPIO_GetDirection |
| 250 | * |
| 251 | * Description: |
| 252 | * This function gets the direction of the specified GPIO. |
| 253 | * |
| 254 | * Parameters: |
| 255 | * pin_name: |
| 256 | * Pin name, one value of Enum_PinName. |
| 257 | * Return: |
| 258 | * 0 INPUT |
| 259 | * 1 OUTPUT |
| 260 | * RES_IO_NOT_SUPPORT, the input GPIO is invalid. |
| 261 | * other place. For example this GPIO has been using as EINT. |
| 262 | *****************************************************************/ |
| 263 | int Ql_GPIO_GetDirection(Enum_PinName pin_name); |
| 264 | |
| 265 | /***************************************************************** |
| 266 | * Function: Ql_GPIO_SetPullSelection |
| 267 | * |
| 268 | * Description: |
| 269 | * This function sets the pull selection of the specified GPIO. |
| 270 | * |
| 271 | * Parameters: |
| 272 | * pin_name: |
| 273 | * Pin name, one value of Enum_PinName. |
| 274 | * Enum_PinPullSel: |
| 275 | * Pull selection, one value of Enum_PinPullSel. |
| 276 | * Return: |
| 277 | * RES_OK, this function succeeds. |
| 278 | * RES_IO_NOT_SUPPORT, the input GPIO is invalid. |
| 279 | * RES_IO_ERR, the function failed |
| 280 | * other place. For example this GPIO has been using as EINT. |
| 281 | *****************************************************************/ |
| 282 | int Ql_GPIO_SetPullSelection(Enum_PinName pin_name, Enum_PinPullSel pull_sel); |
| 283 | |
| 284 | /***************************************************************** |
| 285 | * Function: ql_gpio_get_pull_selection |
| 286 | * |
| 287 | * Description: |
| 288 | * This function gets the pull selection of the specified GPIO. |
| 289 | * |
| 290 | * Parameters: |
| 291 | * pin_name: |
| 292 | * Pin name, one value of Enum_PinName. |
| 293 | * Return: |
| 294 | * 0<<13 no pull |
| 295 | * 5<<13 pull down |
| 296 | * 6<<13 pull up |
| 297 | *****************************************************************/ |
| 298 | int Ql_GPIO_GetPullSelection(Enum_PinName pin_name); |
| 299 | |
| 300 | /***************************************************************** |
| 301 | * Function: Ql_GPIO_Uninit |
| 302 | * |
| 303 | * Description: |
| 304 | * This function releases the specified GPIO that was |
| 305 | * initialized by calling Ql_GPIO_Init() previously. |
| 306 | * After releasing, the GPIO can be used for other purpose. |
| 307 | * Parameters: |
| 308 | * pin_name: |
| 309 | * Pin name, one value of Enum_PinName. |
| 310 | * Return: |
| 311 | * RES_OK, this function succeeds. |
| 312 | * RES_IO_NOT_SUPPORT, the input GPIO is invalid. |
| 313 | * RES_IO_ERR, the function failed |
| 314 | * other place. For example this GPIO has been using as EINT. |
| 315 | *****************************************************************/ |
| 316 | int Ql_GPIO_Uninit(Enum_PinName pin_name); |
| 317 | |
| 318 | //------------------------------------------------------------------------------ |
| 319 | /* |
| 320 | * Description: |
| 321 | * Definition for EINT callback function. |
| 322 | * |
| 323 | * Parameters: |
| 324 | * PinName: |
| 325 | * EINT pin name, one value of Enum_PinName. |
| 326 | * |
| 327 | * level: |
| 328 | * The EINT level value, one value of Enum_PinLevel. |
| 329 | * 0 or 1 |
| 330 | */ |
| 331 | //------------------------------------------------------------------------------ |
| 332 | typedef void (*Ql_EINT_Callback)(Enum_PinName eint_pin_name, int level); |
| 333 | |
| 334 | //------------------------------------------------------------------------------ |
| 335 | /* |
| 336 | * Function: Ql_EINT_Enable |
| 337 | * |
| 338 | * Description: |
| 339 | * Set the interrupt sense mode, and enable interrupt. |
| 340 | * |
| 341 | * Parameters: |
| 342 | * eint_pin_name: |
| 343 | * EINT pin name, one value of Enum_PinName that has |
| 344 | * the interrupt function. |
| 345 | * |
| 346 | * eint_type: |
| 347 | * Interrupt type, level-triggered or edge-triggered. |
| 348 | * Now, only edge-triggered interrupt is supported. |
| 349 | * |
| 350 | * eint_callback: |
| 351 | * call back function |
| 352 | * |
| 353 | * Return: |
| 354 | * RES_OK, this function succeeds. |
| 355 | * else failed to execute the function. |
| 356 | */ |
| 357 | //------------------------------------------------------------------------------ |
| 358 | int Ql_EINT_Enable(Enum_PinName eint_pin_name, Enum_EintType eint_type, Ql_EINT_Callback eint_callback); |
| 359 | |
| 360 | |
| 361 | //------------------------------------------------------------------------------ |
| 362 | /* |
| 363 | * Function: Ql_EINT_Disable |
| 364 | * |
| 365 | * Description: |
| 366 | * Disable the interrupt sense. |
| 367 | * |
| 368 | * Parameters: |
| 369 | * eint_pin_name: |
| 370 | * EINT pin name, one value of Enum_PinName that has |
| 371 | * the interrupt function. |
| 372 | * |
| 373 | * Return: |
| 374 | * RES_OK, this function succeeds. |
| 375 | * else failed to execute the function. |
| 376 | */ |
| 377 | //------------------------------------------------------------------------------ |
| 378 | int Ql_EINT_Disable(Enum_PinName eint_pin_name); |
| 379 | |
| 380 | #endif // __QL_GPIO_H__ |