Linux input输入子系统demo驱动
在TP驱动代码分析中,接触到了input子系统,TP驱动将检测到的所有按键或者坐标都上报给了input子系统。Input子系统是所有I/O设备驱动的中间层,为上层提供了一个统一的界面。例如,在终端系统中,我们不需要去管有多少个键盘,多少个鼠标。它只要从input子系统中去取对应的事件(坐标,按键,鼠标移位等)就可以了。下面是一个input子系统的DEMO驱动,参考价值5颗星,这个是关键代码,有问题欢迎指出,不吝赐教,技术无边,多多交流。
DEMO驱动主要是注册一个input设备,通过工作队列每隔1秒向上层上报event事件。
/**注意:此时会生成/dev/input/eventX // X 为 0 1 2 3*测试:cat /proc/bus/input/devices会发现注册的设备*/#include <linux/module.h>#include <linux/device.h>#include <linux/hrtimer.h>#include <linux/i2c.h>#include <linux/interrupt.h>#include <linux/io.h>#include <linux/platform_device.h>#include <linux/async.h>#include <linux/irq.h>#include <linux/workqueue.h>#include <linux/proc_fs.h>#include <linux/input/mt.h>#include <asm/uaccess.h>#include <linux/version.h>#include <linux/slab.h>#include <linux/of_gpio.h>#include <linux/miscdevice.h>#include <linux/delay.h>#include <linux/input.h> //包含的头文件static struct input_dev *sensor_input_dev; //声明一个input设备结构体#define DEV_NAME "sensor_input_dev" //宏定义输入设备名称为sensor_input_devstatic struct delayed_work send_event; //声明一个delayed_work结构体,延时工作队列static int temperature_report_value(struct input_dev *input, int data) //上报event的调用接口,对接到实际获取数据的接口函数{printk("%s:line=%d, after sensor_report_value data[%d][%x]\n",__func__,__LINE__, data, data);input_report_abs(input, ABS_THROTTLE, data);input_sync(input);return 0;}static int sensor_report_value(void){ int ret;int result = 29; //对接到实际获取数据的接口函数,这里先随便整个数29ret = temperature_report_value(sensor_input_dev, result);printk("__%s(%d)__, ret = %d\n", __func__, __LINE__, ret);return 0;}static void send_event_workq(struct work_struct *work) //延时工作队列要做的事都在这里实现{int ret;ret = sensor_report_value();printk("__%s(%d)__, ret = %d\n", __func__, __LINE__, ret);schedule_delayed_work(&send_event, msecs_to_jiffies(1000)); //每隔一秒执行一次send_event_workq}static int __init test_init(void){int ret;printk("%s init start\n", __func__);sensor_input_dev = input_allocate_device(); //分配输入设备,失败返回NULLsensor_input_dev -> name = DEV_NAME; //输入设备名字set_bit(EV_ABS, sensor_input_dev->evbit); //设置输入设备事件类型为绝对坐标事件input_set_abs_params(sensor_input_dev, ABS_THROTTLE, 100, 65535, 0, 0);//对于ABS_THROTTLE范围是100到65535,数据误差是+-0,中心平滑位置是0ret = input_register_device(sensor_input_dev); //将设备注册进输入子系统if (ret) {pr_err("input_register_device ret: %d\n", ret);input_free_device(sensor_input_dev);//释放内存return -1;}INIT_DELAYED_WORK(&send_event, send_event_workq); //初始化工作队列schedule_delayed_work(&send_event, msecs_to_jiffies(2000)); //2s后开启工作队列printk("%s init end\n", __func__);return 0;}static void __exit test_exit(void){cancel_delayed_work_sync(&send_event); //取消工作队列input_unregister_device(sensor_input_dev); //注销input设备}module_init(test_init);module_exit(test_exit);MODULE_DESCRIPTION("For test input system driver");MODULE_AUTHOR("cai.zhongding");MODULE_LICENSE("GPL");
执行getevent可以看到event上报事件:
rk3399_all:/ # getevent add device 1: /dev/input/event3name: "sensor_input_dev"add device 2: /dev/input/event2name: "rk29-keypad"add device 3: /dev/input/event1name: "rockchip-cdndp-sound DP Jack"add device 4: /dev/input/event0name: "ff420030.pwm"/dev/input/event3: 0003 0006 00000a58/dev/input/event3: 0000 0000 00000000/dev/input/event3: 0003 0006 00000a56/dev/input/event3: 0000 0000 00000000
Linux input输入子系统demo驱动相关推荐
- linux input输入子系统分析《三》:S3C2440的触摸屏驱动实例
1.1 本节阅读前提 本节的说明建立在前两节的基础之上,需要先阅读如下两篇章: linux input输入子系统分析<一>:初识input输入子系统 linux input输入子系统 ...
- linux input输入子系统分析《四》:input子系统整体流程全面分析
1 input输入子系统整体流程 本节分析input子系统在内核中的实现,包括输入子系统(Input Core),事件处理层(Event Handler)和设备驱动层.由于上节代码讲解了设备 ...
- linux input输入子系统分析《一》:初识input输入子系统
主要讲述本人在学习Linux内核input子系统的全部过程,如有分析不当,多谢指正.以下交流方式,文章欢迎转载,保留联系信息,以便交流. 邮箱:eabi010@gmail.com 主页:www.iel ...
- Linux的input输入子系统:设备驱动之按键驱动
环境:kernel-2.6.30.4,arm-linux-gcc-4.3.3,目标板TQ2440 一.设备层驱动程序: #include <linux/module.h> #include ...
- linux input输入子系统分析《二》:s3c2440的ADC简单驱动实例分析
1 mini2440的ADC驱动实例 这节与输入子系统无关,出现在这里是因为后面的章节会讲到触摸屏输入子系统驱动,由于触摸屏也使用ADC,因此本节是为了说明ADC通过驱动代码是如何控制的. ...
- Linux驱动:input输入子系统
input输入子系统 1.input输入子系统 1.1 简介 1.2 相关API函数 1.3 使用流程(驱动框架) 2.驱动示例 3.测试程序 4.测试结果 5.内核自带的input按键驱动 附:对应 ...
- ARM Linux内核Input输入子系统浅解
--以触摸屏驱动为例 第一章.了解linux input子系统 Linux输入设备总类繁杂,常见的包括有按键.键盘.触摸屏.鼠标.摇杆等等,他们本身就是字符设备,而linux内核将这些设备 ...
- Linux输入事件类型EV_SW,Linux的input输入子系统:总体框架
一.input输入子系统总体框架 Linux输入子系统将输入驱动抽象为三层:设备驱动层.核心层.事件处理层. 设备驱动层:将底层的硬件输入事件转化为统一事件形式,向输入核心(Input Core)汇报 ...
- Linux下输入子系统上报触摸屏坐标
Linux下输入子系统上报触摸屏坐标 1.输入子系统简介 在 Linux 中,输入子系统是由输入子系统设备驱动层.输入子系统核心层(Input Core)和输入子系统事件处理层(Event Han ...
- Linux驱动分析——input输入子系统
stm32mp157 盘古开发板 Linux内核版本4.19 目录 1.朱有鹏老师的视频课程笔记和应用测试代码: 2.input子系统架构分析 2.1.输入核心层源码分析 2.1.1.首先是核心模 ...
最新文章
- 据说只有程序员才看得懂 | 每日趣闻
- RhinoMock入门(7)——Do,With和Record-playback
- 网站建设之前需要先了解目标受众
- 带你自学Python系列(二):Python列表总结-思维导图
- Type Conversion(类型转换)
- 文章采集伪原创工具_伪原创文章技巧(如何提高伪原创文章的原创度)
- 解决eclipse启动停在一个空白窗口的问题
- spring aop源码分析总结
- TCPDUMP 用法(转)
- J-Trace入门系列1:感动人心的功能与更感动人心的售价
- 什么是Autorun病毒?它的运作原理是什么?如何手工清除?
- 【Romance of the Three Kingdoms】
- 资源整理 IC/FPGA
- 秋雨,在迷乱的思绪中飞扬
- servlet的多种注册方式
- 学习笔记——HTTP上网过程详解
- numpy 是否为零_一文读懂 NumPy 及应用
- 前端之变(四):进击的前端
- 微云网络连锁行业解决方案
- (批量)删除企微通讯录成员