blob: 144d363b4847b6a76970776243a24fb343cda5f7 [file] [log] [blame]
b.liud440f9f2025-04-18 10:44:31 +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 * Larry.Zhang 24/09/2021 Create.
31 ****************************************************************************/
32
33#ifndef __QL_GPIO_H__
34#define __QL_GPIO_H__
35
36#ifdef __cplusplus
37extern "C" {
38#endif
39
40/* GPIO MAP */
41typedef enum{
42 PINNAME_BEGIN = -1,
43
44 /* GPIO1 ~ GPIO8 */
45 PINNAME_GPIO_117 = 117, /* GPIO1 */
46 PINNAME_GPIO_118 = 118, /* GPIO2 */
47 PINNAME_GPIO_120 = 120, /* GPIO3 */
48 PINNAME_GPIO_122 = 122, /* GPIO4 */
49 PINNAME_GPIO_38 = 38, /* GPIO5 */
50 PINNAME_GPIO_39 = 39, /* GPIO6 */
51 PINNAME_GPIO_37 = 37, /* GPIO7 */
52 PINNAME_GPIO_40 = 40, /* GPIO8 */
53
54 /* The follow pins are not use as GPIO by defaut, please contract Quectel for support */
55
56 /* WLAN */
57 PINNAME_GPIO_58 = 58, /* SDIO1_CMD */
58 PINNAME_GPIO_59 = 59, /* SDIO1_CLK */
59 PINNAME_GPIO_57 = 57, /* SDIO1_DATA0 */
60 PINNAME_GPIO_56 = 56, /* SDIO1_DATA1 */
61 PINNAME_GPIO_55 = 55, /* SDIO1_DATA2 */
62 PINNAME_GPIO_48 = 48, /* SDIO1_DATA3 */
63 PINNAME_GPIO_19 = 19, /* WLAN_EN */
64 PINNAME_GPIO_43 = 43, /* WLAN_SLP_CLK */
65 PINNAME_GPIO_123 = 123, /* WLAN_PWR_EN */
66 PINNAME_GPIO_11 = 11, /* BT_EN */
67 PINNAME_GPIO_127 = 127, /* WLAN_WAKE */
68 PINNAME_GPIO_125 = 125, /* RESERVED */
69
70 /* I2C */
71 PINNAME_GPIO_50 = 50, /* I2C1_SDA */
72 PINNAME_GPIO_49 = 49, /* I2C1_SCL */
73 PINNAME_GPIO_42 = 42, /* I2C2_SDA */
74 PINNAME_GPIO_41 = 41, /* I2C2_SCL */
75
76 /* UART */
77 PINNAME_GPIO_32 = 32, /* MAIN_CTS */
78 PINNAME_GPIO_31 = 31, /* MAIN_RTS */
79 PINNAME_GPIO_51 = 51, /* MAIN_RXD */
80 PINNAME_GPIO_52 = 52, /* MAIN_TXD */
81 PINNAME_GPIO_54 = 54, /* BT_TXD */
82 PINNAME_GPIO_47 = 47, /* BT_CTS */
83 PINNAME_GPIO_53 = 53, /* BT_RXD */
84 PINNAME_GPIO_46 = 46, /* BT_RTS */
85 PINNAME_GPIO_45 = 45, /* GNSS_TXD */
86 PINNAME_GPIO_44 = 44, /* GNSS_RXD */
87
88 /* SPI */
89 PINNAME_GPIO_23 = 23, /* SPI1_DOUT */
90 PINNAME_GPIO_24 = 24, /* SPI1_DIN */
91 PINNAME_GPIO_22 = 22, /* SPI1_CS */
92 PINNAME_GPIO_21 = 21, /* SPI1_CLK */
93 PINNAME_GPIO_34 = 34, /* SPI2_CS */
94 PINNAME_GPIO_35 = 35, /* SPI2_DIN */
95 PINNAME_GPIO_36 = 36, /* SPI2_DOUT */
96 PINNAME_GPIO_33 = 33, /* SPI2_CLK */
97
98 PINNAME_END = 127
99}ENUM_PINNAME;
100
101
102/****************************************************************************
103 * Error Code Definition
104 ***************************************************************************/
105enum {
106 RES_OK = 0,
107 RES_BAD_PARAMETER = -1, ///< Parameter is invalid.
108 RES_IO_NOT_SUPPORT = -2,
109 RES_IO_ERROR = -3,
110 RES_NOT_IMPLEMENTED = -4
111};
112
113typedef enum{
114 PINDIRECTION_IN = 0, /** GPIO input direction */
115 PINDIRECTION_OUT = 1 /** GPIO output direction */
116}ENUM_PIN_DIRECTION;
117
118typedef enum{
119 PINLEVEL_LOW = 0, /** GPIO low level */
120 PINLEVEL_HIGH = 1 /** GPIO high level */
121}ENUM_PIN_LEVEL;
122
123typedef enum{
124 PINPULLSEL_DISABLE = 0, /** Disable pull selection */
125 PINPULLSEL_PULLDOWN = 1, /**pull down */
126 PINPULLSEL_PULLUP = 2 /**pull up */
127}ENUM_PIN_PULLSEL;
128
129/****************************************************************************
130 * GPIO Config Items
131 ***************************************************************************/
132typedef struct{
133 ENUM_PINNAME pin_name; /** GPIO pin_name arrey*/
134 ENUM_PIN_DIRECTION pin_direction; /** GPIO pinDirection arrey*/
135 ENUM_PIN_LEVEL pin_level; /** GPIO pinLevel arrey*/
136 ENUM_PIN_PULLSEL pin_pullSel; /** GPIO pinPullSel arrey*/
137}st_gpio_config;
138
139//------------------------------------------------------------------------------
140/**
141 * The type of GPIO Edge Sensivity.
142 */
143//------------------------------------------------------------------------------
144typedef enum {
145 EINT_SENSE_NONE, // pin is input, but no an interrupt pin.
146 EINT_SENSE_RISING,
147 EINT_SENSE_FALLING,
148 EINT_SENSE_BOTH
149}ENUM_EINT_TYPE;
150
151/*****************************************************************
152* Function: ql_gpio_init
153*
154* Description:
155* This function enables the GPIO function of the specified pin,
156* and initialize the configurations, including direction,
157* level and pull selection.
158*
159* Parameters:
160* pin_name:
161* Pin name, one value of ENUM_PINNAME.
162* dir:
163* The initial direction of GPIO, one value of ENUM_PIN_DIRECTION.
164* level:
165* The initial level of GPIO, one value of ENUM_PIN_LEVEL.
166* pullSel:
167* Pull selection, one value of ENUM_PIN_PULLSEL.
168* Return:
169* RES_OK, this function succeeds.
170* RES_IO_NOT_SUPPORT, the input GPIO is invalid.
171* RES_IO_ERR, the function failed
172* other place. For example this GPIO has been using as EINT.
173*****************************************************************/
174int ql_gpio_init(ENUM_PINNAME pin_name,
175 ENUM_PIN_DIRECTION dir,
176 ENUM_PIN_LEVEL level,
177 ENUM_PIN_PULLSEL pull_sel
178 );
179
180/*****************************************************************
181* Function: ql_gpio_base_init
182*
183* Description:
184* This function enables the GPIO function of the specified pin.
185*
186* Parameters:
187* pin_name:
188* Pin name, one value of ENUM_PINNAME.
189*
190* Return:
191* RES_OK, this function succeeds.
192* RES_IO_NOT_SUPPORT, the input GPIO is invalid.
193* RES_IO_ERR, the function failed
194*****************************************************************/
195int ql_gpio_base_init(ENUM_PINNAME pin_name );
196
197/*****************************************************************
198* Function: ql_gpio_set_level
199*
200* Description:
201* This function sets the level of the specified GPIO.
202*
203* Parameters:
204* pin_name:
205* Pin name, one value of ENUM_PINNAME.
206* level:
207* The initial level of GPIO, one value of ENUM_PIN_LEVEL.
208* Return:
209* RES_OK, this function succeeds.
210* RES_IO_NOT_SUPPORT, the input GPIO is invalid.
211* RES_IO_ERR, the function failed
212* other place. For example this GPIO has been using as EINT.
213*****************************************************************/
214int ql_gpio_set_level(ENUM_PINNAME pin_name, ENUM_PIN_LEVEL level);
215
216/*****************************************************************
217* Function: ql_gpio_get_level
218*
219* Description:
220* This function gets the level of the specified GPIO.
221*
222* Parameters:
223* pin_name:
224* Pin name, one value of ENUM_PINNAME.
225* Return:
226* The level value of the specified GPIO, which is
227* nonnegative integer.
228* RES_IO_NOT_SUPPORT, the input GPIO is invalid.
229*****************************************************************/
230int ql_gpio_get_level(ENUM_PINNAME pin_name);
231
232/*****************************************************************
233* Function: ql_gpio_set_direction
234*
235* Description:
236* This function sets the direction of the specified GPIO.
237*
238* Parameters:
239* pin_name:
240* Pin name, one value of ENUM_PINNAME.
241* dir:
242* The initial direction of GPIO, one value of ENUM_PIN_DIRECTION.
243* Return:
244* RES_OK, this function succeeds.
245* RES_IO_NOT_SUPPORT, the input GPIO is invalid.
246* RES_IO_ERR, the function failed
247* other place. For example this GPIO has been using as EINT.
248*****************************************************************/
249int ql_gpio_set_direction(ENUM_PINNAME pin_name, ENUM_PIN_DIRECTION dir);
250
251/*****************************************************************
252* Function: ql_gpio_get_direction
253*
254* Description:
255* This function gets the direction of the specified GPIO.
256*
257* Parameters:
258* pin_name:
259* Pin name, one value of ENUM_PINNAME.
260* Return:
261* 0 INPUT
262* 1 OUTPUT
263* RES_IO_NOT_SUPPORT, the input GPIO is invalid.
264* other place. For example this GPIO has been using as EINT.
265*****************************************************************/
266int ql_gpio_get_direction(ENUM_PINNAME pin_name);
267
268
269/*****************************************************************
270* Function: ql_gpio_set_pull_selection
271*
272* Description:
273* This function sets the pull selection of the specified GPIO.
274*
275* Parameters:
276* pin_name:
277* Pin name, one value of ENUM_PINNAME.
278* ENUM_PIN_PULLSEL:
279* Pull selection, one value of ENUM_PIN_PULLSEL.
280* Return:
281* RES_OK, this function succeeds.
282* RES_IO_NOT_SUPPORT, the input GPIO is invalid.
283* RES_IO_ERR, the function failed
284* other place. For example this GPIO has been using as EINT.
285*****************************************************************/
286int ql_gpio_set_pull_selection(ENUM_PINNAME pin_name, ENUM_PIN_PULLSEL pull_sel);
287
288/*****************************************************************
289* Function: ql_gpio_get_pull_selection
290*
291* Description:
292* This function gets the pull selection of the specified GPIO.
293*
294* Parameters:
295* pin_name:
296* Pin name, one value of ENUM_PINNAME.
297* Return:
298* 0 no pull
299* 1 pull down
300* 3 pull up
301*****************************************************************/
302int ql_gpio_get_pull_selection(ENUM_PINNAME pin_name);
303
304/*****************************************************************
305* Function: ql_gpio_uninit
306*
307* Description:
308* This function releases the specified GPIO that was
309* initialized by calling ql_gpio_init() previously.
310* After releasing, the GPIO can be used for other purpose.
311* Parameters:
312* pin_name:
313* Pin name, one value of ENUM_PINNAME.
314* Return:
315* RES_OK, this function succeeds.
316* RES_IO_NOT_SUPPORT, the input GPIO is invalid.
317* RES_IO_ERR, the function failed
318* other place. For example this GPIO has been using as EINT.
319*****************************************************************/
320int ql_gpio_uninit(ENUM_PINNAME pin_name);
321
322//------------------------------------------------------------------------------
323/*
324* Description:
325* Definition for EINT callback function.
326*
327* Parameters:
328* pin_name:
329* EINT pin name, one value of ENUM_PINNAME.
330*
331* level:
332* The EINT level value, one value of ENUM_PIN_LEVEL.
333* 0 or 1
334*/
335//------------------------------------------------------------------------------
336typedef void (*ql_eint_callback)(ENUM_PINNAME eint_pin_name, int level);
337
338//------------------------------------------------------------------------------
339/*
340* Function: ql_eint_enable
341*
342* Description:
343* Set the interrupt sense mode, and enable interrupt.
344*
345* Parameters:
346* eint_pin_name:
347* EINT pin name, one value of ENUM_PINNAME that has
348* the interrupt function.
349*
350* eint_type:
351* Interrupt type, level-triggered or edge-triggered.
352* Now, only edge-triggered interrupt is supported.
353*
354* eint_callback:
355* call back function
356*
357* Return:
358* RES_OK, this function succeeds.
359* else failed to execute the function.
360*/
361//------------------------------------------------------------------------------
362int ql_eint_enable(ENUM_PINNAME eint_pin_name, ENUM_EINT_TYPE eint_type, ql_eint_callback eint_callback);
363
364
365//------------------------------------------------------------------------------
366/*
367* Function: ql_eint_disable
368*
369* Description:
370* Disable the interrupt sense.
371*
372* Parameters:
373* eint_pin_name:
374* EINT pin name, one value of ENUM_PINNAME that has
375* the interrupt function.
376*
377* Return:
378* RES_OK, this function succeeds.
379* else failed to execute the function.
380*/
381//------------------------------------------------------------------------------
382int ql_eint_disable(ENUM_PINNAME eint_pin_name);
383
384
385/*-----------------------------------------------------------------------------------------------*/
386/**
387Function: ql_set_gpio_function
388*
389* Description:
390* set pin function.
391*
392* Parameters:
393* pin_name:
394* EINT pin name, one value of ENUM_PINNAME.
395* func:
396* pin function,value range from 0 to 7
397*
398* Return:
399* RES_OK, this function succeeds.
400* else failed to execute the function.
401*/
402/*-----------------------------------------------------------------------------------------------*/
403int ql_set_gpio_function(ENUM_PINNAME pin_name,unsigned int func);
404
405
406/*-----------------------------------------------------------------------------------------------*/
407/*Function: ql_get_gpio_function
408*
409* Description:
410* get pin function.
411*
412* Parameters:
413* pin_name:
414* EINT pin name, one value of ENUM_PINNAME.
415*
416* Return:
417* return 0-7, this function succeeds.
418* else failed to execute the function.
419*/
420/*-----------------------------------------------------------------------------------------------*/
421int ql_get_gpio_function(ENUM_PINNAME pin_name);
422
423/*-----------------------------------------------------------------------------------------------*/
424/*Function: ql_check_pin_function_status
425*
426* Description:
427* Check whether the pin is gpio function.
428*
429* Parameters:
430* pin_name:
431* EINT pin name, one value of ENUM_PINNAME.
432*
433* Return:
434* return 1, this pin is gpio function.
435* return 0, this pin is not gpio function.
436* else failed to execute the function.
437*/
438/*-----------------------------------------------------------------------------------------------*/
439int ql_check_pin_function_status(ENUM_PINNAME pin_name);
440
441#ifdef __cplusplus
442}
443#endif
444
445#endif // __QL_GPIO_H__