Skip to content

Commit 68ba46e

Browse files
committed
uclogic: Add support for touch ring reports
Add support for touch ring to UC-Logic driver. The touch ring reports can be flipped around a specific point to match the orientation and direction reported by the Wacom drivers. The proximity will also be reported similar to the Wacom drivers.
1 parent 988b16e commit 68ba46e

2 files changed

Lines changed: 70 additions & 5 deletions

File tree

hid-uclogic-core.c

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,8 @@ static int uclogic_input_configured(struct hid_device *hdev,
100100
const char *suffix = NULL;
101101
struct hid_field *field;
102102
size_t len;
103+
size_t i;
104+
const struct uclogic_params_frame *frame;
103105

104106
/* no report associated (HID_QUIRK_MULTI_INPUT not set) */
105107
if (!hi->report)
@@ -114,6 +116,20 @@ static int uclogic_input_configured(struct hid_device *hdev,
114116
drvdata->pen_input = hi->input;
115117
}
116118

119+
/* If it's one of the frame devices */
120+
for (i = 0; i < ARRAY_SIZE(params->frame_list); i++) {
121+
frame = &params->frame_list[i];
122+
if (hi->report->id == frame->id) {
123+
/*
124+
* Disable EV_MSC reports for touch ring interfaces to
125+
* make the Wacom driver pickup touch ring extents
126+
*/
127+
if (frame->touch_ring_byte > 0) {
128+
__clear_bit(EV_MSC, hi->input->evbit);
129+
}
130+
}
131+
}
132+
117133
field = hi->report->field[0];
118134

119135
switch (field->application) {
@@ -325,8 +341,16 @@ static int uclogic_raw_event_frame(
325341

326342
/* If need to, and can, set pad device ID for Wacom drivers */
327343
if (frame->dev_id_byte > 0 && frame->dev_id_byte < size) {
328-
data[frame->dev_id_byte] = 0xf;
344+
/* If we also have a touch ring and the finger left it */
345+
if (frame->touch_ring_byte > 0 &&
346+
frame->touch_ring_byte < size &&
347+
data[frame->touch_ring_byte] == 0) {
348+
data[frame->dev_id_byte] = 0;
349+
} else {
350+
data[frame->dev_id_byte] = 0xf;
351+
}
329352
}
353+
330354
/* If need to, and can, read rotary encoder state change */
331355
if (frame->re_lsb > 0 && frame->re_lsb / 8 < size) {
332356
unsigned int byte = frame->re_lsb / 8;
@@ -353,6 +377,19 @@ static int uclogic_raw_event_frame(
353377
drvdata->re_state = state;
354378
}
355379

380+
/* If need to, and can, transform the touch ring reports */
381+
if (frame->touch_ring_byte > 0 && frame->touch_ring_byte < size &&
382+
frame->touch_ring_flip_at != 0) {
383+
__s8 value = data[frame->touch_ring_byte];
384+
if (value != 0) {
385+
value = frame->touch_ring_flip_at - value;
386+
if (value < 0) {
387+
value = frame->touch_ring_max + value;
388+
}
389+
data[frame->touch_ring_byte] = value;
390+
}
391+
}
392+
356393
return 0;
357394
}
358395

hid-uclogic-params.h

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -123,10 +123,32 @@ struct uclogic_params_frame {
123123
/*
124124
* Offset of the Wacom-style device ID byte in the report, to be set
125125
* to pad device ID (0xf), for compatibility with Wacom drivers. Zero
126-
* if no changes to the report should be made. Only valid if "id" is
127-
* not zero.
126+
* if no changes to the report should be made. The ID byte will be set
127+
* to zero whenever the byte pointed by "touch_ring_byte" is zero, if
128+
* the latter is valid. Only valid if "id" is not zero.
128129
*/
129130
unsigned int dev_id_byte;
131+
/*
132+
* Offset of the touch ring state byte, in the report.
133+
* Zero if not present. If dev_id_byte is also valid and non-zero,
134+
* then the device ID byte will be cleared when the byte pointed to by
135+
* this offset is zero. Only valid if "id" is not zero.
136+
*/
137+
unsigned int touch_ring_byte;
138+
139+
/*
140+
* Maximum value of the touch ring report.
141+
* The minimum valid value is considered to be one,
142+
* with zero being out-of-proximity (finger lift) value.
143+
*/
144+
__s8 touch_ring_max;
145+
146+
/*
147+
* The value to anchor the reversed reports at.
148+
* I.e. one, if the reports should be flipped without offset.
149+
* Zero if no reversal should be done.
150+
*/
151+
__s8 touch_ring_flip_at;
130152
};
131153

132154
/*
@@ -191,7 +213,10 @@ extern int uclogic_params_init(struct uclogic_params *params,
191213
".frame_list[0].desc_size = %u\n" \
192214
".frame_list[0].id = %u\n" \
193215
".frame_list[0].re_lsb = %u\n" \
194-
".frame_list[0].dev_id_byte = %u\n"
216+
".frame_list[0].dev_id_byte = %u\n" \
217+
".frame_list[0].touch_ring_byte = %u\n" \
218+
".frame_list[0].touch_ring_max = %hhd\n" \
219+
".frame_list[0].touch_ring_flip_at = %hhd\n"
195220

196221
/* Tablet interface parameters *printf format arguments */
197222
#define UCLOGIC_PARAMS_FMT_ARGS(_params) \
@@ -210,7 +235,10 @@ extern int uclogic_params_init(struct uclogic_params *params,
210235
(_params)->frame_list[0].desc_size, \
211236
(_params)->frame_list[0].id, \
212237
(_params)->frame_list[0].re_lsb, \
213-
(_params)->frame_list[0].dev_id_byte
238+
(_params)->frame_list[0].dev_id_byte, \
239+
(_params)->frame_list[0].touch_ring_byte, \
240+
(_params)->frame_list[0].touch_ring_max, \
241+
(_params)->frame_list[0].touch_ring_flip_at
214242

215243
/* Get a replacement report descriptor for a tablet's interface. */
216244
extern int uclogic_params_get_desc(const struct uclogic_params *params,

0 commit comments

Comments
 (0)