Linux 设备驱动.doc

上传人:bao****ty 文档编号:144607474 上传时间:2020-09-11 格式:DOC 页数:23 大小:220.50KB
返回 下载 相关 举报
Linux 设备驱动.doc_第1页
第1页 / 共23页
Linux 设备驱动.doc_第2页
第2页 / 共23页
Linux 设备驱动.doc_第3页
第3页 / 共23页
Linux 设备驱动.doc_第4页
第4页 / 共23页
Linux 设备驱动.doc_第5页
第5页 / 共23页
点击查看更多>>
资源描述

《Linux 设备驱动.doc》由会员分享,可在线阅读,更多相关《Linux 设备驱动.doc(23页珍藏版)》请在金锄头文库上搜索。

1、Linux input设备驱动Linux input设备驱动一. 输入设备结构体1. input_dev 输入设备struct input_dev const char *name; /设备名const char *phys; /设备系统层的物理路径const char *uniq; /struct input_id id;/输入设备id 总线类型;厂商编号,产品id,产品版本unsigned long evbitBITS_TO_LONGS(EV_CNT);/事件类型标志位unsigned long keybitBITS_TO_LONGS(KEY_CNT);/键盘事件标志位unsigned l

2、ong relbitBITS_TO_LONGS(REL_CNT);/相对位移事件标志位unsigned long absbitBITS_TO_LONGS(ABS_CNT);/绝对位移事件标志位unsigned long mscbitBITS_TO_LONGS(MSC_CNT);/杂项事件标志位unsigned long ledbitBITS_TO_LONGS(LED_CNT);/led指示灯标志位unsigned long sndbitBITS_TO_LONGS(SND_CNT);/声音事件unsigned long ffbitBITS_TO_LONGS(FF_CNT);/强制反馈事件unsi

3、gned long swbitBITS_TO_LONGS(SW_CNT);/开关事件标志位unsigned int hint_events_per_packet;unsigned int keycodemax; /键盘码表大小unsigned int keycodesize; /键盘码大小void *keycode; /键盘码表指针int (*setkeycode)(struct input_dev *dev,unsigned int scancode, unsigned int keycode);/设置键盘码int (*getkeycode)(struct input_dev *dev,un

4、signed int scancode, unsigned int *keycode);/获取键盘码int (*setkeycode_new)(struct input_dev *dev,const struct input_keymap_entry *ke,unsigned int *old_keycode);int (*getkeycode_new)(struct input_dev *dev,struct input_keymap_entry *ke);struct ff_device *ff;/强制反馈设备unsigned int repeat_key;/重复按键标志位struct t

5、imer_list timer;/定时器int repREP_CNT; /重复次数struct input_mt_slot *mt;int mtsize;int slot;struct input_absinfo *absinfo;unsigned long keyBITS_TO_LONGS(KEY_CNT);/unsigned long ledBITS_TO_LONGS(LED_CNT);/unsigned long sndBITS_TO_LONGS(SND_CNT);/unsigned long swBITS_TO_LONGS(SW_CNT);/int (*open)(struct inp

6、ut_dev *dev); /open方法void (*close)(struct input_dev *dev);/close方法int (*flush)(struct input_dev *dev, struct file *file);int (*event)(struct input_dev *dev, unsigned int type, unsigned int code, int value);struct input_handle _rcu *grab;spinlock_t event_lock;struct mutex mutex;unsigned int users;boo

7、l going_away;bool sync;struct device dev; /设备文件struct list_headh_list;/input_handler处理器链表头struct list_headnode;/input_device设备链表头;2. input_handler 输入处理器struct input_handler void *private;/私有数据void (*event)(struct input_handle *handle, unsigned int type, unsigned int code, int value);/事件处理bool (*filt

8、er)(struct input_handle *handle, unsigned int type, unsigned int code, int value);/过滤器bool (*match)(struct input_handler *handler, struct input_dev *dev);/设备匹配int (*connect)(struct input_handler *handler, struct input_dev *dev, const struct input_device_id *id);/设备连接void (*disconnect)(struct input_h

9、andle *handle);/设备断开连接void (*start)(struct input_handle *handle);const struct file_operations *fops;/输入操作函数集int minor;/次设备号const char *name;/设备名const struct input_device_id *id_table;/输入设备 id表struct list_headh_list;/input_handler处理器链表头struct list_headnode;/input_device设备链表头;二. 输入系统初始化1 input_initsta

10、tic int _init input_init(void)int err;err = class_register(&input_class);/注册类 创建/sys/inputif (err) printk(KERN_ERR input: unable to register input_dev classn); return err;err = input_proc_init();/初始化/proc/bus/input接口if (err) goto fail1;err = register_chrdev(INPUT_MAJOR, input, &input_fops);/注册所有输入字符

11、设备,并捆绑input_fopsif (err) printk(KERN_ERR input: unable to register char major %d, INPUT_MAJOR); goto fail2;return 0;fail2:input_proc_exit();fail1:class_unregister(&input_class);return err;2. /proc 接口2.1 创建/proc/bus/input下的文件static int _init input_proc_init(void)struct proc_dir_entry *entry;proc_bus_

12、input_dir = proc_mkdir(bus/input, NULL);/创建/proc/bus/inputif (!proc_bus_input_dir) return -ENOMEM;entry = proc_create(devices, 0, proc_bus_input_dir,&input_devices_fileops);/创建/proc/bus/input/devicesif (!entry) goto fail1;entry = proc_create(handlers, 0, proc_bus_input_dir,&input_handlers_fileops);/

13、创建/proc/bus/input/handlersif (!entry) goto fail2;return 0;fail2:remove_proc_entry(devices, proc_bus_input_dir);fail1: remove_proc_entry(bus/input, NULL);return -ENOMEM;2.2 devices文件static const struct file_operations input_devices_fileops = .owner = THIS_MODULE,.open = input_proc_devices_open,.poll

14、= input_proc_devices_poll,.read = seq_read,.llseek = seq_lseek,.release= seq_release,;2.2.1 限于篇幅及省略啰嗦这里当我们去cat /proc/bus/input/devices时候,会调用input_proc_devices_open函数,接着调用seq_open(file, &input_devices_seq_ops),捆绑了input_devices_seq_ops操作函数集,其seq_operations函数集中声明了.show方法为input_devices_seq_show,该方法打印了些信息到seq文件,接着cat命令会调用read方法,read方法会调用.show方法,接着把打印到文件的信息复制用户空间的缓冲区中.这里主要看看.show方法吧2.2.2 input_devices_seq_showstatic int input_devices_seq_show(struct seq_file *seq, void *v)struct input_dev *dev = container_of(v, struct input_dev, node);/获取到输入设备结构体cons

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 高等教育 > 其它相关文档

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号