7
7
sys .path .append ("../../tools/usb_descriptor" )
8
8
9
9
from adafruit_usb_descriptor import cdc , hid , msc , standard , util
10
+ import hid_report_descriptors
10
11
11
12
parser = argparse .ArgumentParser (description = 'Generate USB descriptors.' )
12
13
parser .add_argument ('--manufacturer' , type = str ,
@@ -122,32 +123,43 @@ def strings_in_order(cls):
122
123
standard .EndpointDescriptor (
123
124
description = "MSC in" ,
124
125
bEndpointAddress = 0x0 | standard .EndpointDescriptor .DIRECTION_IN ,
125
- bmAttributes = standard .EndpointDescriptor .TYPE_BULK ),
126
+ bmAttributes = standard .EndpointDescriptor .TYPE_BULK ,
127
+ bInterval = 0 ),
126
128
standard .EndpointDescriptor (
127
129
description = "MSC out" ,
128
130
bEndpointAddress = 0x1 | standard .EndpointDescriptor .DIRECTION_OUT ,
129
- bmAttributes = standard .EndpointDescriptor .TYPE_BULK )
131
+ bmAttributes = standard .EndpointDescriptor .TYPE_BULK ,
132
+ bInterval = 0 )
130
133
]
131
134
)
132
135
]
133
136
134
- hid_report_descriptor = hid .ReportDescriptor .MOUSE_KEYBOARD_CONSUMER_SYS_CONTROL_REPORT
135
- hid_report_ids = hid .ReportDescriptor .REPORT_IDS
136
- hid_report_lengths = hid .ReportDescriptor .REPORT_LENGTHS
137
- hid_max_report_length = max (hid_report_lengths .values ())
137
+ # Include only these HID devices.
138
+ # DIGITIZER works on Linux but conflicts with MOUSE, so leave it out for now.
139
+ hid_devices = ("KEYBOARD" , "MOUSE" , "CONSUMER" , "GAMEPAD" )
140
+
141
+ combined_hid_report_descriptor = hid .ReportDescriptor (
142
+ description = "MULTIDEVICE" ,
143
+ report_descriptor = b'' .join (
144
+ hid_report_descriptors .REPORT_DESCRIPTORS [name ].report_descriptor for name in hid_devices ))
145
+
146
+ hid_report_ids_dict = { name : hid_report_descriptors .REPORT_IDS [name ] for name in hid_devices }
147
+ hid_report_lengths_dict = { name : hid_report_descriptors .REPORT_LENGTHS [name ] for name in hid_devices }
148
+ hid_max_report_length = max (hid_report_lengths_dict .values ())
138
149
139
150
# ASF4 expects keyboard and generic devices to have both in and out endpoints,
140
151
# and will fail (possibly silently) if both are not supplied.
141
152
hid_endpoint_in_descriptor = standard .EndpointDescriptor (
142
153
description = "HID in" ,
143
154
bEndpointAddress = 0x0 | standard .EndpointDescriptor .DIRECTION_IN ,
144
155
bmAttributes = standard .EndpointDescriptor .TYPE_INTERRUPT ,
145
- bInterval = 0x02 )
156
+ bInterval = 10 )
146
157
147
158
hid_endpoint_out_descriptor = standard .EndpointDescriptor (
148
159
description = "HID out" ,
149
160
bEndpointAddress = 0x0 | standard .EndpointDescriptor .DIRECTION_OUT ,
150
- bmAttributes = standard .EndpointDescriptor .TYPE_INTERRUPT )
161
+ bmAttributes = standard .EndpointDescriptor .TYPE_INTERRUPT ,
162
+ bInterval = 10 )
151
163
152
164
hid_interfaces = [
153
165
standard .InterfaceDescriptor (
@@ -159,7 +171,7 @@ def strings_in_order(cls):
159
171
subdescriptors = [
160
172
hid .HIDDescriptor (
161
173
description = "HID" ,
162
- wDescriptorLength = len (bytes (hid_report_descriptor ))),
174
+ wDescriptorLength = len (bytes (combined_hid_report_descriptor ))),
163
175
hid_endpoint_in_descriptor ,
164
176
hid_endpoint_out_descriptor ,
165
177
]
@@ -274,7 +286,7 @@ def strings_in_order(cls):
274
286
"""
275
287
.format (SERIAL_NUMBER_OFFSET = serial_number_offset ,
276
288
SERIAL_NUMBER_LENGTH = args .serial_number_length ,
277
- HID_REPORT_DESCRIPTOR_LENGTH = len (bytes (hid_report_descriptor )),
289
+ HID_REPORT_DESCRIPTOR_LENGTH = len (bytes (combined_hid_report_descriptor )),
278
290
HID_ENDPOINT_IN_ADDRESS = hex (hid_endpoint_in_descriptor .bEndpointAddress ),
279
291
HID_ENDPOINT_OUT_ADDRESS = hex (hid_endpoint_out_descriptor .bEndpointAddress )))
280
292
@@ -294,7 +306,7 @@ def strings_in_order(cls):
294
306
h_file .write ("\n " )
295
307
296
308
# #define the report ID's used in the combined HID descriptor
297
- for name , id in hid_report_ids .items ():
309
+ for name , id in hid_report_ids_dict .items ():
298
310
h_file .write ("""\
299
311
#define USB_HID_REPORT_ID_{NAME} {ID}
300
312
""" .format (NAME = name ,
@@ -303,7 +315,7 @@ def strings_in_order(cls):
303
315
h_file .write ("\n " )
304
316
305
317
# #define the report sizes used in the combined HID descriptor
306
- for name , length in hid_report_lengths .items ():
318
+ for name , length in hid_report_lengths_dict .items ():
307
319
h_file .write ("""\
308
320
#define USB_HID_REPORT_LENGTH_{NAME} {LENGTH}
309
321
""" .format (NAME = name ,
@@ -314,17 +326,17 @@ def strings_in_order(cls):
314
326
h_file .write ("""\
315
327
#define USB_HID_NUM_DEVICES {NUM_DEVICES}
316
328
#define USB_HID_MAX_REPORT_LENGTH {MAX_LENGTH}
317
- """ .format (NUM_DEVICES = len (hid_report_lengths ),
329
+ """ .format (NUM_DEVICES = len (hid_report_lengths_dict ),
318
330
MAX_LENGTH = hid_max_report_length ))
319
331
320
332
321
333
322
334
# Write out the report descriptor and info
323
335
c_file .write ("""\
324
336
uint8_t hid_report_descriptor[{HID_DESCRIPTOR_LENGTH}] = {{
325
- """ .format (HID_DESCRIPTOR_LENGTH = len (bytes (hid_report_descriptor ))))
337
+ """ .format (HID_DESCRIPTOR_LENGTH = len (bytes (combined_hid_report_descriptor ))))
326
338
327
- for b in bytes (hid_report_descriptor ):
339
+ for b in bytes (combined_hid_report_descriptor ):
328
340
c_file .write ("0x{:02x}, " .format (b ))
329
341
c_file .write ("""
330
342
};
0 commit comments