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. Table of Contents - Nginx

    Downloading and  Installing Nginx Nginx for Windows Basic Nginx Configuration Configuration File Syn ...

  2. 慎用memset();

    <span style="font-family: Arial, Helvetica, sans-serif;">void *(memset) (void *s,int ...

  3. Java之组合数组2

    编写函数Fun,其功能是将两个两位数的正整数A.B合并为一个整数放在C中,将A数的十位和个位一次放在C的个位和十位上,A数的十位和个位一次放在C的百位和千位上.例如,当 A=16,B=35,调用该函数 ...

  4. sql server创建表相关

    1,设置主键的sql的三种方式 a.字段名 int primary key b.字段名 int constraint 主键名 primary key clustered(字段名) c.创建表是,后置一 ...

  5. 简单bat语法

    一.简单批处理内部命令简介 1.Echo 命令 打开回显或关闭请求回显功能,或显示消息.如果没有任何参数,echo 命令将显示当前回显设置. 语法 echo [{on off}] [message] ...

  6. spring3+struts2+hibernate3整合出现的问题,No mapping found for dependency [type=java.lang.String, name='struts.objectFactory.spring.enableAopSupport']

    七月 11, 2016 3:49:24 下午 org.apache.tomcat.util.digester.SetPropertiesRule begin警告: [SetPropertiesRule ...

  7. 使用eBay API基本步骤介绍

    要开始使用eBay API,需要如下基本步骤: 1.    注册开发帐号: https://developer.ebay.com/join/Default.aspx 2.    选择API类型: eB ...

  8. 20141009---Visual Studio 2012 预定义数据类型

    预定义数据类型 一.值类型 整型:(整数) 有符号整型和无符号整形,区别是有符号的有负数无符号的都是正数, 2x+1 常用int 有符号:              带有正负数,范围为按所写依次增大 ...

  9. UI2_ButtonChess

    // // AppDelegate.m // UI2_ButtonChess // // Created by zhangxueming on 15/6/30. // Copyright (c) 20 ...

  10. ionic项目相关的操作命令

     更新npmD:\Program Files\npm-3.9.0\npmnode cli.js install npm -gf vs安装 更新node.js  windows版直接从官网下载安装包 n ...