From b2dede96923654de8dfc41413e0f2fceda131efa Mon Sep 17 00:00:00 2001 From: Henrik Rydberg Date: Sat, 28 Aug 2010 17:43:22 +0200 Subject: New upstream version pending Supports 60 fingers using MT slots Signed-off-by: Henrik Rydberg --- usr/src/dkms_source_tree/hid-3m-pct.c | 186 ++++++++++++++++++---------------- 1 file changed, 100 insertions(+), 86 deletions(-) (limited to 'usr') diff --git a/usr/src/dkms_source_tree/hid-3m-pct.c b/usr/src/dkms_source_tree/hid-3m-pct.c index 1a6b02b..65441e0 100644 --- a/usr/src/dkms_source_tree/hid-3m-pct.c +++ b/usr/src/dkms_source_tree/hid-3m-pct.c @@ -24,29 +24,34 @@ MODULE_LICENSE("GPL"); #include "hid-ids.h" -#define MAX_SLOTS 20 -#define MAX_TRACKING_ID 0xfff -#define SN_MOVE 2048 -#define SN_WIDTH 512 +#define MAX_SLOTS 60 +#define MAX_TRKID USHRT_MAX +#define MAX_EVENTS 360 +#define SN_MOVE 2048 +#define SN_WIDTH 128 struct mmm_finger { __s32 x, y, w, h; - int touch, valid; - int last_touch, id; + __u16 id; + bool prev_touch; + bool touch, valid; }; struct mmm_data { struct mmm_finger f[MAX_SLOTS]; - int touch, valid; - int slot; + __u16 id; + __u8 curid; + __u8 nexp, nreal; + bool touch, valid; }; static int mmm_input_mapping(struct hid_device *hdev, struct hid_input *hi, struct hid_field *field, struct hid_usage *usage, unsigned long **bit, int *max) { - struct input_dev *input = hi->input; - int delta = field->logical_maximum - field->logical_minimum; + int f1 = field->logical_minimum; + int f2 = field->logical_maximum; + int df = f2 - f1; switch (usage->hid & HID_USAGE_PAGE) { @@ -57,27 +62,21 @@ static int mmm_input_mapping(struct hid_device *hdev, struct hid_input *hi, switch (usage->hid) { case HID_GD_X: hid_map_usage(hi, usage, bit, max, - EV_ABS, ABS_MT_POSITION_X); - input_set_abs_params(input, ABS_MT_POSITION_X, - field->logical_minimum, - field->logical_maximum, - delta / SN_MOVE, 0); - input_set_abs_params(input, ABS_X, - field->logical_minimum, - field->logical_maximum, - delta / SN_MOVE, 0); + EV_ABS, ABS_MT_POSITION_X); + input_set_abs_params(hi->input, ABS_MT_POSITION_X, + f1, f2, df / SN_MOVE, 0); + /* touchscreen emulation */ + input_set_abs_params(hi->input, ABS_X, + f1, f2, df / SN_MOVE, 0); return 1; case HID_GD_Y: hid_map_usage(hi, usage, bit, max, - EV_ABS, ABS_MT_POSITION_Y); - input_set_abs_params(input, ABS_MT_POSITION_Y, - field->logical_minimum, - field->logical_maximum, - delta / SN_MOVE, 0); - input_set_abs_params(input, ABS_Y, - field->logical_minimum, - field->logical_maximum, - delta / SN_MOVE, 0); + EV_ABS, ABS_MT_POSITION_Y); + input_set_abs_params(hi->input, ABS_MT_POSITION_Y, + f1, f2, df / SN_MOVE, 0); + /* touchscreen emulation */ + input_set_abs_params(hi->input, ABS_Y, + f1, f2, df / SN_MOVE, 0); return 1; } return 0; @@ -95,37 +94,33 @@ static int mmm_input_mapping(struct hid_device *hdev, struct hid_input *hi, case HID_DG_CONFIDENCE: return -1; case HID_DG_TIPSWITCH: + /* touchscreen emulation */ hid_map_usage(hi, usage, bit, max, EV_KEY, BTN_TOUCH); - input_set_capability(input, EV_KEY, BTN_TOUCH); + input_set_capability(hi->input, EV_KEY, BTN_TOUCH); return 1; case HID_DG_WIDTH: hid_map_usage(hi, usage, bit, max, - EV_ABS, ABS_MT_TOUCH_MAJOR); - input_set_abs_params(input, ABS_MT_TOUCH_MAJOR, - field->logical_minimum, - field->logical_maximum, - delta / SN_WIDTH, 0); + EV_ABS, ABS_MT_TOUCH_MAJOR); + input_set_abs_params(hi->input, ABS_MT_TOUCH_MAJOR, + f1, f2, df / SN_WIDTH, 0); return 1; case HID_DG_HEIGHT: hid_map_usage(hi, usage, bit, max, - EV_ABS, ABS_MT_TOUCH_MINOR); - input_set_abs_params(input, ABS_MT_TOUCH_MINOR, - field->logical_minimum, - field->logical_maximum, - delta / SN_WIDTH, 0); - input_set_abs_params(input, ABS_MT_ORIENTATION, - 1, 1, 0, 0); + EV_ABS, ABS_MT_TOUCH_MINOR); + input_set_abs_params(hi->input, ABS_MT_TOUCH_MINOR, + f1, f2, df / SN_WIDTH, 0); + input_set_abs_params(hi->input, ABS_MT_ORIENTATION, + 1, 1, 0, 0); return 1; case HID_DG_CONTACTID: - field->logical_maximum = MAX_TRACKING_ID; + field->logical_maximum = MAX_TRKID; hid_map_usage(hi, usage, bit, max, - EV_ABS, ABS_MT_TRACKING_ID); - input_set_abs_params(input, ABS_MT_TRACKING_ID, - 0, MAX_TRACKING_ID, 0, 0); - if (!input->mt) { - input_mt_create_slots(input, MAX_SLOTS); - input_set_events_per_packet(input, 150); - } + EV_ABS, ABS_MT_TRACKING_ID); + input_set_abs_params(hi->input, ABS_MT_TRACKING_ID, + 0, MAX_TRKID, 0, 0); + if (!hi->input->mt) + input_mt_create_slots(hi->input, MAX_SLOTS); + input_set_events_per_packet(hi->input, MAX_EVENTS); return 1; } /* let hid-input decide for the others */ @@ -143,6 +138,7 @@ static int mmm_input_mapped(struct hid_device *hdev, struct hid_input *hi, struct hid_field *field, struct hid_usage *usage, unsigned long **bit, int *max) { + /* tell hid-input to skip setup of these event types */ if (usage->type == EV_KEY || usage->type == EV_ABS) set_bit(usage->type, hi->input->evbit); return -1; @@ -154,40 +150,46 @@ static int mmm_input_mapped(struct hid_device *hdev, struct hid_input *hi, */ static void mmm_filter_event(struct mmm_data *md, struct input_dev *input) { - static int trkid; - int i, sx = 0, sy = 0, count = 0; + struct mmm_finger *oldest = 0; + int i; for (i = 0; i < MAX_SLOTS; ++i) { struct mmm_finger *f = &md->f[i]; - if (!f->valid) + if (!f->valid) { + /* this finger is just placeholder data, ignore */ continue; + } input_mt_slot(input, i); if (f->touch) { - int wide = f->w > f->h; - int major = wide ? f->w : f->h; - int minor = wide ? f->h : f->w; + /* this finger is on the screen */ + int wide = (f->w > f->h); + if (!f->prev_touch) + f->id = md->id++; + input_event(input, EV_ABS, ABS_MT_TRACKING_ID, f->id); input_event(input, EV_ABS, ABS_MT_POSITION_X, f->x); input_event(input, EV_ABS, ABS_MT_POSITION_Y, f->y); input_event(input, EV_ABS, ABS_MT_ORIENTATION, wide); - input_event(input, EV_ABS, ABS_MT_TOUCH_MAJOR, major); - input_event(input, EV_ABS, ABS_MT_TOUCH_MINOR, minor); - if (!f->last_touch) - f->id = trkid++ & MAX_TRACKING_ID; - if (!count++) - sx = f->x, sy = f->y; + input_event(input, EV_ABS, ABS_MT_TOUCH_MAJOR, + wide ? f->w : f->h); + input_event(input, EV_ABS, ABS_MT_TOUCH_MINOR, + wide ? f->h : f->w); + /* touchscreen emulation: pick the oldest contact */ + if (!oldest || ((f->id - oldest->id) & (SHRT_MAX + 1))) + oldest = f; } else { - f->id = -1; + /* this finger took off the screen */ + input_event(input, EV_ABS, ABS_MT_TRACKING_ID, -1); } - input_event(input, EV_ABS, ABS_MT_TRACKING_ID, f->id); - f->last_touch = f->touch; - } - for (i = 0; i < MAX_SLOTS; ++i) { - struct mmm_finger *f = &md->f[i]; - f->valid = f->touch = 0; + f->prev_touch = f->touch; + f->valid = 0; } - input_report_key(input, BTN_TOUCH, count > 0); - if (count > 0) { - input_report_abs(input, ABS_X, sx); - input_report_abs(input, ABS_Y, sy); + + /* touchscreen emulation */ + if (oldest) { + input_event(input, EV_KEY, BTN_TOUCH, 1); + input_event(input, EV_ABS, ABS_X, oldest->x); + input_event(input, EV_ABS, ABS_Y, oldest->y); + } else { + input_event(input, EV_KEY, BTN_TOUCH, 0); } input_sync(input); } @@ -208,32 +210,44 @@ static int mmm_event(struct hid_device *hid, struct hid_field *field, if (hid->claimed & HID_CLAIMED_INPUT) { struct input_dev *input = field->hidinput->input; switch (usage->hid) { - case HID_DG_CONTACTCOUNT: - break; case HID_DG_TIPSWITCH: md->touch = value; break; case HID_DG_CONFIDENCE: - if (md->valid && !value) - mmm_filter_event(md, input); md->valid = value; break; + case HID_DG_WIDTH: + if (md->valid) + md->f[md->curid].w = value; + break; + case HID_DG_HEIGHT: + if (md->valid) + md->f[md->curid].h = value; + break; case HID_DG_CONTACTID: - md->slot = value < MAX_SLOTS ? value : 0; - md->f[md->slot].touch = md->touch; - md->f[md->slot].valid = md->valid; + value = clamp_val(value, 0, MAX_SLOTS - 1); + if (md->valid) { + md->curid = value; + md->f[value].touch = md->touch; + md->f[value].valid = 1; + md->nreal++; + } break; case HID_GD_X: - md->f[md->slot].x = value; + if (md->valid) + md->f[md->curid].x = value; break; case HID_GD_Y: - md->f[md->slot].y = value; - break; - case HID_DG_WIDTH: - md->f[md->slot].w = value; + if (md->valid) + md->f[md->curid].y = value; break; - case HID_DG_HEIGHT: - md->f[md->slot].h = value; + case HID_DG_CONTACTCOUNT: + if (value) + md->nexp = value; + if (md->nreal >= md->nexp) { + mmm_filter_event(md, input); + md->nreal = 0; + } break; } } -- cgit v1.2.3