文章目录
- 1. 电阻屏原理
- 2. ADC
- 2.1 Device:
- 2.2 Driver:
- 3. TouchSceen
- 3.1 Device
- 3.2 Driver
- 3.3 uDev
- 4. KeyBoard
- 4.1 Device
- 4.2 Driver
- 5. InputDevice
- 5.1 Input字符设备
- 5.2 input_register_device()
- 5.3 input_register_handler()
- 5.4 input_attach_handler()
- 5.5 input event的读取
- 5.5 input event的上报
- 5.6 InputEvent调试
1. 电阻屏原理
电阻屏X层上X-到X+和Y-到Y+的电阻是均匀分布的。
当计算触摸点时分为两步:
1、计算Y坐标,在Y+电极施加驱动电压V,Y-接地,芯片通过X+测量接触点的电压。
由于ITO层均匀导电,触点电压与V电压之比等于触点Y坐标与屏高度之比。
2、计算X坐标,在X+电极施加驱动电压V, X-电极接地,Y+做为引出端测量得到接触点的电压,由于ITO层均匀导电,触点电压与Vdrive电压之比等于触点X坐标与屏宽度之比。
测得的电压通常由ADC转化为数字信号,再进行简单处理就可以做为坐标判断触点的实际位置。
2. ADC
2.1 Device:
kernel\arch\arm\mach-omap2\board-am335xevm.c
中定义了device:
/* TSc controller */static struct tsc_data am335x_touchscreen_data = {.wires = 4,.x_plate_resistance = 600,.steps_to_configure = 5,
};static struct adc_data am335x_adc_data = {.adc_channels = 4,
};static struct mfd_tscadc_board tscadc = {.tsc_init = &am335x_touchscreen_data,.adc_init = &am335x_adc_data,
};
创建了对应的Platform Device:mfd_tscadc_init() -> am33xx_register_mfd_tscadc() -> omap_device_build() -> omap_device_build_ss() -> omap_device_register()
2.2 Driver:
kernel\arch\arm\plat-omap\omap_device.c
中定义了driver:
static struct platform_driver ti_tscadc_driver = {.driver = {.name = "ti_tscadc",.owner = THIS_MODULE,},.probe = ti_tscadc_probe,.remove = __devexit_p(ti_tscadc_remove),.suspend = tscadc_suspend,.resume = tscadc_resume,
};↓static int __devinit ti_tscadc_probe(struct platform_device *pdev)
{/* 解析出Touch Screen Controller的配置:其中4路ADC用来做为电阻式触摸屏控制器*//* TSC Cell */if (pdata->tsc_init) {cell = &tscadc->cells[children];cell->name = "tsc";cell->platform_data = tscadc;cell->pdata_size = sizeof(*tscadc);children++;}/* 解析出ADC的配置:另外4路ADC用来做独立的ADC使用*//* ADC Cell */if (pdata->adc_init) {cell = &tscadc->cells[children];cell->name = "tiadc";cell->platform_data = tscadc;cell->pdata_size = sizeof(*tscadc);children++;}/* 创建TSC和ADC对应的Platform Device */err = mfd_add_devices(&pdev->dev, pdev->id, tscadc->cells,children, NULL, 0);}
3. TouchSceen
触摸屏设备对应event1
和touchscreen0
:
root@am335x-evm:~# ls /dev/input/event1
/dev/input/event1
root@am335x-evm:~# ls -l /dev/input/touchscreen0
lrwxrwxrwx 1 root root 6 Jan 1 00:03 /dev/input/touchscreen0 -> event1
/dev/input/event1
读取出的数据是原始的ADC数据,它的最大值为2^12。需要经过tslib根据fb的分辨率转换以后,才能得到需要使用的X、Y轴的坐标值。
3.1 Device
在kernel\arch\arm\plat-omap\omap_device.c
驱动的ti_tscadc_probe函数中创建了TSC的Platform Device。
3.2 Driver
drivers/input/touchscreen/ti_tsc.c
:
static struct platform_driver ti_tsc_driver = {.probe = tscadc_probe,.remove = __devexit_p(tscadc_remove),.driver = {.name = "tsc",.owner = THIS_MODULE,},.suspend = tsc_suspend,.resume = tsc_resume,
};↓
初始化时注册input_device,对应/sys/class/input/input0/
:
static int __devinit tscadc_probe(struct platform_device *pdev)
{input_dev = input_allocate_device();input_dev->name = "ti-tsc";input_dev->dev.parent = &pdev->dev;input_dev->evbit[0] = BIT_MASK(EV_KEY) | BIT_MASK(EV_ABS);input_dev->keybit[BIT_WORD(BTN_TOUCH)] = BIT_MASK(BTN_TOUCH);input_set_abs_params(input_dev, ABS_X, 0, MAX_12BIT, 0, 0);input_set_abs_params(input_dev, ABS_Y, 0, MAX_12BIT, 0, 0);input_set_abs_params(input_dev, ABS_PRESSURE, 0, MAX_12BIT, 0, 0);/* register to the input system */err = input_register_device(input_dev);}
中断时上报input_event:
static irqreturn_t tscadc_interrupt(int irq, void *dev)
{/** Sample found inconsistent by debouncing* or pressure is beyond the maximum.* Don't report it to user space.*//* 上报电阻触摸屏的X、Y、Z值。X、Y为坐标值,Z为压力值*/if (pen == 0) {if ((diffx < 15) && (diffy < 15)&& (z <= MAX_12BIT)) {input_report_abs(input_dev, ABS_X,val_x);input_report_abs(input_dev, ABS_Y,val_y);input_report_abs(input_dev, ABS_PRESSURE,z);input_report_key(input_dev, BTN_TOUCH,1);input_sync(input_dev);}}status = tscadc_readl(ts_dev, TSCADC_REG_RAWIRQSTATUS);if (status & TSCADC_IRQENB_PENUP) {/* Pen up event */fsm = tscadc_readl(ts_dev, TSCADC_REG_ADCFSM);if (fsm == 0x10) {pen = 1;bckup_x = 0;bckup_y = 0;input_report_key(input_dev, BTN_TOUCH, 0);input_report_abs(input_dev, ABS_PRESSURE, 0);input_sync(input_dev);} else {pen = 0;}irqclr |= TSCADC_IRQENB_PENUP;}}
3.3 uDev
Udev就是在用户空间接收内核sysfs netlink热插拔消息的程序,而内核态调用用户空间程序的方式调用的是“/sbin/hotplug”,后一种方式已经被淘汰。
用户空间对热插拔消息的处理有几类动作:
1、创建或者移除设备的设备节点;如果设备有devt属性,即“/sys/class/” 路径下包含“dev”文件属性的内核设备,发生增加或移除操作时,udev会帮其在用户空间“/dev”路径下增加或移除设备节点。
2、根据规则文件,给设备改名、创建符号链接等。
3、根据规则文件,调用外部程序。例如,调用modprobe插入驱动。
/etc/udev/rules.d/local.rules:
# Create a symlink to any touchscreen input device
SUBSYSTEM=="input", KERNEL=="event[0-9]*", ATTRS{modalias}=="input:*-e0*,3,*a0,1
4. KeyBoard
键盘设备对应event0
:
root@am335x-evm:~# ls /dev/input/event0
/dev/input/event0
4.1 Device
kernel\arch\arm\mach-omap2\board-am335xevm.c
中定义了device:
/* Matrix GPIO Keypad Support for profile-0 only: TODO *//* pinmux for keypad device */
static struct pinmux_config matrix_keypad_pin_mux[] = {{"gpmc_a7.gpio1_23", OMAP_MUX_MODE7 | AM33XX_PIN_INPUT}, //T15{"gpmc_a10.gpio1_26", OMAP_MUX_MODE7 | AM33XX_PIN_INPUT}, //T16{"gpmc_a2.gpio1_18", OMAP_MUX_MODE7 | AM33XX_PIN_INPUT}, //U14{"gpmc_a8.gpio1_24", OMAP_MUX_MODE7 | AM33XX_PIN_OUTPUT}, //V16{"gpmc_a6.gpio1_22", OMAP_MUX_MODE7 | AM33XX_PIN_OUTPUT}, //U15{"gpmc_a5.gpio1_21", OMAP_MUX_MODE7 | AM33XX_PIN_OUTPUT}, //V15{"gpmc_a1.gpio1_17", OMAP_MUX_MODE7 | AM33XX_PIN_OUTPUT}, //V14{"gpmc_a4.gpio1_20", OMAP_MUX_MODE7 | AM33XX_PIN_OUTPUT}, //R14{"gpmc_a3.gpio1_19", OMAP_MUX_MODE7 | AM33XX_PIN_OUTPUT}, //T14{"mcasp0_axr0.gpio3_16", OMAP_MUX_MODE7 | AM33XX_PIN_OUTPUT}, //D12
// {"ecap0_in_pwm0_out.gpio0_7", OMAP_MUX_MODE7 | AM33XX_PIN_OUTPUT}, //C18. hx del 12.13{"uart1_rxd.gpio0_14", OMAP_MUX_MODE7 | AM33XX_PIN_OUTPUT},//D16 {NULL, 0},
};/* Keys mapping */
static const uint32_t am335x_evm_matrix_keys[] = {KEY(0, 0, KEY_F1), KEY(0, 1, KEY_F2), KEY(0, 2, KEY_F3), KEY(0, 3, KEY_F4), KEY(0, 4, KEY_1), KEY(0, 5, KEY_2), KEY(0, 6, KEY_3), KEY(0, 7, KEY_0),KEY(1, 0, KEY_F5), KEY(1, 1, KEY_F6), KEY(1, 2, KEY_F7), KEY(1, 3, KEY_BACKSPACE), KEY(1, 4, KEY_4), KEY(1, 5, KEY_5), KEY(1, 6, KEY_6), KEY(1, 7, KEY_MINUS),KEY(2, 0, KEY_F9), KEY(2, 1, KEY_ENTER), KEY(2, 2, KEY_F11), KEY(2, 3, KEY_F12), KEY(2, 4, KEY_7), KEY(2, 5, KEY_8), KEY(2, 6, KEY_9), KEY(2, 7, KEY_DOT),
};const struct matrix_keymap_data am335x_evm_keymap_data = {.keymap = am335x_evm_matrix_keys,.keymap_size = ARRAY_SIZE(am335x_evm_matrix_keys),
};static const unsigned int am335x_evm_keypad_row_gpios[] = {GPIO_TO_PIN(1, 18), GPIO_TO_PIN(1, 26), GPIO_TO_PIN(1, 23)
};static const unsigned int am335x_evm_keypad_col_gpios[] = {GPIO_TO_PIN(1, 24), GPIO_TO_PIN(1, 22), GPIO_TO_PIN(1, 21), GPIO_TO_PIN(1, 17),GPIO_TO_PIN(1, 20), GPIO_TO_PIN(1, 19), GPIO_TO_PIN(3, 16), GPIO_TO_PIN(0, 14)
};static struct matrix_keypad_platform_data am335x_evm_keypad_platform_data = {.keymap_data = &am335x_evm_keymap_data,.row_gpios = am335x_evm_keypad_row_gpios,.num_row_gpios = ARRAY_SIZE(am335x_evm_keypad_row_gpios),.col_gpios = am335x_evm_keypad_col_gpios,.num_col_gpios = ARRAY_SIZE(am335x_evm_keypad_col_gpios),.active_low = false,.debounce_ms = 5,.col_scan_delay_us = 2,
};static struct platform_device am335x_evm_keyboard = {.name = "matrix-keypad",.id = -1,.dev = {.platform_data = &am335x_evm_keypad_platform_data,},
};static void matrix_keypad_init(int evm_id, int profile)
{int err;setup_pin_mux(matrix_keypad_pin_mux);err = platform_device_register(&am335x_evm_keyboard);if (err) {pr_err("failed to register matrix keypad (2x3) device\n");}
}
4.2 Driver
kernel\drivers\input\keyboard\matrix_keypad.c
:
static struct platform_driver matrix_keypad_driver = {.probe = matrix_keypad_probe,.remove = __devexit_p(matrix_keypad_remove),.driver = {.name = "matrix-keypad",.owner = THIS_MODULE,
#ifdef CONFIG_PM.pm = &matrix_keypad_pm_ops,
#endif},
};↓
5. InputDevice
5.1 Input字符设备
Input event是通过/dev/input/event*
这些设备节点上报的,这些节点对应一个字符设备的多个从设备:
root@am335x-evm:~# ls -l /dev/input/
crw-r----- 1 root root 13, 64 Jan 1 00:03 event0
crw-r----- 1 root root 13, 65 Jan 1 00:03 event1
crw-r----- 1 root root 13, 66 Jan 1 00:03 event2
crw-r----- 1 root root 13, 63 Jan 1 00:03 mice
crw-r----- 1 root root 13, 32 Jan 1 00:03 mouse0
lrwxrwxrwx 1 root root 6 Jan 1 00:03 touchscreen0 -> event1
这个主的字符设备是在input系统初始化时创建的,kernel\drivers\input\input.c:
static int __init input_init(void)
{int err;err = class_register(&input_class);if (err) {pr_err("unable to register input_dev class\n");return err;}err = input_proc_init();if (err)goto fail1;/* 创建input字符设备 */err = register_chrdev(INPUT_MAJOR, "input", &input_fops);if (err) {pr_err("unable to register char major %d", INPUT_MAJOR);goto fail2;}return 0;fail2: input_proc_exit();fail1: class_unregister(&input_class);return err;
}static const struct file_operations input_fops = {.owner = THIS_MODULE,.open = input_open_file,.llseek = noop_llseek,
};
这个字符设备其实只是一个空架子,它不会做任何实际事情的,在open的时候把fops悄悄换成了从设备handler的fops:
static int input_open_file(struct inode *inode, struct file *file)
{struct input_handler *handler;const struct file_operations *old_fops, *new_fops = NULL;int err;err = mutex_lock_interruptible(&input_mutex);if (err)return err;/* No load-on-demand here? *//* (1) 获取从设备handler的fops */handler = input_table[iminor(inode) >> 5];if (handler)new_fops = fops_get(handler->fops);mutex_unlock(&input_mutex);/** That's _really_ odd. Usually NULL ->open means "nothing special",* not "no device". Oh, well...*/if (!new_fops || !new_fops->open) {fops_put(new_fops);err = -ENODEV;goto out;}/* (2) 把当前节点的fops换成从设备handler的fops */old_fops = file->f_op;file->f_op = new_fops;/* (3) 使用新的fops来open() */err = new_fops->open(inode, file);if (err) {fops_put(file->f_op);file->f_op = fops_get(old_fops);}fops_put(old_fops);
out:return err;
}
5.2 input_register_device()
input硬件设备驱动,把硬件设备注册成input device。对应以下节点:
root@am335x-evm:~# ls -l /sys/class/input/input*
lrwxrwxrwx 1 root root 0 Jan 1 00:00 /sys/class/input/input0 -> ../../devices/platform/matrix-keypad/input/input0
lrwxrwxrwx 1 root root 0 Jan 1 00:00 /sys/class/input/input1 -> ../../devices/platform/omap/ti_tscadc/tsc/input/input1
lrwxrwxrwx 1 root root 0 Jan 1 00:00 /sys/class/input/input2 -> ../../devices/platform/gpio-keys/input/input2
具体过程如下:
int input_register_device(struct input_dev *dev)
{...dev_set_name(&dev->dev, "input%ld",(unsigned long) atomic_inc_return(&input_no) - 1);/* (1) 注册input deive设备 */error = device_add(&dev->dev);if (error)return error;list_add_tail(&dev->node, &input_dev_list);/* (2) 遍历input handler链表来进行适配和绑定 */list_for_each_entry(handler, &input_handler_list, node)input_attach_handler(dev, handler);input_wakeup_procfs_readers();mutex_unlock(&input_mutex);return 0;
}
5.3 input_register_handler()
硬件设备注册成了input device,但是设备产生的event并不是直接传送给用户,中间还得经过一层input handler的处理。
一个input device可以对应多个input handler,input handler通过input_register_handler()来进行注册:
int input_register_handler(struct input_handler *handler)
{/* (1) 把handler和从设备号绑定 */if (handler->fops != NULL) {if (input_table[handler->minor >> 5]) {retval = -EBUSY;goto out;}input_table[handler->minor >> 5] = handler;}/* (2) 把handler加入链表 */list_add_tail(&handler->node, &input_handler_list);/* (3) 尝试适配新的handler和已有的input device */list_for_each_entry(dev, &input_dev_list, node)input_attach_handler(dev, handler);input_wakeup_procfs_readers();out:mutex_unlock(&input_mutex);return retval;
}
最常用默认的handler是evdev,kernel\drivers\input\evdev.c:
static const struct input_device_id evdev_ids[] = {{ .driver_info = 1 }, /* Matches all devices */{ }, /* Terminating zero entry */
};MODULE_DEVICE_TABLE(input, evdev_ids);static struct input_handler evdev_handler = {.event = evdev_event,.connect = evdev_connect,.disconnect = evdev_disconnect,.fops = &evdev_fops,.minor = EVDEV_MINOR_BASE,.name = "evdev",.id_table = evdev_ids,
};static int __init evdev_init(void)
{return input_register_handler(&evdev_handler);
}
5.4 input_attach_handler()
在input device和input handler都注册完成后,最关键的就是两者的适配和绑定操作。在input_register_device()和input_register_handler()都会调用input_attach_handler():
static int input_attach_handler(struct input_dev *dev, struct input_handler *handler)
{const struct input_device_id *id;int error;/* (1) 判断device和handler是否匹配 */id = input_match_device(handler, dev);if (!id)return -ENODEV;/* (2) 匹配则调用handler的connect()函数 */error = handler->connect(handler, dev, id);if (error && error != -ENODEV)pr_err("failed to attach handler %s to device %s, error: %d\n",handler->name, kobject_name(&dev->dev.kobj), error);return error;
}
以evdev为例,handler->connect()对应evdev_connect():
static int evdev_connect(struct input_handler *handler, struct input_dev *dev,const struct input_device_id *id)
{...dev_set_name(&evdev->dev, "event%d", minor);evdev->exist = true;evdev->minor = minor;evdev->handle.dev = input_get_device(dev);evdev->handle.name = dev_name(&evdev->dev);evdev->handle.handler = handler;evdev->handle.private = evdev;evdev->dev.devt = MKDEV(INPUT_MAJOR, EVDEV_MINOR_BASE + minor);evdev->dev.class = &input_class;evdev->dev.parent = &dev->dev;evdev->dev.release = evdev_free;device_initialize(&evdev->dev);/* (1) 注册input handle */error = input_register_handle(&evdev->handle);if (error)goto err_free_evdev;/* (2) 创建一个内部evdev */error = evdev_install_chrdev(evdev);if (error)goto err_unregister_handle;/* (3) 注册'/sys/class/input/event*' */error = device_add(&evdev->dev);if (error)goto err_cleanup_evdev;return 0;}
到了这一步才会创建/sys/class/input/event*
文件节点,uDev又会根据这些节点/dev目录下创建/dev/input/event*
文件节点。
我们会在/sys/class/input/
目录下发现两套文件节点:
/sys/class/input/input*
文件,是在input_register_device()时创建的,每一个对应一个input设备。/sys/class/input/event*
文件,是在evdev_connect()时创建的,每一个对应一个input event虚拟设备。
可以看到input device并不是和input event虚拟设备一一对应的,一个input device可以和多个input handler绑定生成多个input event虚拟设备。
同时,一个input handler也是可以和多个input device进行绑定的。
同时,一个input device和一个input handler绑定生成的一个input event虚拟设备,使用input handle数据结构来记录,并调用input_register_handle()注册。(注意handle和handler的不同)
5.5 input event的读取
经过input_attach_handler() -> evdev_connect()调用以后,系统在/dev/input
目录下面已经创建好了设备节点:
root@am335x-evm:~# ls -l /dev/input/
crw-r----- 1 root root 13, 64 Jan 1 00:03 event0
crw-r----- 1 root root 13, 65 Jan 1 00:03 event1
crw-r----- 1 root root 13, 66 Jan 1 00:03 event2
crw-r----- 1 root root 13, 63 Jan 1 00:03 mice
crw-r----- 1 root root 13, 32 Jan 1 00:03 mouse0
lrwxrwxrwx 1 root root 6 Jan 1 00:03 touchscreen0 -> event1
用户程序就可以通过对/dev/input/event1
文件节点来读取input event了。
open() → input_open_file() → evdev_open()read() → evdev_read()↓static ssize_t evdev_read(struct file *file, char __user *buffer,size_t count, loff_t *ppos)
{.../* (1) 阻塞等待EV_SYN信号 */retval = wait_event_interruptible(evdev->wait,client->packet_head != client->tail || !evdev->exist);if (retval)return retval;if (!evdev->exist)return -ENODEV;/* (2) 读取evdev buffer中的event值 */while (retval + input_event_size() <= count &&evdev_fetch_next_event(client, &event)) {if (input_event_to_user(buffer + retval, &event))return -EFAULT;retval += input_event_size();}return retval;
}
5.5 input event的上报
在input device驱动中,会调用input_report_abs()、input_report_key()、input_sync()来上报event。这些函数最后调用的都是input_event()。
static irqreturn_t tscadc_interrupt(int irq, void *dev)
{if ((diffx < 15) && (diffy < 15)&& (z <= MAX_12BIT)) {input_report_abs(input_dev, ABS_X,val_x);input_report_abs(input_dev, ABS_Y,val_y);input_report_abs(input_dev, ABS_PRESSURE,z);input_report_key(input_dev, BTN_TOUCH,1);input_sync(input_dev);}}↓static inline void input_report_abs(struct input_dev *dev, unsigned int code, int value)
{input_event(dev, EV_ABS, code, value);
}↓input_event() → input_handle_event()
input_handle_event()做了一些上报的预处理工作,最重要的是在这里做了去重工作,如果重复的键值上报,在这里会被过滤掉
↓static void input_handle_event(struct input_dev *dev,unsigned int type, unsigned int code, int value)
{int disposition = INPUT_IGNORE_EVENT;switch (type) {case EV_SYN:switch (code) {case SYN_CONFIG:disposition = INPUT_PASS_TO_ALL;break;case SYN_REPORT:if (!dev->sync) {dev->sync = true;disposition = INPUT_PASS_TO_HANDLERS;}break;case SYN_MT_REPORT:dev->sync = false;disposition = INPUT_PASS_TO_HANDLERS;break;}break;case EV_KEY:if (is_event_supported(code, dev->keybit, KEY_MAX) &&!!test_bit(code, dev->key) != value) {if (value != 2) {__change_bit(code, dev->key);if (value)input_start_autorepeat(dev, code);elseinput_stop_autorepeat(dev);}disposition = INPUT_PASS_TO_HANDLERS;}break;case EV_SW:if (is_event_supported(code, dev->swbit, SW_MAX) &&!!test_bit(code, dev->sw) != value) {__change_bit(code, dev->sw);disposition = INPUT_PASS_TO_HANDLERS;}break;case EV_ABS:if (is_event_supported(code, dev->absbit, ABS_MAX))disposition = input_handle_abs_event(dev, code, &value);break;case EV_REL:if (is_event_supported(code, dev->relbit, REL_MAX) && value)disposition = INPUT_PASS_TO_HANDLERS;break;case EV_MSC:if (is_event_supported(code, dev->mscbit, MSC_MAX))disposition = INPUT_PASS_TO_ALL;break;case EV_LED:if (is_event_supported(code, dev->ledbit, LED_MAX) &&!!test_bit(code, dev->led) != value) {__change_bit(code, dev->led);disposition = INPUT_PASS_TO_ALL;}break;case EV_SND:if (is_event_supported(code, dev->sndbit, SND_MAX)) {if (!!test_bit(code, dev->snd) != !!value)__change_bit(code, dev->snd);disposition = INPUT_PASS_TO_ALL;}break;case EV_REP:if (code <= REP_MAX && value >= 0 && dev->rep[code] != value) {dev->rep[code] = value;disposition = INPUT_PASS_TO_ALL;}break;case EV_FF:if (value >= 0)disposition = INPUT_PASS_TO_ALL;break;case EV_PWR:disposition = INPUT_PASS_TO_ALL;break;}if (disposition != INPUT_IGNORE_EVENT && type != EV_SYN)dev->sync = false;if ((disposition & INPUT_PASS_TO_DEVICE) && dev->event)dev->event(dev, type, code, value);if (disposition & INPUT_PASS_TO_HANDLERS)input_pass_event(dev, type, code, value);
}↓input_pass_event()↓handler->event()↓evdev_event()
最后调用到了evdev handler的event函数:
static void evdev_event(struct input_handle *handle,unsigned int type, unsigned int code, int value)
{/* (1) 把event发送到等待的buffer中 */client = rcu_dereference(evdev->grab);if (client)evdev_pass_event(client, &event);elselist_for_each_entry_rcu(client, &evdev->client_list, node)evdev_pass_event(client, &event);rcu_read_unlock();/* (2) 如果是EV_SYN键值,唤醒在阻塞读取`/dev/input/event*`的用户程序 */if (type == EV_SYN && code == SYN_REPORT)wake_up_interruptible(&evdev->wait);
}
5.6 InputEvent调试
- 定义
struct input_event {struct timeval time; /* 8 字节:表示输入时的时间 */__u16 type; /* 2 字节:表示输入设备时那个东西,常用的有鼠标,键盘等 */__u16 code; /* 2 字节:根据不同的type有code,类型比如键盘的那个按键,鼠标的那个按键等 */__s32 value; /* 4 字节:根据不同的type和code决定,比如键盘A键按下和松开,鼠标的移动方向等 */
};
- 调试
使用hexdump查看event上报事件。
电阻屏:
root@am335x-evm:~# hexdump /dev/input/event1
0000000 5780 386d b7e8 0006 0003 0000 03b6 0000 // 0003=EV_ABS, 0000=ABS_X, 000009e7=ADC Value // X轴
0000010 5780 386d b7e8 0006 0003 0001 0d96 0000 // 0003=EV_ABS, 0001=ABS_Y, 00000d5b=ADC Value // Y轴
0000020 5780 386d b7e8 0006 0003 0018 0077 0000 // 0003=EV_ABS, 0018=ABS_PRESSURE, 000000ba= // 压力值
0000030 5780 386d b7e8 0006 0001 014a 0001 0000 // 0001=EV_KEY, 014a=BTN_TOUCH, 0001=PRESS //touch按下
0000040 5780 386d b7e8 0006 0000 0000 0000 0000 // 0000=EV_SYN0000050 5780 386d ce33 0006 0003 0000 03bc 0000 // 0003=EV_ABS, 0000=ABS_X, 000009e7=ADC Value
0000060 5780 386d ce33 0006 0003 0001 0da3 0000 // 0003=EV_ABS, 0001=ABS_Y, 00000d5b=ADC Value
0000070 5780 386d ce33 0006 0000 0000 0000 0000 // 0000=EV_SYN0000080 5780 386d dcfb 0006 0003 0000 03ba 0000
0000090 5780 386d dd19 0006 0003 0001 0da4 0000
00000a0 5780 386d dd19 0006 0000 0000 0000 000000000b0 5780 386d faaa 0006 0003 0000 03bd 0000
00000c0 5780 386d faaa 0006 0003 0001 0da2 0000
00000d0 5780 386d faaa 0006 0000 0000 0000 000000000e0 5780 386d 0972 0007 0003 0000 03bf 0000
00000f0 5780 386d 0972 0007 0003 0001 0da7 0000
0000100 5780 386d 0972 0007 0000 0000 0000 00000000110 5780 386d 10d6 0007 0003 0000 03bb 0000
0000120 5780 386d 10f5 0007 0003 0018 0078 0000
0000130 5780 386d 10f5 0007 0000 0000 0000 00000000140 5780 386d 1859 0007 0003 0000 03bc 0000
0000150 5780 386d 1859 0007 0003 0001 0da8 0000
0000160 5780 386d 1859 0007 0003 0018 0077 0000
0000170 5780 386d 1859 0007 0000 0000 0000 00000000180 5780 386d 2fb6 0007 0001 014a 0000 0000 // 0001=EV_KEY, 014a=BTN_TOUCH, 0000=RELEASE // touch释放
0000190 5780 386d 2fb6 0007 0003 0018 0000 0000 // 0003=EV_ABS, 0018=ABS_PRESSURE, 00000000=
00001a0 5780 386d 2fb6 0007 0000 0000 0000 0000 // 0000=EV_SYN
键盘:
root@am335x-evm:~# hexdump /dev/input/event0
0000000 5445 386d bce7 0000 0004 0004 0016 0000 // 0004=EV_MSC, 0004=MSC_SCAN, 0016=MATRIX_SCAN_CODE
0000010 5445 386d bd05 0000 0001 000a 0001 0000 // 0001=EV_KEY, 000a=KEY_9, 0001=PRESS // 键按下
0000020 5445 386d bd05 0000 0000 0000 0000 0000 // 0000=EV_SYN0000030 5445 386d b87f 0002 0004 0004 0016 0000 // 0004=EV_MSC, 0004=MSC_SCAN, 0016=MATRIX_SCAN_CODE
0000040 5445 386d b87f 0002 0001 000a 0000 0000 // 0001=EV_KEY, 000a=KEY_9, 0000=RELEASE // 键释放
0000050 5445 386d b87f 0002 0000 0000 0000 0000 // 0000=EV_SYN
触摸屏(电容屏):
# cat /dev/input/event1 | hexdump0000250 f832 4e15 c502 0006 0003 0039 0020 0000
0000260 f832 4e15 c50f 0006 0003 0030 0004 0000
0000270 f832 4e15 c514 0006 0003 0035 0263 0000
0000280 f832 4e15 c519 0006 0003 0036 01fd 0000
0000290 f832 4e15 c520 0006 0001 014a 0001 0000
00002a0 f832 4e15 c525 0006 0003 0000 0263 0000
00002b0 f832 4e15 c52b 0006 0003 0001 01fd 0000
00002c0 f832 4e15 c530 0006 0000 0000 0000 0000
00002d0 f832 4e15 be99 0007 0003 0039 ffff ffff
00002e0 f832 4e15 bea5 0007 0001 014a 0000 0000
00002f0 f832 4e15 bea8 0007 0000 0000 0000 0000第七列表示上报事件和: 0039 --> ABS_MT_TRACKING_ID; 0030 --> ABS_MT_TOUCH_MAJOR; 0035 --> ABS_MT_POSITION_X; 0036 --> ABS_MT_POSITION_Y014a --> BTN_TOUCH
第八列表示上报值
多点触摸的参数解析:
/* 因为触摸类设备现在用的越来越多,所以专门在绝对坐标里做了触摸设备的参数描述信息 */
#define ABS_MT_TOUCH_MAJOR 0x30 /* Major axis of touching ellipse */
#define ABS_MT_TOUCH_MINOR 0x31 /* Minor axis (omit if circular) */
#define ABS_MT_WIDTH_MAJOR 0x32 /* Major axis of approaching ellipse */
#define ABS_MT_WIDTH_MINOR 0x33 /* Minor axis (omit if circular) */
#define ABS_MT_ORIENTATION 0x34 /* Ellipse orientation */
#define ABS_MT_POSITION_X 0x35 /* Center X ellipse position */
#define ABS_MT_POSITION_Y 0x36 /* Center Y ellipse position */
#define ABS_MT_TOOL_TYPE 0x37 /* Type of touching device */
#define ABS_MT_BLOB_ID 0x38 /* Group a set of packets as a blob */
#define ABS_MT_TRACKING_ID 0x39 /* Unique ID of initiated contact */
#define ABS_MT_PRESSURE 0x3a /* Pressure on contact area */ABS_MT_POSITION_X 接触面的形心的X坐标值
ABS_MT_POSITION_Y 接触面的形心的Y坐标值
ABS_MT_TOUCH_MAJOR 提供手指的大小
ABS_MT_WIDTH_MAJOR 提供触摸面积大小 TOUCH 和 WIDTH参数给出了个,想想如果一个手指按在玻璃上,透过玻璃你将看到两个区域:
一个是手指与玻璃接触的区域,用 ABS_MT_TOUCH_MAJOR描述,
一个是手指本身大小的区域,ABS_MT_WIDTH_MAJOR描述,
手指与玻璃接触的面积要小于手指本身的大小,通过这两个参数,可以换算出手指的压力。也可通过 ABS_MT_PRESSURE参数直接提供手指的压力。
除了 MAJOR这个参数,还可以提供一个 MINOR参数,手指可以被认为是一个椭圆,MAJOR和 MINOR可以认为是这个椭圆的长轴和短轴,椭圆的中心可以被 ORIENTATION这个参数描述。ABS_MT_PRESSURE 接触工具对接触面的压力大小,可以用来代替上面的四个参数。
ABS_MT_ORIENTATION 描述随圆的转动趋势,这是一个抽相值,O值表示接触面在平行与触摸屏的Y轴,向左是负值,向右是正值,如果完全平行于X轴,则上向返回最大值。如果接触面是圆形,则可以忽略这个参数。如果内核不能获得这个参数有有效值,但可以区分接触面的长短轴,这个功能还是可以被部份支持,在一些设备中, ABS_MT_ORIENTATION 的值只能是 0和1。
ABS_MT_TOOL_TYPE 描述接触工具类型(手指,触控笔等 ),很多内核驱动无法区分此参数如手指及笔,如果是这样,该参数可以不用,协议目前支持MT_TOOL_FINGER和MT_TOOL_PEN两种类型。
ABS_MT_BLOB_ID 形状集ID,集合几个点以描述一个形状,很多驱动没有形状属性,此参数可以不用。
ABS_MT_TRACKING_ID 描述了从接触开始到释放的整个过程的集合,如果设备不支持,此参数可是不用。计算方法:
一些设备将触摸面作为一个矩形上报,可以通过下面这些公式来计算出协议中所需要的信息。
ABS_MT_TOUCH_MAJOR := max(X, Y)
ABS_MT_TOUCH_MINOR := min(X, Y)
ABS_MT_ORIENTATION := bool(X > Y)
ABS_MT_ORIENTATION的取值范围为0至1,用来标识矩形接触面偏向X轴或Y轴的程度。触摸轨迹
仅有少数设备可以明触的标识真实的 trackingID,多数情况下 trackingID只能来标识一次触摸动作的过程。手势
多点触摸指定的应用是创建手势动作, TOUCH和 WIDTH参数经常用来区别手指的压力和手指间的距离,另外 MINOR类的参数可以用来区别设备的接触面的大小(点接触还是面接触),ORIENTATION可以产生旋转事件。
- 键值查询:
具体的type的有哪些
/** Event types*/
#define EV_SYN 0x00 /* 同步事件,通常一个输入事件结束都会有一个同步事件,作为分隔两个输入事件 */
#define EV_KEY 0x01 /* 按键类事件,作为描述设备的键值 */
#define EV_REL 0x02 /* relative相对输入事件,主要是用来描述鼠标类设备这次移动相对上次移动的偏移值*/
#define EV_ABS 0x03 /* absoluate绝对输入事件,主要是用来描述触摸屏类设备的按键值 */
#define EV_MSC 0x04 /* 其它事件 */
#define EV_SW 0x05 /* 开关事件 */
#define EV_LED 0x11 /* 灯光事件 */
#define EV_SND 0x12 /* 声音事件,比如:hey,Siri */
#define EV_REP 0x14 /* 重复类事件 */
#define EV_FF 0x15 /* 力反馈事件,比如指纹识别 */
#define EV_PWR 0x16 /* 电源事件,比如我按了电源按键,手机就应该处于待机状态 */
#define EV_FF_STATUS 0x17 /* 受力状态事件,比如按下电源键5s,就应该关机 */
#define EV_MAX 0x1f
#define EV_CNT (EV_MAX+1)
EV_SYN的code定义:
/** Synchronization events.*/#define SYN_REPORT 0
#define SYN_CONFIG 1
#define SYN_MT_REPORT 2
#define SYN_DROPPED 3
EV_ABS的code定义:
/** Absolute axes /* 绝对坐标(主要是用于触摸屏和写字板类设备) */*/#define ABS_X 0x00
#define ABS_Y 0x01
#define ABS_Z 0x02
#define ABS_RX 0x03
#define ABS_RY 0x04
#define ABS_RZ 0x05
#define ABS_THROTTLE 0x06
#define ABS_RUDDER 0x07
#define ABS_WHEEL 0x08
#define ABS_GAS 0x09
#define ABS_BRAKE 0x0a
#define ABS_HAT0X 0x10
#define ABS_HAT0Y 0x11
#define ABS_HAT1X 0x12
#define ABS_HAT1Y 0x13
#define ABS_HAT2X 0x14
#define ABS_HAT2Y 0x15
#define ABS_HAT3X 0x16
#define ABS_HAT3Y 0x17
#define ABS_PRESSURE 0x18
#define ABS_DISTANCE 0x19
#define ABS_TILT_X 0x1a
#define ABS_TILT_Y 0x1b
#define ABS_TOOL_WIDTH 0x1c
#define ABS_VOLUME 0x20
#define ABS_MISC 0x28
/* 因为触摸类设备现在用的越来越多,所以专门在绝对坐标里做了触摸设备的参数描述信息 */
#define ABS_MT_TOUCH_MAJOR 0x30 /* Major axis of touching ellipse */
#define ABS_MT_TOUCH_MINOR 0x31 /* Minor axis (omit if circular) */
#define ABS_MT_WIDTH_MAJOR 0x32 /* Major axis of approaching ellipse */
#define ABS_MT_WIDTH_MINOR 0x33 /* Minor axis (omit if circular) */
#define ABS_MT_ORIENTATION 0x34 /* Ellipse orientation */
#define ABS_MT_POSITION_X 0x35 /* Center X ellipse position */
#define ABS_MT_POSITION_Y 0x36 /* Center Y ellipse position */
#define ABS_MT_TOOL_TYPE 0x37 /* Type of touching device */
#define ABS_MT_BLOB_ID 0x38 /* Group a set of packets as a blob */
#define ABS_MT_TRACKING_ID 0x39 /* Unique ID of initiated contact */
#define ABS_MT_PRESSURE 0x3a /* Pressure on contact area */#define ABS_MAX 0x3f
#define ABS_CNT (ABS_MAX+1)
EV_REL的code定义:
/** Relative axes 相对位置类(主要是用于鼠标和笔记本电脑的触控板)*/ #define REL_X 0x00 /* x轴相对上次的x轴的偏移坐标 */
#define REL_Y 0x01 /* y轴相对上次的y轴的偏移坐标 */
#define REL_Z 0x02 /* z轴相对上次的z轴的偏移坐标 */
#define REL_RX 0x03 /* 其它用到了再学,我用到了再补充这个博客 */
#define REL_RY 0x04
#define REL_RZ 0x05
#define REL_HWHEEL 0x06
#define REL_DIAL 0x07
#define REL_WHEEL 0x08
#define REL_MISC 0x09
#define REL_MAX 0x0f
#define REL_CNT (REL_MAX+1)
EV_KEY的code定义:
/** Keys and buttons /* 下面的键值特别多,我们主要知道键盘鼠标之类的就可以遇到特殊设备了在学习 */** Most of the keys/buttons are modeled after USB HUT 1.12* (see http://www.usb.org/developers/hidpage).* Abbreviations in the comments:* AC - Application Control /* 应用控制 */* AL - Application Launch Button /* 应用启动按键 */* SC - System Control /* 系统控制按键 */*//* 0是保留的,下面就是键盘设备每个键的键值 */
#define KEY_RESERVED 0
#define KEY_ESC 1
#define KEY_1 2
#define KEY_2 3
#define KEY_3 4
#define KEY_4 5
#define KEY_5 6
#define KEY_6 7
#define KEY_7 8
#define KEY_8 9
#define KEY_9 10
#define KEY_0 11
#define KEY_MINUS 12
#define KEY_EQUAL 13
#define KEY_BACKSPACE 14
#define KEY_TAB 15
#define KEY_Q 16
#define KEY_W 17
#define KEY_E 18
#define KEY_R 19
#define KEY_T 20
#define KEY_Y 21
#define KEY_U 22
#define KEY_I 23
#define KEY_O 24
#define KEY_P 25
#define KEY_LEFTBRACE 26
#define KEY_RIGHTBRACE 27
#define KEY_ENTER 28
#define KEY_LEFTCTRL 29
#define KEY_A 30
#define KEY_S 31
#define KEY_D 32
#define KEY_F 33
#define KEY_G 34
#define KEY_H 35
#define KEY_J 36
#define KEY_K 37
#define KEY_L 38
#define KEY_SEMICOLON 39
#define KEY_APOSTROPHE 40
#define KEY_GRAVE 41
#define KEY_LEFTSHIFT 42
#define KEY_BACKSLASH 43
#define KEY_Z 44
#define KEY_X 45
#define KEY_C 46
#define KEY_V 47
#define KEY_B 48
#define KEY_N 49
#define KEY_M 50
#define KEY_COMMA 51
#define KEY_DOT 52
#define KEY_SLASH 53
#define KEY_RIGHTSHIFT 54
#define KEY_KPASTERISK 55
#define KEY_LEFTALT 56
#define KEY_SPACE 57
#define KEY_CAPSLOCK 58
#define KEY_F1 59
#define KEY_F2 60
#define KEY_F3 61
#define KEY_F4 62
#define KEY_F5 63
#define KEY_F6 64
#define KEY_F7 65
#define KEY_F8 66
#define KEY_F9 67
#define KEY_F10 68
#define KEY_NUMLOCK 69
#define KEY_SCROLLLOCK 70
#define KEY_KP7 71
#define KEY_KP8 72
#define KEY_KP9 73
#define KEY_KPMINUS 74
#define KEY_KP4 75
#define KEY_KP5 76
#define KEY_KP6 77
#define KEY_KPPLUS 78
#define KEY_KP1 79
#define KEY_KP2 80
#define KEY_KP3 81
#define KEY_KP0 82
#define KEY_KPDOT 83#define KEY_ZENKAKUHANKAKU 85
#define KEY_102ND 86
#define KEY_F11 87
#define KEY_F12 88
#define KEY_RO 89
#define KEY_KATAKANA 90
#define KEY_HIRAGANA 91
#define KEY_HENKAN 92
#define KEY_KATAKANAHIRAGANA 93
#define KEY_MUHENKAN 94
#define KEY_KPJPCOMMA 95
#define KEY_KPENTER 96
#define KEY_RIGHTCTRL 97
#define KEY_KPSLASH 98
#define KEY_SYSRQ 99
#define KEY_RIGHTALT 100
#define KEY_LINEFEED 101
#define KEY_HOME 102
#define KEY_UP 103
#define KEY_PAGEUP 104
#define KEY_LEFT 105
#define KEY_RIGHT 106
#define KEY_END 107
#define KEY_DOWN 108
#define KEY_PAGEDOWN 109
#define KEY_INSERT 110
#define KEY_DELETE 111
#define KEY_MACRO 112
#define KEY_MUTE 113
#define KEY_VOLUMEDOWN 114
#define KEY_VOLUMEUP 115
#define KEY_POWER 116 /* SC System Power Down */
#define KEY_KPEQUAL 117
#define KEY_KPPLUSMINUS 118
#define KEY_PAUSE 119
#define KEY_SCALE 120 /* AL Compiz Scale (Expose) */#define KEY_KPCOMMA 121
#define KEY_HANGEUL 122
#define KEY_HANGUEL KEY_HANGEUL
#define KEY_HANJA 123
#define KEY_YEN 124
#define KEY_LEFTMETA 125
#define KEY_RIGHTMETA 126
#define KEY_COMPOSE 127/* 下面可以理解为是一些组合按键,比如copy是ctrl + c,paste是ctrl + v等等 */
#define KEY_STOP 128 /* AC Stop */
#define KEY_AGAIN 129
#define KEY_PROPS 130 /* AC Properties */
#define KEY_UNDO 131 /* AC Undo */
#define KEY_FRONT 132
#define KEY_COPY 133 /* AC Copy */
#define KEY_OPEN 134 /* AC Open */
#define KEY_PASTE 135 /* AC Paste */
#define KEY_FIND 136 /* AC Search */
#define KEY_CUT 137 /* AC Cut */
#define KEY_HELP 138 /* AL Integrated Help Center */
#define KEY_MENU 139 /* Menu (show menu) */
#define KEY_CALC 140 /* AL Calculator */
#define KEY_SETUP 141
#define KEY_SLEEP 142 /* SC System Sleep */
#define KEY_WAKEUP 143 /* System Wake Up */
#define KEY_FILE 144 /* AL Local Machine Browser */
#define KEY_SENDFILE 145
#define KEY_DELETEFILE 146
#define KEY_XFER 147
#define KEY_PROG1 148
#define KEY_PROG2 149
#define KEY_WWW 150 /* AL Internet Browser */
#define KEY_MSDOS 151
#define KEY_COFFEE 152 /* AL Terminal Lock/Screensaver */
#define KEY_SCREENLOCK KEY_COFFEE
#define KEY_DIRECTION 153
#define KEY_CYCLEWINDOWS 154
#define KEY_MAIL 155
#define KEY_BOOKMARKS 156 /* AC Bookmarks */
#define KEY_COMPUTER 157
#define KEY_BACK 158 /* AC Back */
#define KEY_FORWARD 159 /* AC Forward */
#define KEY_CLOSECD 160
#define KEY_EJECTCD 161
#define KEY_EJECTCLOSECD 162
#define KEY_NEXTSONG 163
#define KEY_PLAYPAUSE 164
#define KEY_PREVIOUSSONG 165
#define KEY_STOPCD 166
#define KEY_RECORD 167
#define KEY_REWIND 168
#define KEY_PHONE 169 /* Media Select Telephone */
#define KEY_ISO 170
#define KEY_CONFIG 171 /* AL Consumer Control Configuration */
#define KEY_HOMEPAGE 172 /* AC Home */
#define KEY_REFRESH 173 /* AC Refresh */
#define KEY_EXIT 174 /* AC Exit */
#define KEY_MOVE 175
#define KEY_EDIT 176
#define KEY_SCROLLUP 177
#define KEY_SCROLLDOWN 178
#define KEY_KPLEFTPAREN 179
#define KEY_KPRIGHTPAREN 180
#define KEY_NEW 181 /* AC New */
#define KEY_REDO 182 /* AC Redo/Repeat *//* 这个应该是特殊键盘使用吧?我的键盘就到F12耶 */
#define KEY_F13 183
#define KEY_F14 184
#define KEY_F15 185
#define KEY_F16 186
#define KEY_F17 187
#define KEY_F18 188
#define KEY_F19 189
#define KEY_F20 190
#define KEY_F21 191
#define KEY_F22 192
#define KEY_F23 193
#define KEY_F24 194#define KEY_PLAYCD 200
#define KEY_PAUSECD 201
#define KEY_PROG3 202
#define KEY_PROG4 203
#define KEY_DASHBOARD 204 /* AL Dashboard */
#define KEY_SUSPEND 205
#define KEY_CLOSE 206 /* AC Close */
#define KEY_PLAY 207
#define KEY_FASTFORWARD 208
#define KEY_BASSBOOST 209
#define KEY_PRINT 210 /* AC Print */
#define KEY_HP 211
#define KEY_CAMERA 212
#define KEY_SOUND 213
#define KEY_QUESTION 214
#define KEY_EMAIL 215
#define KEY_CHAT 216
#define KEY_SEARCH 217
#define KEY_CONNECT 218
#define KEY_FINANCE 219 /* AL Checkbook/Finance */
#define KEY_SPORT 220
#define KEY_SHOP 221
#define KEY_ALTERASE 222
#define KEY_CANCEL 223 /* AC Cancel */
#define KEY_BRIGHTNESSDOWN 224
#define KEY_BRIGHTNESSUP 225
#define KEY_MEDIA 226#define KEY_SWITCHVIDEOMODE 227 /* Cycle between available videooutputs (Monitor/LCD/TV-out/etc) */
#define KEY_KBDILLUMTOGGLE 228
#define KEY_KBDILLUMDOWN 229
#define KEY_KBDILLUMUP 230#define KEY_SEND 231 /* AC Send */
#define KEY_REPLY 232 /* AC Reply */
#define KEY_FORWARDMAIL 233 /* AC Forward Msg */
#define KEY_SAVE 234 /* AC Save */
#define KEY_DOCUMENTS 235#define KEY_BATTERY 236#define KEY_BLUETOOTH 237
#define KEY_WLAN 238
#define KEY_UWB 239#define KEY_UNKNOWN 240#define KEY_VIDEO_NEXT 241 /* drive next video source */
#define KEY_VIDEO_PREV 242 /* drive previous video source */
#define KEY_BRIGHTNESS_CYCLE 243 /* brightness up, after max is min */
#define KEY_BRIGHTNESS_ZERO 244 /* brightness off, use ambient */
#define KEY_DISPLAY_OFF 245 /* display device to off state */#define KEY_WIMAX 246
#define KEY_RFKILL 247 /* Key that controls all radios *//* Code 255 is reserved for special needs of AT keyboard driver */#define BTN_MISC 0x100
#define BTN_0 0x100
#define BTN_1 0x101
#define BTN_2 0x102
#define BTN_3 0x103
#define BTN_4 0x104
#define BTN_5 0x105
#define BTN_6 0x106
#define BTN_7 0x107
#define BTN_8 0x108
#define BTN_9 0x109/* 鼠标按键,包括,左,右,中,以及游戏鼠标新增的一些按键等 */
#define BTN_MOUSE 0x110
#define BTN_LEFT 0x110
#define BTN_RIGHT 0x111
#define BTN_MIDDLE 0x112
#define BTN_SIDE 0x113
#define BTN_EXTRA 0x114
#define BTN_FORWARD 0x115
#define BTN_BACK 0x116
#define BTN_TASK 0x117#define BTN_JOYSTICK 0x120
#define BTN_TRIGGER 0x120
#define BTN_THUMB 0x121
#define BTN_THUMB2 0x122
#define BTN_TOP 0x123
#define BTN_TOP2 0x124
#define BTN_PINKIE 0x125
#define BTN_BASE 0x126
#define BTN_BASE2 0x127
#define BTN_BASE3 0x128
#define BTN_BASE4 0x129
#define BTN_BASE5 0x12a
#define BTN_BASE6 0x12b
#define BTN_DEAD 0x12f#define BTN_GAMEPAD 0x130
#define BTN_A 0x130
#define BTN_B 0x131
#define BTN_C 0x132
#define BTN_X 0x133
#define BTN_Y 0x134
#define BTN_Z 0x135
#define BTN_TL 0x136
#define BTN_TR 0x137
#define BTN_TL2 0x138
#define BTN_TR2 0x139
#define BTN_SELECT 0x13a
#define BTN_START 0x13b
#define BTN_MODE 0x13c
#define BTN_THUMBL 0x13d
#define BTN_THUMBR 0x13e#define BTN_DIGI 0x140
#define BTN_TOOL_PEN 0x140
#define BTN_TOOL_RUBBER 0x141
#define BTN_TOOL_BRUSH 0x142
#define BTN_TOOL_PENCIL 0x143
#define BTN_TOOL_AIRBRUSH 0x144
#define BTN_TOOL_FINGER 0x145
#define BTN_TOOL_MOUSE 0x146
#define BTN_TOOL_LENS 0x147
#define BTN_TOUCH 0x14a /* BTN_TOUCH must be used to report when a touch is active on the screen. */
#define BTN_STYLUS 0x14b
#define BTN_STYLUS2 0x14c
#define BTN_TOOL_DOUBLETAP 0x14d
#define BTN_TOOL_TRIPLETAP 0x14e
#define BTN_TOOL_QUADTAP 0x14f /* Four fingers on trackpad */#define BTN_WHEEL 0x150
#define BTN_GEAR_DOWN 0x150
#define BTN_GEAR_UP 0x151#define KEY_OK 0x160
#define KEY_SELECT 0x161
#define KEY_GOTO 0x162
#define KEY_CLEAR 0x163
#define KEY_POWER2 0x164
#define KEY_OPTION 0x165
#define KEY_INFO 0x166 /* AL OEM Features/Tips/Tutorial */
#define KEY_TIME 0x167
#define KEY_VENDOR 0x168
#define KEY_ARCHIVE 0x169
#define KEY_PROGRAM 0x16a /* Media Select Program Guide */
#define KEY_CHANNEL 0x16b
#define KEY_FAVORITES 0x16c
#define KEY_EPG 0x16d
#define KEY_PVR 0x16e /* Media Select Home */
#define KEY_MHP 0x16f
#define KEY_LANGUAGE 0x170
#define KEY_TITLE 0x171
#define KEY_SUBTITLE 0x172
#define KEY_ANGLE 0x173
#define KEY_ZOOM 0x174
#define KEY_MODE 0x175
#define KEY_KEYBOARD 0x176
#define KEY_SCREEN 0x177
#define KEY_PC 0x178 /* Media Select Computer */
#define KEY_TV 0x179 /* Media Select TV */
#define KEY_TV2 0x17a /* Media Select Cable */
#define KEY_VCR 0x17b /* Media Select VCR */
#define KEY_VCR2 0x17c /* VCR Plus */
#define KEY_SAT 0x17d /* Media Select Satellite */
#define KEY_SAT2 0x17e
#define KEY_CD 0x17f /* Media Select CD */
#define KEY_TAPE 0x180 /* Media Select Tape */
#define KEY_RADIO 0x181
#define KEY_TUNER 0x182 /* Media Select Tuner */
#define KEY_PLAYER 0x183
#define KEY_TEXT 0x184
#define KEY_DVD 0x185 /* Media Select DVD */
#define KEY_AUX 0x186
#define KEY_MP3 0x187
#define KEY_AUDIO 0x188
#define KEY_VIDEO 0x189
#define KEY_DIRECTORY 0x18a
#define KEY_LIST 0x18b
#define KEY_MEMO 0x18c /* Media Select Messages */
#define KEY_CALENDAR 0x18d
#define KEY_RED 0x18e
#define KEY_GREEN 0x18f
#define KEY_YELLOW 0x190
#define KEY_BLUE 0x191
#define KEY_CHANNELUP 0x192 /* Channel Increment */
#define KEY_CHANNELDOWN 0x193 /* Channel Decrement */
#define KEY_FIRST 0x194
#define KEY_LAST 0x195 /* Recall Last */
#define KEY_AB 0x196
#define KEY_NEXT 0x197
#define KEY_RESTART 0x198
#define KEY_SLOW 0x199
#define KEY_SHUFFLE 0x19a
#define KEY_BREAK 0x19b
#define KEY_PREVIOUS 0x19c
#define KEY_DIGITS 0x19d
#define KEY_TEEN 0x19e
#define KEY_TWEN 0x19f
#define KEY_VIDEOPHONE 0x1a0 /* Media Select Video Phone */
#define KEY_GAMES 0x1a1 /* Media Select Games */
#define KEY_ZOOMIN 0x1a2 /* AC Zoom In */
#define KEY_ZOOMOUT 0x1a3 /* AC Zoom Out */
#define KEY_ZOOMRESET 0x1a4 /* AC Zoom */
#define KEY_WORDPROCESSOR 0x1a5 /* AL Word Processor */
#define KEY_EDITOR 0x1a6 /* AL Text Editor */
#define KEY_SPREADSHEET 0x1a7 /* AL Spreadsheet */
#define KEY_GRAPHICSEDITOR 0x1a8 /* AL Graphics Editor */
#define KEY_PRESENTATION 0x1a9 /* AL Presentation App */
#define KEY_DATABASE 0x1aa /* AL Database App */
#define KEY_NEWS 0x1ab /* AL Newsreader */
#define KEY_VOICEMAIL 0x1ac /* AL Voicemail */
#define KEY_ADDRESSBOOK 0x1ad /* AL Contacts/Address Book */
#define KEY_MESSENGER 0x1ae /* AL Instant Messaging */
#define KEY_DISPLAYTOGGLE 0x1af /* Turn display (LCD) on and off */
#define KEY_SPELLCHECK 0x1b0 /* AL Spell Check */
#define KEY_LOGOFF 0x1b1 /* AL Logoff */#define KEY_DOLLAR 0x1b2
#define KEY_EURO 0x1b3#define KEY_FRAMEBACK 0x1b4 /* Consumer - transport controls */
#define KEY_FRAMEFORWARD 0x1b5
#define KEY_CONTEXT_MENU 0x1b6 /* GenDesc - system context menu */
#define KEY_MEDIA_REPEAT 0x1b7 /* Consumer - transport control */#define KEY_DEL_EOL 0x1c0
#define KEY_DEL_EOS 0x1c1
#define KEY_INS_LINE 0x1c2
#define KEY_DEL_LINE 0x1c3#define KEY_FN 0x1d0
#define KEY_FN_ESC 0x1d1
#define KEY_FN_F1 0x1d2
#define KEY_FN_F2 0x1d3
#define KEY_FN_F3 0x1d4
#define KEY_FN_F4 0x1d5
#define KEY_FN_F5 0x1d6
#define KEY_FN_F6 0x1d7
#define KEY_FN_F7 0x1d8
#define KEY_FN_F8 0x1d9
#define KEY_FN_F9 0x1da
#define KEY_FN_F10 0x1db
#define KEY_FN_F11 0x1dc
#define KEY_FN_F12 0x1dd
#define KEY_FN_1 0x1de
#define KEY_FN_2 0x1df
#define KEY_FN_D 0x1e0
#define KEY_FN_E 0x1e1
#define KEY_FN_F 0x1e2
#define KEY_FN_S 0x1e3
#define KEY_FN_B 0x1e4#define KEY_BRL_DOT1 0x1f1
#define KEY_BRL_DOT2 0x1f2
#define KEY_BRL_DOT3 0x1f3
#define KEY_BRL_DOT4 0x1f4
#define KEY_BRL_DOT5 0x1f5
#define KEY_BRL_DOT6 0x1f6
#define KEY_BRL_DOT7 0x1f7
#define KEY_BRL_DOT8 0x1f8
#define KEY_BRL_DOT9 0x1f9
#define KEY_BRL_DOT10 0x1fa#define KEY_NUMERIC_0 0x200 /* used by phones, remote controls, */
#define KEY_NUMERIC_1 0x201 /* and other keypads */
#define KEY_NUMERIC_2 0x202
#define KEY_NUMERIC_3 0x203
#define KEY_NUMERIC_4 0x204
#define KEY_NUMERIC_5 0x205
#define KEY_NUMERIC_6 0x206
#define KEY_NUMERIC_7 0x207
#define KEY_NUMERIC_8 0x208
#define KEY_NUMERIC_9 0x209
#define KEY_NUMERIC_STAR 0x20a
#define KEY_NUMERIC_POUND 0x20b#define KEY_CAMERA_FOCUS 0x210
#define KEY_WPS_BUTTON 0x211 /* WiFi Protected Setup key */#define BTN_TRIGGER_HAPPY 0x2c0
#define BTN_TRIGGER_HAPPY1 0x2c0
#define BTN_TRIGGER_HAPPY2 0x2c1
#define BTN_TRIGGER_HAPPY3 0x2c2
#define BTN_TRIGGER_HAPPY4 0x2c3
#define BTN_TRIGGER_HAPPY5 0x2c4
#define BTN_TRIGGER_HAPPY6 0x2c5
#define BTN_TRIGGER_HAPPY7 0x2c6
#define BTN_TRIGGER_HAPPY8 0x2c7
#define BTN_TRIGGER_HAPPY9 0x2c8
#define BTN_TRIGGER_HAPPY10 0x2c9
#define BTN_TRIGGER_HAPPY11 0x2ca
#define BTN_TRIGGER_HAPPY12 0x2cb
#define BTN_TRIGGER_HAPPY13 0x2cc
#define BTN_TRIGGER_HAPPY14 0x2cd
#define BTN_TRIGGER_HAPPY15 0x2ce
#define BTN_TRIGGER_HAPPY16 0x2cf
#define BTN_TRIGGER_HAPPY17 0x2d0
#define BTN_TRIGGER_HAPPY18 0x2d1
#define BTN_TRIGGER_HAPPY19 0x2d2
#define BTN_TRIGGER_HAPPY20 0x2d3
#define BTN_TRIGGER_HAPPY21 0x2d4
#define BTN_TRIGGER_HAPPY22 0x2d5
#define BTN_TRIGGER_HAPPY23 0x2d6
#define BTN_TRIGGER_HAPPY24 0x2d7
#define BTN_TRIGGER_HAPPY25 0x2d8
#define BTN_TRIGGER_HAPPY26 0x2d9
#define BTN_TRIGGER_HAPPY27 0x2da
#define BTN_TRIGGER_HAPPY28 0x2db
#define BTN_TRIGGER_HAPPY29 0x2dc
#define BTN_TRIGGER_HAPPY30 0x2dd
#define BTN_TRIGGER_HAPPY31 0x2de
#define BTN_TRIGGER_HAPPY32 0x2df
#define BTN_TRIGGER_HAPPY33 0x2e0
#define BTN_TRIGGER_HAPPY34 0x2e1
#define BTN_TRIGGER_HAPPY35 0x2e2
#define BTN_TRIGGER_HAPPY36 0x2e3
#define BTN_TRIGGER_HAPPY37 0x2e4
#define BTN_TRIGGER_HAPPY38 0x2e5
#define BTN_TRIGGER_HAPPY39 0x2e6
#define BTN_TRIGGER_HAPPY40 0x2e7/* We avoid low common keys in module aliases so they don't get huge. */
#define KEY_MIN_INTERESTING KEY_MUTE
#define KEY_MAX 0x2ff
#define KEY_CNT (KEY_MAX+1)