输入子系统由驱动层(Drivers),输入子系统核心层(Input Core)和事件处理层(EventHandler)三部份组成;
(1)从设备驱动开始分析,以kernel/driver/touchscreen/ft5x06_ts.c的tp驱动为例,在tp驱动probe的过程当中,创建input_dev;
struct input_dev {
......
struct input_id id;
unsigned long evbit[BITS_TO_LONGS(EV_CNT)];//事件类型
unsigned long keybit[BITS_TO_LONGS(KEY_CNT)];//按键
unsigned long relbit[BITS_TO_LONGS(REL_CNT)];//相对设备
unsigned long absbit[BITS_TO_LONGS(ABS_CNT)];//绝对设备,tp的坐标x,y就用这表示
unsigned long mscbit[BITS_TO_LONGS(MSC_CNT)];//杂项设备
unsigned long ledbit[BITS_TO_LONGS(LED_CNT)];//led灯
unsigned long sndbit[BITS_TO_LONGS(SND_CNT)];//声音设备
unsigned long ffbit[BITS_TO_LONGS(FF_CNT)];//强制反馈设备
unsigned long swbit[BITS_TO_LONGS(SW_CNT)];//开关设备
unsigned int hint_events_per_packet;
......
struct device dev;
struct list_head h_list;
struct list_head node;
};
然后分配大小input = input_allocate_device();原型在/kernel/driver/input/input.c里面,很简单通过kmalloc分配大小,并初始话后面会用到的两个链表;
下面为tp驱动当中设置input事件的类型和初始值和范围,
__set_bit(EV_KEY, input->evbit);
__set_bit(EV_ABS, input->evbit);
__set_bit(EV_SYN, input->evbit);
__set_bit(BTN_TOUCH, input->keybit);
__set_bit(ABS_MT_TOUCH_MAJOR, input->absbit);//tp按下去压力值
__set_bit(ABS_MT_POSITION_X, input->absbit);//x坐标值
__set_bit(ABS_MT_POSITION_Y, input->absbit);//y坐标值
__set_bit(ABS_MT_WIDTH_MAJOR, input->absbit);//按键的范围值
__set_bit(KEY_MENU, input->keybit);
__set_bit(KEY_BACK, input->keybit);
__set_bit(KEY_HOME, input->keybit);
__set_bit(KEY_SEARCH, input->keybit);
input_set_abs_params(input, ABS_MT_TOUCH_MAJOR, 0, 255, 0, 0);
input_set_abs_params(input, ABS_MT_POSITION_X, 0, X_MAX, 0, 0);
input_set_abs_params(input, ABS_MT_POSITION_Y, 0, Y_MAX, 0, 0);
input_set_abs_params(input, ABS_MT_WIDTH_MAJOR, 0, 200, 0, 0);