blob: 74402e98d5152f87dfea53f4e69a822d5738dd06 [file] [log] [blame]
liubin281ac462023-07-19 14:22:54 +08001/*****************************************************************************
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
36typedef 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,
64 /*PIN-62*/ PINNAME_GPIO6 = 62,
65 /*PIN-63*/ PINNAME_DCD = 63,
66 /*PIN-66*/ PINNAME_DTR = 66,
67 /*PIN-64*/ PINNAME_MAIN_CTS = 64,
68 /*PIN-65*/ PINNAME_MAIN_RTS = 65,
69 /*PIN-67*/ PINNAME_MAIN_TXD = 67,
70 /*PIN-68*/ PINNAME_MAIN_RXD = 68,
71 /*PIN-73*/ PINNAME_RMII_RXD1 = 73,
72 /*PIN-74*/ PINNAME_RMII_RXCL = 74,
73 /*PIN-75*/ PINNAME_RMII_CLK = 75,
74 /*PIN-76*/ PINNAME_RMII_RXD0 = 76,
75 /*PIN-77*/ PINNAME_RMII_TXD0 = 77,
76 /*PIN-78*/ PINNAME_RMII_TXD1 = 78,
77 /*PIN-79*/ PINNAME_RMII_RXD2 = 79,
78 /*PIN-80*/ PINNAME_RMII_TXD2 = 80,
79 /*PIN-81*/ PINNAME_RMII_TX_CTRL = 81,
80 /*PIN-82*/ PINNAME_RMII_RXD3 = 82,
81 /*PIN-83*/ PINNAME_RMII_TXCL = 83,
82 /*PIN-84*/ PINNAME_RMII_TXD3 = 84,
83 /*PIN-118*/ PINNAME_WLAN_SLP_CLK = 118,
84 /*PIN-119*/ PINNAME_RMII_RST = 119,
85 /*PIN-120*/ PINNAME_RMII_INT = 120,
86 /*PIN-121*/ PINNAME_RMII_MDIO = 121,
87 /*PIN-122*/ PINNAME_RMII_MDC = 122,
88 /*PIN-127*/ PINNAME_WLAN_PER_EN = 127,
89 /*PIN-135*/ PINNAME_WLAN_WAKE = 135,
90 /*PIN-136*/ PINNAME_WLAN_EN = 136,
91 /*PIN-139*/ PINNAME_GPIO8 = 139,
92 PINNAME_END
93}Enum_PinName;
94
95/****************************************************************************
96 * Error Code Definition
97 ***************************************************************************/
98enum {
99 RES_OK = 0,
100 RES_BAD_PARAMETER = -1, ///< Parameter is invalid.
101 RES_IO_NOT_SUPPORT = -2,
102 RES_IO_ERROR = -3,
103 RES_NOT_IMPLEMENTED = -4
104};
105
106typedef enum{
107 PINDIRECTION_IN = 0,
108 PINDIRECTION_OUT = 1
109}Enum_PinDirection;
110
111typedef enum{
112 PINLEVEL_LOW = 0,
113 PINLEVEL_HIGH = 1
114}Enum_PinLevel;
115
116typedef enum{
117 PINPULLSEL_DISABLE = (0<<13), // Disable pull selection
118 PINPULLSEL_PULLDOWN = (5<<13), // Pull-down
119 PINPULLSEL_PULLUP = (6<<13) // Pull-up
120}Enum_PinPullSel;
121
122/****************************************************************************
123 * GPIO Config Items
124 ***************************************************************************/
125typedef struct{
126 Enum_PinName pin_name;
127 Enum_PinDirection pinDirection;
128 Enum_PinLevel pinLevel;
129 Enum_PinPullSel pinPullSel;
130}ST_GPIOConfig;
131
132//------------------------------------------------------------------------------
133/**
134 * The type of GPIO Edge Sensivity.
135 */
136//------------------------------------------------------------------------------
137typedef enum {
138 EINT_SENSE_NONE, // pin is input, but no an interrupt pin.
139 EINT_SENSE_RISING,
140 EINT_SENSE_FALLING,
141 EINT_SENSE_BOTH
142}Enum_EintType;
143
144/*****************************************************************
145* Function: Ql_GPIO_Init
146*
147* Description:
148* This function enables the GPIO function of the specified pin,
149* and initialize the configurations, including direction,
150* level and pull selection.
151*
152* Parameters:
153* pin_name:
154* Pin name, one value of Enum_PinName.
155* dir:
156* The initial direction of GPIO, one value of Enum_PinDirection.
157* level:
158* The initial level of GPIO, one value of Enum_PinLevel.
159* pull_sel:
160* Pull selection, one value of Enum_PinPullSel.
161* Return:
162* RES_OK, this function succeeds.
163* RES_IO_NOT_SUPPORT, the input GPIO is invalid.
164* RES_IO_ERR, the function failed
165* other place. For example this GPIO has been using as EINT.
166*****************************************************************/
167int Ql_GPIO_Init(Enum_PinName pin_name,
168 Enum_PinDirection dir,
169 Enum_PinLevel level,
170 Enum_PinPullSel pull_sel
171 );
172
173/*****************************************************************
174* Function: Ql_GPIO_Base_Init
175*
176* Description:
177* This function enables the GPIO function of the specified pin.
178*
179* Parameters:
180* pin_name:
181* Pin name, one value of Enum_PinName.
182*
183* Return:
184* RES_OK, this function succeeds.
185* RES_IO_NOT_SUPPORT, the input GPIO is invalid.
186* RES_IO_ERR, the function failed
187*****************************************************************/
188int Ql_GPIO_Base_Init(Enum_PinName pin_name );
189
190/*****************************************************************
191* Function: Ql_GPIO_SetLevel
192*
193* Description:
194* This function sets the level of the specified GPIO.
195*
196* Parameters:
197* pin_name:
198* Pin name, one value of Enum_PinName.
199* level:
200* The initial level of GPIO, one value of Enum_PinLevel.
201* Return:
202* RES_OK, this function succeeds.
203* RES_IO_NOT_SUPPORT, the input GPIO is invalid.
204* RES_IO_ERR, the function failed
205* other place. For example this GPIO has been using as EINT.
206*****************************************************************/
207int Ql_GPIO_SetLevel(Enum_PinName pin_name, Enum_PinLevel level);
208
209/*****************************************************************
210* Function: Ql_GPIO_GetLevel
211*
212* Description:
213* This function gets the level of the specified GPIO.
214*
215* Parameters:
216* pin_name:
217* Pin name, one value of Enum_PinName.
218* Return:
219* The level value of the specified GPIO, which is
220* nonnegative integer.
221* RES_IO_NOT_SUPPORT, the input GPIO is invalid.
222*****************************************************************/
223int Ql_GPIO_GetLevel(Enum_PinName pin_name);
224
225/*****************************************************************
226* Function: Ql_GPIO_SetDirection
227*
228* Description:
229* This function sets the direction of the specified GPIO.
230*
231* Parameters:
232* pin_name:
233* Pin name, one value of Enum_PinName.
234* dir:
235* The initial direction of GPIO, one value of Enum_PinDirection.
236* Return:
237* RES_OK, this function succeeds.
238* RES_IO_NOT_SUPPORT, the input GPIO is invalid.
239* RES_IO_ERR, the function failed
240* other place. For example this GPIO has been using as EINT.
241*****************************************************************/
242int Ql_GPIO_SetDirection(Enum_PinName pin_name, Enum_PinDirection dir);
243
244/*****************************************************************
245* Function: Ql_GPIO_GetDirection
246*
247* Description:
248* This function gets the direction of the specified GPIO.
249*
250* Parameters:
251* pin_name:
252* Pin name, one value of Enum_PinName.
253* Return:
254* 0 INPUT
255* 1 OUTPUT
256* RES_IO_NOT_SUPPORT, the input GPIO is invalid.
257* other place. For example this GPIO has been using as EINT.
258*****************************************************************/
259int Ql_GPIO_GetDirection(Enum_PinName pin_name);
260
261/*****************************************************************
262* Function: Ql_GPIO_SetPullSelection
263*
264* Description:
265* This function sets the pull selection of the specified GPIO.
266*
267* Parameters:
268* pin_name:
269* Pin name, one value of Enum_PinName.
270* Enum_PinPullSel:
271* Pull selection, one value of Enum_PinPullSel.
272* Return:
273* RES_OK, this function succeeds.
274* RES_IO_NOT_SUPPORT, the input GPIO is invalid.
275* RES_IO_ERR, the function failed
276* other place. For example this GPIO has been using as EINT.
277*****************************************************************/
278int Ql_GPIO_SetPullSelection(Enum_PinName pin_name, Enum_PinPullSel pull_sel);
279
280/*****************************************************************
281* Function: ql_gpio_get_pull_selection
282*
283* Description:
284* This function gets the pull selection of the specified GPIO.
285*
286* Parameters:
287* pin_name:
288* Pin name, one value of Enum_PinName.
289* Return:
290* 0<<13 no pull
291* 5<<13 pull down
292* 6<<13 pull up
293*****************************************************************/
294int Ql_GPIO_GetPullSelection(Enum_PinName pin_name);
295
296/*****************************************************************
297* Function: Ql_GPIO_Uninit
298*
299* Description:
300* This function releases the specified GPIO that was
301* initialized by calling Ql_GPIO_Init() previously.
302* After releasing, the GPIO can be used for other purpose.
303* Parameters:
304* pin_name:
305* Pin name, one value of Enum_PinName.
306* Return:
307* RES_OK, this function succeeds.
308* RES_IO_NOT_SUPPORT, the input GPIO is invalid.
309* RES_IO_ERR, the function failed
310* other place. For example this GPIO has been using as EINT.
311*****************************************************************/
312int Ql_GPIO_Uninit(Enum_PinName pin_name);
313
314//------------------------------------------------------------------------------
315/*
316* Description:
317* Definition for EINT callback function.
318*
319* Parameters:
320* PinName:
321* EINT pin name, one value of Enum_PinName.
322*
323* level:
324* The EINT level value, one value of Enum_PinLevel.
325* 0 or 1
326*/
327//------------------------------------------------------------------------------
328typedef void (*Ql_EINT_Callback)(Enum_PinName eint_pin_name, int level);
329
330//------------------------------------------------------------------------------
331/*
332* Function: Ql_EINT_Enable
333*
334* Description:
335* Set the interrupt sense mode, and enable interrupt.
336*
337* Parameters:
338* eint_pin_name:
339* EINT pin name, one value of Enum_PinName that has
340* the interrupt function.
341*
342* eint_type:
343* Interrupt type, level-triggered or edge-triggered.
344* Now, only edge-triggered interrupt is supported.
345*
346* eint_callback:
347* call back function
348*
349* Return:
350* RES_OK, this function succeeds.
351* else failed to execute the function.
352*/
353//------------------------------------------------------------------------------
354int Ql_EINT_Enable(Enum_PinName eint_pin_name, Enum_EintType eint_type, Ql_EINT_Callback eint_callback);
355
356
357//------------------------------------------------------------------------------
358/*
359* Function: Ql_EINT_Disable
360*
361* Description:
362* Disable the interrupt sense.
363*
364* Parameters:
365* eint_pin_name:
366* EINT pin name, one value of Enum_PinName that has
367* the interrupt function.
368*
369* Return:
370* RES_OK, this function succeeds.
371* else failed to execute the function.
372*/
373//------------------------------------------------------------------------------
374int Ql_EINT_Disable(Enum_PinName eint_pin_name);
375
376#endif // __QL_GPIO_H__