Lines Matching +full:touch +full:- +full:max +full:- +full:y
1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * HID driver for N-Trig touchscreens
5 * Copyright (c) 2008-2010 Rafi Rubin
6 * Copyright (c) 2009-2010 Stephane Chatty
19 #include "hid-ids.h"
25 MODULE_PARM_DESC(min_width, "Minimum touch contact width to accept.");
29 MODULE_PARM_DESC(min_height, "Minimum touch contact height to accept.");
33 MODULE_PARM_DESC(activate_slack, "Number of touch frames to ignore at "
34 "the start of touch input.");
39 "deactivating touch.");
44 "processing touch events.");
49 "processing touch events.");
53 __u16 x, y, w, h; member
111 struct hid_report *report = hdev->report_enum[HID_FEATURE_REPORT]. in ntrig_get_mode()
114 if (!report || report->maxfield < 1 || in ntrig_get_mode()
115 report->field[0]->report_count < 1) in ntrig_get_mode()
116 return -EINVAL; in ntrig_get_mode()
120 return (int)report->field[0]->value[0]; in ntrig_get_mode()
131 report = hdev->report_enum[HID_FEATURE_REPORT]. in ntrig_set_mode()
178 return sprintf(buf, "%d\n", nd->sensor_physical_width); in show_phys_width()
190 return sprintf(buf, "%d\n", nd->sensor_physical_height); in show_phys_height()
202 return sprintf(buf, "%d\n", nd->sensor_logical_width); in show_log_width()
214 return sprintf(buf, "%d\n", nd->sensor_logical_height); in show_log_height()
226 return sprintf(buf, "%d\n", nd->min_width * in show_min_width()
227 nd->sensor_physical_width / in show_min_width()
228 nd->sensor_logical_width); in show_min_width()
241 return -EINVAL; in set_min_width()
243 if (val > nd->sensor_physical_width) in set_min_width()
244 return -EINVAL; in set_min_width()
246 nd->min_width = val * nd->sensor_logical_width / in set_min_width()
247 nd->sensor_physical_width; in set_min_width()
261 return sprintf(buf, "%d\n", nd->min_height * in show_min_height()
262 nd->sensor_physical_height / in show_min_height()
263 nd->sensor_logical_height); in show_min_height()
276 return -EINVAL; in set_min_height()
278 if (val > nd->sensor_physical_height) in set_min_height()
279 return -EINVAL; in set_min_height()
281 nd->min_height = val * nd->sensor_logical_height / in set_min_height()
282 nd->sensor_physical_height; in set_min_height()
297 return sprintf(buf, "%d\n", nd->activate_slack); in show_activate_slack()
310 return -EINVAL; in set_activate_slack()
313 return -EINVAL; in set_activate_slack()
315 nd->activate_slack = val; in set_activate_slack()
330 return sprintf(buf, "%d\n", nd->activation_width * in show_activation_width()
331 nd->sensor_physical_width / in show_activation_width()
332 nd->sensor_logical_width); in show_activation_width()
345 return -EINVAL; in set_activation_width()
347 if (val > nd->sensor_physical_width) in set_activation_width()
348 return -EINVAL; in set_activation_width()
350 nd->activation_width = val * nd->sensor_logical_width / in set_activation_width()
351 nd->sensor_physical_width; in set_activation_width()
366 return sprintf(buf, "%d\n", nd->activation_height * in show_activation_height()
367 nd->sensor_physical_height / in show_activation_height()
368 nd->sensor_logical_height); in show_activation_height()
381 return -EINVAL; in set_activation_height()
383 if (val > nd->sensor_physical_height) in set_activation_height()
384 return -EINVAL; in set_activation_height()
386 nd->activation_height = val * nd->sensor_logical_height / in set_activation_height()
387 nd->sensor_physical_height; in set_activation_height()
402 return sprintf(buf, "%d\n", -nd->deactivate_slack); in show_deactivate_slack()
415 return -EINVAL; in set_deactivate_slack()
420 * touch emulation stuck down. in set_deactivate_slack()
423 return -EINVAL; in set_deactivate_slack()
425 nd->deactivate_slack = -val; in set_deactivate_slack()
453 * - dual pen/finger single touch
454 * - finger multitouch, pen not working
459 unsigned long **bit, int *max) in ntrig_input_mapping() argument
463 /* No special mappings needed for the pen and single touch */ in ntrig_input_mapping()
464 if (field->physical) in ntrig_input_mapping()
467 switch (usage->hid & HID_USAGE_PAGE) { in ntrig_input_mapping()
469 switch (usage->hid) { in ntrig_input_mapping()
471 hid_map_usage(hi, usage, bit, max, in ntrig_input_mapping()
473 input_set_abs_params(hi->input, ABS_X, in ntrig_input_mapping()
474 field->logical_minimum, in ntrig_input_mapping()
475 field->logical_maximum, 0, 0); in ntrig_input_mapping()
477 if (!nd->sensor_logical_width) { in ntrig_input_mapping()
478 nd->sensor_logical_width = in ntrig_input_mapping()
479 field->logical_maximum - in ntrig_input_mapping()
480 field->logical_minimum; in ntrig_input_mapping()
481 nd->sensor_physical_width = in ntrig_input_mapping()
482 field->physical_maximum - in ntrig_input_mapping()
483 field->physical_minimum; in ntrig_input_mapping()
484 nd->activation_width = activation_width * in ntrig_input_mapping()
485 nd->sensor_logical_width / in ntrig_input_mapping()
486 nd->sensor_physical_width; in ntrig_input_mapping()
487 nd->min_width = min_width * in ntrig_input_mapping()
488 nd->sensor_logical_width / in ntrig_input_mapping()
489 nd->sensor_physical_width; in ntrig_input_mapping()
493 hid_map_usage(hi, usage, bit, max, in ntrig_input_mapping()
495 input_set_abs_params(hi->input, ABS_Y, in ntrig_input_mapping()
496 field->logical_minimum, in ntrig_input_mapping()
497 field->logical_maximum, 0, 0); in ntrig_input_mapping()
499 if (!nd->sensor_logical_height) { in ntrig_input_mapping()
500 nd->sensor_logical_height = in ntrig_input_mapping()
501 field->logical_maximum - in ntrig_input_mapping()
502 field->logical_minimum; in ntrig_input_mapping()
503 nd->sensor_physical_height = in ntrig_input_mapping()
504 field->physical_maximum - in ntrig_input_mapping()
505 field->physical_minimum; in ntrig_input_mapping()
506 nd->activation_height = activation_height * in ntrig_input_mapping()
507 nd->sensor_logical_height / in ntrig_input_mapping()
508 nd->sensor_physical_height; in ntrig_input_mapping()
509 nd->min_height = min_height * in ntrig_input_mapping()
510 nd->sensor_logical_height / in ntrig_input_mapping()
511 nd->sensor_physical_height; in ntrig_input_mapping()
518 switch (usage->hid) { in ntrig_input_mapping()
524 return -1; in ntrig_input_mapping()
528 hid_map_usage(hi, usage, bit, max, in ntrig_input_mapping()
532 hid_map_usage(hi, usage, bit, max, in ntrig_input_mapping()
534 input_set_abs_params(hi->input, ABS_MT_ORIENTATION, in ntrig_input_mapping()
541 /* we do not want to map these: no input-oriented meaning */ in ntrig_input_mapping()
542 return -1; in ntrig_input_mapping()
550 unsigned long **bit, int *max) in ntrig_input_mapped() argument
552 /* No special mappings needed for the pen and single touch */ in ntrig_input_mapped()
553 if (field->physical) in ntrig_input_mapped()
556 if (usage->type == EV_KEY || usage->type == EV_REL in ntrig_input_mapped()
557 || usage->type == EV_ABS) in ntrig_input_mapped()
558 clear_bit(usage->code, *bit); in ntrig_input_mapped()
566 * decide whether we are in multi or single touch mode
576 if (!(hid->claimed & HID_CLAIMED_INPUT)) in ntrig_event()
581 if(!(field->hidinput && field->hidinput->input)) in ntrig_event()
582 return -EINVAL; in ntrig_event()
584 input = field->hidinput->input; in ntrig_event()
587 if (field->application == HID_DG_PEN) in ntrig_event()
590 switch (usage->hid) { in ntrig_event()
593 nd->reading_mt = true; in ntrig_event()
594 nd->first_contact_touch = false; in ntrig_event()
597 nd->tipswitch = value; in ntrig_event()
598 /* Prevent emission of touch until validated */ in ntrig_event()
601 nd->confidence = value; in ntrig_event()
604 nd->x = value; in ntrig_event()
606 nd->mt_foot_count = 0; in ntrig_event()
609 nd->y = value; in ntrig_event()
612 nd->id = value; in ntrig_event()
615 nd->w = value; in ntrig_event()
618 nd->h = value; in ntrig_event()
620 * when in single touch mode, this is the last in ntrig_event()
622 * to emit a normal (X, Y) position in ntrig_event()
624 if (!nd->reading_mt) { in ntrig_event()
627 * finger in single touch mode. in ntrig_event()
630 nd->tipswitch); in ntrig_event()
632 nd->tipswitch); in ntrig_event()
633 input_event(input, EV_ABS, ABS_X, nd->x); in ntrig_event()
634 input_event(input, EV_ABS, ABS_Y, nd->y); in ntrig_event()
646 if (nd->mt_foot_count >= 4) in ntrig_event()
649 nd->mt_footer[nd->mt_foot_count++] = value; in ntrig_event()
652 if (nd->mt_foot_count != 4) in ntrig_event()
656 if (nd->mt_footer[2]) { in ntrig_event()
658 * When the pen deactivates touch, we see a in ntrig_event()
664 nd->act_state = deactivate_slack - 1; in ntrig_event()
665 nd->confidence = false; in ntrig_event()
673 if (nd->mt_footer[0]) { in ntrig_event()
679 if (nd->w < nd->min_width || in ntrig_event()
680 nd->h < nd->min_height) in ntrig_event()
681 nd->confidence = false; in ntrig_event()
685 if (nd->act_state > 0) { in ntrig_event()
689 if (nd->w >= nd->activation_width && in ntrig_event()
690 nd->h >= nd->activation_height) { in ntrig_event()
691 if (nd->id) in ntrig_event()
695 nd->act_state = 0; in ntrig_event()
702 nd->act_state = 1; in ntrig_event()
714 if (!nd->confidence) in ntrig_event()
717 /* emit a normal (X, Y) for the first point only */ in ntrig_event()
718 if (nd->id == 0) { in ntrig_event()
725 nd->first_contact_touch = nd->confidence; in ntrig_event()
726 input_event(input, EV_ABS, ABS_X, nd->x); in ntrig_event()
727 input_event(input, EV_ABS, ABS_Y, nd->y); in ntrig_event()
731 input_event(input, EV_ABS, ABS_MT_POSITION_X, nd->x); in ntrig_event()
732 input_event(input, EV_ABS, ABS_MT_POSITION_Y, nd->y); in ntrig_event()
738 if (nd->w > nd->h) { in ntrig_event()
742 ABS_MT_TOUCH_MAJOR, nd->w); in ntrig_event()
744 ABS_MT_TOUCH_MINOR, nd->h); in ntrig_event()
749 ABS_MT_TOUCH_MAJOR, nd->h); in ntrig_event()
751 ABS_MT_TOUCH_MINOR, nd->w); in ntrig_event()
753 input_mt_sync(field->hidinput->input); in ntrig_event()
757 if (!nd->reading_mt) /* Just to be sure */ in ntrig_event()
760 nd->reading_mt = false; in ntrig_event()
769 * state < -deactivate_slack: in ntrig_event()
770 * Pen termination of touch in ntrig_event()
779 * state == -deactivate_slack in ntrig_event()
784 if (nd->act_state > 0) { /* Currently inactive */ in ntrig_event()
790 nd->act_state = (nd->act_state > value) in ntrig_event()
791 ? nd->act_state - value in ntrig_event()
798 nd->act_state = nd->activate_slack; in ntrig_event()
807 if (value && nd->act_state >= in ntrig_event()
808 nd->deactivate_slack) in ntrig_event()
813 nd->act_state = 0; in ntrig_event()
814 else if (nd->act_state <= nd->deactivate_slack) in ntrig_event()
819 nd->act_state = in ntrig_event()
820 nd->activate_slack; in ntrig_event()
822 nd->act_state--; in ntrig_event()
827 if (nd->first_contact_touch && nd->act_state <= 0) { in ntrig_event()
830 * emitting touch events. in ntrig_event()
848 /* fall-back to the generic hidinput handling */ in ntrig_event()
855 if ((hid->claimed & HID_CLAIMED_HIDDEV) && hid->hiddev_hid_event) in ntrig_event()
856 hid->hiddev_hid_event(hid, field, usage, value); in ntrig_event()
865 struct input_dev *input = hidinput->input; in ntrig_input_configured()
867 if (hidinput->report->maxfield < 1) in ntrig_input_configured()
870 switch (hidinput->report->field[0]->application) { in ntrig_input_configured()
872 input->name = "N-Trig Pen"; in ntrig_input_configured()
877 __clear_bit(BTN_TOOL_PEN, input->keybit); in ntrig_input_configured()
878 __clear_bit(BTN_TOOL_FINGER, input->keybit); in ntrig_input_configured()
879 __clear_bit(BTN_0, input->keybit); in ntrig_input_configured()
880 __set_bit(BTN_TOOL_DOUBLETAP, input->keybit); in ntrig_input_configured()
882 * The physical touchscreen (single touch) in ntrig_input_configured()
887 input->name = (hidinput->report->field[0]->physical) ? in ntrig_input_configured()
888 "N-Trig Touchscreen" : in ntrig_input_configured()
889 "N-Trig MultiTouch"; in ntrig_input_configured()
902 if (id->driver_data) in ntrig_probe()
903 hdev->quirks |= HID_QUIRK_MULTI_INPUT in ntrig_probe()
908 hid_err(hdev, "cannot allocate N-Trig data\n"); in ntrig_probe()
909 return -ENOMEM; in ntrig_probe()
912 nd->reading_mt = false; in ntrig_probe()
913 nd->min_width = 0; in ntrig_probe()
914 nd->min_height = 0; in ntrig_probe()
915 nd->activate_slack = activate_slack; in ntrig_probe()
916 nd->act_state = activate_slack; in ntrig_probe()
917 nd->deactivate_slack = -deactivate_slack; in ntrig_probe()
918 nd->sensor_logical_width = 1; in ntrig_probe()
919 nd->sensor_logical_height = 1; in ntrig_probe()
920 nd->sensor_physical_width = 1; in ntrig_probe()
921 nd->sensor_physical_height = 1; in ntrig_probe()
938 report = hdev->report_enum[HID_FEATURE_REPORT].report_id_hash[0x0a]; in ntrig_probe()
955 ret = sysfs_create_group(&hdev->dev.kobj, in ntrig_probe()
968 sysfs_remove_group(&hdev->dev.kobj, in ntrig_remove()
1019 { HID_ANY_ID - 1, HID_ANY_ID - 1, HID_ANY_ID - 1 }
1035 MODULE_DESCRIPTION("HID driver for N-Trig touchscreens");