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. My Linux API

    @图形界面与命令行界面切换 Linux预设提供了六个命令窗口终端机让我们来登录.默认我们登录的就是第一个窗口,也就是tty1,这个六个窗口分别为tty1,tty2 … tty6,你可以按下Ctrl + ...

  2. phpQuery用法

    了解phpQuery使用前了温习jquery.js的选择用法 jquery选择器,还有一个衍生产品QueryList 例: include 'phpQuery.php'; phpQuery::newD ...

  3. Asp.net MVC 4 模型的数据注释

    [Bind(…)] Lists fields to exclude or include when binding parameter or form values to model properti ...

  4. 【转载]】Microsoft SQL Server, 错误:4064的解决方法

    SQL SERVER – Fix : Error: 4064 – Cannot open user default database. Login failed. Login failed for u ...

  5. ListViewDemo

    ListView Layout示例:MainActivity.java中定义待显示的数据countryArray, 在activity_main中定义ListView,activity_listvie ...

  6. Part 56 Generics in C#

     

  7. au3 命令

    Case $Button1                        _RunDOS(@SystemDir &"\sysdm.cpl");打开系统属性          ...

  8. 本地wamp的Internal Server Error错误解决方法

    一.本地wamp下调试url重写,加入htaccess文件后提示:500 Internal Server Error...,而删除这个文件网站又可以正常访问,其实就是没有开启url重写的功能.开启一下 ...

  9. 【学习笔记】【C语言】选择结构-if

    1.if的第1种结构 if(条件) {     语句1;     语句2;     ...... } 如果if右边小括号()中的条件成立,也就是为“真”时,就会执行大括号{}中的语句: 如果条件为假, ...

  10. J2EE5(Servlet2.5)对EL表达式的支持

    JAVA EE5默认 支持EL表达式. 办法一:在每个jsp文件的最上方加入以下代码: <%@ page language="java" import="java. ...