staticunsignedint activate_slack = 1;
module_param(activate_slack, uint, 0644);
MODULE_PARM_DESC(activate_slack, "Number of touch frames to ignore at " "the start of touch input.");
staticunsignedint deactivate_slack = 4;
module_param(deactivate_slack, uint, 0644);
MODULE_PARM_DESC(deactivate_slack, "Number of empty frames to ignore before " "deactivating touch.");
/* * No more than 8 terminal frames have been observed so far * and higher slack is highly likely to leave the single * touch emulation stuck down.
*/ if (val > 7) return -EINVAL;
case HID_UP_DIGITIZER: switch (usage->hid) { /* we do not want to map these for now */ case HID_DG_CONTACTID: /* Not trustworthy, squelch for now */ case HID_DG_INPUTMODE: case HID_DG_DEVICEINDEX: case HID_DG_CONTACTMAX: return -1;
case 0xff000000: /* we do not want to map these: no input-oriented meaning */ return -1;
}
return 0;
}
staticint ntrig_input_mapped(struct hid_device *hdev, struct hid_input *hi, struct hid_field *field, struct hid_usage *usage, unsignedlong **bit, int *max)
{ /* No special mappings needed for the pen and single touch */ if (field->physical) return 0;
/* * this function is called upon all reports * so that we can filter contact point information, * decide whether we are in multi or single touch mode * and call input_mt_sync after each point if necessary
*/ staticint ntrig_event (struct hid_device *hid, struct hid_field *field, struct hid_usage *usage, __s32 value)
{ struct ntrig_data *nd = hid_get_drvdata(hid); struct input_dev *input;
/* Skip processing if not a claimed input */ if (!(hid->claimed & HID_CLAIMED_INPUT)) goto not_claimed_input;
/* This function is being called before the structures are fully
* initialized */ if(!(field->hidinput && field->hidinput->input)) return -EINVAL;
input = field->hidinput->input;
/* No special handling needed for the pen */ if (field->application == HID_DG_PEN) return 0;
switch (usage->hid) { case 0xff000001: /* Tag indicating the start of a multitouch group */
nd->reading_mt = true;
nd->first_contact_touch = false; break; case HID_DG_TIPSWITCH:
nd->tipswitch = value; /* Prevent emission of touch until validated */ return 1; case HID_DG_CONFIDENCE:
nd->confidence = value; break; case HID_GD_X:
nd->x = value; /* Clear the contact footer */
nd->mt_foot_count = 0; break; case HID_GD_Y:
nd->y = value; break; case HID_DG_CONTACTID:
nd->id = value; break; case HID_DG_WIDTH:
nd->w = value; break; case HID_DG_HEIGHT:
nd->h = value; /* * when in single touch mode, this is the last * report received in a finger event. We want * to emit a normal (X, Y) position
*/ if (!nd->reading_mt) { /* * TipSwitch indicates the presence of a * finger in single touch mode.
*/
input_report_key(input, BTN_TOUCH,
nd->tipswitch);
input_report_key(input, BTN_TOOL_DOUBLETAP,
nd->tipswitch);
input_event(input, EV_ABS, ABS_X, nd->x);
input_event(input, EV_ABS, ABS_Y, nd->y);
} break; case 0xff000002: /* * we receive this when the device is in multitouch * mode. The first of the three values tagged with * this usage tells if the contact point is real * or a placeholder
*/
/* Shouldn't get more than 4 footer packets, so skip */ if (nd->mt_foot_count >= 4) break;
nd->mt_footer[nd->mt_foot_count++] = value;
/* if the footer isn't complete break */ if (nd->mt_foot_count != 4) break;
/* Pen activity signal. */ if (nd->mt_footer[2]) { /* * When the pen deactivates touch, we see a * bogus frame with ContactCount > 0. * We can * save a bit of work by ensuring act_state < 0 * even if deactivation slack is turned off.
*/
nd->act_state = deactivate_slack - 1;
nd->confidence = false; break;
}
/* * The first footer value indicates the presence of a * finger.
*/ if (nd->mt_footer[0]) { /* * We do not want to process contacts under * the size threshold, but do not want to * ignore them for activation state
*/ if (nd->w < nd->min_width ||
nd->h < nd->min_height)
nd->confidence = false;
} else break;
if (nd->act_state > 0) { /* * Contact meets the activation size threshold
*/ if (nd->w >= nd->activation_width &&
nd->h >= nd->activation_height) { if (nd->id) /* * first contact, activate now
*/
nd->act_state = 0; else { /* * avoid corrupting this frame * but ensure next frame will * be active
*/
nd->act_state = 1; break;
}
} else /* * Defer adjusting the activation state * until the end of the frame.
*/ break;
}
/* Discarding this contact */ if (!nd->confidence) break;
/* emit a normal (X, Y) for the first point only */ if (nd->id == 0) { /* * TipSwitch is superfluous in multitouch * mode. The footer events tell us * if there is a finger on the screen or * not.
*/
nd->first_contact_touch = nd->confidence;
input_event(input, EV_ABS, ABS_X, nd->x);
input_event(input, EV_ABS, ABS_Y, nd->y);
}
/* * Translate from height and width to size * and orientation.
*/ if (nd->w > nd->h) {
input_event(input, EV_ABS,
ABS_MT_ORIENTATION, 1);
input_event(input, EV_ABS,
ABS_MT_TOUCH_MAJOR, nd->w);
input_event(input, EV_ABS,
ABS_MT_TOUCH_MINOR, nd->h);
} else {
input_event(input, EV_ABS,
ABS_MT_ORIENTATION, 0);
input_event(input, EV_ABS,
ABS_MT_TOUCH_MAJOR, nd->h);
input_event(input, EV_ABS,
ABS_MT_TOUCH_MINOR, nd->w);
}
input_mt_sync(field->hidinput->input); break;
case HID_DG_CONTACTCOUNT: /* End of a multitouch group */ if (!nd->reading_mt) /* Just to be sure */ break;
nd->reading_mt = false;
/* * Activation state machine logic: * * Fundamental states: * state > 0: Inactive * state <= 0: Active * state < -deactivate_slack: * Pen termination of touch * * Specific values of interest * state == activate_slack * no valid input since the last reset * * state == 0 * general operational state * * state == -deactivate_slack * read sufficient empty frames to accept * the end of input and reset
*/
if (nd->act_state > 0) { /* Currently inactive */ if (value) /* * Consider each live contact as * evidence of intentional activity.
*/
nd->act_state = (nd->act_state > value)
? nd->act_state - value
: 0; else /* * Empty frame before we hit the * activity threshold, reset.
*/
nd->act_state = nd->activate_slack;
/* * Entered this block inactive and no * coordinates sent this frame, so hold off * on button state.
*/ break;
} else { /* Currently active */ if (value && nd->act_state >=
nd->deactivate_slack) /* * Live point: clear accumulated * deactivation count.
*/
nd->act_state = 0; elseif (nd->act_state <= nd->deactivate_slack) /* * We've consumed the deactivation * slack, time to deactivate and reset.
*/
nd->act_state =
nd->activate_slack; else { /* Move towards deactivation */
nd->act_state--; break;
}
}
if (nd->first_contact_touch && nd->act_state <= 0) { /* * Check to see if we're ready to start * emitting touch events. * * Note: activation slack will decrease over * the course of the frame, and it will be * inconsistent from the start to the end of * the frame. However if the frame starts * with slack, first_contact_touch will still * be 0 and we will not get to this point.
*/
input_report_key(input, BTN_TOOL_DOUBLETAP, 1);
input_report_key(input, BTN_TOUCH, 1);
} else {
input_report_key(input, BTN_TOOL_DOUBLETAP, 0);
input_report_key(input, BTN_TOUCH, 0);
} break;
default: /* fall-back to the generic hidinput handling */ return 0;
}
not_claimed_input:
/* we have handled the hidinput part, now remains hiddev */ if ((hid->claimed & HID_CLAIMED_HIDDEV) && hid->hiddev_hid_event)
hid->hiddev_hid_event(hid, field, usage, value);
switch (hidinput->report->field[0]->application) { case HID_DG_PEN:
input->name = "N-Trig Pen"; break; case HID_DG_TOUCHSCREEN: /* These keys are redundant for fingers, clear them
* to prevent incorrect identification */
__clear_bit(BTN_TOOL_PEN, input->keybit);
__clear_bit(BTN_TOOL_FINGER, input->keybit);
__clear_bit(BTN_0, input->keybit);
__set_bit(BTN_TOOL_DOUBLETAP, input->keybit); /* * The physical touchscreen (single touch) * input has a value for physical, whereas * the multitouch only has logical input * fields.
*/
input->name = (hidinput->report->field[0]->physical) ? "N-Trig Touchscreen" : "N-Trig MultiTouch"; break;
}
ret = hid_parse(hdev); if (ret) {
hid_err(hdev, "parse failed\n"); goto err_free;
}
ret = hid_hw_start(hdev, HID_CONNECT_DEFAULT & ~HID_CONNECT_FF); if (ret) {
hid_err(hdev, "hw start failed\n"); goto err_free;
}
/* This is needed for devices with more recent firmware versions */
report = hdev->report_enum[HID_FEATURE_REPORT].report_id_hash[0x0a]; if (report) { /* Let the device settle to ensure the wakeup message gets
* through */
hid_hw_wait(hdev);
hid_hw_request(hdev, report, HID_REQ_GET_REPORT);
/* * Sanity check: if the current mode is invalid reset it to * something reasonable.
*/ if (ntrig_get_mode(hdev) >= 4)
ntrig_set_mode(hdev, 3);
}
ntrig_report_version(hdev);
ret = sysfs_create_group(&hdev->dev.kobj,
&ntrig_attribute_group); if (ret)
hid_err(hdev, "cannot create sysfs group\n");
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.