77sys .path .append ("../../tools/usb_descriptor" )
88
99from adafruit_usb_descriptor import cdc , hid , msc , standard , util
10+ import hid_report_descriptors
1011
1112parser = argparse .ArgumentParser (description = 'Generate USB descriptors.' )
1213parser .add_argument ('--manufacturer' , type = str ,
@@ -122,32 +123,43 @@ def strings_in_order(cls):
122123 standard .EndpointDescriptor (
123124 description = "MSC in" ,
124125 bEndpointAddress = 0x0 | standard .EndpointDescriptor .DIRECTION_IN ,
125- bmAttributes = standard .EndpointDescriptor .TYPE_BULK ),
126+ bmAttributes = standard .EndpointDescriptor .TYPE_BULK ,
127+ bInterval = 0 ),
126128 standard .EndpointDescriptor (
127129 description = "MSC out" ,
128130 bEndpointAddress = 0x1 | standard .EndpointDescriptor .DIRECTION_OUT ,
129- bmAttributes = standard .EndpointDescriptor .TYPE_BULK )
131+ bmAttributes = standard .EndpointDescriptor .TYPE_BULK ,
132+ bInterval = 0 )
130133 ]
131134 )
132135]
133136
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 ())
138149
139150# ASF4 expects keyboard and generic devices to have both in and out endpoints,
140151# and will fail (possibly silently) if both are not supplied.
141152hid_endpoint_in_descriptor = standard .EndpointDescriptor (
142153 description = "HID in" ,
143154 bEndpointAddress = 0x0 | standard .EndpointDescriptor .DIRECTION_IN ,
144155 bmAttributes = standard .EndpointDescriptor .TYPE_INTERRUPT ,
145- bInterval = 0x02 )
156+ bInterval = 10 )
146157
147158hid_endpoint_out_descriptor = standard .EndpointDescriptor (
148159 description = "HID out" ,
149160 bEndpointAddress = 0x0 | standard .EndpointDescriptor .DIRECTION_OUT ,
150- bmAttributes = standard .EndpointDescriptor .TYPE_INTERRUPT )
161+ bmAttributes = standard .EndpointDescriptor .TYPE_INTERRUPT ,
162+ bInterval = 10 )
151163
152164hid_interfaces = [
153165 standard .InterfaceDescriptor (
@@ -159,7 +171,7 @@ def strings_in_order(cls):
159171 subdescriptors = [
160172 hid .HIDDescriptor (
161173 description = "HID" ,
162- wDescriptorLength = len (bytes (hid_report_descriptor ))),
174+ wDescriptorLength = len (bytes (combined_hid_report_descriptor ))),
163175 hid_endpoint_in_descriptor ,
164176 hid_endpoint_out_descriptor ,
165177 ]
@@ -274,7 +286,7 @@ def strings_in_order(cls):
274286"""
275287.format (SERIAL_NUMBER_OFFSET = serial_number_offset ,
276288 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 )),
278290 HID_ENDPOINT_IN_ADDRESS = hex (hid_endpoint_in_descriptor .bEndpointAddress ),
279291 HID_ENDPOINT_OUT_ADDRESS = hex (hid_endpoint_out_descriptor .bEndpointAddress )))
280292
@@ -294,7 +306,7 @@ def strings_in_order(cls):
294306h_file .write ("\n " )
295307
296308# #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 ():
298310 h_file .write ("""\
299311 #define USB_HID_REPORT_ID_{NAME} {ID}
300312""" .format (NAME = name ,
@@ -303,7 +315,7 @@ def strings_in_order(cls):
303315h_file .write ("\n " )
304316
305317# #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 ():
307319 h_file .write ("""\
308320 #define USB_HID_REPORT_LENGTH_{NAME} {LENGTH}
309321""" .format (NAME = name ,
@@ -314,17 +326,17 @@ def strings_in_order(cls):
314326h_file .write ("""\
315327 #define USB_HID_NUM_DEVICES {NUM_DEVICES}
316328#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 ),
318330 MAX_LENGTH = hid_max_report_length ))
319331
320332
321333
322334# Write out the report descriptor and info
323335c_file .write ("""\
324336 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 ))))
326338
327- for b in bytes (hid_report_descriptor ):
339+ for b in bytes (combined_hid_report_descriptor ):
328340 c_file .write ("0x{:02x}, " .format (b ))
329341c_file .write ("""
330342};
0 commit comments