本页面只读。您可以查看源文件,但不能更改它。如果您觉得这是系统错误,请联系管理员。
=== GPIO应用编程 === {{page>:template:temp_gpio}} C参考代码如下: <code C> #include <stdio.h> #include <stdlib.h> #include <sys/types.h> #include <sys/stat.h> #include <fcntl.h> #include <unistd.h> #include <string.h> static char gpio_path[100]; //设置GPIO方向、高低电平 static int gpio_config(const char *value) { char config_path[100]; int len; int fd; sprintf(config_path, "%s", gpio_path); if (0 > (fd = open(config_path, O_WRONLY))) { perror("open error"); return fd; } len = strlen(value); if (len != write(fd, value, len)) { perror("write error"); close(fd); return -1; } close(fd); return 0; } int main(int argc, char *argv[]) { if (4 != argc) { if (3 != argc) { fprintf(stderr, "set gpio out : %s <gpio> <out> <value>\n", argv[0]); fprintf(stderr, "set gpio in : %s <gpio> <in>\n", argv[0]); exit(-1); } } sprintf(gpio_path, "/sys/class/io_control/gpio_op%s", argv[1]); if (access(gpio_path, F_OK)) { printf("%s inexistence,export %s... \n",gpio_path,argv[1]); } if ( 0 == strcmp("out",argv[2] ) && argc == 4 ) { if(gpio_config(argv[3])) exit(-1); } printf("gpio_op%s:\n",argv[1]); printf("direction : %s\n", argv[2]); printf("value : %s\n", argv[3]); exit(0); } </code> 交叉编译源码: aarch64-linux-gnu-gcc -o gpio gpio.c 将编译好的gpio程序使用scp拷贝到 3399 主板上,执行测试: 使用方法: set gpio out : ./gpio <gpio> <out> <value> set gpio in : ./gpio <gpio> <in> {{:arm:rk3399:linux:gpio编程-1.png?600|}}
您的足迹:
登录
文章
讨论
阅读
显示源文件
修订记录
搜索
导航
首页
Main_En
帮助
联系我们
打印/导出
可打印版本
工具
最近更改
媒体管理器
网站地图
永久链接
引用此文