发一个2410的键盘驱动程序代码.doc

  1. 1、原创力文档(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。。
  2. 2、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载
  3. 3、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
查看更多
发一个2410的键盘驱动程序代码.doc

发一个2410的键盘驱动程序代码 字体: 小 中 大 | 打印 发表于: 2007-8-15 19:46 ?? 作者: armstar ?? 来源: 中国电子开发网 /*这段代码是一个用户模式下的DEMO,不是真正的驱动,它负责把按键的键值打印输出*/ #include stdio.h #include stdlib.h #include unistd.h #include sys/ioctl.h #include sys/types.h #include sys/stat.h #include fcntl.h #include sys/select.h #include sys/time.h #include errno.h int main(void) { ??int buttons_fd; ??int key_value; ??buttons_fd = open(/dev/buttons, 0); ??if (buttons_fd 0) { ? ? perror(open device buttons); ? ? exit(1); ??} ??for (;;) { ? ? fd_set rds; ? ? int ret; ? ? FD_ZERO(rds); ? ? FD_SET(buttons_fd, rds); ? ? ret = select(buttons_fd + 1, rds, NULL, NULL, NULL); ? ? if (ret 0) { ? ?? ???perror(select); ? ?? ???exit(1); ? ? } ? ? if (ret == 0) { ? ?? ???printf(Timeout.\n); ? ? } else if (FD_ISSET(buttons_fd, rds)) { ? ?? ???int ret = read(buttons_fd, key_value, sizeof key_value); ? ?? ???if (ret != sizeof key_value) { ? ?? ?? ?? ?if (errno != EAGAIN) ? ?? ?? ?? ???perror(read buttons\n); ? ?? ?? ?? ?continue; ? ?? ???} else { ? ?? ?? ?? ?printf(buttons_value: %d\n, key_value); ? ?? ???} ? ?? ?? ?? ? ? ? } ??} ??close(buttons_fd); ??return 0; } /*下面是真正的驱动部分*/ #include linux/config.h #include linux/module.h #include linux/kernel.h #include linux/init.h #include linux/miscdevice.h #include linux/sched.h #include linux/delay.h #include linux/poll.h #include linux/spinlock.h #include linux/irq.h #include linux/delay.h #include asm/hardware.h #define DEVICE_NAME? ?buttons #define BUTTON_MAJOR 232 static struct key_info { ??int irq_no; ??unsigned int gpio_port; ??int key_no; } key_info_tab[4] = { ??{ IRQ_EINT1, GPIO_F1, 1 }, ??{ IRQ_EINT2, GPIO_F2, 2 }, ??{ IRQ_EINT3, GPIO_F3, 3 }, ??{ IRQ_EINT7, GPIO_F7, 4 }, }; static int ready = 0; static int key_value = 0; static DECLARE_WAIT_QUEUE_HEAD(buttons_wait); static void buttons_irq(int irq, void *dev_id, struct pt_regs *reg) { ??struct key_info *k; ??int i; ??int found = 0; ??int up; ??int flags; ??for (i = 0; i sizeof key_info_tab / sizeof key_info_tab

文档评论(0)

gsgtshb + 关注
实名认证
内容提供者

该用户很懒,什么也没介绍

1亿VIP精品文档

相关文档