📄 gpio.c
字号:
/* * Description: * example for GPIO. * What is shown in this example: * 1. How to open gpio * 2. How to get count of GPIO and DIP_SW * 3. How to get status of GPIO and DIP_SW * * */#include <stdio.h>#include <sys/types.h>#include <sys/stat.h>#include <fcntl.h>#include "matrix500.h"int main(void){ int gpio, dip_sw, i; int fd = open("/dev/gpio",O_RDWR); /*get count of GPIO*/ if(ioctl(fd, GPIO_IOCTL_COUNT, &gpio) == 0) printf("GPIO count:%d\n",gpio); /*get count of DIPSW*/ if(ioctl(fd, GPIO_IOCTL_DIPSW, &dip_sw) == 0) printf("DIP_SW count:%d\n",dip_sw); /*show status of GPIO and DIPSW*/ for(i=0; i<(gpio+dip_sw); i++){ printf("GPIO%d->%d\n", i,ioctl(fd, GPIO_IOCTL_GET, &i)); } close(fd); return 0;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -