@@ -173,17 +173,21 @@ def strings_in_order(cls):
173173# args.hid_devices[1] has report_id 2
174174# etc.
175175
176+ report_ids = {}
177+
176178if len (args .hid_devices ) == 1 :
177179 name = args .hid_devices [0 ]
178180 combined_hid_report_descriptor = hid .ReportDescriptor (
179181 description = name ,
180182 report_descriptor = bytes (hid_report_descriptors .REPORT_DESCRIPTOR_FUNCTIONS [name ](0 )))
183+ report_ids [name ] = 0
181184else :
182185 report_id = 1
183186 concatenated_descriptors = bytearray ()
184187 for name in args .hid_devices :
185188 concatenated_descriptors .extend (
186189 bytes (hid_report_descriptors .REPORT_DESCRIPTOR_FUNCTIONS [name ](report_id )))
190+ report_ids [name ] = report_id
187191 report_id += 1
188192 combined_hid_report_descriptor = hid .ReportDescriptor (
189193 description = "MULTIDEVICE" ,
@@ -288,10 +292,24 @@ def strings_in_order(cls):
288292# Audio streaming interfaces must occur before MIDI ones.
289293audio_interfaces = [audio_control_interface ] + cs_ac_interface .audio_streaming_interfaces + cs_ac_interface .midi_streaming_interfaces
290294
291- # This will renumber the endpoints to make them unique across descriptors,
295+ interfaces_to_join = []
296+
297+ if 'CDC' in args .devices :
298+ interfaces_to_join .append (cdc_interfaces )
299+
300+ if 'MSC' in args .devices :
301+ interfaces_to_join .append (msc_interfaces )
302+
303+ if 'HID' in args .devices :
304+ interfaces_to_join .append (hid_interfaces )
305+
306+ if 'AUDIO' in args .devices :
307+ interfaces_to_join .append (audio_interfaces )
308+
309+ # util.join_interfaces() will renumber the endpoints to make them unique across descriptors,
292310# and renumber the interfaces in order. But we still need to fix up certain
293311# interface cross-references.
294- interfaces = util .join_interfaces (cdc_interfaces , msc_interfaces , hid_interfaces , audio_interfaces )
312+ interfaces = util .join_interfaces (* interfaces_to_join )
295313
296314# Now adjust the CDC interface cross-references.
297315
@@ -323,13 +341,15 @@ def strings_in_order(cls):
323341if 'MSC' in args .devices :
324342 descriptor_list .extend (msc_interfaces )
325343
344+ if 'HID' in args .devices :
345+ descriptor_list .extend (hid_interfaces )
346+
326347if 'AUDIO' in args .devices :
327348 # Only add the control interface because other audio interfaces are managed by it to ensure the
328349 # correct ordering.
329350 descriptor_list .append (audio_control_interface )
330351
331- if 'HID' in args .devices :
332- descriptor_list .extend (hid_interfaces )
352+ # Finally, build the composite descriptor.
333353
334354configuration = standard .ConfigurationDescriptor (
335355 description = "Composite configuration" ,
@@ -502,7 +522,7 @@ def strings_in_order(cls):
502522""" )
503523
504524# Write out USB HID report buffer definitions.
505- for report_id , name in enumerate ( args .hid_devices , start = 1 ) :
525+ for name in args .hid_devices :
506526 c_file .write ("""\
507527 static uint8_t {name}_report_buffer[{report_length}];
508528""" .format (name = name .lower (), report_length = hid_report_descriptors .HID_DEVICE_DATA [name ].report_length ))
@@ -511,18 +531,18 @@ def strings_in_order(cls):
511531c_file .write ("""
512532usb_hid_device_obj_t usb_hid_devices[] = {
513533""" );
514- for report_id , name in enumerate ( args .hid_devices , start = 1 ) :
534+ for name in args .hid_devices :
515535 device_data = hid_report_descriptors .HID_DEVICE_DATA [name ]
516536 c_file .write ("""\
517537 {{
518538 .base = {{ .type = &usb_hid_device_type }},
519539 .report_buffer = {name}_report_buffer,
520- .report_id = {report_id: },
540+ .report_id = {report_id},
521541 .report_length = {report_length},
522542 .usage_page = {usage_page:#04x},
523543 .usage = {usage:#04x},
524544 }},
525- """ .format (name = name .lower (), report_id = report_id ,
545+ """ .format (name = name .lower (), report_id = report_ids [ name ] ,
526546 report_length = device_data .report_length ,
527547 usage_page = device_data .usage_page ,
528548 usage = device_data .usage ))
0 commit comments