@@ -173,17 +173,21 @@ def strings_in_order(cls):
173
173
# args.hid_devices[1] has report_id 2
174
174
# etc.
175
175
176
+ report_ids = {}
177
+
176
178
if len (args .hid_devices ) == 1 :
177
179
name = args .hid_devices [0 ]
178
180
combined_hid_report_descriptor = hid .ReportDescriptor (
179
181
description = name ,
180
182
report_descriptor = bytes (hid_report_descriptors .REPORT_DESCRIPTOR_FUNCTIONS [name ](0 )))
183
+ report_ids [name ] = 0
181
184
else :
182
185
report_id = 1
183
186
concatenated_descriptors = bytearray ()
184
187
for name in args .hid_devices :
185
188
concatenated_descriptors .extend (
186
189
bytes (hid_report_descriptors .REPORT_DESCRIPTOR_FUNCTIONS [name ](report_id )))
190
+ report_ids [name ] = report_id
187
191
report_id += 1
188
192
combined_hid_report_descriptor = hid .ReportDescriptor (
189
193
description = "MULTIDEVICE" ,
@@ -288,10 +292,24 @@ def strings_in_order(cls):
288
292
# Audio streaming interfaces must occur before MIDI ones.
289
293
audio_interfaces = [audio_control_interface ] + cs_ac_interface .audio_streaming_interfaces + cs_ac_interface .midi_streaming_interfaces
290
294
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,
292
310
# and renumber the interfaces in order. But we still need to fix up certain
293
311
# interface cross-references.
294
- interfaces = util .join_interfaces (cdc_interfaces , msc_interfaces , hid_interfaces , audio_interfaces )
312
+ interfaces = util .join_interfaces (* interfaces_to_join )
295
313
296
314
# Now adjust the CDC interface cross-references.
297
315
@@ -323,13 +341,15 @@ def strings_in_order(cls):
323
341
if 'MSC' in args .devices :
324
342
descriptor_list .extend (msc_interfaces )
325
343
344
+ if 'HID' in args .devices :
345
+ descriptor_list .extend (hid_interfaces )
346
+
326
347
if 'AUDIO' in args .devices :
327
348
# Only add the control interface because other audio interfaces are managed by it to ensure the
328
349
# correct ordering.
329
350
descriptor_list .append (audio_control_interface )
330
351
331
- if 'HID' in args .devices :
332
- descriptor_list .extend (hid_interfaces )
352
+ # Finally, build the composite descriptor.
333
353
334
354
configuration = standard .ConfigurationDescriptor (
335
355
description = "Composite configuration" ,
@@ -502,7 +522,7 @@ def strings_in_order(cls):
502
522
""" )
503
523
504
524
# 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 :
506
526
c_file .write ("""\
507
527
static uint8_t {name}_report_buffer[{report_length}];
508
528
""" .format (name = name .lower (), report_length = hid_report_descriptors .HID_DEVICE_DATA [name ].report_length ))
@@ -511,18 +531,18 @@ def strings_in_order(cls):
511
531
c_file .write ("""
512
532
usb_hid_device_obj_t usb_hid_devices[] = {
513
533
""" );
514
- for report_id , name in enumerate ( args .hid_devices , start = 1 ) :
534
+ for name in args .hid_devices :
515
535
device_data = hid_report_descriptors .HID_DEVICE_DATA [name ]
516
536
c_file .write ("""\
517
537
{{
518
538
.base = {{ .type = &usb_hid_device_type }},
519
539
.report_buffer = {name}_report_buffer,
520
- .report_id = {report_id: },
540
+ .report_id = {report_id},
521
541
.report_length = {report_length},
522
542
.usage_page = {usage_page:#04x},
523
543
.usage = {usage:#04x},
524
544
}},
525
- """ .format (name = name .lower (), report_id = report_id ,
545
+ """ .format (name = name .lower (), report_id = report_ids [ name ] ,
526
546
report_length = device_data .report_length ,
527
547
usage_page = device_data .usage_page ,
528
548
usage = device_data .usage ))
0 commit comments