您的位置:首页 > 其它

arm 驱动基础:字符设备驱动程序之定时器防振动

2012-05-20 11:33 337 查看
实现原理图:

buttons_test.c

#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <stdio.h>
#include <poll.h>
#include <signal.h>
#include <sys/types.h>
#include <unistd.h>
#include <fcntl.h>

/* sixthdrvtest
*/
int fd;

void my_signal_fun(int signum)
{
unsigned char key_val;
read(fd, &key_val, 1);
printf("key_val: 0x%x\n", key_val);
}

int main(int argc, char **argv)
{
unsigned char key_val;
int ret;
int Oflags;

//signal(SIGIO, my_signal_fun);

fd = open("/dev/buttons", O_RDWR);
if (fd < 0)
{
printf("can't open!\n");
return -1;
}

//fcntl(fd, F_SETOWN, getpid());

//Oflags = fcntl(fd, F_GETFL);

//fcntl(fd, F_SETFL, Oflags | FASYNC);

while (1)
{
ret = read(fd, &key_val, 1);
printf("key_val: 0x%x, ret = %d\n", key_val, ret);
//sleep(5);
}

return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐