📄 gpiotest.c
字号:
//written by bcng xiyong,2007-7-1
//set gpj4 to zero to give a kill signal to chip ltc2950
//a guidline about how to use gpio_driver
//p[0] is the address of the iocon of the io
//p[1] is the bit place, from 0 to xx,
//for example, GPJ4, p[1] is 0x4;
//for write function, the 3th parameter, if the second bit is set, them use keep before
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <stdio.h>
#include <termios.h>
#include <unistd.h>
#define GPJCON 0x560000d0
#define GPJ2 0x2
#define GPGCON 0x56000060
#define GPG4 0x4
int main(int argc,char *argv[] )
{
int fd,FunctionIndex;
unsigned long conreg,pin;
unsigned long p[2];
fd=open("/dev/gpio",O_RDWR | O_NOCTTY);
if (fd < 0)
{
printf("can not open led!\n");
return -1;
}
p[0]=GPGCON; //GPJCON
p[1]=GPG4;
if (argc==3)
{
sscanf(argv[1], "%x", &conreg);
sscanf(argv[2], "%x", &pin);
p[0]=conreg; //GPJCON
p[1]=pin;
printf("con is %x,pin is %x\n",p[0],p[1]);
}
else
{
printf("inpt error\n");
return -1;
}
printf("+----------------------------------------+\n");
printf("| ARM Linux GPIO driver test |\n");
printf("| Write on 2007.7.1 xiyong bcng GPG4 |\n");
printf("+----------------------------------------+\n");
printf("\n");
printf("\n Please select the function to test ( Main Menu):");
printf("\n 1: write 1 ");
printf("\n 2: write 0 ");
printf("\n 3: set pin to function10 ");
printf("\n 4: set pin to function11 ");
printf("\n 5: set pin to input ");
printf("\n 6: set pullup ");
printf("\n 7: disable pullup ");
printf("\n 8: display register value ");
printf("\n 0: exit ");
for(;;)
{
scanf("%d",&FunctionIndex);
switch(FunctionIndex)
{
case 1:
printf("write 1\n");
write(fd,p,1);
break;
case 2:
printf("write 0\n");
write(fd,p,0);
break;
case 3:
printf("set pin to function10 \n");
write(fd,p,2);
break;
case 4:
printf("set pin to function11 \n");
write(fd,p,4);
break;
case 5:
printf("set pin to input \n");
read(fd,p,0);
break;
case 6:
printf("set pullup\n");
read(fd,p,3);
break;
case 7:
printf("disable pullup\n");
read(fd,p,2);
break;
case 8:
printf("display register value\n");
read(fd,p,8);
break;
case 0:
close(fd);
exit(1);
default:
close(fd);
exit(1);
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -