#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <string.h>
#include <termios.h>
#include <errno.h>
#include <linux/ioctl.h>
#include "../inc/at91_ioctl.h"
#include "../inc/at91_gpio.h"
#define DEV_GPIO "/dev/gpio"
/* gpio pins can be used are list below:
PIN_ISI_D0, PIN_ISI_D1, PIN_ISI_D2, PIN_ISI_D3, PIN_ISI_D4, PIN_ISI_D5, PIN_ISI_D6,
PIN_ISI_D7, PIN_ISI_PCK, PIN_ISI_VSYNC, PIN_ISI_HSYNC, PIN_ISI_MCK, PIN_SPIO_MISO,
PIN_SPI0_MOSI, PIN_SPI0_SPCK, PIN_SPI0_NPCS0, PIN_TIOA2, PIN_TIOA1, PIN_TIOA0, PIN_TCLK0,
PIN_TWCK, PIN_TWD, PIN_IRQ0, PIN_IRQ1, PIN_RXD3, PIN_TXD3, PIN_RXD4, PIN_TXD4, PIN_RXD5,
PIN_TXD5, PIN_AD0, PIN_AD1, PIN_AD2, PIN_AD3, PIN_ADTRG
CAREFUL: Some of the gpio pins are multiplexed with peripheral signals,
so make sure right gpio pins are used.
*/
int main(int argc, void *argv[])
{
at91_gpio_arg arg_x1, arg_x2, arg_y1, arg_y2;
int fd = -1;
int i;
printf("AT91 GPIO test ...\n\n\n\n");
fd = open(DEV_GPIO, O_RDWR);
if (fd < 0) {
printf("open GPIO device error! %d\n", fd);
return -1;
}
arg_x1.pin = PIN_ISI_D0;
arg_x1.data = 1;
ioctl(fd, IOCTL_GPIO_SETOUTPUT, &arg_x1);
printf("set ISI_D0 high level\n");
arg_x2.pin = PIN_ISI_D1;
arg_x2.data = 1;
ioctl(fd, IOCTL_GPIO_SETOUTPUT, &arg_x2);
printf("set ISI_D1 high level\n");
sleep(1);
arg_x2.data = 0;
ioctl(fd, IOCTL_GPIO_SETVALUE, &arg_x2);
printf("set ISI_D1 low level\n");
arg_y1.pin = PIN_ISI_D2;
arg_y1.usepullup = 1;
ioctl(fd, IOCTL_GPIO_SETINPUT, &arg_y1);
arg_y2.pin = PIN_ISI_D3;
arg_y2.usepullup = 0;
ioctl(fd, IOCTL_GPIO_SETINPUT, &arg_y2);
for (i =0; i< 5*60; i ++){
sleep(1);
ioctl(fd, IOCTL_GPIO_GETVALUE, &arg_y1);
ioctl(fd, IOCTL_GPIO_GETVALUE, &arg_y2);
printf("value of PIN ISI_D2: %d, ISI_D3: %d\n", arg_y1.data, arg_y2.data);
}
close (fd);
return 1;
}
评论0