Skip to content

Commit 867c892

Browse files
JoseExpositoJiri Kosina
authored andcommitted
HID: uclogic: Allow to generate frame templates
Add a new template placeholder to allow configuring the number of buttons in the drawing tablet frame and update the KUnit tests to cover the new case. Signed-off-by: José Expósito <[email protected]> Signed-off-by: Jiri Kosina <[email protected]>
1 parent 2d167aa commit 867c892

File tree

3 files changed

+53
-3
lines changed

3 files changed

+53
-3
lines changed

drivers/hid/hid-uclogic-rdesc-test.c

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@ static const s32 params_pen_some[] = {
3131
[UCLOGIC_RDESC_PEN_PH_ID_X_PM] = 0xBB,
3232
};
3333

34+
static const s32 params_frame_all[UCLOGIC_RDESC_PH_ID_NUM] = {
35+
[UCLOGIC_RDESC_FRAME_PH_ID_UM] = 0xFF,
36+
};
37+
3438
static const __u8 template_empty[] = { };
3539
static const __u8 template_small[] = { 0x00 };
3640
static const __u8 template_no_ph[] = { 0xAA, 0xFE, 0xAA, 0xED, 0x1D };
@@ -39,6 +43,10 @@ static const __u8 template_pen_ph_end[] = {
3943
0xAA, 0xBB, UCLOGIC_RDESC_PEN_PH_HEAD
4044
};
4145

46+
static const __u8 template_btn_ph_end[] = {
47+
0xAA, 0xBB, UCLOGIC_RDESC_FRAME_PH_BTN_HEAD
48+
};
49+
4250
static const __u8 template_pen_all_params[] = {
4351
UCLOGIC_RDESC_PEN_PH(X_LM),
4452
0x47, UCLOGIC_RDESC_PEN_PH(X_PM),
@@ -55,6 +63,18 @@ static const __u8 expected_pen_all_params[] = {
5563
0x00, 0xEE, 0x00, 0x00, 0x00,
5664
};
5765

66+
static const __u8 template_frame_all_params[] = {
67+
0x01, 0x02,
68+
UCLOGIC_RDESC_FRAME_PH_BTN,
69+
0x99,
70+
};
71+
72+
static const __u8 expected_frame_all_params[] = {
73+
0x01, 0x02,
74+
0x2A, 0xFF, 0x00,
75+
0x99,
76+
};
77+
5878
static const __u8 template_pen_some_params[] = {
5979
0x01, 0x02,
6080
UCLOGIC_RDESC_PEN_PH(X_LM),
@@ -108,6 +128,14 @@ static struct uclogic_template_case uclogic_template_cases[] = {
108128
.param_num = ARRAY_SIZE(params_pen_all),
109129
.expected = template_pen_ph_end,
110130
},
131+
{
132+
.name = "Frame button placeholder at the end, without ID",
133+
.template = template_btn_ph_end,
134+
.template_size = sizeof(template_btn_ph_end),
135+
.param_list = params_frame_all,
136+
.param_num = ARRAY_SIZE(params_frame_all),
137+
.expected = template_btn_ph_end,
138+
},
111139
{
112140
.name = "All params present in the pen template",
113141
.template = template_pen_all_params,
@@ -116,6 +144,14 @@ static struct uclogic_template_case uclogic_template_cases[] = {
116144
.param_num = ARRAY_SIZE(params_pen_all),
117145
.expected = expected_pen_all_params,
118146
},
147+
{
148+
.name = "All params present in the frame template",
149+
.template = template_frame_all_params,
150+
.template_size = sizeof(template_frame_all_params),
151+
.param_list = params_frame_all,
152+
.param_num = ARRAY_SIZE(params_frame_all),
153+
.expected = expected_frame_all_params,
154+
},
119155
{
120156
.name = "Some params present in the pen template (complete param list)",
121157
.template = template_pen_some_params,

drivers/hid/hid-uclogic-rdesc.c

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -979,7 +979,7 @@ const size_t uclogic_rdesc_xppen_deco01_frame_size =
979979
* uclogic_rdesc_template_apply() - apply report descriptor parameters to a
980980
* report descriptor template, creating a report descriptor. Copies the
981981
* template over to the new report descriptor and replaces every occurrence of
982-
* UCLOGIC_RDESC_PEN_PH_HEAD, followed by an index byte, with the value from the
982+
* the template placeholders, followed by an index byte, with the value from the
983983
* parameter list at that index.
984984
*
985985
* @template_ptr: Pointer to the template buffer.
@@ -996,6 +996,7 @@ __u8 *uclogic_rdesc_template_apply(const __u8 *template_ptr,
996996
const s32 *param_list,
997997
size_t param_num)
998998
{
999+
static const __u8 btn_head[] = {UCLOGIC_RDESC_FRAME_PH_BTN_HEAD};
9991000
static const __u8 pen_head[] = {UCLOGIC_RDESC_PEN_PH_HEAD};
10001001
__u8 *rdesc_ptr;
10011002
__u8 *p;
@@ -1005,12 +1006,19 @@ __u8 *uclogic_rdesc_template_apply(const __u8 *template_ptr,
10051006
if (rdesc_ptr == NULL)
10061007
return NULL;
10071008

1008-
for (p = rdesc_ptr; p + sizeof(pen_head) < rdesc_ptr + template_size;) {
1009-
if (memcmp(p, pen_head, sizeof(pen_head)) == 0 &&
1009+
for (p = rdesc_ptr; p + sizeof(btn_head) < rdesc_ptr + template_size;) {
1010+
if (p + sizeof(pen_head) < rdesc_ptr + template_size &&
1011+
memcmp(p, pen_head, sizeof(pen_head)) == 0 &&
10101012
p[sizeof(pen_head)] < param_num) {
10111013
v = param_list[p[sizeof(pen_head)]];
10121014
put_unaligned(cpu_to_le32(v), (s32 *)p);
10131015
p += sizeof(pen_head) + 1;
1016+
} else if (memcmp(p, btn_head, sizeof(btn_head)) == 0 &&
1017+
p[sizeof(btn_head)] < param_num) {
1018+
v = param_list[p[sizeof(btn_head)]];
1019+
put_unaligned((__u8)0x2A, p); /* Usage Maximum */
1020+
put_unaligned_le16((__force u16)cpu_to_le16(v), p + 1);
1021+
p += sizeof(btn_head) + 1;
10141022
} else {
10151023
p++;
10161024
}

drivers/hid/hid-uclogic-rdesc.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ extern const size_t uclogic_rdesc_twha60_fixed1_size;
8282

8383
/* Report descriptor template placeholder head */
8484
#define UCLOGIC_RDESC_PEN_PH_HEAD 0xFE, 0xED, 0x1D
85+
#define UCLOGIC_RDESC_FRAME_PH_BTN_HEAD 0xFE, 0xED
8586

8687
/* Apply report descriptor parameters to a report descriptor template */
8788
extern __u8 *uclogic_rdesc_template_apply(const __u8 *template_ptr,
@@ -96,13 +97,18 @@ enum uclogic_rdesc_ph_id {
9697
UCLOGIC_RDESC_PEN_PH_ID_Y_LM,
9798
UCLOGIC_RDESC_PEN_PH_ID_Y_PM,
9899
UCLOGIC_RDESC_PEN_PH_ID_PRESSURE_LM,
100+
UCLOGIC_RDESC_FRAME_PH_ID_UM,
99101
UCLOGIC_RDESC_PH_ID_NUM
100102
};
101103

102104
/* Report descriptor pen template placeholder */
103105
#define UCLOGIC_RDESC_PEN_PH(_ID) \
104106
UCLOGIC_RDESC_PEN_PH_HEAD, UCLOGIC_RDESC_PEN_PH_ID_##_ID
105107

108+
/* Report descriptor frame buttons template placeholder */
109+
#define UCLOGIC_RDESC_FRAME_PH_BTN \
110+
UCLOGIC_RDESC_FRAME_PH_BTN_HEAD, UCLOGIC_RDESC_FRAME_PH_ID_UM
111+
106112
/* Report ID for v1 pen reports */
107113
#define UCLOGIC_RDESC_V1_PEN_ID 0x07
108114

0 commit comments

Comments
 (0)