// SPDX-License-Identifier: GPL-2.0+ /* * HID driver for UC-Logic devices not fully compliant with HID standard * * Copyright (c) 2010-2014 Nikolai Kondrashov * Copyright (c) 2013 Martin Rusko
*/
/* * This program is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License as published by the Free * Software Foundation; either version 2 of the License, or (at your option) * any later version.
*/
/** * uclogic_inrange_timeout - handle pen in-range state timeout. * Emulate input events normally generated when pen goes out of range for * tablets which don't report that. * * @t: The timer the timeout handler is attached to, stored in a struct * uclogic_drvdata.
*/ staticvoid uclogic_inrange_timeout(struct timer_list *t)
{ struct uclogic_drvdata *drvdata = timer_container_of(drvdata, t,
inrange_timer); struct input_dev *input = drvdata->pen_input;
if (input == NULL) return;
input_report_abs(input, ABS_PRESSURE, 0); /* If BTN_TOUCH state is changing */ if (test_bit(BTN_TOUCH, input->key)) {
input_event(input, EV_MSC, MSC_SCAN, /* Digitizer Tip Switch usage */
0xd0042);
input_report_key(input, BTN_TOUCH, 0);
}
input_report_key(input, BTN_TOOL_PEN, 0);
input_sync(input);
}
if (field->application == HID_GD_KEYPAD) { /* * Remap input buttons to sensible ones that are not invalid. * This only affects previous behavior for devices with more than ten or so buttons.
*/ constint key = (usage->hid & HID_USAGE) - 1;
/* no report associated (HID_QUIRK_MULTI_INPUT not set) */ if (!hi->report) return 0;
/* * If this is the input corresponding to the pen report * in need of tweaking.
*/ if (hi->report->id == params->pen.id) { /* Remember the input device so we can simulate events */
drvdata->pen_input = hi->input;
}
/* If it's one of the frame devices */ for (i = 0; i < ARRAY_SIZE(params->frame_list); i++) {
frame = ¶ms->frame_list[i]; if (hi->report->id == frame->id) { /* Assign custom suffix, if any */
suffix = frame->suffix; /* * Disable EV_MSC reports for touch ring interfaces to * make the Wacom driver pickup touch ring extents
*/ if (frame->touch_byte > 0)
__clear_bit(EV_MSC, hi->input->evbit);
}
}
if (!suffix) {
field = hi->report->field[0];
switch (field->application) { case HID_GD_KEYBOARD:
suffix = "Keyboard"; break; case HID_GD_MOUSE:
suffix = "Mouse"; break; case HID_GD_KEYPAD:
suffix = "Pad"; break; case HID_DG_PEN: case HID_DG_DIGITIZER:
suffix = "Pen"; break; case HID_CP_CONSUMER_CONTROL:
suffix = "Consumer Control"; break; case HID_GD_SYSTEM_CONTROL:
suffix = "System Control"; break;
}
} else {
hi->input->name = devm_kasprintf(&hdev->dev, GFP_KERNEL, "%s %s", hdev->name, suffix); if (!hi->input->name) return -ENOMEM;
}
/* * libinput requires the pad interface to be on a different node * than the pen, so use QUIRK_MULTI_INPUT for all tablets.
*/
hdev->quirks |= HID_QUIRK_MULTI_INPUT;
hdev->quirks |= HID_QUIRK_HIDINPUT_FORCE;
return 0;
failure: /* Assume "remove" might not be called if "probe" failed */ if (params_initialized)
uclogic_params_cleanup(&drvdata->params); return rc;
}
/* Re-initialize the device, but discard parameters */
rc = uclogic_params_init(¶ms, hdev); if (rc != 0)
hid_err(hdev, "failed to re-initialize the device\n"); else
uclogic_params_cleanup(¶ms);
return rc;
} #endif
/** * uclogic_exec_event_hook - if the received event is hooked schedules the * associated work. * * @p: Tablet interface report parameters. * @event: Raw event. * @size: The size of event. * * Returns: * Whether the event was hooked or not.
*/ staticbool uclogic_exec_event_hook(struct uclogic_params *p, u8 *event, int size)
{ struct uclogic_raw_event_hook *curr;
/* If in-range reports are inverted */ if (pen->inrange ==
UCLOGIC_PARAMS_PEN_INRANGE_INVERTED) { /* Invert the in-range bit */
data[1] ^= 0x40;
} /* * If report contains fragmented high-resolution pen * coordinates
*/ if (size >= 10 && pen->fragmented_hires) {
u8 pressure_low_byte;
u8 pressure_high_byte;
/* Lift pressure bytes */
pressure_low_byte = data[6];
pressure_high_byte = data[7]; /* * Move Y coord to make space for high-order X * coord byte
*/
data[6] = data[5];
data[5] = data[4]; /* Move high-order X coord byte */
data[4] = data[8]; /* Move high-order Y coord byte */
data[7] = data[9]; /* Place pressure bytes */
data[8] = pressure_low_byte;
data[9] = pressure_high_byte;
} /* If we need to emulate in-range detection */ if (pen->inrange == UCLOGIC_PARAMS_PEN_INRANGE_NONE) { /* Set in-range bit */
data[1] |= 0x40; /* (Re-)start in-range timeout */
mod_timer(&drvdata->inrange_timer,
jiffies + msecs_to_jiffies(100));
} /* If we report tilt and Y direction is flipped */ if (size >= 12 && pen->tilt_y_flipped)
data[11] = -data[11];
return 0;
}
/** * uclogic_raw_event_frame - handle raw frame events (frame HID reports). * * @drvdata: Driver data. * @frame: The parameters of the frame controls to handle. * @data: Report data buffer, can be modified. * @size: Report data size, bytes. * * Returns: * Negative value on error (stops event delivery), zero for success.
*/ staticint uclogic_raw_event_frame( struct uclogic_drvdata *drvdata, conststruct uclogic_params_frame *frame,
u8 *data, int size)
{
WARN_ON(drvdata == NULL);
WARN_ON(data == NULL && size != 0);
/* If need to, and can, set pad device ID for Wacom drivers */ if (frame->dev_id_byte > 0 && frame->dev_id_byte < size) { /* If we also have a touch ring and the finger left it */ if (frame->touch_byte > 0 && frame->touch_byte < size &&
data[frame->touch_byte] == 0) {
data[frame->dev_id_byte] = 0;
} else {
data[frame->dev_id_byte] = 0xf;
}
}
/* If need to, and can, read rotary encoder state change */ if (frame->re_lsb > 0 && frame->re_lsb / 8 < size) { unsignedint byte = frame->re_lsb / 8; unsignedint bit = frame->re_lsb % 8;
u8 change;
u8 prev_state = drvdata->re_state; /* Read Gray-coded state */
u8 state = (data[byte] >> bit) & 0x3; /* Encode state change into 2-bit signed integer */ if ((prev_state == 1 && state == 0) ||
(prev_state == 2 && state == 3)) {
change = 1;
} elseif ((prev_state == 2 && state == 0) ||
(prev_state == 1 && state == 3)) {
change = 3;
} else {
change = 0;
} /* Write change */
data[byte] = (data[byte] & ~((u8)3 << bit)) |
(change << bit); /* Remember state */
drvdata->re_state = state;
}
/* If need to, and can, transform the touch ring reports */ if (frame->touch_byte > 0 && frame->touch_byte < size) {
__s8 value = data[frame->touch_byte];
if (value != 0) { if (frame->touch_flip_at != 0) {
value = frame->touch_flip_at - value; if (value <= 0)
value = frame->touch_max + value;
}
data[frame->touch_byte] = value - 1;
}
}
/* If need to, and can, transform the bitmap dial reports */ if (frame->bitmap_dial_byte > 0 && frame->bitmap_dial_byte < size) { switch (data[frame->bitmap_dial_byte]) { case 2:
data[frame->bitmap_dial_byte] = -1; break;
/* Everything below here is for tablets that shove multiple dials into 1 byte */ case 16:
data[frame->bitmap_dial_byte] = 0;
data[frame->bitmap_second_dial_destination_byte] = 1; break;
/* Do not handle anything but input reports */ if (report->type != HID_INPUT_REPORT) return 0;
if (uclogic_exec_event_hook(params, data, size)) return 0;
while (true) { /* Tweak pen reports, if necessary */ if ((report_id == params->pen.id) && (size >= 2)) {
subreport_list_end =
params->pen.subreport_list +
ARRAY_SIZE(params->pen.subreport_list); /* Try to match a subreport */ for (subreport = params->pen.subreport_list;
subreport < subreport_list_end; subreport++) { if (subreport->value != 0 &&
subreport->value == data[1]) { break;
}
} /* If a subreport matched */ if (subreport < subreport_list_end) { /* Change to subreport ID, and restart */
report_id = data[0] = subreport->id; continue;
} else { return uclogic_raw_event_pen(drvdata, data, size);
}
}
/* Tweak frame control reports, if necessary */ for (i = 0; i < ARRAY_SIZE(params->frame_list); i++) { if (report_id == params->frame_list[i].id) { return uclogic_raw_event_frame(
drvdata, ¶ms->frame_list[i],
data, size);
}
}
MODULE_AUTHOR("Martin Rusko");
MODULE_AUTHOR("Nikolai Kondrashov");
MODULE_DESCRIPTION("HID driver for UC-Logic devices not fully compliant with HID standard");
MODULE_LICENSE("GPL");
MODULE_DESCRIPTION("HID driver for UC-Logic devices not fully compliant with HID standard");
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.