gpio.c

来自「The source code example of ARM9 developm」· C语言 代码 · 共 36 行

C
36
字号
/* *	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 + =
减小字号Ctrl + -
显示快捷键?