• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2 * Copyright (c) 2022 Unionman Technology Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15 
16 #ifndef __UM_GPIO_H__
17 #define __UM_GPIO_H__
18 
19 #define UM_GPIO_EXPORT "/sys/class/gpio/export"
20 #define UM_GPIO_UNEXPORT "/sys/class/gpio/unexport"
21 #define UM_GPIO_PEX "/sys/class/gpio/gpio"
22 
23 // hilog
24 #undef LOG_DOMAIN
25 #undef LOG_TAG
26 #define LOG_DOMAIN 0  // 标识业务领域,范围0x0~0xFFFFF
27 #define LOG_TAG "GPIO_TEST"
28 
29 // gpios
30 #define UM_GPIO_01 380 /* GPIO.7 */
31 #define UM_GPIO_02 381 /* GPIO.0 */
32 #define UM_GPIO_03 382 /* GPIO.2 */
33 #define UM_GPIO_04 383 /* GPIO.3 */
34 #define UM_GPIO_05 384 /* GPIO.21 */
35 #define UM_GPIO_06 385 /* GPIO.22 */
36 #define UM_GPIO_07 386 /* GPIO.23 */
37 #define UM_GPIO_08 387 /* GPIO.24 */
38 #define UM_GPIO_09 388 /* GPIO.25 */
39 #define UM_GPIO_10 389 /* GPIO.1 */
40 #define UM_GPIO_11 390 /* GPIO.4 */
41 #define UM_GPIO_12 391 /* GPIO.5 */
42 #define UM_GPIO_13 392 /* GPIO.6 */
43 #define UM_GPIO_14 393 /* GPIO.30 */
44 #define UM_GPIO_15 394 /* GPIO.26 */
45 #define UM_GPIO_16 395 /* GPIO.27 */
46 
47 // spi cs
48 #define UM_GPIO_SPI_CS 486 /* SS0 */
49 
50 // direction
51 #define UM_GPIO_DIRECTION_IN 0
52 #define UM_GPIO_DIRECTION_OUT 1
53 
54 // is export
55 #define UM_GPIO_NOT_EXPORT 0
56 #define UM_GPIO_EXPORTED 1
57 
58 // errno
59 #define UM_GPIO_ERR (-1)
60 #define UM_GPIO_NOT_EXPROT_ERROR (-2)
61 
62 // value high - low level
63 #define UM_GPIO_LOW_LEVE 0
64 #define UM_GPIO_HIGH_LEVE 1
65 
66 /**
67  * set gpio export
68  * @param gpioNum gpioNum
69  * @param bExport export,0:not export 1:export
70  */
71 int UM_GPIO_Export(int gpioNum, int bExport);
72 
73 /**
74  * set gpio direction
75  * @param gpioNum gpioNum
76  * @param direction direction,0:in 1:out
77  */
78 int UM_GPIO_SetDirection(int gpioNum, int direction);
79 
80 /**
81  * set gpio value
82  * @param gpioNum gpioNum
83  * @param value value,0:low 1:high
84  */
85 int UM_GPIO_SetValue(int gpioNum, int value);
86 
87 /**
88  * check gpio export or not
89  * @param gpioNum gpioNum
90  * @param *value export,0:not export 1:exported
91  */
92 int UM_GPIO_IsExport(int gpioNum, int *value);
93 
94 /**
95  * get gpio direction
96  * @param gpioNum gpioNum
97  * @param *value direction,0:in 1:out
98  */
99 int UM_GPIO_GetDirection(int gpioNum, int *value);
100 
101 /**
102  * get gpio value
103  * @param gpioNum gpioNum
104  * @param *value value,0:low 1:high
105  */
106 int UM_GPIO_GetValue(int gpioNum, int *value);
107 
108 #endif /* __UM_GPIO_H__ */