Input event驱动

Linux 专门对输入设备。
键盘,鼠标,手柄,触摸屏。按键。封装一个类驱动。
主要统一与应用程序接口。这一类的设备结点都是在/dev/input/eventn( 0<=n)
用户程序读驱动的输入都采用统一格式,即struct input_event,方便应用程序来读写

Linux/input.h

struct input_event {
    struct timeval time;
    __u16 type;
    __u16 code;
    __s32 value;
};

INPUT驱动查看

查看设备结点
ls -l /dev/input
查看设备信息
ls -l /proc/bus/input/
cat /proc/bus/input/devices
查看input class信息

ls /sys/class/input

input device 优点

统一应用程序使用外部输入设备的接口。这样简化编程。
Input core是没有缓存队列的,如果应用程序没有及时取事件,则事件被丢弃。

input输入驱动编程

输入驱动数据结构
 struct input_dev *input_dev;
在驱动中必须动态分配input_dev结构,这里使用
input_allocate_device();
初始化input_dev的参数
调用 input_register_device()注册,
退出时调用 input_unregister_device()

与应用程序的交互

Input 驱动的子系统已经控制I/O,换句话read/write不需要驱动直接.
驱动只需要input_report_xxx()上传信息
input_report_key()上传按键
input_report_abs() 绝对坐标
它们最终调用input_event来向input core上传信息,并最后转交给应用程序.
Input core没有缓存事件信息,这样在应用程序开始read前的信息全部被丢弃.

input_dev 的初始化

evbit 表示这个驱动支持哪一些事件,有两种等效的方法
set_bit(EV_KEY, input_dev->evbit); set_bit(EV_REL, input_dev->evbit);
input_dev->evbit  = BIT_MASK(EV_KEY) | BIT_MASK(EV_REL);

初始化/proc/bus/input/devices的信息

#define DEVICE_NAME "s3c6410 gpio button"

myinput_dev->name = DEVICE_NAME;
    myinput_dev->phys = "gpio-button/input100";
    
    myinput_dev->id.bustype = BUS_HOST;  //设备
    myinput_dev->id.vendor =  0x0001;
    myinput_dev->id.product = 0x0001;
    myinput_dev->id.version = 0x0001;

cat /proc/bus/input/devices

I: Bus=0019 Vendor=0001 Product=0001 Version=0001
N: Name="s3c6410 gpio button"
P: Phys=gpio-button/input100
S: Sysfs=/class/input/input2
U: Uniq=
H: Handlers=kbd event2
B: EV=3
B: KEY=1680 0 0 10000002

[root@urbetter 01]# insmod myinput.ko
 myinput_init 08:
myinput_register_irq: rquest_irq: irq 101,name KYE1-UP
myinput_register_irq: rquest_irq: irq 102,name KYE2-LEFT
myinput_register_irq: rquest_irq: irq 103,name KYE3-RIGHT
myinput_register_irq: rquest_irq: irq 104,name KYE4-DOWN
myinput_register_irq: rquest_irq: irq 105,name KYE5-ESC
myinput_register_irq: rquest_irq: irq 106,name KYE6-RETURN
myinput_init: sizeof(evbit)=4,EV_CNT 32,BITS_LONGS 1
myinput_init: sizeof(keybit)=96,KEY_CNT 768,BITS_LONGS 24
input: s3c6410 gpio button as /class/input/input2
[root@urbetter 01]# ls -l /dev/input
crw-rw----    1 root     root      13,  64 Mar 23  2000 event0
crw-rw----    1 root     root      13,  65 Mar 23  2000 event1
crw-rw----    1 root     root      13,  66 Mar 23 12:08 event2
crw-rw----    1 root     root      13,  63 Mar 23  2000 mice
crw-rw----    1 root     root      13,  32 Mar 23  2000 mouse0

USB键盘测试

USB键盘是在 hid/usbhid/usbkbd.c

I: Bus=0003 Vendor=413c Product=2003 Version=0110
N: Name="Dell Dell USB Keyboard"
P: Phys=usb-s3c24xx-1/input0
S: Sysfs=/class/input/input2
U: Uniq=
H: Handlers=kbd event2
B: EV=120013
B: KEY=10000 7 ff9f207a c14057ff febeffdf ffefffff ffffffff fffffffe
B: MSC=10
B: LED=7

[root@urbetter 01]# ls -l /dev/input
crw-rw----    1 root     root      13,  64 Mar 23  2000 event0
crw-rw----    1 root     root      13,  65 Mar 23  2000 event1
crw-rw----    1 root     root      13,  66 Mar 23 14:17 event2
crw-rw----    1 root     root      13,  67 Mar 23 14:19 event3
crw-rw----    1 root     root      13,  63 Mar 23  2000 mice
crw-rw----    1 root     root      13,  32 Mar 23  2000 mouse0

usb 1-1: new low speed USB device using s3c2410-ohci and address 2
usb 1-1: configuration #1 chosen from 1 choice
input: Dell Dell USB Keyboard as /class/input/input2
generic-usb 0003:413C:2003.0001: input: USB HID v1.10 Keyboard [Dell Dell USB Ke
yboard] on usb-s3c24xx-1/input0

Input event驱动的更多相关文章

  1. 如何读取Linux键值,输入子系统,key,dev/input/event,dev/event,C语言键盘【转】

    转自:https://blog.csdn.net/lanmanck/article/details/8423669 相信各位使用嵌入式的都希望直接读取键值,特别是芯片厂家已经提供input驱动的情况下 ...

  2. Linux input子系统学习总结(三)----Input设备驱动

    Input 设备驱动 ---操作硬件获取硬件寄存器中设备输入的数据,并把数据交给核心层: 一 .设备驱动的注册步骤: 1.分配一个struct  input_dev :          struct ...

  3. input子系统驱动学习之中的一个

        刚開始学习linux这门课就被分配编写一个设备的input子系统驱动.这对我的确有点困难.只是实际的操作中发现困难远比我想象的要大的多.本以为依照老师课上的步骤就行非常快的完毕这项任务.后来发 ...

  4. input子系统驱动

    input子系统驱动 框架分析 核心层 文件为:/drivers/input/input.c: 首先找到入口函数为**static int __init input_init(void)**,在该函数 ...

  5. 如何区分/dev/input/event

    方法是把每一个/dev/input/event打开.通过ioctl函数来读取设备name,每一个设备name是固定的,可以根据name区分event.我这是查找触摸事件为例:代码如下: static ...

  6. Exception dispatching input event. use XlistView

    今天上午解决Bug,一个上午的时间: log: 11-01 14:49:14.826: E/InputEventReceiver(30810): Exception dispatching input ...

  7. 利用input event 实时监听input输入的内容

    <div id="addNumber"> <p>How many people would you like to invite?</p> &l ...

  8. js & input event & input change event

    js & input event & input change event vue & search & input change <input @click=& ...

  9. Linux-hexdump命令调试event驱动—详解(13)

    hexdump: 查看文件的内容,比如二进制文件中包含的某些字符串,通常用来调试驱动用 1.调试 键盘驱动 讲解 当我们insmod挂载了键盘驱动后,找到键盘驱动被放在event1设备里, 此时没有按 ...

随机推荐

  1. [转]Android 应用的自动升级、更新模块的实现

    本文转自:http://www.oschina.net/question/163910_28462 我们看到很多Android应用都具有自动更新功能,用户一键就可以完成软件的升级更新.得益于Andro ...

  2. 业务系统的JVM启动参数推荐

    关键业务系统的JVM启动参数推荐,原文链接请参见:http://calvin1978.blogcn.com/articles/jvmoption-2.html

  3. shell命令getopts解析

    getopts是一条获取和处理命令行选项的语句,格式为getopts option_string variable .其中option_string中包含一个有效的单字符选项,若getopts命令在命 ...

  4. php删除数组中相同的元素,只保留一个相同元素

    <?php// 删除数组中相同元素,只保留一个相同元素function formatArray($array){sort($array);$tem = ”;$temarray = array() ...

  5. Today’s dictation

    A united nations expert on human rights in north korea has warned that the country's dictator, kim j ...

  6. python基础:三元运算

    学习条件运算时,对于简单的 if else 语句,可以使用三元运算来表示,即: 1 2 3 4 5 6 7 8 # 普通条件语句 if 1 == 1:     name = 'wupeiqi' els ...

  7. ApplicationContext容器的设计原理

    1.在ApplicationContext容器中,我们以常用的FileSystemXmlApplicationContext的实现为例来说明ApplicationContext容器的设计原理. 2.在 ...

  8. 【ASP.NET】获取网站目录的方法

         获取网站物理路径: HttpRuntime.AppDomainAppPath 获取网站虚拟路径: HttpRuntime.AppDomainAppVirtualPath

  9. A@2a139a55 结果产生的原因

    程序代码: public class ExplorationJDKSource { /** * @param args */ public static void main(String[] args ...

  10. java mail jar冲突

    开发环境:jdk1.6.0_25     MyEclipse-8.6     J2EE5   程序编译通过,J2EE5的库里面已经含有javaee.jar文件.里面的javax.mail包下面是jav ...