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 #include <string.h>
17 #include <stdlib.h>
18 #include <stdio.h>
19 #include <unistd.h>
20
21 #include "um_gpio.h"
22
main(int argc,char ** argv)23 int main(int argc, char **argv)
24 {
25 int gpioNum = UM_GPIO_07;
26 int bExport = UM_GPIO_EXPORTED;
27 int direction = UM_GPIO_DIRECTION_OUT;
28 int value = UM_GPIO_HIGH_LEVE;
29 int getValue = -1;
30
31 // 判断是否有输入参数,如有,则赋值指定gpio口
32 if (argv[1] != NULL) {
33 getValue = atoi(argv[1]);
34 if (getValue >= UM_GPIO_01 && getValue <= UM_GPIO_16) {
35 gpioNum = getValue;
36 } else {
37 printf("please input the gpioNum between 380 and 395.\n");
38 return UM_GPIO_ERR;
39 }
40 }
41
42 // 判断gpio口是否已经导出,如未导出则执行对应函数
43 UM_GPIO_IsExport(gpioNum, &getValue);
44 if (getValue == UM_GPIO_NOT_EXPORT) {
45 UM_GPIO_Export(gpioNum, bExport);
46 }
47
48 // 设置gpio口为输入或输出模式
49 UM_GPIO_SetDirection(gpioNum, direction);
50 // 设置gpio口为高低电平
51 UM_GPIO_SetValue(gpioNum, value);
52
53 // 获取对应gpio口的模式并打印
54 UM_GPIO_GetDirection(gpioNum, &getValue);
55 printf("gpioNum:[%d], direction:[%d]\n", gpioNum, getValue);
56
57 // 获取对应gpio口的电平值并打印
58 UM_GPIO_GetValue(gpioNum, &getValue);
59 printf("gpioNum:[%d], value:[%d]\n", gpioNum, getValue);
60
61 return 0;
62 }
63