三层结构:
Input Device Drivers 、Input core 、Input Event Drivers
设备描述
intput设备用struct input_dev描述
设备驱动的核心工作是向系统报告输入事件(input_event结构体描述),不再需要关心文件操作接口;因为input子系统已经完成了文件操作接口中。驱动报告的事件经过Inputcore和Eventhandler最终达到用户空间
注册输入设备的函数为:
int input_register_device(struct input_dev *dev)
驱动实现
1、事件支持
常用事件EV_REL、EV_ABS、EV_KEY,通过set_bit()告诉input子系统它支持哪些事件;如set_bit(EV_KEY,button_dev.evbit)
2、报告事件
void input_report_key(struct input_dev *dev, unsigned int code , int value)
报告按键,三个参数:报告事件的设备,按键的编码(哪个键),按键的值(按下为1,松开为0)
void input_report_abs()
报告绝对坐标
intput_sync()用于事件同步,它告知Inputcore(事件的接收者):驱动已经发出了一个完整的报告。
input_sync(input_dev);
应用程序
与访问字符设备的区别:使用read函数读出来的数据有一定的格式(Input event driver对事件经过处理后),在应用层读到的是一个struct input_event结构;
解析读到的input_event结构