wait_event_interruptible(button_waitq, ev_press);
}
ev_press = 0;
err = copy_to_user(buff, (const void *)key_values, min(sizeof(key_values), count));
return err -EFAULT : min(sizeof(key_values), count);
}
#if 0
static unsigned int s3c24xx_buttons_poll( struct file *file, struct poll_table_struct *wait)
{
unsigned int mask = 0;
poll_wait(file, &button_waitq, wait);
if (ev_press)
mask |= POLLIN | POLLRDNORM;
return mask;
}
#endif
static struct file_operations dev_fops = {
.owner = THIS_MODULE,
.open = s3c24xx_buttons_open,
.release = s3c24xx_buttons_close,
.read = s3c24xx_buttons_read,
//.poll = s3c24xx_buttons_poll,
};
static struct miscdevice misc = {
.minor = MISC_DYNAMIC_MINOR,
.name = DEVICE_NAME,
.fops = &dev_fops,
};
static int __init dev_init(void)
{
int ret;
ret = misc_register(&misc);
printk (DEVICE_NAME"\tinitialized\n");
return ret;
}
static void __exit dev_exit(void)
{
misc_deregister(&misc);
}
module_init(dev_init);
module_exit(dev_exit);
MODULE_LICENSE("GPL");
MODULE_AUTHOR("MARK");
MODULE_DESCRIPTION("Study S3C2440");
Makefile 文件如下:
obj-m:=buttons_driver.o
CURRENT_PATH:=$(shell pwd)
ARM_LINUX_KERNEL:=/opt/linux-2.6.29.1
all:
$(MAKE) -C $(ARM_LINUX_KERNEL) SUBDIRS=$(CURRENT_PATH) modules
clean:
rm -rf *.cmd *.o *.ko *.mod.c *.symvers *.order
测试程序如下:
/*buttons_test.c*/
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
int main(void)
{
int buttons_fd;
char buttons[6] = {'0', '0', '0', '0', '0', '0'};
buttons_fd = open("/dev/buttons", 0);
if (buttons_fd < 0) {
perror("open device buttons");
exit(1);
}
for (;;) {
char current_buttons[6];
int i;
if (read(buttons_fd, current_buttons, sizeof current_buttons) != sizeof current_buttons) {
perror("read buttons:");
exit(1);
}
for (i = 0; i < sizeof buttons / sizeof buttons[0]; i++) {
if (buttons[i] != current_buttons[i]) {
buttons[i] = current_buttons[i];
printf("The %d key is pressed!\n",i+1);
}
}
}
close(buttons_fd);
return 0;
}
Makefile文件如下:
all:
arm-linux-gcc buttons_test.c -o buttons_test
clean:
rm -rf *.o buttons_test
总结一下:参考的资料是韦东山的《嵌入式Linux应用开发完全手册》,这本书我买了,感觉里面既将了入门的知识,也讲了需要一定基础才能掌握的知识,作为参考是本不错的书,虽然没有把每一步都完全讲出来,也不可能讲得那么详细。还有就是《Linux设备驱动程序(第三版)》,这本书我也买了,个人感觉很不错,LW写的书就是专业,讲的都是核心知识。还有就是《Linux设备驱动开发详解》,宋宝华编的,看过他的资料,从他写的书中可以看出他Linux方面非常专业,非常深入,有一股傲气,向他学习没错。很想买这本书,可惜暂时没Money(可怜的人啊),等过一段时间一定买一本。