File Index
Files and directories
Sign in
FILE

Huion__Kamvas13Gen3.bpf.c

File preview with syntax highlighting.

linux-6.19.14/drivers/hid/bpf/progs/Huion__Kamvas13Gen3.bpf.c C
   1// SPDX-License-Identifier: GPL-2.0-only
   2/* Copyright (c) 2025 Nicholas LaPointe
   3 */
   4
   5#include "vmlinux.h"
   6#include "hid_bpf.h"
   7#include "hid_bpf_helpers.h"
   8#include "hid_report_helpers.h"
   9#include <bpf/bpf_tracing.h>
  10
  11#define VID_HUION 0x256c
  12#define PID_KAMVAS13_GEN3 0x2008
  13
  14#define VENDOR_DESCRIPTOR_LENGTH 36
  15#define TABLET_DESCRIPTOR_LENGTH 368
  16#define WHEEL_DESCRIPTOR_LENGTH 108
  17
  18#define VENDOR_REPORT_ID 8
  19#define VENDOR_REPORT_LENGTH 14
  20
  21#define VENDOR_REPORT_SUBTYPE_PEN 0x08
  22#define VENDOR_REPORT_SUBTYPE_PEN_OUT 0x00
  23#define VENDOR_REPORT_SUBTYPE_BUTTONS 0x0e
  24#define VENDOR_REPORT_SUBTYPE_WHEELS 0x0f
  25
  26/* For the reports that we create ourselves */
  27#define CUSTOM_PAD_REPORT_ID 9
  28
  29HID_BPF_CONFIG(
  30	HID_DEVICE(BUS_USB, HID_GROUP_ANY, VID_HUION, PID_KAMVAS13_GEN3),
  31);
  32
  33
  34/*
  35 * This tablet can send reports using one of two different data formats,
  36 * depending on what "mode" the tablet is in.
  37 *
  38 * By default, the tablet will send reports that can be decoded using its
  39 * included HID descriptors (descriptors 1 and 2, shown below).
  40 * This mode will be called "firmware mode" throughout this file.
  41 *
  42 * The HID descriptor that describes pen events in firmware mode (descriptor 1)
  43 * has multiple bugs:
  44 *	* "Secondary Tip Switch" instead of "Secondary Barrel Switch"
  45 *	* "Invert" instead of (or potentially shared with) third barrel button
  46 *	* Specified tablet area of 2048 in³ instead of 293.8 x 165.2mm
  47 *	* Specified tilt range of -90 to +90 instead of -60 to +60
  48 *
  49 * While these can be easily patched up by editing the descriptor, a larger
  50 * problem with the firmware mode exists: it is impossible to tell which of the
  51 * two wheels are being rotated (or having their central button pressed).
  52 *
  53 *
  54 * By using a tool such as huion-switcher (https://github.com/whot/huion-switcher),
  55 * the tablet can be made to send reports using a proprietary format that is not
  56 * adequately described by its relevant descriptor (descriptor 0, shown below).
  57 * This mode will be called "vendor mode" throughout this file.
  58 *
  59 * The reports sent while in vendor mode allow for proper decoding of the wheels.
  60 *
  61 * For simplicity and maximum functionality, this BPF focuses strictly on
  62 * enabling one to make use of the vendor mode.
  63 */
  64
  65/*
  66 * DESCRIPTORS
  67 *	DESCRIPTOR 0
  68 *		#   0x06, 0x00, 0xff,              // Usage Page (Vendor Defined Page FF00)     0
  69 *		#   0x09, 0x01,                    // Usage (Vendor Usage 0x01)                 3
  70 *		#   0xa1, 0x01,                    // Collection (Application)                  5
  71 *		# ┅ 0x85, 0x08,                    //   Report ID (8)                           7
  72 *		#   0x75, 0x68,                    //   Report Size (104)                       9
  73 *		#   0x95, 0x01,                    //   Report Count (1)                        11
  74 *		#   0x09, 0x01,                    //   Usage (Vendor Usage 0x01)               13
  75 *		# ┇ 0x81, 0x02,                    //   Input (Data,Var,Abs)                    15
  76 *		#   0xc0,                          // End Collection                            17
  77 *		#   0x06, 0x00, 0xff,              // Usage Page (Vendor Defined Page FF00)     18
  78 *		#   0x09, 0x01,                    // Usage (Vendor Usage 0x01)                 21
  79 *		#   0xa1, 0x01,                    // Collection (Application)                  23
  80 *		# ┅ 0x85, 0x16,                    //   Report ID (22)                          25
  81 *		#   0x75, 0x08,                    //   Report Size (8)                         27
  82 *		#   0x95, 0x07,                    //   Report Count (7)                        29
  83 *		#   0x09, 0x01,                    //   Usage (Vendor Usage 0x01)               31
  84 *		# ║ 0xb1, 0x02,                    //   Feature (Data,Var,Abs)                  33
  85 *		#   0xc0,                          // End Collection                            35
  86 *		R: 36 06 00 ff 09 01 a1 01 85 08 75 68 95 01 09 01 81 02 c0 06 00 ff 09 01 a1 01 85 16 75 08 95 07 09 01 b1 02 c0
  87 *		N: HUION Huion Tablet_GS1333
  88 *		I: 3 256c 2008
  89 *
  90 *	DESCRIPTOR 1
  91 *		#   0x05, 0x0d,                    // Usage Page (Digitizers)                   0
  92 *		#   0x09, 0x02,                    // Usage (Pen)                               2
  93 *		#   0xa1, 0x01,                    // Collection (Application)                  4
  94 *		# ┅ 0x85, 0x0a,                    //   Report ID (10)                          6
  95 *		#   0x09, 0x20,                    //   Usage (Stylus)                          8
  96 *		#   0xa1, 0x01,                    //   Collection (Application)                10
  97 *		#   0x09, 0x42,                    //     Usage (Tip Switch)                    12
  98 *		#   0x09, 0x44,                    //     Usage (Barrel Switch)                 14
  99 *		#   0x09, 0x43,                    //     Usage (Secondary Tip Switch)          16
 100 *		#   0x09, 0x3c,                    //     Usage (Invert)                        18
 101 *		#   0x09, 0x45,                    //     Usage (Eraser)                        20
 102 *		#   0x15, 0x00,                    //     Logical Minimum (0)                   22
 103 *		#   0x25, 0x01,                    //     Logical Maximum (1)                   24
 104 *		#   0x75, 0x01,                    //     Report Size (1)                       26
 105 *		#   0x95, 0x06,                    //     Report Count (6)                      28
 106 *		# ┇ 0x81, 0x02,                    //     Input (Data,Var,Abs)                  30
 107 *		#   0x09, 0x32,                    //     Usage (In Range)                      32
 108 *		#   0x75, 0x01,                    //     Report Size (1)                       34
 109 *		#   0x95, 0x01,                    //     Report Count (1)                      36
 110 *		# ┇ 0x81, 0x02,                    //     Input (Data,Var,Abs)                  38
 111 *		# ┇ 0x81, 0x03,                    //     Input (Cnst,Var,Abs)                  40
 112 *		#   0x05, 0x01,                    //     Usage Page (Generic Desktop)          42
 113 *		#   0x09, 0x30,                    //     Usage (X)                             44
 114 *		#   0x09, 0x31,                    //     Usage (Y)                             46
 115 *		#   0x55, 0x0d,                    //     Unit Exponent (-3)                    48
 116 *		#   0x65, 0x33,                    //     Unit (EnglishLinear: in³)             50
 117 *		#   0x26, 0xff, 0x7f,              //     Logical Maximum (32767)               52
 118 *		#   0x35, 0x00,                    //     Physical Minimum (0)                  55
 119 *		#   0x46, 0x00, 0x08,              //     Physical Maximum (2048)               57
 120 *		#   0x75, 0x10,                    //     Report Size (16)                      60
 121 *		#   0x95, 0x02,                    //     Report Count (2)                      62
 122 *		# ┇ 0x81, 0x02,                    //     Input (Data,Var,Abs)                  64
 123 *		#   0x05, 0x0d,                    //     Usage Page (Digitizers)               66
 124 *		#   0x09, 0x30,                    //     Usage (Tip Pressure)                  68
 125 *		#   0x26, 0xff, 0x3f,              //     Logical Maximum (16383)               70
 126 *		#   0x75, 0x10,                    //     Report Size (16)                      73
 127 *		#   0x95, 0x01,                    //     Report Count (1)                      75
 128 *		# ┇ 0x81, 0x02,                    //     Input (Data,Var,Abs)                  77
 129 *		#   0x09, 0x3d,                    //     Usage (X Tilt)                        79
 130 *		#   0x09, 0x3e,                    //     Usage (Y Tilt)                        81
 131 *		#   0x15, 0xa6,                    //     Logical Minimum (-90)                 83
 132 *		#   0x25, 0x5a,                    //     Logical Maximum (90)                  85
 133 *		#   0x75, 0x08,                    //     Report Size (8)                       87
 134 *		#   0x95, 0x02,                    //     Report Count (2)                      89
 135 *		# ┇ 0x81, 0x02,                    //     Input (Data,Var,Abs)                  91
 136 *		#   0xc0,                          //   End Collection                          93
 137 *		#   0xc0,                          // End Collection                            94
 138 *		#   0x05, 0x0d,                    // Usage Page (Digitizers)                   95
 139 *		#   0x09, 0x04,                    // Usage (Touch Screen)                      97
 140 *		#   0xa1, 0x01,                    // Collection (Application)                  99
 141 *		# ┅ 0x85, 0x04,                    //   Report ID (4)                           101
 142 *		#   0x09, 0x22,                    //   Usage (Finger)                          103
 143 *		#   0xa1, 0x02,                    //   Collection (Logical)                    105
 144 *		#   0x05, 0x0d,                    //     Usage Page (Digitizers)               107
 145 *		#   0x95, 0x01,                    //     Report Count (1)                      109
 146 *		#   0x75, 0x06,                    //     Report Size (6)                       111
 147 *		#   0x09, 0x51,                    //     Usage (Contact Identifier)            113
 148 *		#   0x15, 0x00,                    //     Logical Minimum (0)                   115
 149 *		#   0x25, 0x3f,                    //     Logical Maximum (63)                  117
 150 *		# ┇ 0x81, 0x02,                    //     Input (Data,Var,Abs)                  119
 151 *		#   0x09, 0x42,                    //     Usage (Tip Switch)                    121
 152 *		#   0x25, 0x01,                    //     Logical Maximum (1)                   123
 153 *		#   0x75, 0x01,                    //     Report Size (1)                       125
 154 *		#   0x95, 0x01,                    //     Report Count (1)                      127
 155 *		# ┇ 0x81, 0x02,                    //     Input (Data,Var,Abs)                  129
 156 *		#   0x75, 0x01,                    //     Report Size (1)                       131
 157 *		#   0x95, 0x01,                    //     Report Count (1)                      133
 158 *		# ┇ 0x81, 0x03,                    //     Input (Cnst,Var,Abs)                  135
 159 *		#   0x05, 0x01,                    //     Usage Page (Generic Desktop)          137
 160 *		#   0x75, 0x10,                    //     Report Size (16)                      139
 161 *		#   0x55, 0x0e,                    //     Unit Exponent (-2)                    141
 162 *		#   0x65, 0x11,                    //     Unit (SILinear: cm)                   143
 163 *		#   0x09, 0x30,                    //     Usage (X)                             145
 164 *		#   0x26, 0xff, 0x7f,              //     Logical Maximum (32767)               147
 165 *		#   0x35, 0x00,                    //     Physical Minimum (0)                  150
 166 *		#   0x46, 0x15, 0x0c,              //     Physical Maximum (3093)               152
 167 *		# ┇ 0x81, 0x42,                    //     Input (Data,Var,Abs,Null)             155
 168 *		#   0x09, 0x31,                    //     Usage (Y)                             157
 169 *		#   0x26, 0xff, 0x7f,              //     Logical Maximum (32767)               159
 170 *		#   0x46, 0xcb, 0x06,              //     Physical Maximum (1739)               162
 171 *		# ┇ 0x81, 0x42,                    //     Input (Data,Var,Abs,Null)             165
 172 *		#   0x05, 0x0d,                    //     Usage Page (Digitizers)               167
 173 *		#   0x09, 0x30,                    //     Usage (Tip Pressure)                  169
 174 *		#   0x26, 0xff, 0x1f,              //     Logical Maximum (8191)                171
 175 *		#   0x75, 0x10,                    //     Report Size (16)                      174
 176 *		#   0x95, 0x01,                    //     Report Count (1)                      176
 177 *		# ┇ 0x81, 0x02,                    //     Input (Data,Var,Abs)                  178
 178 *		#   0xc0,                          //   End Collection                          180
 179 *		#   0x05, 0x0d,                    //   Usage Page (Digitizers)                 181
 180 *		#   0x09, 0x22,                    //   Usage (Finger)                          183
 181 *		#   0xa1, 0x02,                    //   Collection (Logical)                    185
 182 *		#   0x05, 0x0d,                    //     Usage Page (Digitizers)               187
 183 *		#   0x95, 0x01,                    //     Report Count (1)                      189
 184 *		#   0x75, 0x06,                    //     Report Size (6)                       191
 185 *		#   0x09, 0x51,                    //     Usage (Contact Identifier)            193
 186 *		#   0x15, 0x00,                    //     Logical Minimum (0)                   195
 187 *		#   0x25, 0x3f,                    //     Logical Maximum (63)                  197
 188 *		# ┇ 0x81, 0x02,                    //     Input (Data,Var,Abs)                  199
 189 *		#   0x09, 0x42,                    //     Usage (Tip Switch)                    201
 190 *		#   0x25, 0x01,                    //     Logical Maximum (1)                   203
 191 *		#   0x75, 0x01,                    //     Report Size (1)                       205
 192 *		#   0x95, 0x01,                    //     Report Count (1)                      207
 193 *		# ┇ 0x81, 0x02,                    //     Input (Data,Var,Abs)                  209
 194 *		#   0x75, 0x01,                    //     Report Size (1)                       211
 195 *		#   0x95, 0x01,                    //     Report Count (1)                      213
 196 *		# ┇ 0x81, 0x03,                    //     Input (Cnst,Var,Abs)                  215
 197 *		#   0x05, 0x01,                    //     Usage Page (Generic Desktop)          217
 198 *		#   0x75, 0x10,                    //     Report Size (16)                      219
 199 *		#   0x55, 0x0e,                    //     Unit Exponent (-2)                    221
 200 *		#   0x65, 0x11,                    //     Unit (SILinear: cm)                   223
 201 *		#   0x09, 0x30,                    //     Usage (X)                             225
 202 *		#   0x26, 0xff, 0x7f,              //     Logical Maximum (32767)               227
 203 *		#   0x35, 0x00,                    //     Physical Minimum (0)                  230
 204 *		#   0x46, 0x15, 0x0c,              //     Physical Maximum (3093)               232
 205 *		# ┇ 0x81, 0x42,                    //     Input (Data,Var,Abs,Null)             235
 206 *		#   0x09, 0x31,                    //     Usage (Y)                             237
 207 *		#   0x26, 0xff, 0x7f,              //     Logical Maximum (32767)               239
 208 *		#   0x46, 0xcb, 0x06,              //     Physical Maximum (1739)               242
 209 *		# ┇ 0x81, 0x42,                    //     Input (Data,Var,Abs,Null)             245
 210 *		#   0x05, 0x0d,                    //     Usage Page (Digitizers)               247
 211 *		#   0x09, 0x30,                    //     Usage (Tip Pressure)                  249
 212 *		#   0x26, 0xff, 0x1f,              //     Logical Maximum (8191)                251
 213 *		#   0x75, 0x10,                    //     Report Size (16)                      254
 214 *		#   0x95, 0x01,                    //     Report Count (1)                      256
 215 *		# ┇ 0x81, 0x02,                    //     Input (Data,Var,Abs)                  258
 216 *		#   0xc0,                          //   End Collection                          260
 217 *		#   0x05, 0x0d,                    //   Usage Page (Digitizers)                 261
 218 *		#   0x09, 0x56,                    //   Usage (Scan Time)                       263
 219 *		#   0x55, 0x00,                    //   Unit Exponent (0)                       265
 220 *		#   0x65, 0x00,                    //   Unit (None)                             267
 221 *		#   0x27, 0xff, 0xff, 0xff, 0x7f,  //   Logical Maximum (2147483647)            269
 222 *		#   0x95, 0x01,                    //   Report Count (1)                        274
 223 *		#   0x75, 0x20,                    //   Report Size (32)                        276
 224 *		# ┇ 0x81, 0x02,                    //   Input (Data,Var,Abs)                    278
 225 *		#   0x09, 0x54,                    //   Usage (Contact Count)                   280
 226 *		#   0x25, 0x7f,                    //   Logical Maximum (127)                   282
 227 *		#   0x95, 0x01,                    //   Report Count (1)                        284
 228 *		#   0x75, 0x08,                    //   Report Size (8)                         286
 229 *		# ┇ 0x81, 0x02,                    //   Input (Data,Var,Abs)                    288
 230 *		#   0x75, 0x08,                    //   Report Size (8)                         290
 231 *		#   0x95, 0x08,                    //   Report Count (8)                        292
 232 *		# ┇ 0x81, 0x03,                    //   Input (Cnst,Var,Abs)                    294
 233 *		# ┅ 0x85, 0x05,                    //   Report ID (5)                           296
 234 *		#   0x09, 0x55,                    //   Usage (Contact Count Maximum)           298
 235 *		#   0x25, 0x0a,                    //   Logical Maximum (10)                    300
 236 *		#   0x75, 0x08,                    //   Report Size (8)                         302
 237 *		#   0x95, 0x01,                    //   Report Count (1)                        304
 238 *		# ║ 0xb1, 0x02,                    //   Feature (Data,Var,Abs)                  306
 239 *		#   0x06, 0x00, 0xff,              //   Usage Page (Vendor Defined Page FF00)   308
 240 *		#   0x09, 0xc5,                    //   Usage (Vendor Usage 0xc5)               311
 241 *		# ┅ 0x85, 0x06,                    //   Report ID (6)                           313
 242 *		#   0x15, 0x00,                    //   Logical Minimum (0)                     315
 243 *		#   0x26, 0xff, 0x00,              //   Logical Maximum (255)                   317
 244 *		#   0x75, 0x08,                    //   Report Size (8)                         320
 245 *		#   0x96, 0x00, 0x01,              //   Report Count (256)                      322
 246 *		# ║ 0xb1, 0x02,                    //   Feature (Data,Var,Abs)                  325
 247 *		#   0xc0,                          // End Collection                            327
 248 *		#   0x05, 0x01,                    // Usage Page (Generic Desktop)              328
 249 *		#   0x09, 0x06,                    // Usage (Keyboard)                          330
 250 *		#   0xa1, 0x01,                    // Collection (Application)                  332
 251 *		# ┅ 0x85, 0x03,                    //   Report ID (3)                           334
 252 *		#   0x05, 0x07,                    //   Usage Page (Keyboard/Keypad)            336
 253 *		#   0x19, 0xe0,                    //   UsageMinimum (224)                      338
 254 *		#   0x29, 0xe7,                    //   UsageMaximum (231)                      340
 255 *		#   0x15, 0x00,                    //   Logical Minimum (0)                     342
 256 *		#   0x25, 0x01,                    //   Logical Maximum (1)                     344
 257 *		#   0x75, 0x01,                    //   Report Size (1)                         346
 258 *		#   0x95, 0x08,                    //   Report Count (8)                        348
 259 *		# ┇ 0x81, 0x02,                    //   Input (Data,Var,Abs)                    350
 260 *		#   0x05, 0x07,                    //   Usage Page (Keyboard/Keypad)            352
 261 *		#   0x19, 0x00,                    //   UsageMinimum (0)                        354
 262 *		#   0x29, 0xff,                    //   UsageMaximum (255)                      356
 263 *		#   0x26, 0xff, 0x00,              //   Logical Maximum (255)                   358
 264 *		#   0x75, 0x08,                    //   Report Size (8)                         361
 265 *		#   0x95, 0x06,                    //   Report Count (6)                        363
 266 *		# ┇ 0x81, 0x00,                    //   Input (Data,Arr,Abs)                    365
 267 *		#   0xc0,                          // End Collection                            367
 268 *		R: 368 05 0d 09 02 a1 01 85 0a 09 20 a1 01 09 42 09 44 09 43 09 3c 09 45 15 00 25 01 75 01 95 06 81 02 09 32 75 01 95 01 81 02 81 03 05 01 09 30 09 31 55 0d 65 33 26 ff 7f 35 00 46 00 08 75 10 95 02 81 02 05 0d 09 30 26 ff 3f 75 10 95 01 81 02 09 3d 09 3e 15 a6 25 5a 75 08 95 02 81 02 c0 c0 05 0d 09 04 a1 01 85 04 09 22 a1 02 05 0d 95 01 75 06 09 51 15 00 25 3f 81 02 09 42 25 01 75 01 95 01 81 02 75 01 95 01 81 03 05 01 75 10 55 0e 65 11 09 30 26 ff 7f 35 00 46 15 0c 81 42 09 31 26 ff 7f 46 cb 06 81 42 05 0d 09 30 26 ff 1f 75 10 95 01 81 02 c0 05 0d 09 22 a1 02 05 0d 95 01 75 06 09 51 15 00 25 3f 81 02 09 42 25 01 75 01 95 01 81 02 75 01 95 01 81 03 05 01 75 10 55 0e 65 11 09 30 26 ff 7f 35 00 46 15 0c 81 42 09 31 26 ff 7f 46 cb 06 81 42 05 0d 09 30 26 ff 1f 75 10 95 01 81 02 c0 05 0d 09 56 55 00 65 00 27 ff ff ff 7f 95 01 75 20 81 02 09 54 25 7f 95 01 75 08 81 02 75 08 95 08 81 03 85 05 09 55 25 0a 75 08 95 01 b1 02 06 00 ff 09 c5 85 06 15 00 26 ff 00 75 08 96 00 01 b1 02 c0 05 01 09 06 a1 01 85 03 05 07 19 e0 29 e7 15 00 25 01 75 01 95 08 81 02 05 07 19 00 29 ff 26 ff 00 75 08 95 06 81 00 c0
 269 *		N: HUION Huion Tablet_GS1333
 270 *		I: 3 256c 2008
 271 *
 272 *	DESCRIPTOR 2
 273 *		#   0x05, 0x01,                    // Usage Page (Generic Desktop)              0
 274 *		#   0x09, 0x0e,                    // Usage (System Multi-Axis Controller)      2
 275 *		#   0xa1, 0x01,                    // Collection (Application)                  4
 276 *		# ┅ 0x85, 0x11,                    //   Report ID (17)                          6
 277 *		#   0x05, 0x0d,                    //   Usage Page (Digitizers)                 8
 278 *		#   0x09, 0x21,                    //   Usage (Puck)                            10
 279 *		#   0xa1, 0x02,                    //   Collection (Logical)                    12
 280 *		#   0x15, 0x00,                    //     Logical Minimum (0)                   14
 281 *		#   0x25, 0x01,                    //     Logical Maximum (1)                   16
 282 *		#   0x75, 0x01,                    //     Report Size (1)                       18
 283 *		#   0x95, 0x01,                    //     Report Count (1)                      20
 284 *		#   0xa1, 0x00,                    //     Collection (Physical)                 22
 285 *		#   0x05, 0x09,                    //       Usage Page (Button)                 24
 286 *		#   0x09, 0x01,                    //       Usage (Button 1)                    26
 287 *		# ┇ 0x81, 0x02,                    //       Input (Data,Var,Abs)                28
 288 *		#   0x05, 0x0d,                    //       Usage Page (Digitizers)             30
 289 *		#   0x09, 0x33,                    //       Usage (Touch)                       32
 290 *		# ┇ 0x81, 0x02,                    //       Input (Data,Var,Abs)                34
 291 *		#   0x95, 0x06,                    //       Report Count (6)                    36
 292 *		# ┇ 0x81, 0x03,                    //       Input (Cnst,Var,Abs)                38
 293 *		#   0xa1, 0x02,                    //       Collection (Logical)                40
 294 *		#   0x05, 0x01,                    //         Usage Page (Generic Desktop)      42
 295 *		#   0x09, 0x37,                    //         Usage (Dial)                      44
 296 *		#   0x16, 0x00, 0x80,              //         Logical Minimum (-32768)          46
 297 *		#   0x26, 0xff, 0x7f,              //         Logical Maximum (32767)           49
 298 *		#   0x75, 0x10,                    //         Report Size (16)                  52
 299 *		#   0x95, 0x01,                    //         Report Count (1)                  54
 300 *		# ┇ 0x81, 0x06,                    //         Input (Data,Var,Rel)              56
 301 *		#   0x35, 0x00,                    //         Physical Minimum (0)              58
 302 *		#   0x46, 0x10, 0x0e,              //         Physical Maximum (3600)           60
 303 *		#   0x15, 0x00,                    //         Logical Minimum (0)               63
 304 *		#   0x26, 0x10, 0x0e,              //         Logical Maximum (3600)            65
 305 *		#   0x09, 0x48,                    //         Usage (Resolution Multiplier)     68
 306 *		# ║ 0xb1, 0x02,                    //         Feature (Data,Var,Abs)            70
 307 *		#   0x45, 0x00,                    //         Physical Maximum (0)              72
 308 *		#   0xc0,                          //       End Collection                      74
 309 *		#   0x75, 0x08,                    //       Report Size (8)                     75
 310 *		#   0x95, 0x01,                    //       Report Count (1)                    77
 311 *		# ┇ 0x81, 0x01,                    //       Input (Cnst,Arr,Abs)                79
 312 *		#   0x75, 0x08,                    //       Report Size (8)                     81
 313 *		#   0x95, 0x01,                    //       Report Count (1)                    83
 314 *		# ┇ 0x81, 0x01,                    //       Input (Cnst,Arr,Abs)                85
 315 *		#   0x75, 0x08,                    //       Report Size (8)                     87
 316 *		#   0x95, 0x01,                    //       Report Count (1)                    89
 317 *		# ┇ 0x81, 0x01,                    //       Input (Cnst,Arr,Abs)                91
 318 *		#   0x75, 0x08,                    //       Report Size (8)                     93
 319 *		#   0x95, 0x01,                    //       Report Count (1)                    95
 320 *		# ┇ 0x81, 0x01,                    //       Input (Cnst,Arr,Abs)                97
 321 *		#   0x75, 0x08,                    //       Report Size (8)                     99
 322 *		#   0x95, 0x01,                    //       Report Count (1)                    101
 323 *		# ┇ 0x81, 0x01,                    //       Input (Cnst,Arr,Abs)                103
 324 *		#   0xc0,                          //     End Collection                        105
 325 *		#   0xc0,                          //   End Collection                          106
 326 *		#   0xc0,                          // End Collection                            107
 327 *		R: 108 05 01 09 0e a1 01 85 11 05 0d 09 21 a1 02 15 00 25 01 75 01 95 01 a1 00 05 09 09 01 81 02 05 0d 09 33 81 02 95 06 81 03 a1 02 05 01 09 37 16 00 80 26 ff 7f 75 10 95 01 81 06 35 00 46 10 0e 15 00 26 10 0e 09 48 b1 02 45 00 c0 75 08 95 01 81 01 75 08 95 01 81 01 75 08 95 01 81 01 75 08 95 01 81 01 75 08 95 01 81 01 c0 c0 c0
 328 *		N: HUION Huion Tablet_GS1333
 329 *		I: 3 256c 2008
 330 *
 331 *
 332 *
 333 *
 334 *
 335 *
 336 *
 337 *
 338 * VENDOR MODE
 339 *	HUION_FIRMWARE_ID="HUION_M22c_240606"
 340 *	HUION_MAGIC_BYTES="140388e500108100ff3fd8130307008008004010"
 341 *
 342 *	MAGIC BYTES
 343 *	          [LogicalMaximum, X]    [LogicalMaximum, Y]    [LogicalMaximum, Pressure] [  LPI]
 344 *	    14 03 [            88 e5] 00 [            10 81] 00 [                   ff 3f] [d8 13] 03 07 00 80 08 00 40 10
 345 *
 346 *
 347 *	HIDRAW 0
 348 *		DESCRIPTIONS
 349 *			report_subtype = (data[1] >> 4) & 0x0f
 350 *
 351 *			REPORT SUBTYPES
 352 *				0x0e		Buttons
 353 *							(data[4] & 0x01)	button 1
 354 *							(data[4] & 0x02)	button 2
 355 *							(data[4] & 0x04)	button 3
 356 *							(data[4] & 0x08)	button 4
 357 *							(data[4] & 0x10)	button 5
 358 *							(data[4] & 0x20)	button 6 (top wheel button)
 359 *							(data[4] & 0x40)	button 7 (bottom wheel button)
 360 *
 361 *							All tablet buttons release with the same report:
 362 *								08 e0 01 01 00 00 00 00 00 00 00 00 00 00
 363 *
 364 *							Despite data[4] looking like a bit field, only one button
 365 *							can be unambiguously tracked at a time.
 366 *							(See NOTES ON SIMULTANEOUS BUTTON HOLDS at the end of this
 367 *							comment for examples of the confusion this can create.)
 368 *
 369 *							All buttons, with the exceptions of 6 and 7, will repeatedly
 370 *							report a press event approximately every 225ms while held.
 371 *
 372 *				0x0f		Wheels
 373 *							data[3] == 1: top wheel
 374 *							data[3] == 2: bottom wheel
 375 *							data[5] == 1: clockwise
 376 *							data[5] == 2: counter-clockwise
 377 *
 378 *				0x08/0x00	Pen
 379 *							report_subtype == 0x08: in-range
 380 *							report_subtype == 0x00: out-of-range
 381 *								For clarity, this is also equivalent to:
 382 *									(data[1] & 0x80)	in-range
 383 *
 384 *							Switches
 385 *								(data[1] & 0x01)	tip switch
 386 *								(data[1] & 0x02)	barrel switch
 387 *								(data[1] & 0x04)	secondary barrel switch
 388 *								(data[1] & 0x08)	third barrel switch
 389 *
 390 *								Unfortunately, I don't have a pen with an eraser, so I can't
 391 *								confirm where the invert and eraser bits reside.
 392 *								If we guess using the definitions from HID descriptor 1,
 393 *								then they might be...
 394 *									(data[1] & 0x08)	invert (conflicts with third barrel switch)
 395 *									(data[1] & 0x10)	eraser
 396 *
 397 *							data[2], data[3]	X (little-endian, maximum 0xe588)
 398 *
 399 *							data[4], data[5]	Y (little-endian, maximum 0x8110)
 400 *
 401 *							data[6], data[7]	Pressure (little-endian, maximum 0x3fff)
 402 *
 403 *							data[10]		X tilt	(signed, -60 to +60)
 404 *							data[11]		Y tilt	(signed, -60 to +60, inverted)
 405 *
 406 *
 407 *		EXAMPLE REPORTS
 408 *			Top wheel button, press, hold, then release
 409 *				E: 000000.000040 14 08 e0 01 01 20 00 00 00 00 00 00 00 00 00
 410 *				E: 000001.531559 14 08 e0 01 01 00 00 00 00 00 00 00 00 00 00
 411 *
 412 *			Bottom wheel button, press, hold, then release
 413 *				E: 000002.787603 14 08 e0 01 01 40 00 00 00 00 00 00 00 00 00
 414 *				E: 000004.215609 14 08 e0 01 01 00 00 00 00 00 00 00 00 00 00
 415 *
 416 *
 417 *			Top wheel rotation, one detent CW
 418 *				E: 000194.003899 14 08 f1 01 01 00 01 00 00 00 00 00 00 00 00
 419 *
 420 *			Top wheel rotation, one detent CCW
 421 *				E: 000194.997812 14 08 f1 01 01 00 02 00 00 00 00 00 00 00 00
 422 *
 423 *			Bottom wheel rotation, one detent CW
 424 *				E: 000196.693840 14 08 f1 01 02 00 01 00 00 00 00 00 00 00 00
 425 *
 426 *			Bottom wheel rotation, one detent CCW
 427 *				E: 000197.757895 14 08 f1 01 02 00 02 00 00 00 00 00 00 00 00
 428 *
 429 *
 430 *			Button 1, press, hold, then release
 431 *				E: 000000.000149 14 08 e0 01 01 01 00 00 00 00 00 00 00 00 00 < press
 432 *				E: 000000.447598 14 08 e0 01 01 01 00 00 00 00 00 00 00 00 00 < starting to auto-repeat, every ~225ms
 433 *				E: 000000.673586 14 08 e0 01 01 01 00 00 00 00 00 00 00 00 00
 434 *				E: 000000.900582 14 08 e0 01 01 01 00 00 00 00 00 00 00 00 00
 435 *				E: 000001.126703 14 08 e0 01 01 01 00 00 00 00 00 00 00 00 00
 436 *				E: 000001.347706 14 08 e0 01 01 01 00 00 00 00 00 00 00 00 00
 437 *				E: 000001.533721 14 08 e0 01 01 00 00 00 00 00 00 00 00 00 00 < release
 438 *
 439 *			Button 2, press, hold, then release
 440 *				E: 000003.304735 14 08 e0 01 01 02 00 00 00 00 00 00 00 00 00 < press
 441 *				E: 000003.746743 14 08 e0 01 01 02 00 00 00 00 00 00 00 00 00 < starting to auto-repeat, every ~225ms
 442 *				E: 000003.973741 14 08 e0 01 01 02 00 00 00 00 00 00 00 00 00
 443 *				E: 000004.199832 14 08 e0 01 01 02 00 00 00 00 00 00 00 00 00
 444 *				E: 000004.426732 14 08 e0 01 01 02 00 00 00 00 00 00 00 00 00
 445 *				E: 000004.647738 14 08 e0 01 01 02 00 00 00 00 00 00 00 00 00
 446 *				E: 000004.874733 14 08 e0 01 01 02 00 00 00 00 00 00 00 00 00
 447 *				E: 000004.930713 14 08 e0 01 01 00 00 00 00 00 00 00 00 00 00 < release
 448 *
 449 *			Button 3, press, hold, then release
 450 *				E: 000006.650346 14 08 e0 01 01 04 00 00 00 00 00 00 00 00 00 < press
 451 *				E: 000007.051782 14 08 e0 01 01 04 00 00 00 00 00 00 00 00 00 < starting to auto-repeat, every ~225ms
 452 *				E: 000007.273738 14 08 e0 01 01 04 00 00 00 00 00 00 00 00 00
 453 *				E: 000007.499794 14 08 e0 01 01 04 00 00 00 00 00 00 00 00 00
 454 *				E: 000007.726725 14 08 e0 01 01 04 00 00 00 00 00 00 00 00 00
 455 *				E: 000007.947765 14 08 e0 01 01 04 00 00 00 00 00 00 00 00 00
 456 *				E: 000008.174755 14 08 e0 01 01 04 00 00 00 00 00 00 00 00 00
 457 *				E: 000008.328786 14 08 e0 01 01 00 00 00 00 00 00 00 00 00 00 < release
 458 *
 459 *			Button 4, press, hold, then release
 460 *				E: 000009.893820 14 08 e0 01 01 08 00 00 00 00 00 00 00 00 00 < press
 461 *				E: 000010.274781 14 08 e0 01 01 08 00 00 00 00 00 00 00 00 00 < starting to auto-repeat, every ~225ms
 462 *				E: 000010.500931 14 08 e0 01 01 08 00 00 00 00 00 00 00 00 00
 463 *				E: 000010.722777 14 08 e0 01 01 08 00 00 00 00 00 00 00 00 00
 464 *				E: 000010.948778 14 08 e0 01 01 08 00 00 00 00 00 00 00 00 00
 465 *				E: 000011.175799 14 08 e0 01 01 08 00 00 00 00 00 00 00 00 00
 466 *				E: 000011.401153 14 08 e0 01 01 08 00 00 00 00 00 00 00 00 00
 467 *				E: 000011.432114 14 08 e0 01 01 00 00 00 00 00 00 00 00 00 00 < release
 468 *
 469 *			Button 5, press, hold, then release
 470 *				E: 000013.007778 14 08 e0 01 01 10 00 00 00 00 00 00 00 00 00 < press
 471 *				E: 000013.424741 14 08 e0 01 01 10 00 00 00 00 00 00 00 00 00 < starting to auto-repeat, every ~225ms
 472 *				E: 000013.651715 14 08 e0 01 01 10 00 00 00 00 00 00 00 00 00
 473 *				E: 000013.872763 14 08 e0 01 01 10 00 00 00 00 00 00 00 00 00
 474 *				E: 000014.099789 14 08 e0 01 01 10 00 00 00 00 00 00 00 00 00
 475 *				E: 000014.325734 14 08 e0 01 01 10 00 00 00 00 00 00 00 00 00
 476 *				E: 000014.438080 14 08 e0 01 01 00 00 00 00 00 00 00 00 00 00 < release
 477 *
 478 *
 479 *			Pen: Top-left, then out of range
 480 *				E: 000368.572184 14 08 80 00 00 00 00 00 00 00 00 fb ed 03 00
 481 *				E: 000368.573030 14 08 00 00 00 00 00 00 00 00 00 fb ed 03 00
 482 *
 483 *			Pen: Bottom-right, then out of range
 484 *				E: 000544.433185 14 08 80 88 e5 10 81 00 00 00 00 00 00 03 00
 485 *				E: 000544.434183 14 08 00 88 e5 10 81 00 00 00 00 00 00 03 00
 486 *
 487 *			Pen: Max Y tilt (tip of pen points down)
 488 *				E: 000002.231927 14 08 80 f5 5d 6c 36 00 00 00 00 09 3c 03 00
 489 *
 490 *			Pen: Min Y Tilt (tip of pen points up)
 491 *				E: 000657.593338 14 08 80 5f 69 fa 2c 00 00 00 00 fe c4 03 00
 492 *
 493 *			Pen: Max X tilt (tip of pen points left)
 494 *				E: 000742.246503 14 08 80 2a 4f c4 38 00 00 00 00 3c ed 03 00
 495 *
 496 *			Pen: Min X Tilt (tip of pen points right)
 497 *				E: 000776.404446 14 08 00 18 85 7c 3b 00 00 00 00 c4 ed 03 00
 498 *
 499 *			Pen: Tip switch, max pressure, then low pressure
 500 *				E: 001138.935675 14 08 81 d2 66 04 40 ff 3f 00 00 00 08 03 00
 501 *
 502 *				E: 001142.403715 14 08 81 9d 69 47 3e 82 04 00 00 00 07 03 00
 503 *
 504 *			Pen: Barrel switch
 505 *				E: 001210.645652 14 08 82 0d 72 ea 2b 00 00 00 00 db c4 03 00
 506 *
 507 *			Pen: Secondary barrel switch
 508 *				E: 001211.519729 14 08 84 2c 71 51 2b 00 00 00 00 da c4 03 00
 509 *
 510 *			Pen: Third switch
 511 *				E: 001212.443722 14 08 88 1d 72 df 2b 00 00 00 00 dc c4 03 00
 512 *
 513 *
 514 *	HIDRAW 1
 515 *		No reports
 516 *
 517 *
 518 *	HIDRAW 2
 519 *		No reports
 520 *
 521 *
 522 *
 523 *
 524 *
 525 *
 526 *
 527 *
 528 * FIRMWARE MODE
 529 *	HIDRAW 0
 530 *		No reports
 531 *
 532 *
 533 *	HIDRAW 1
 534 *		EXAMPLE REPORTS
 535 *			Top wheel button, *release*
 536 *				E: 000067.043739 8 03 00 00 00 00 00 00 00
 537 *
 538 *			Bottom wheel button, *release*
 539 *				E: 000068.219161 8 03 00 00 00 00 00 00 00
 540 *
 541 *
 542 *			Button 1, press, then release
 543 *				E: 000163.767870 8 03 00 05 00 00 00 00 00
 544 *				E: 000165.969193 8 03 00 00 00 00 00 00 00
 545 *
 546 *			Button 2, press, then release
 547 *				E: 000261.728935 8 03 05 11 00 00 00 00 00
 548 *				E: 000262.956220 8 03 00 00 00 00 00 00 00
 549 *
 550 *			Button 3, press, then release
 551 *				E: 000289.127881 8 03 01 16 00 00 00 00 00
 552 *				E: 000290.014594 8 03 00 00 00 00 00 00 00
 553 *
 554 *			Button 4, press, then release
 555 *				E: 000303.025839 8 03 00 2c 00 00 00 00 00
 556 *				E: 000303.994479 8 03 00 00 00 00 00 00 00
 557 *
 558 *			Button 5, press, then release
 559 *				E: 000315.500835 8 03 05 1d 00 00 00 00 00
 560 *				E: 000316.603274 8 03 00 00 00 00 00 00 00
 561 *
 562 *			BUTTON SUMMARY
 563 *					1	E: 000163.767870 8 03 00 05 00 00 00 00 00   Keyboard: B
 564 *					2	E: 000261.728935 8 03 05 11 00 00 00 00 00   Keyboard: LCtrl+LAlt N
 565 *					3	E: 000289.127881 8 03 01 16 00 00 00 00 00   Keyboard: LCtrl S
 566 *					4	E: 000303.025839 8 03 00 2c 00 00 00 00 00   Keyboard: Space
 567 *					5	E: 000315.500835 8 03 05 1d 00 00 00 00 00   Keyboard: LCtrl+LAlt
 568 *
 569 *					All buttons (including the wheel buttons) release the same way:
 570 *						03 00 00 00 00 00 00 00
 571 *
 572 *
 573 *			Pen: Top-left, then out of range
 574 *				E: 000063.196828 10 0a c0 00 00 00 00 00 00 00 02
 575 *				E: 000063.197762 10 0a 00 00 00 00 00 00 00 00 02
 576 *
 577 *			Pen: Bottom-right, then out of range
 578 *				E: 000197.123138 10 0a c0 ff 7f ff 7f 00 00 00 00
 579 *				E: 000197.124915 10 0a 00 ff 7f ff 7f 00 00 00 00
 580 *
 581 *			Pen: Max Y Tilt (tip of pen points up)
 582 *				E: 000291.399541 10 0a c0 19 32 0b 58 00 00 00 3c
 583 *
 584 *			Pen: Min Y tilt (tip of pen points down)
 585 *				E: 000340.888288 10 0a c0 85 40 89 6e 00 00 17 c4
 586 *
 587 *			Pen: Max X tilt (tip of pen points left)
 588 *				E: 000165.575115 10 0a c0 a7 34 99 42 00 00 3c f4
 589 *
 590 *			Pen: Min X Tilt (tip of pen points right)
 591 *				E: 000129.507883 10 0a c0 ea 4b 08 40 00 00 c4 1a
 592 *
 593 *			Pen: Tip switch, max pressure, then low pressure
 594 *				E: 000242.077160 10 0a c1 7e 3c 12 31 ff 3f 03 fd
 595 *
 596 *				E: 000339.139188 10 0a c1 ee 3a 9e 32 b5 00 06 f6
 597 *
 598 *			Pen: Barrel switch
 599 *				E: 000037.949777 10 0a c2 5c 28 47 2a 00 00 f6 3c
 600 *
 601 *			Pen: Secondary barrel switch
 602 *				E: 000038.320840 10 0a c4 e4 27 fd 29 00 00 f3 38
 603 *
 604 *			Pen: Third switch
 605 *				E: 000038.923822 10 0a c8 97 27 5f 29 00 00 f2 33
 606 *
 607 *
 608 *	HIDRAW 2
 609 *		EXAMPLE REPORTS
 610 *			Either wheel rotation, one detent CW
 611 *				E: 000097.276573 9 11 00 01 00 00 00 00 00 00
 612 *
 613 *			Either wheel rotation, one detent CCW
 614 *				E: 000153.416538 9 11 00 ff ff 00 00 00 00 00
 615 *
 616 *			Either wheel rotation, increasing rotation speed CW
 617 *				(Note that the wheels on my particular tablet may be
 618 *				 damaged, so the false rotation direction changes
 619 *				 that can be observed might not happen on other units.)
 620 *				E: 000210.514925 9 11 00 01 00 00 00 00 00 00
 621 *				E: 000210.725718 9 11 00 01 00 00 00 00 00 00
 622 *				E: 000210.924009 9 11 00 01 00 00 00 00 00 00
 623 *				E: 000211.205629 9 11 00 01 00 00 00 00 00 00
 624 *				E: 000211.280521 9 11 00 0b 00 00 00 00 00 00
 625 *				E: 000211.340121 9 11 00 0e 00 00 00 00 00 00
 626 *				E: 000211.404018 9 11 00 0d 00 00 00 00 00 00
 627 *				E: 000211.462060 9 11 00 0e 00 00 00 00 00 00
 628 *				E: 000211.544886 9 11 00 0a 00 00 00 00 00 00
 629 *				E: 000211.606130 9 11 00 0d 00 00 00 00 00 00
 630 *				E: 000211.674560 9 11 00 0c 00 00 00 00 00 00
 631 *				E: 000211.712039 9 11 00 16 00 00 00 00 00 00
 632 *				E: 000211.748076 9 11 00 17 00 00 00 00 00 00
 633 *				E: 000211.786016 9 11 00 17 00 00 00 00 00 00
 634 *				E: 000211.832960 9 11 00 11 00 00 00 00 00 00
 635 *				E: 000211.874081 9 11 00 14 00 00 00 00 00 00
 636 *				E: 000211.925094 9 11 00 10 00 00 00 00 00 00
 637 *				E: 000211.959048 9 11 00 18 00 00 00 00 00 00
 638 *				E: 000212.006937 9 11 00 11 00 00 00 00 00 00
 639 *				E: 000212.050055 9 11 00 13 00 00 00 00 00 00
 640 *				E: 000212.091947 9 11 00 14 00 00 00 00 00 00
 641 *				E: 000212.122989 9 11 00 1a 00 00 00 00 00 00
 642 *				E: 000212.160866 9 11 00 16 00 00 00 00 00 00
 643 *				E: 000212.194002 9 11 00 19 00 00 00 00 00 00
 644 *				E: 000212.242249 9 11 00 11 00 00 00 00 00 00
 645 *				E: 000212.278061 9 11 00 18 00 00 00 00 00 00
 646 *				E: 000212.328899 9 11 00 10 00 00 00 00 00 00
 647 *				E: 000212.354005 9 11 00 22 00 00 00 00 00 00
 648 *				E: 000212.398995 9 11 00 12 00 00 00 00 00 00
 649 *				E: 000212.432050 9 11 00 19 00 00 00 00 00 00
 650 *				E: 000212.471164 9 11 00 16 00 00 00 00 00 00
 651 *				E: 000212.507047 9 11 00 17 00 00 00 00 00 00
 652 *				E: 000212.540964 9 11 00 19 00 00 00 00 00 00
 653 *				E: 000212.567942 9 11 00 1f 00 00 00 00 00 00
 654 *				E: 000212.610007 9 11 00 14 00 00 00 00 00 00
 655 *				E: 000212.641101 9 11 00 1b 00 00 00 00 00 00
 656 *				E: 000212.674113 9 11 00 19 00 00 00 00 00 00
 657 *				E: 000212.674909 9 11 00 01 00 00 00 00 00 00
 658 *				E: 000212.677062 9 11 00 00 02 00 00 00 00 00
 659 *				E: 000212.679048 9 11 00 55 01 00 00 00 00 00
 660 *				E: 000212.682166 9 11 00 55 01 00 00 00 00 00
 661 *				E: 000212.682788 9 11 00 ff ff 00 00 00 00 00
 662 *				E: 000212.683899 9 11 00 01 00 00 00 00 00 00
 663 *				E: 000212.685827 9 11 00 67 fe 00 00 00 00 00
 664 *				E: 000212.686941 9 11 00 00 08 00 00 00 00 00
 665 *				E: 000212.727840 9 11 00 14 00 00 00 00 00 00
 666 *				E: 000212.772884 9 11 00 13 00 00 00 00 00 00
 667 *				E: 000212.810975 9 11 00 16 00 00 00 00 00 00
 668 *				E: 000212.811793 9 11 00 00 08 00 00 00 00 00
 669 *				E: 000212.812683 9 11 00 01 00 00 00 00 00 00
 670 *				E: 000212.813905 9 11 00 01 00 00 00 00 00 00
 671 *				E: 000212.814909 9 11 00 00 04 00 00 00 00 00
 672 *				E: 000212.816942 9 11 00 01 00 00 00 00 00 00
 673 *				E: 000212.817851 9 11 00 ff ff 00 00 00 00 00
 674 *				E: 000212.818752 9 11 00 01 00 00 00 00 00 00
 675 *				E: 000212.819910 9 11 00 56 fd 00 00 00 00 00
 676 *				E: 000212.820781 9 11 00 ff ff 00 00 00 00 00
 677 *				E: 000212.821811 9 11 00 00 04 00 00 00 00 00
 678 *				E: 000212.822920 9 11 00 00 08 00 00 00 00 00
 679 *				E: 000212.823861 9 11 00 00 02 00 00 00 00 00
 680 *				E: 000212.828781 9 11 00 ba 00 00 00 00 00 00
 681 *				E: 000212.874097 9 11 00 12 00 00 00 00 00 00
 682 *				E: 000212.874872 9 11 00 00 fc 00 00 00 00 00
 683 *				E: 000212.876136 9 11 00 00 fc 00 00 00 00 00
 684 *				E: 000212.877036 9 11 00 00 f8 00 00 00 00 00
 685 *				E: 000212.877993 9 11 00 00 f8 00 00 00 00 00
 686 *				E: 000212.879748 9 11 00 01 00 00 00 00 00 00
 687 *				E: 000212.880728 9 11 00 01 00 00 00 00 00 00
 688 *				E: 000212.881956 9 11 00 00 04 00 00 00 00 00
 689 *				E: 000212.885065 9 11 00 ff ff 00 00 00 00 00
 690 *				E: 000212.917060 9 11 00 1a 00 00 00 00 00 00
 691 *				E: 000212.936458 9 11 00 2d 00 00 00 00 00 00
 692 *				E: 000212.957860 9 11 00 25 00 00 00 00 00 00
 693 *				E: 000212.984019 9 11 00 20 00 00 00 00 00 00
 694 *				E: 000213.017915 9 11 00 19 00 00 00 00 00 00
 695 *				E: 000213.039973 9 11 00 27 00 00 00 00 00 00
 696 *				E: 000213.065933 9 11 00 21 00 00 00 00 00 00
 697 *				E: 000213.085807 9 11 00 28 00 00 00 00 00 00
 698 *				E: 000213.108888 9 11 00 25 00 00 00 00 00 00
 699 *				E: 000213.129726 9 11 00 29 00 00 00 00 00 00
 700 *				E: 000213.172043 9 11 00 14 00 00 00 00 00 00
 701 *				E: 000213.195873 9 11 00 23 00 00 00 00 00 00
 702 *				E: 000213.222884 9 11 00 20 00 00 00 00 00 00
 703 *				E: 000213.243220 9 11 00 2a 00 00 00 00 00 00
 704 *				E: 000213.266778 9 11 00 24 00 00 00 00 00 00
 705 *				E: 000213.285951 9 11 00 2b 00 00 00 00 00 00
 706 *				E: 000213.306045 9 11 00 2a 00 00 00 00 00 00
 707 *				E: 000213.306796 9 11 00 ff ff 00 00 00 00 00
 708 *				E: 000213.307755 9 11 00 ff ff 00 00 00 00 00
 709 *				E: 000213.308820 9 11 00 ff ff 00 00 00 00 00
 710 *				E: 000213.309971 9 11 00 ff ff 00 00 00 00 00
 711 *				E: 000213.310980 9 11 00 01 00 00 00 00 00 00
 712 *				E: 000213.311853 9 11 00 01 00 00 00 00 00 00
 713 *				E: 000213.312861 9 11 00 aa 02 00 00 00 00 00
 714 *				E: 000213.313884 9 11 00 00 f8 00 00 00 00 00
 715 *				E: 000213.315111 9 11 00 ff ff 00 00 00 00 00
 716 *				E: 000213.315992 9 11 00 01 00 00 00 00 00 00
 717 *				E: 000213.316955 9 11 00 00 08 00 00 00 00 00
 718 *				E: 000213.346065 9 11 00 1d 00 00 00 00 00 00
 719 *				E: 000213.346963 9 11 00 ff ff 00 00 00 00 00
 720 *				E: 000213.347874 9 11 00 00 08 00 00 00 00 00
 721 *				E: 000213.348736 9 11 00 00 08 00 00 00 00 00
 722 *				E: 000213.349795 9 11 00 00 04 00 00 00 00 00
 723 *				E: 000213.350791 9 11 00 01 00 00 00 00 00 00
 724 *				E: 000213.351791 9 11 00 01 00 00 00 00 00 00
 725 *				E: 000213.352729 9 11 00 00 f8 00 00 00 00 00
 726 *				E: 000213.353811 9 11 00 01 00 00 00 00 00 00
 727 *				E: 000213.354755 9 11 00 00 f8 00 00 00 00 00
 728 *				E: 000213.355795 9 11 00 00 f8 00 00 00 00 00
 729 *				E: 000213.356813 9 11 00 01 00 00 00 00 00 00
 730 *				E: 000213.357817 9 11 00 00 04 00 00 00 00 00
 731 *				E: 000213.393838 9 11 00 17 00 00 00 00 00 00
 732 *				E: 000213.394719 9 11 00 00 04 00 00 00 00 00
 733 *				E: 000213.395682 9 11 00 00 08 00 00 00 00 00
 734 *				E: 000213.396679 9 11 00 00 04 00 00 00 00 00
 735 *				E: 000213.397651 9 11 00 00 fc 00 00 00 00 00
 736 *				E: 000213.398661 9 11 00 ff ff 00 00 00 00 00
 737 *				E: 000213.400308 9 11 00 56 fd 00 00 00 00 00
 738 *				E: 000213.400909 9 11 00 00 f8 00 00 00 00 00
 739 *				E: 000213.401837 9 11 00 01 00 00 00 00 00 00
 740 *
 741 *			Either wheel rotation, increasing rotation speed CCW
 742 *				(Note that the wheels on my particular tablet may be
 743 *				 damaged, so the false rotation direction changes
 744 *				 that can be observed might not happen on other units.)
 745 *				E: 000040.527820 9 11 00 ff ff 00 00 00 00 00
 746 *				E: 000040.816644 9 11 00 ff ff 00 00 00 00 00
 747 *				E: 000040.880423 9 11 00 f3 ff 00 00 00 00 00
 748 *				E: 000040.882570 9 11 00 ff ff 00 00 00 00 00
 749 *				E: 000040.883381 9 11 00 ff ff 00 00 00 00 00
 750 *				E: 000040.885463 9 11 00 aa 02 00 00 00 00 00
 751 *				E: 000040.924106 9 11 00 ea ff 00 00 00 00 00
 752 *				E: 000041.006155 9 11 00 f6 ff 00 00 00 00 00
 753 *				E: 000041.085799 9 11 00 f6 ff 00 00 00 00 00
 754 *				E: 000041.168492 9 11 00 f6 ff 00 00 00 00 00
 755 *				E: 000041.233453 9 11 00 f3 ff 00 00 00 00 00
 756 *				E: 000041.296641 9 11 00 f3 ff 00 00 00 00 00
 757 *				E: 000041.370302 9 11 00 f5 ff 00 00 00 00 00
 758 *				E: 000041.437410 9 11 00 f4 ff 00 00 00 00 00
 759 *				E: 000041.474514 9 11 00 e9 ff 00 00 00 00 00
 760 *				E: 000041.522171 9 11 00 ef ff 00 00 00 00 00
 761 *				E: 000041.568160 9 11 00 ee ff 00 00 00 00 00
 762 *				E: 000041.608146 9 11 00 ec ff 00 00 00 00 00
 763 *				E: 000041.627132 9 11 00 d3 ff 00 00 00 00 00
 764 *				E: 000041.656151 9 11 00 e3 ff 00 00 00 00 00
 765 *				E: 000041.682264 9 11 00 e0 ff 00 00 00 00 00
 766 *				E: 000041.714186 9 11 00 e6 ff 00 00 00 00 00
 767 *				E: 000041.740339 9 11 00 e0 ff 00 00 00 00 00
 768 *				E: 000041.772087 9 11 00 e5 ff 00 00 00 00 00
 769 *				E: 000041.801093 9 11 00 e3 ff 00 00 00 00 00
 770 *				E: 000041.834051 9 11 00 e7 ff 00 00 00 00 00
 771 *				E: 000041.863094 9 11 00 e3 ff 00 00 00 00 00
 772 *				E: 000041.901016 9 11 00 ea ff 00 00 00 00 00
 773 *				E: 000041.901956 9 11 00 00 04 00 00 00 00 00
 774 *				E: 000041.902837 9 11 00 00 fe 00 00 00 00 00
 775 *				E: 000041.903927 9 11 00 01 00 00 00 00 00 00
 776 *				E: 000041.905066 9 11 00 01 00 00 00 00 00 00
 777 *				E: 000041.907214 9 11 00 00 fe 00 00 00 00 00
 778 *				E: 000041.909011 9 11 00 01 00 00 00 00 00 00
 779 *				E: 000041.909953 9 11 00 01 00 00 00 00 00 00
 780 *				E: 000041.910917 9 11 00 00 08 00 00 00 00 00
 781 *				E: 000041.913280 9 11 00 00 fe 00 00 00 00 00
 782 *				E: 000041.914121 9 11 00 56 fd 00 00 00 00 00
 783 *				E: 000041.915346 9 11 00 ff ff 00 00 00 00 00
 784 *				E: 000041.962101 9 11 00 ee ff 00 00 00 00 00
 785 *				E: 000041.964062 9 11 00 56 fd 00 00 00 00 00
 786 *				E: 000041.964978 9 11 00 00 fc 00 00 00 00 00
 787 *				E: 000041.968058 9 11 00 24 01 00 00 00 00 00
 788 *				E: 000041.968880 9 11 00 56 fd 00 00 00 00 00
 789 *				E: 000041.970977 9 11 00 aa 02 00 00 00 00 00
 790 *				E: 000041.971932 9 11 00 ff ff 00 00 00 00 00
 791 *				E: 000041.972943 9 11 00 01 00 00 00 00 00 00
 792 *				E: 000041.975291 9 11 00 ff ff 00 00 00 00 00
 793 *				E: 000041.978274 9 11 00 01 00 00 00 00 00 00
 794 *				E: 000042.035079 9 11 00 01 00 00 00 00 00 00
 795 *				E: 000042.041283 9 11 00 ff ff 00 00 00 00 00
 796 *				E: 000042.042057 9 11 00 00 04 00 00 00 00 00
 797 *				E: 000042.045169 9 11 00 ff ff 00 00 00 00 00
 798 *				E: 000042.051242 9 11 00 ff ff 00 00 00 00 00
 799 *				E: 000042.056099 9 11 00 63 ff 00 00 00 00 00
 800 *				E: 000042.106329 9 11 00 ef ff 00 00 00 00 00
 801 *				E: 000042.108601 9 11 00 ff ff 00 00 00 00 00
 802 *				E: 000042.116259 9 11 00 6b 00 00 00 00 00 00
 803 *				E: 000042.119140 9 11 00 55 01 00 00 00 00 00
 804 *				E: 000042.126101 9 11 00 88 ff 00 00 00 00 00
 805 *				E: 000042.158009 9 11 00 e6 ff 00 00 00 00 00
 806 *				E: 000042.172108 9 11 00 be ff 00 00 00 00 00
 807 *				E: 000042.207417 9 11 00 e8 ff 00 00 00 00 00
 808 *				E: 000042.223155 9 11 00 cc ff 00 00 00 00 00
 809 *				E: 000042.255185 9 11 00 e6 ff 00 00 00 00 00
 810 *				E: 000042.276280 9 11 00 d7 ff 00 00 00 00 00
 811 *				E: 000042.302128 9 11 00 e0 ff 00 00 00 00 00
 812 *				E: 000042.317423 9 11 00 c8 ff 00 00 00 00 00
 813 *				E: 000042.345226 9 11 00 e1 ff 00 00 00 00 00
 814 *				E: 000042.357243 9 11 00 bc ff 00 00 00 00 00
 815 *				E: 000042.381308 9 11 00 dc ff 00 00 00 00 00
 816 *				E: 000042.383180 9 11 00 dc fe 00 00 00 00 00
 817 *				E: 000042.412288 9 11 00 e3 ff 00 00 00 00 00
 818 *				E: 000042.451216 9 11 00 eb ff 00 00 00 00 00
 819 *				E: 000042.478372 9 11 00 e0 ff 00 00 00 00 00
 820 *				E: 000042.502116 9 11 00 dd ff 00 00 00 00 00
 821 *				E: 000042.520105 9 11 00 d3 ff 00 00 00 00 00
 822 *				E: 000042.540345 9 11 00 d6 ff 00 00 00 00 00
 823 *				E: 000042.541021 9 11 00 00 08 00 00 00 00 00
 824 *				E: 000042.542009 9 11 00 01 00 00 00 00 00 00
 825 *				E: 000042.543045 9 11 00 00 04 00 00 00 00 00
 826 *				E: 000042.544279 9 11 00 ff ff 00 00 00 00 00
 827 *				E: 000042.545097 9 11 00 ff ff 00 00 00 00 00
 828 *				E: 000042.546074 9 11 00 00 08 00 00 00 00 00
 829 *				E: 000042.547237 9 11 00 00 08 00 00 00 00 00
 830 *				E: 000042.548029 9 11 00 ff ff 00 00 00 00 00
 831 *				E: 000042.549304 9 11 00 00 f8 00 00 00 00 00
 832 *				E: 000042.553123 9 11 00 00 ff 00 00 00 00 00
 833 *				E: 000042.581186 9 11 00 e1 ff 00 00 00 00 00
 834 *				E: 000042.582238 9 11 00 00 f8 00 00 00 00 00
 835 *				E: 000042.583150 9 11 00 00 fc 00 00 00 00 00
 836 *				E: 000042.584273 9 11 00 00 f8 00 00 00 00 00
 837 *				E: 000042.585019 9 11 00 00 fc 00 00 00 00 00
 838 *				E: 000042.586059 9 11 00 01 00 00 00 00 00 00
 839 *				E: 000042.589012 9 11 00 67 fe 00 00 00 00 00
 840 *				E: 000042.590066 9 11 00 00 fc 00 00 00 00 00
 841 *				E: 000042.592916 9 11 00 dc fe 00 00 00 00 00
 842 *				E: 000042.621124 9 11 00 e1 ff 00 00 00 00 00
 843 *				E: 000042.622092 9 11 00 ff ff 00 00 00 00 00
 844 *				E: 000042.623069 9 11 00 01 00 00 00 00 00 00
 845 *				E: 000042.624030 9 11 00 ff ff 00 00 00 00 00
 846 *				E: 000042.625006 9 11 00 00 08 00 00 00 00 00
 847 *				E: 000042.626068 9 11 00 00 04 00 00 00 00 00
 848 *				E: 000042.626876 9 11 00 00 08 00 00 00 00 00
 849 *				E: 000042.628392 9 11 00 00 08 00 00 00 00 00
 850 *				E: 000042.628918 9 11 00 01 00 00 00 00 00 00
 851 *				E: 000042.630009 9 11 00 ff ff 00 00 00 00 00
 852 *				E: 000042.631934 9 11 00 00 fe 00 00 00 00 00
 853 *				E: 000042.656285 9 11 00 dd ff 00 00 00 00 00
 854 *				E: 000042.659870 9 11 00 cc 00 00 00 00 00 00
 855 *				E: 000042.666128 9 11 00 9d 00 00 00 00 00 00
 856 *				E: 000042.672458 9 11 00 80 ff 00 00 00 00 00
 857 *				E: 000042.696106 9 11 00 dc ff 00 00 00 00 00
 858 *				E: 000042.705129 9 11 00 61 00 00 00 00 00 00
 859 *				E: 000042.731303 9 11 00 e0 ff 00 00 00 00 00
 860 *				E: 000042.741278 9 11 00 ab ff 00 00 00 00 00
 861 *				E: 000042.788181 9 11 00 ee ff 00 00 00 00 00
 862 *				E: 000042.810441 9 11 00 db ff 00 00 00 00 00
 863 *				E: 000042.838073 9 11 00 e1 ff 00 00 00 00 00
 864 *				E: 000042.852235 9 11 00 c4 ff 00 00 00 00 00
 865 *				E: 000042.882290 9 11 00 e4 ff 00 00 00 00 00
 866 *
 867 *			Either wheel button, press, hold, then release
 868 *				E: 000202.084982 9 11 02 00 00 00 00 00 00 00
 869 *				E: 000202.090172 9 11 03 00 00 00 00 00 00 00
 870 *				E: 000202.094139 9 11 03 00 00 00 00 00 00 00
 871 *				E: 000202.099172 9 11 03 00 00 00 00 00 00 00
 872 *				E: 000202.105055 9 11 03 00 00 00 00 00 00 00
 873 *				E: 000202.109132 9 11 03 00 00 00 00 00 00 00
 874 *				E: 000202.114185 9 11 03 00 00 00 00 00 00 00
 875 *				E: 000202.119212 9 11 03 00 00 00 00 00 00 00
 876 *				E: 000202.124264 9 11 03 00 00 00 00 00 00 00
 877 *				E: 000202.130147 9 11 03 00 00 00 00 00 00 00
 878 *				E: 000202.135138 9 11 03 00 00 00 00 00 00 00
 879 *				E: 000202.140072 9 11 03 00 00 00 00 00 00 00
 880 *				E: 000202.145146 9 11 03 00 00 00 00 00 00 00
 881 *				E: 000202.150157 9 11 03 00 00 00 00 00 00 00
 882 *				E: 000202.155339 9 11 03 00 00 00 00 00 00 00
 883 *				E: 000202.160064 9 11 03 00 00 00 00 00 00 00
 884 *				E: 000202.165026 9 11 03 00 00 00 00 00 00 00
 885 *				E: 000202.170037 9 11 03 00 00 00 00 00 00 00
 886 *				E: 000202.175154 9 11 03 00 00 00 00 00 00 00
 887 *				E: 000202.180044 9 11 03 00 00 00 00 00 00 00
 888 *				E: 000202.186280 9 11 03 00 00 00 00 00 00 00
 889 *				E: 000202.191281 9 11 03 00 00 00 00 00 00 00
 890 *				E: 000202.196106 9 11 03 00 00 00 00 00 00 00
 891 *				E: 000202.201083 9 11 03 00 00 00 00 00 00 00
 892 *				E: 000202.206166 9 11 03 00 00 00 00 00 00 00
 893 *				E: 000202.211084 9 11 03 00 00 00 00 00 00 00
 894 *				E: 000202.216175 9 11 03 00 00 00 00 00 00 00
 895 *				E: 000202.221036 9 11 03 00 00 00 00 00 00 00
 896 *				E: 000202.226271 9 11 03 00 00 00 00 00 00 00
 897 *				E: 000202.231150 9 11 03 00 00 00 00 00 00 00
 898 *				E: 000202.235924 9 11 03 00 00 00 00 00 00 00
 899 *				E: 000202.242046 9 11 03 00 00 00 00 00 00 00
 900 *				E: 000202.247164 9 11 03 00 00 00 00 00 00 00
 901 *				E: 000202.252359 9 11 03 00 00 00 00 00 00 00
 902 *				E: 000202.257295 9 11 03 00 00 00 00 00 00 00
 903 *				E: 000202.262167 9 11 03 00 00 00 00 00 00 00
 904 *				E: 000202.267081 9 11 03 00 00 00 00 00 00 00
 905 *				E: 000202.272175 9 11 03 00 00 00 00 00 00 00
 906 *				E: 000202.277085 9 11 03 00 00 00 00 00 00 00
 907 *				E: 000202.282596 9 11 03 00 00 00 00 00 00 00
 908 *				E: 000202.287078 9 11 03 00 00 00 00 00 00 00
 909 *				E: 000202.292191 9 11 03 00 00 00 00 00 00 00
 910 *				E: 000202.298196 9 11 03 00 00 00 00 00 00 00
 911 *				E: 000202.303004 9 11 03 00 00 00 00 00 00 00
 912 *				E: 000202.308113 9 11 03 00 00 00 00 00 00 00
 913 *				E: 000202.313079 9 11 03 00 00 00 00 00 00 00
 914 *				E: 000202.318243 9 11 03 00 00 00 00 00 00 00
 915 *				E: 000202.323309 9 11 03 00 00 00 00 00 00 00
 916 *				E: 000202.328190 9 11 03 00 00 00 00 00 00 00
 917 *				E: 000202.333050 9 11 03 00 00 00 00 00 00 00
 918 *				E: 000202.338162 9 11 03 00 00 00 00 00 00 00
 919 *				E: 000202.343022 9 11 03 00 00 00 00 00 00 00
 920 *				E: 000202.348113 9 11 03 00 00 00 00 00 00 00
 921 *				E: 000202.354133 9 11 03 00 00 00 00 00 00 00
 922 *				E: 000202.359132 9 11 03 00 00 00 00 00 00 00
 923 *				E: 000202.364053 9 11 03 00 00 00 00 00 00 00
 924 *				E: 000202.369034 9 11 03 00 00 00 00 00 00 00
 925 *				E: 000202.374144 9 11 03 00 00 00 00 00 00 00
 926 *				E: 000202.379027 9 11 03 00 00 00 00 00 00 00
 927 *				E: 000202.384238 9 11 03 00 00 00 00 00 00 00
 928 *				E: 000202.389249 9 11 03 00 00 00 00 00 00 00
 929 *				E: 000202.394049 9 11 03 00 00 00 00 00 00 00
 930 *				E: 000202.398949 9 11 03 00 00 00 00 00 00 00
 931 *				E: 000202.404203 9 11 03 00 00 00 00 00 00 00
 932 *				E: 000202.410098 9 11 03 00 00 00 00 00 00 00
 933 *				E: 000202.415237 9 11 00 00 00 00 00 00 00 00
 934 *
 935 *
 936 *			Top wheel button press and release while holding bottom wheel button
 937 *				(The reverse action (a bottom wheel button press while holding the top wheel button) is invisible.)
 938 *				E: 000071.126966 9 11 03 00 00 00 00 00 00 00
 939 *				E: 000071.133117 9 11 03 00 00 00 00 00 00 00
 940 *				E: 000071.137481 9 11 03 00 00 00 00 00 00 00
 941 *				E: 000071.142036 9 11 03 00 00 00 00 00 00 00
 942 *				E: 000071.147027 9 11 03 00 00 00 00 00 00 00
 943 *				E: 000071.151988 9 11 03 00 00 00 00 00 00 00
 944 *				E: 000071.157945 9 11 03 00 00 00 00 00 00 00
 945 *				E: 000071.163657 9 11 03 00 00 00 00 00 00 00
 946 *				E: 000071.168240 9 11 03 00 00 00 00 00 00 00
 947 *				E: 000071.173109 9 11 02 00 00 00 00 00 00 00 < top wheel button press?
 948 *				E: 000071.178119 9 11 03 00 00 00 00 00 00 00
 949 *				E: 000071.183046 9 11 03 00 00 00 00 00 00 00
 950 *				E: 000071.187983 9 11 03 00 00 00 00 00 00 00
 951 *				E: 000071.192996 9 11 03 00 00 00 00 00 00 00
 952 *				E: 000071.198341 9 11 03 00 00 00 00 00 00 00
 953 *				E: 000071.203122 9 11 03 00 00 00 00 00 00 00
 954 *				E: 000071.208998 9 11 03 00 00 00 00 00 00 00
 955 *				E: 000071.214037 9 11 03 00 00 00 00 00 00 00
 956 *				E: 000071.218945 9 11 03 00 00 00 00 00 00 00
 957 *				E: 000071.223835 9 11 03 00 00 00 00 00 00 00
 958 *				E: 000071.228987 9 11 03 00 00 00 00 00 00 00
 959 *				E: 000071.234082 9 11 03 00 00 00 00 00 00 00
 960 *				E: 000071.239028 9 11 03 00 00 00 00 00 00 00
 961 *				E: 000071.244307 9 11 00 00 00 00 00 00 00 00 < top wheel button release?
 962 *				E: 000071.245867 9 11 03 00 00 00 00 00 00 00 < continued hold of bottom button
 963 *				E: 000071.249959 9 11 03 00 00 00 00 00 00 00
 964 *				E: 000071.255032 9 11 03 00 00 00 00 00 00 00
 965 *				E: 000071.259972 9 11 03 00 00 00 00 00 00 00
 966 *				E: 000071.265409 9 11 03 00 00 00 00 00 00 00
 967 *				E: 000071.270156 9 11 03 00 00 00 00 00 00 00
 968 *				E: 000071.275530 9 11 03 00 00 00 00 00 00 00
 969 *				E: 000071.279975 9 11 03 00 00 00 00 00 00 00
 970 *				E: 000071.285046 9 11 03 00 00 00 00 00 00 00
 971 *				E: 000071.290906 9 11 03 00 00 00 00 00 00 00
 972 *				E: 000071.296146 9 11 03 00 00 00 00 00 00 00
 973 *				E: 000071.301288 9 11 03 00 00 00 00 00 00 00
 974 *
 975 *			Top wheel button hold while top wheel rotate CCW
 976 *				(I did not test the other combinations of this)
 977 *				E: 000022.253144 9 11 03 00 00 00 00 00 00 00
 978 *				E: 000022.258157 9 11 03 00 00 00 00 00 00 00
 979 *				E: 000022.262011 9 11 00 ff ff 00 00 00 00 00
 980 *				E: 000022.264015 9 11 03 00 00 00 00 00 00 00
 981 *				E: 000022.268976 9 11 03 00 00 00 00 00 00 00
 982 *
 983 *
 984 *
 985 *
 986 *
 987 *
 988 *
 989 *
 990 * NOTES ON SIMULTANEOUS BUTTON HOLDS
 991 *	(applies to vendor mode only)
 992 *	Value replacements for ease of reading:
 993 *		.7 = 0x40 (button 7, a wheel button)
 994 *		.1 = 0x01 (button 1, a pad button)
 995 *		rr = 0x00 (no buttons pressed)
 996 *
 997 *	Press 7
 998 *	Press 1
 999 *	Release 7
1000 *	Release 1
1001 *		B: 000000.000152 42 08 e0 01 01    .7 00 00 00 00 00 00 00 00 00
1002 *		B: 000000.781784 42 08 e0 01 01    .1 00 00 00 00 00 00 00 00 00
1003 *		B: 000000.869845 42 08 e0 01 01    .1 00 00 00 00 00 00 00 00 00
1004 *		B: 000001.095688 42 08 e0 01 01    .1 00 00 00 00 00 00 00 00 00
1005 *		B: 000001.322635 42 08 e0 01 01    .1 00 00 00 00 00 00 00 00 00
1006 *		B: 000001.543643 42 08 e0 01 01    .1 00 00 00 00 00 00 00 00 00
1007 *		B: 000001.770652 42 08 e0 01 01    .1 00 00 00 00 00 00 00 00 00
1008 *		B: 000001.885659 42 08 e0 01 01    rr 00 00 00 00 00 00 00 00 00	release of 7
1009 *		B: 000001.993620 42 08 e0 01 01    .1 00 00 00 00 00 00 00 00 00
1010 *		B: 000002.220671 42 08 e0 01 01    .1 00 00 00 00 00 00 00 00 00
1011 *		B: 000002.446589 42 08 e0 01 01    .1 00 00 00 00 00 00 00 00 00
1012 *		B: 000002.672559 42 08 e0 01 01    .1 00 00 00 00 00 00 00 00 00
1013 *		B: 000002.765183 42 08 e0 01 01    rr 00 00 00 00 00 00 00 00 00	release of 1
1014 *
1015 *	Press 7
1016 *	Press 1
1017 *	Release 1
1018 *	Release 7
1019 *		B: 000017.071517 42 08 e0 01 01    .7 00 00 00 00 00 00 00 00 00
1020 *		B: 000018.270461 42 08 e0 01 01    .1 00 00 00 00 00 00 00 00 00
1021 *		B: 000018.419486 42 08 e0 01 01    .1 00 00 00 00 00 00 00 00 00
1022 *		B: 000018.646438 42 08 e0 01 01    .1 00 00 00 00 00 00 00 00 00
1023 *		B: 000018.872493 42 08 e0 01 01    .1 00 00 00 00 00 00 00 00 00
1024 *		B: 000019.094422 42 08 e0 01 01    .1 00 00 00 00 00 00 00 00 00
1025 *		B: 000019.320488 42 08 e0 01 01    .1 00 00 00 00 00 00 00 00 00
1026 *		B: 000020.360505 42 08 e0 01 01    rr 00 00 00 00 00 00 00 00 00	release of 1 is not reported until 7 is released, then both are rapidly reported
1027 *		B: 000020.361091 42 08 e0 01 01    rr 00 00 00 00 00 00 00 00 00
1028 *
1029 *	Press 1
1030 *	Press 7
1031 *	Release 7
1032 *	Release 1
1033 *		B: 000031.516315 42 08 e0 01 01    .1 00 00 00 00 00 00 00 00 00
1034 *		B: 000031.922299 42 08 e0 01 01    .1 00 00 00 00 00 00 00 00 00
1035 *		B: 000032.144165 42 08 e0 01 01    .1 00 00 00 00 00 00 00 00 00
1036 *		B: 000032.370262 42 08 e0 01 01    .1 00 00 00 00 00 00 00 00 00
1037 *		B: 000032.396242 42 08 e0 01 01    .7 00 00 00 00 00 00 00 00 00
1038 *		B: 000032.597270 42 08 e0 01 01    .1 00 00 00 00 00 00 00 00 00
1039 *		B: 000032.818187 42 08 e0 01 01    .1 00 00 00 00 00 00 00 00 00
1040 *		B: 000033.045143 42 08 e0 01 01    .1 00 00 00 00 00 00 00 00 00
1041 *		B: 000033.267535 42 08 e0 01 01    rr 00 00 00 00 00 00 00 00 00	release of 7
1042 *		B: 000033.272602 42 08 e0 01 01    .1 00 00 00 00 00 00 00 00 00
1043 *		B: 000033.494246 42 08 e0 01 01    .1 00 00 00 00 00 00 00 00 00
1044 *		B: 000033.721266 42 08 e0 01 01    .1 00 00 00 00 00 00 00 00 00
1045 *		B: 000033.947237 42 08 e0 01 01    .1 00 00 00 00 00 00 00 00 00
1046 *		B: 000034.169294 42 08 e0 01 01    .1 00 00 00 00 00 00 00 00 00
1047 *		B: 000034.183585 42 08 e0 01 01    rr 00 00 00 00 00 00 00 00 00	release of 1
1048 *
1049 *	Press 1
1050 *	Press 7
1051 *	Release 1
1052 *	Release 7
1053 *		B: 000056.628429 42 08 e0 01 01    .1 00 00 00 00 00 00 00 00 00
1054 *		B: 000057.046348 42 08 e0 01 01    .1 00 00 00 00 00 00 00 00 00
1055 *		B: 000057.272044 42 08 e0 01 01    .1 00 00 00 00 00 00 00 00 00
1056 *		B: 000057.494434 42 08 e0 01 01    .1 00 00 00 00 00 00 00 00 00
1057 *		B: 000057.601224 42 08 e0 01 01    .7 00 00 00 00 00 00 00 00 00
1058 *		B: 000057.719262 42 08 e0 01 01    .1 00 00 00 00 00 00 00 00 00
1059 *		B: 000057.946941 42 08 e0 01 01    .1 00 00 00 00 00 00 00 00 00
1060 *		B: 000058.172346 42 08 e0 01 01    .1 00 00 00 00 00 00 00 00 00
1061 *		B: 000058.393994 42 08 e0 01 01    .1 00 00 00 00 00 00 00 00 00
1062 *		B: 000059.434576 42 08 e0 01 01    rr 00 00 00 00 00 00 00 00 00	release of 1 is not reported until 7 is released, then both are rapidly reported
1063 *		B: 000059.435857 42 08 e0 01 01    rr 00 00 00 00 00 00 00 00 00
1064 */
1065
1066
1067/* Filled in by udev-hid-bpf */
1068char UDEV_PROP_HUION_FIRMWARE_ID[64];
1069
1070char EXPECTED_FIRMWARE_ID[] = "HUION_M22c_";
1071
1072__u8 last_button_state;
1073
1074static const __u8 disabled_rdesc_tablet[] = {
1075	FixedSizeVendorReport(28)	/* Input report 4 */
1076};
1077
1078static const __u8 disabled_rdesc_wheel[] = {
1079	FixedSizeVendorReport(9)	/* Input report 17 */
1080};
1081
1082static const __u8 fixed_rdesc_vendor[] = {
1083	UsagePage_Digitizers
1084	Usage_Dig_Pen
1085	CollectionApplication(
1086		ReportId(VENDOR_REPORT_ID)
1087		UsagePage_Digitizers
1088		Usage_Dig_Pen
1089		CollectionPhysical(
1090			/*
1091			 * I have only examined the tablet's behavior while using
1092			 * the PW600L pen, which does not have an eraser.
1093			 * Because of this, I don't know where the Eraser and Invert
1094			 * bits will go, or if they work as one would expect.
1095			 *
1096			 * For the time being, there is no expectation that a pen
1097			 * with an eraser will work without modifications here.
1098			 */
1099			ReportSize(1)
1100			LogicalMinimum_i8(0)
1101			LogicalMaximum_i8(1)
1102			ReportCount(3)
1103			Usage_Dig_TipSwitch
1104			Usage_Dig_BarrelSwitch
1105			Usage_Dig_SecondaryBarrelSwitch
1106			Input(Var|Abs)
1107			PushPop(
1108				ReportCount(1)
1109				UsagePage_Button
1110				Usage_i8(0x4a)	/* (BTN_STYLUS3 + 1) & 0xff */
1111				Input(Var|Abs)
1112			)
1113			ReportCount(3)
1114			Input(Const)
1115			ReportCount(1)
1116			Usage_Dig_InRange
1117			Input(Var|Abs)
1118			ReportSize(16)
1119			ReportCount(1)
1120			PushPop(
1121				UsagePage_GenericDesktop
1122				Unit(cm)
1123				UnitExponent(-2)
1124				LogicalMinimum_i16(0)
1125				PhysicalMinimum_i16(0)
1126				/*
1127				 * The tablet has a logical maximum of 58760 x 33040
1128				 * and a claimed resolution of 5080 LPI (200 L/mm)
1129				 * This works out to a physical maximum of
1130				 * 293.8 x 165.2mm, which matches Huion's advertised
1131				 * active area dimensions from
1132				 * https://www.huion.com/products/pen_display/Kamvas/kamvas-13-gen-3.html
1133				 */
1134				LogicalMaximum_i16(58760)
1135				PhysicalMaximum_i16(2938)
1136				Usage_GD_X
1137				Input(Var|Abs)
1138				LogicalMaximum_i16(33040)
1139				PhysicalMaximum_i16(1652)
1140				Usage_GD_Y
1141				Input(Var|Abs)
1142			)
1143			LogicalMinimum_i16(0)
1144			LogicalMaximum_i16(16383)
1145			Usage_Dig_TipPressure
1146			Input(Var|Abs)
1147			ReportCount(1)
1148			Input(Const)
1149			ReportSize(8)
1150			ReportCount(2)
1151			PushPop(
1152				Unit(deg)
1153				UnitExponent(0)
1154				LogicalMinimum_i8(-60)
1155				PhysicalMinimum_i8(-60)
1156				LogicalMaximum_i8(60)
1157				PhysicalMaximum_i8(60)
1158				Usage_Dig_XTilt
1159				Usage_Dig_YTilt
1160				Input(Var|Abs)
1161			)
1162		)
1163	)
1164	UsagePage_GenericDesktop
1165	Usage_GD_Keypad
1166	CollectionApplication(
1167		ReportId(CUSTOM_PAD_REPORT_ID)
1168		LogicalMinimum_i8(0)
1169		LogicalMaximum_i8(1)
1170		UsagePage_Digitizers
1171		Usage_Dig_TabletFunctionKeys
1172		CollectionPhysical(
1173			/*
1174			 * The first 3 bytes are somewhat vestigial and will
1175			 * always be set to zero. Their presence here is needed
1176			 * to ensure that this device will be detected as a
1177			 * tablet pad by software that otherwise wouldn't know
1178			 * any better.
1179			 */
1180			/* (data[1] & 0x01)	barrel switch */
1181			ReportSize(1)
1182			ReportCount(1)
1183			Usage_Dig_BarrelSwitch
1184			Input(Var|Abs)
1185			ReportCount(7)
1186			Input(Const)
1187			/* data[2]	X */
1188			/* data[3]	Y */
1189			ReportSize(8)
1190			ReportCount(2)
1191			UsagePage_GenericDesktop
1192			Usage_GD_X
1193			Usage_GD_Y
1194			Input(Var|Abs)
1195			/*
1196			 * (data[4] & 0x01)	button 1
1197			 * (data[4] & 0x02)	button 2
1198			 * (data[4] & 0x04)	button 3
1199			 * (data[4] & 0x08)	button 4
1200			 * (data[4] & 0x10)	button 5
1201			 * (data[4] & 0x20)	button 6 (top wheel button)
1202			 * (data[4] & 0x40)	button 7 (bottom wheel button)
1203			 */
1204			ReportSize(1)
1205			ReportCount(7)
1206			UsagePage_Button
1207			UsageMinimum_i8(1)
1208			UsageMaximum_i8(7)
1209			Input(Var|Abs)
1210			ReportCount(1)
1211			Input(Const)
1212			/* data[5]	top wheel (signed, positive clockwise) */
1213			ReportSize(8)
1214			ReportCount(1)
1215			UsagePage_GenericDesktop
1216			Usage_GD_Wheel
1217			LogicalMinimum_i8(-1)
1218			LogicalMaximum_i8(1)
1219			Input(Var|Rel)
1220			/* data[6]	bottom wheel (signed, positive clockwise) */
1221			UsagePage_Consumer
1222			Usage_Con_ACPan
1223			Input(Var|Rel)
1224		)
1225		/*
1226		 * The kernel will drop reports that are bigger than the
1227		 * largest report specified in the HID descriptor.
1228		 * Therefore, our modified descriptor needs to have at least one
1229		 * HID report that is as long as, or longer than, the largest
1230		 * report in the original descriptor.
1231		 *
1232		 * This macro expands to a no-op report that is padded to the
1233		 * provided length.
1234		 */
1235		FixedSizeVendorReport(VENDOR_REPORT_LENGTH)
1236	)
1237};
1238
1239SEC(HID_BPF_RDESC_FIXUP)
1240int BPF_PROG(hid_fix_rdesc_huion_kamvas13_gen3, struct hid_bpf_ctx *hid_ctx)
1241{
1242	__u8 *data = hid_bpf_get_data(hid_ctx, 0 /* offset */, HID_MAX_DESCRIPTOR_SIZE /* size */);
1243	__s32 rdesc_size = hid_ctx->size;
1244	__u8 have_fw_id;
1245
1246	if (!data)
1247		return 0; /* EPERM check */
1248
1249	have_fw_id = __builtin_memcmp(UDEV_PROP_HUION_FIRMWARE_ID,
1250					EXPECTED_FIRMWARE_ID,
1251					sizeof(EXPECTED_FIRMWARE_ID) - 1) == 0;
1252
1253	if (have_fw_id) {
1254		/*
1255		 * Tablet should be in vendor mode.
1256		 * Disable the unused devices
1257		 */
1258		if (rdesc_size == TABLET_DESCRIPTOR_LENGTH) {
1259			__builtin_memcpy(data, disabled_rdesc_tablet,
1260					 sizeof(disabled_rdesc_tablet));
1261			return sizeof(disabled_rdesc_tablet);
1262		}
1263
1264		if (rdesc_size == WHEEL_DESCRIPTOR_LENGTH) {
1265			__builtin_memcpy(data, disabled_rdesc_wheel,
1266					 sizeof(disabled_rdesc_wheel));
1267			return sizeof(disabled_rdesc_wheel);
1268		}
1269	}
1270
1271	/*
1272	 * Regardless of which mode the tablet is in, always fix the vendor
1273	 * descriptor in case the udev property just happened to not be set
1274	 */
1275	if (rdesc_size == VENDOR_DESCRIPTOR_LENGTH) {
1276		__builtin_memcpy(data, fixed_rdesc_vendor, sizeof(fixed_rdesc_vendor));
1277		return sizeof(fixed_rdesc_vendor);
1278	}
1279
1280	return 0;
1281}
1282
1283SEC(HID_BPF_DEVICE_EVENT)
1284int BPF_PROG(hid_fix_event_huion_kamvas13_gen3, struct hid_bpf_ctx *hid_ctx)
1285{
1286	__u8 *data = hid_bpf_get_data(hid_ctx, 0 /* offset */, VENDOR_REPORT_LENGTH /* size */);
1287
1288	if (!data)
1289		return 0; /* EPERM check */
1290
1291	/* Handle vendor reports only */
1292	if (hid_ctx->size != VENDOR_REPORT_LENGTH)
1293		return 0;
1294	if (data[0] != VENDOR_REPORT_ID)
1295		return 0;
1296
1297	__u8 report_subtype = (data[1] >> 4) & 0x0f;
1298
1299	if (report_subtype == VENDOR_REPORT_SUBTYPE_PEN ||
1300	    report_subtype == VENDOR_REPORT_SUBTYPE_PEN_OUT) {
1301		/* Invert Y tilt */
1302		data[11] = -data[11];
1303
1304	} else if (report_subtype == VENDOR_REPORT_SUBTYPE_BUTTONS ||
1305		   report_subtype == VENDOR_REPORT_SUBTYPE_WHEELS) {
1306		struct pad_report {
1307			__u8 report_id;
1308			__u8 btn_stylus:1;
1309			__u8 padding:7;
1310			__u8 x;
1311			__u8 y;
1312			__u8 buttons;
1313			__s8 top_wheel;
1314			__s8 bottom_wheel;
1315		} __attribute__((packed)) *pad_report;
1316
1317		__s8 top_wheel = 0;
1318		__s8 bottom_wheel = 0;
1319
1320		switch (report_subtype) {
1321		case VENDOR_REPORT_SUBTYPE_WHEELS:
1322			/*
1323			 * The wheel direction byte is 1 for clockwise rotation
1324			 * and 2 for counter-clockwise.
1325			 * Change it to 1 and -1, respectively.
1326			 */
1327			switch (data[3]) {
1328			case 1:
1329				top_wheel = (data[5] == 1) ? 1 : -1;
1330				break;
1331			case 2:
1332				bottom_wheel = (data[5] == 1) ? 1 : -1;
1333				break;
1334			}
1335			break;
1336
1337		case VENDOR_REPORT_SUBTYPE_BUTTONS:
1338			/*
1339			 * If a button is already being held, ignore any new
1340			 * button event unless it's a release.
1341			 *
1342			 * The tablet only cleanly handles one button being held
1343			 * at a time, and trying to hold multiple buttons
1344			 * (particularly wheel+pad buttons) can result in sequences
1345			 * of reports that look like imaginary presses and releases.
1346			 *
1347			 * This is an imperfect way to filter out some of these
1348			 * reports.
1349			 */
1350			if (last_button_state != 0x00 && data[4] != 0x00)
1351				break;
1352
1353			last_button_state = data[4];
1354			break;
1355		}
1356
1357
1358		pad_report = (struct pad_report *)data;
1359
1360		pad_report->report_id = CUSTOM_PAD_REPORT_ID;
1361		pad_report->btn_stylus = 0;
1362		pad_report->x = 0;
1363		pad_report->y = 0;
1364		pad_report->buttons = last_button_state;
1365		pad_report->top_wheel = top_wheel;
1366		pad_report->bottom_wheel = bottom_wheel;
1367
1368		return sizeof(struct pad_report);
1369	}
1370
1371	return 0;
1372}
1373
1374HID_BPF_OPS(huion_kamvas13_gen3) = {
1375	.hid_device_event = (void *)hid_fix_event_huion_kamvas13_gen3,
1376	.hid_rdesc_fixup = (void *)hid_fix_rdesc_huion_kamvas13_gen3,
1377};
1378
1379SEC("syscall")
1380int probe(struct hid_bpf_probe_args *ctx)
1381{
1382	switch (ctx->rdesc_size) {
1383	case VENDOR_DESCRIPTOR_LENGTH:
1384	case TABLET_DESCRIPTOR_LENGTH:
1385	case WHEEL_DESCRIPTOR_LENGTH:
1386		ctx->retval = 0;
1387		break;
1388	default:
1389		ctx->retval = -EINVAL;
1390	}
1391
1392	return 0;
1393}
1394
1395char _license[] SEC("license") = "GPL";
~/ Read-only file preview.