完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
1.在/opt/下解压LINUX内核文件 2.cd /opt/opt/EmbedSky/linux-2.6.30.4/drivers/input/keyboard 3.gedit Kconfig 4.config TQ2440_IRQ_BUTTON tristate "EmbedSky TQ2440 Board user buttons" depends on ARCH_S3C2440 default y if ARCH_S3C2440 help IRQ Button for EmbedSky TQ2440 Board. 拷贝楼上粘贴如下 config BLACK //这里改改 tristate "EmbedSky" //这里也改改 depends on ARCH_S3C2440 default y if ARCH_S3C2440 help IRQ Button for EmbedSky TQ2440 Board. 4.gedit Makefile 最后一行 obj-$(CONFIG_BLACK/*这里改成自己的命名*/) += keyIrq.o/*这里改成自己的.o*/ 5.cd 到linux-2.6.30.4这里进行裁剪系统,make menuconfig->Device Drivers->Input device support->Keybords->去掉系统的*,把自己的加上*(在最后一个) 用空格来切换添加删除 6.cp 自己代码到 /drivers/input/keyboard下 7.cp config_EmbedSky_W43 .config 8.cp config_EmbedSky_W43 config 9../config 10.make clean;make 已成功一大半 11.将编译得到的zImage.bin内核文件烧写进[color=rgb(68, 68, 68) !important]ARM板,要清除原来的,UBOOT,系统也要重新烧写(9,1,3,6 来一遍) 12.驱动代码如下(记得改makefile) #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include //#include #include //#include #include /* 定义并初始化等待队列头 */ static DECLARE_WAIT_QUEUE_HEAD(button_waitq); static struct class *thirddrv_class; static struct device *thirddrv_device; static struct pin_desc{ unsigned int pin; unsigned int key_val; }; static struct pin_desc pins_desc[4] = { {S3C2410_GPF1,0x01}, {S3C2410_GPF4,0x02}, {S3C2410_GPF2,0x03}, {S3C2410_GPF0,0x04}, }; static int ev_press = 0; /* 键值: 按下时, 0x01, 0x02, 0x03, 0x04 */ /* 键值: 松开时, 0x81, 0x82, 0x83, 0x84 */ static unsigned char key_val; int major; /* 用户中断处理函数 */ static irqreturn_t buttons_irq(int irq, void *dev_id) { struct pin_desc *pindesc = (struct pin_desc *)dev_id; unsigned int pinval; pinval = s3c2410_gpio_getpin(pindesc->pin); if(pinval) { /* 松开 */ key_val = 0x80 | (pindesc->key_val); } else { /* 按下 */ key_val = pindesc->key_val; } ev_press = 1; /* 表示中断已经发生 */ wake_up_interruptible(&button_waitq); /* 唤醒休眠的进程 */ return IRQ_HANDLED; } static int third_drv_open(struct inode * inode, struct file * filp) { /* K1 ---- EINT1,K2 ---- EINT4,K3 ---- EINT2,K4 ---- EINT0 * 配置GPF1、GPF4、GPF2、GPF0为相应的外部中断引脚 * IRQT_BOTHEDGE应该改为IRQ_TYPE_EDGE_BOTH */ request_irq(IRQ_EINT1, buttons_irq, IRQ_TYPE_EDGE_BOTH, "K1",&pins_desc[0]); request_irq(IRQ_EINT4, buttons_irq, IRQ_TYPE_EDGE_BOTH, "K2",&pins_desc[1]); request_irq(IRQ_EINT2, buttons_irq, IRQ_TYPE_EDGE_BOTH, "K3",&pins_desc[2]); request_irq(IRQ_EINT0, buttons_irq, IRQ_TYPE_EDGE_BOTH, "K4",&pins_desc[3]); return 0; } static ssize_t third_drv_read(struct file *file, char __user *user, size_t size,loff_t *ppos) { if (size != 1) return -EINVAL; /* 当没有按键按下时,休眠。 * 即ev_press = 0; * 当有按键按下时,发生中断,在中断处理函数会唤醒 * 即ev_press = 1; * 唤醒后,接着继续将数据通过copy_to_user函数传递给应用程序 */ wait_event_interruptible(button_waitq, ev_press); copy_to_user(user, &key_val, 1); /* 将ev_press清零 */ ev_press = 0; return 1; } static int third_drv_close(struct inode *inode, struct file *file) { free_irq(IRQ_EINT1,&pins_desc[0]); free_irq(IRQ_EINT4,&pins_desc[1]); free_irq(IRQ_EINT2,&pins_desc[2]); free_irq(IRQ_EINT0,&pins_desc[3]); return 0; } /* File operations struct for character device */ static const struct file_operations third_drv_fops = { .owner = THIS_MODULE, .open = third_drv_open, .read = third_drv_read, .release = third_drv_close, }; /* 驱动入口函数 */ static int third_drv_init(void) { /* 主设备号设置为0表示由系统自动分配主设备号 */ major = register_chrdev(0, "third_drv", &third_drv_fops); /* 创建thirddrv类 */ thirddrv_class = class_create(THIS_MODULE, "thirddrv"); /* 在thirddrv类下创建buttons设备,供应用程序打开设备*/ thirddrv_device = device_create(thirddrv_class, NULL, MKDEV(major, 0), NULL, "buttons"); return 0; } /* 驱动出口函数 */ static void third_drv_exit(void) { unregister_chrdev(major, "third_drv"); device_unregister(thirddrv_device); //卸载类下的设备 class_destroy(thirddrv_class); //卸载类 } module_init(third_drv_init); //用于修饰入口函数 module_exit(third_drv_exit); //用于修饰出口函数 MODULE_AUTHOR("LWJ"); MODULE_DESCRIPTION("Just for Demon"); MODULE_LICENSE("GPL"); //遵循GPL协议 13.再创建一个.c文件,测试代码 #include #include #include #include #include int main(int argc ,char *argv[]) { int fd; unsigned char key_val; fd = open("/dev/buttons",O_RDWR); if (fd < 0) { printf("open errorn"); } while(1) { read(fd,&key_val,1); printf("key_val = 0x%xn",key_val); } return 0; } 14.接下来就是在系统上分别编译这两个代码 15.打开超级终端,重启系统,将得到的.ko和可执行文件发送到/home下 16.insmod .ko 17../可执行文件 18.分别按上下左右按键,效果如下:
|
|
相关推荐
|
|
|
|
|
|
|
|
|
|
|
|
|
|
858 浏览 0 评论
ElfBoard ELF 1板卡-开发板启动后打印random: nonblocking pool is initialized
542 浏览 0 评论
G2D图像处理硬件调用和测试-基于米尔-全志T113-i开发板
3702 浏览 0 评论
飞凌嵌入式ElfBoard ELF 1板卡- 减少uboot阶段的等待时间
1583 浏览 0 评论
嵌入式学习-飞凌ElfBoard ELF 1板卡 - 重新打包文件系统发现ftp无法正常连接
1831 浏览 0 评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-4-25 17:09 , Processed in 0.560606 second(s), Total 70, Slave 52 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号