Skip to content

Commit ed990d7

Browse files
committed
uclogic: Move param printing to a function
Move parameter printing from a format string/argument list to a function to allow printing the full parameters, which now wouldn't fit into a single print call.
1 parent f0d0fef commit ed990d7

3 files changed

Lines changed: 93 additions & 116 deletions

File tree

hid-uclogic-core.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -221,8 +221,8 @@ static int uclogic_probe(struct hid_device *hdev,
221221
goto failure;
222222
}
223223
params_initialized = true;
224-
hid_dbg(hdev, "parameters:\n" UCLOGIC_PARAMS_FMT_STR,
225-
UCLOGIC_PARAMS_FMT_ARGS(&drvdata->params));
224+
hid_dbg(hdev, "parameters:\n");
225+
uclogic_params_hid_dbg(hdev, &drvdata->params);
226226
if (drvdata->params.invalid) {
227227
hid_info(hdev, "interface is invalid, ignoring\n");
228228
rc = -ENODEV;

hid-uclogic-params.c

Lines changed: 87 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@
3030
* Returns:
3131
* The string representing the type, or NULL if the type is unknown.
3232
*/
33-
const char *uclogic_params_pen_inrange_to_str(
34-
enum uclogic_params_pen_inrange inrange)
33+
static const char *uclogic_params_pen_inrange_to_str(
34+
enum uclogic_params_pen_inrange inrange)
3535
{
3636
switch (inrange) {
3737
case UCLOGIC_PARAMS_PEN_INRANGE_NORMAL:
@@ -45,6 +45,91 @@ const char *uclogic_params_pen_inrange_to_str(
4545
}
4646
}
4747

48+
/**
49+
* Dump tablet interface pen parameters with hid_dbg(), indented with one tab.
50+
*
51+
* @hdev: The HID device the pen parameters describe.
52+
* @pen: The pen parameters to dump.
53+
*/
54+
static void uclogic_params_pen_hid_dbg(const struct hid_device *hdev,
55+
const struct uclogic_params_pen *pen)
56+
{
57+
size_t i;
58+
59+
hid_dbg(hdev, "\t.usage_invalid = %s\n",
60+
(pen->usage_invalid ? "true" : "false"));
61+
hid_dbg(hdev, "\t.desc_ptr = %p\n", pen->desc_ptr);
62+
hid_dbg(hdev, "\t.desc_size = %u\n", pen->desc_size);
63+
hid_dbg(hdev, "\t.id = %u\n", pen->id);
64+
hid_dbg(hdev, "\t.subreport_list = {\n");
65+
for (i = 0; i < ARRAY_SIZE(pen->subreport_list); i++) {
66+
hid_dbg(hdev, "\t\t{0x%02hhx, %hhu}%s\n",
67+
pen->subreport_list[i].value,
68+
pen->subreport_list[i].id,
69+
i < (ARRAY_SIZE(pen->subreport_list) - 1) ? "," : "");
70+
}
71+
hid_dbg(hdev, "\t}\n");
72+
hid_dbg(hdev, "\t.inrange = %s\n",
73+
uclogic_params_pen_inrange_to_str(pen->inrange));
74+
hid_dbg(hdev, "\t.fragmented_hires = %s\n",
75+
(pen->fragmented_hires ? "true" : "false"));
76+
hid_dbg(hdev, "\t.tilt_y_flipped = %s\n",
77+
(pen->tilt_y_flipped ? "true" : "false"));
78+
}
79+
80+
/**
81+
* Dump tablet interface frame parameters with hid_dbg(), indented with two
82+
* tabs.
83+
*
84+
* @hdev: The HID device the pen parameters describe.
85+
* @frame: The frame parameters to dump.
86+
*/
87+
static void uclogic_params_frame_hid_dbg(
88+
const struct hid_device *hdev,
89+
const struct uclogic_params_frame *frame)
90+
{
91+
hid_dbg(hdev, "\t\t.desc_ptr = %p\n", frame->desc_ptr);
92+
hid_dbg(hdev, "\t\t.desc_size = %u\n", frame->desc_size);
93+
hid_dbg(hdev, "\t\t.id = %u\n", frame->id);
94+
hid_dbg(hdev, "\t\t.suffix = %s\n", frame->suffix);
95+
hid_dbg(hdev, "\t\t.re_lsb = %u\n", frame->re_lsb);
96+
hid_dbg(hdev, "\t\t.dev_id_byte = %u\n", frame->dev_id_byte);
97+
hid_dbg(hdev, "\t\t.touch_ring_byte = %u\n", frame->touch_ring_byte);
98+
hid_dbg(hdev, "\t\t.touch_ring_max = %hhd\n", frame->touch_ring_max);
99+
hid_dbg(hdev, "\t\t.touch_ring_flip_at = %hhd\n",
100+
frame->touch_ring_flip_at);
101+
hid_dbg(hdev, "\t\t.bitmap_dial_byte = %u\n",
102+
frame->bitmap_dial_byte);
103+
}
104+
105+
/**
106+
* Dump tablet interface parameters with hid_dbg().
107+
*
108+
* @hdev: The HID device the parameters describe.
109+
* @params: The parameters to dump.
110+
*/
111+
void uclogic_params_hid_dbg(const struct hid_device *hdev,
112+
const struct uclogic_params *params)
113+
{
114+
size_t i;
115+
116+
hid_dbg(hdev, ".invalid = %s\n",
117+
params->invalid ? "true" : "false");
118+
hid_dbg(hdev, ".desc_ptr = %p\n", params->desc_ptr);
119+
hid_dbg(hdev, ".desc_size = %u\n", params->desc_size);
120+
hid_dbg(hdev, ".pen = {\n");
121+
uclogic_params_pen_hid_dbg(hdev, &params->pen);
122+
hid_dbg(hdev, "\t}\n");
123+
hid_dbg(hdev, ".frame_list = {\n");
124+
for (i = 0; i < ARRAY_SIZE(params->frame_list); i++) {
125+
hid_dbg(hdev, "\t{\n");
126+
uclogic_params_frame_hid_dbg(hdev, &params->frame_list[i]);
127+
hid_dbg(hdev, "\t}%s\n",
128+
i < (ARRAY_SIZE(params->frame_list) - 1) ? "," : "");
129+
}
130+
hid_dbg(hdev, "}\n");
131+
}
132+
48133
/**
49134
* uclogic_params_get_str_desc - retrieve a string descriptor from a HID
50135
* device interface, putting it into a kmalloc-allocated buffer as is, without

hid-uclogic-params.h

Lines changed: 4 additions & 112 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,6 @@ enum uclogic_params_pen_inrange {
2929
UCLOGIC_PARAMS_PEN_INRANGE_NONE,
3030
};
3131

32-
/* Convert a pen in-range reporting type to a string */
33-
extern const char *uclogic_params_pen_inrange_to_str(
34-
enum uclogic_params_pen_inrange inrange);
35-
36-
3732
/*
3833
* Pen report's subreport data.
3934
*/
@@ -213,113 +208,6 @@ struct uclogic_params {
213208
extern int uclogic_params_init(struct uclogic_params *params,
214209
struct hid_device *hdev);
215210

216-
/* Tablet interface parameters *printf format string */
217-
#define UCLOGIC_PARAMS_FMT_STR \
218-
".invalid = %s\n" \
219-
".desc_ptr = %p\n" \
220-
".desc_size = %u\n" \
221-
".pen = {\n" \
222-
"\t.usage_invalid = %s\n" \
223-
"\t.desc_ptr = %p\n" \
224-
"\t.desc_size = %u\n" \
225-
"\t.id = %u\n" \
226-
"\t.subreport_list = {\n" \
227-
"\t\t{0x%02hhx, %hhu},\n" \
228-
"\t\t{0x%02hhx, %hhu},\n" \
229-
"\t\t{0x%02hhx, %hhu},\n" \
230-
"\t}\n" \
231-
"\t.inrange = %s\n" \
232-
"\t.fragmented_hires = %s\n" \
233-
"\t.tilt_y_flipped = %s\n" \
234-
"}\n" \
235-
".frame_list = {\n" \
236-
"\t{\n" \
237-
"\t\t.desc_ptr = %p\n" \
238-
"\t\t.desc_size = %u\n" \
239-
"\t\t.id = %u\n" \
240-
"\t\t.suffix = %s\n" \
241-
"\t\t.re_lsb = %u\n" \
242-
"\t\t.dev_id_byte = %u\n" \
243-
"\t\t.touch_ring_byte = %u\n" \
244-
"\t\t.touch_ring_max = %hhd\n" \
245-
"\t\t.touch_ring_flip_at = %hhd\n" \
246-
"\t\t.bitmap_dial_byte = %u\n" \
247-
"\t},\n" \
248-
"\t{\n" \
249-
"\t\t.desc_ptr = %p\n" \
250-
"\t\t.desc_size = %u\n" \
251-
"\t\t.id = %u\n" \
252-
"\t\t.suffix = %s\n" \
253-
"\t\t.re_lsb = %u\n" \
254-
"\t\t.dev_id_byte = %u\n" \
255-
"\t\t.touch_ring_byte = %u\n" \
256-
"\t\t.touch_ring_max = %hhd\n" \
257-
"\t\t.touch_ring_flip_at = %hhd\n" \
258-
"\t\t.bitmap_dial_byte = %u\n" \
259-
"\t},\n" \
260-
"\t{\n" \
261-
"\t\t.desc_ptr = %p\n" \
262-
"\t\t.desc_size = %u\n" \
263-
"\t\t.id = %u\n" \
264-
"\t\t.suffix = %s\n" \
265-
"\t\t.re_lsb = %u\n" \
266-
"\t\t.dev_id_byte = %u\n" \
267-
"\t\t.touch_ring_byte = %u\n" \
268-
"\t\t.touch_ring_max = %hhd\n" \
269-
"\t\t.touch_ring_flip_at = %hhd\n" \
270-
"\t\t.bitmap_dial_byte = %u\n" \
271-
"\t},\n" \
272-
"}\n"
273-
274-
/* Tablet interface parameters *printf format arguments */
275-
#define UCLOGIC_PARAMS_FMT_ARGS(_params) \
276-
((_params)->invalid ? "true" : "false"), \
277-
(_params)->desc_ptr, \
278-
(_params)->desc_size, \
279-
((_params)->pen.usage_invalid ? "true" : "false"), \
280-
(_params)->pen.desc_ptr, \
281-
(_params)->pen.desc_size, \
282-
(_params)->pen.id, \
283-
(_params)->pen.subreport_list[0].value, \
284-
(_params)->pen.subreport_list[0].id, \
285-
(_params)->pen.subreport_list[1].value, \
286-
(_params)->pen.subreport_list[1].id, \
287-
(_params)->pen.subreport_list[2].value, \
288-
(_params)->pen.subreport_list[2].id, \
289-
uclogic_params_pen_inrange_to_str((_params)->pen.inrange), \
290-
((_params)->pen.fragmented_hires ? "true" : "false"), \
291-
((_params)->pen.tilt_y_flipped ? "true" : "false"), \
292-
(_params)->frame_list[0].desc_ptr, \
293-
(_params)->frame_list[0].desc_size, \
294-
(_params)->frame_list[0].id, \
295-
(_params)->frame_list[0].suffix, \
296-
(_params)->frame_list[0].re_lsb, \
297-
(_params)->frame_list[0].dev_id_byte, \
298-
(_params)->frame_list[0].touch_ring_byte, \
299-
(_params)->frame_list[0].touch_ring_max, \
300-
(_params)->frame_list[0].touch_ring_flip_at, \
301-
(_params)->frame_list[0].bitmap_dial_byte, \
302-
(_params)->frame_list[1].desc_ptr, \
303-
(_params)->frame_list[1].desc_size, \
304-
(_params)->frame_list[1].id, \
305-
(_params)->frame_list[1].suffix, \
306-
(_params)->frame_list[1].re_lsb, \
307-
(_params)->frame_list[1].dev_id_byte, \
308-
(_params)->frame_list[1].touch_ring_byte, \
309-
(_params)->frame_list[1].touch_ring_max, \
310-
(_params)->frame_list[1].touch_ring_flip_at, \
311-
(_params)->frame_list[1].bitmap_dial_byte, \
312-
(_params)->frame_list[2].desc_ptr, \
313-
(_params)->frame_list[2].desc_size, \
314-
(_params)->frame_list[2].id, \
315-
(_params)->frame_list[2].suffix, \
316-
(_params)->frame_list[2].re_lsb, \
317-
(_params)->frame_list[2].dev_id_byte, \
318-
(_params)->frame_list[2].touch_ring_byte, \
319-
(_params)->frame_list[2].touch_ring_max, \
320-
(_params)->frame_list[2].touch_ring_flip_at, \
321-
(_params)->frame_list[2].bitmap_dial_byte
322-
323211
/* Get a replacement report descriptor for a tablet's interface. */
324212
extern int uclogic_params_get_desc(const struct uclogic_params *params,
325213
__u8 **pdesc,
@@ -328,4 +216,8 @@ extern int uclogic_params_get_desc(const struct uclogic_params *params,
328216
/* Free resources used by tablet interface's parameters */
329217
extern void uclogic_params_cleanup(struct uclogic_params *params);
330218

219+
/* Dump tablet interface parameters with hid_dbg() */
220+
extern void uclogic_params_hid_dbg(const struct hid_device *hdev,
221+
const struct uclogic_params *params);
222+
331223
#endif /* _HID_UCLOGIC_PARAMS_H */

0 commit comments

Comments
 (0)