Skip to content

Commit 1205d3e

Browse files
committed
Add validation
1 parent 7aefcc4 commit 1205d3e

2 files changed

Lines changed: 26 additions & 13 deletions

File tree

supervisor/supervisor.mk

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,8 @@ ifndef USB_HID_DEVICES
9494
USB_HID_DEVICES = "KEYBOARD,MOUSE,CONSUMER,GAMEPAD"
9595
endif
9696

97-
ifndef USB_RELATIVE_EP_NUM
98-
USB_RELATIVE_EP_NUM = 1
97+
ifndef USB_RENUMBER_ENDPOINTS
98+
USB_RENUMBER_ENDPOINTS = 1
9999
endif
100100

101101
ifndef USB_CDC_EP_NUM_NOTIFICATION
@@ -149,7 +149,7 @@ autogen_usb_descriptor.intermediate: ../../tools/gen_usb_descriptor.py Makefile
149149
--serial_number_length $(USB_SERIAL_NUMBER_LENGTH)\
150150
--devices $(USB_DEVICES)\
151151
--hid_devices $(USB_HID_DEVICES)\
152-
--relative_ep_num $(USB_RELATIVE_EP_NUM)\
152+
--renumber_endpoints $(USB_RENUMBER_ENDPOINTS)\
153153
--cdc_ep_num_notification $(USB_CDC_EP_NUM_NOTIFICATION)\
154154
--cdc_ep_num_data_out $(USB_CDC_EP_NUM_DATA_OUT)\
155155
--cdc_ep_num_data_in $(USB_CDC_EP_NUM_DATA_IN)\

tools/gen_usb_descriptor.py

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
help='devices to include in descriptor (AUDIO includes MIDI support)')
3333
parser.add_argument('--hid_devices', type=lambda l: tuple(l.split(',')), default=DEFAULT_HID_DEVICES,
3434
help='HID devices to include in HID report descriptor')
35-
parser.add_argument('--relative_ep_num', type=int, default=1,
35+
parser.add_argument('--renumber_endpoints', type=int, default=1,
3636
help='use relative(1) or absolute(0) endpoint number')
3737
parser.add_argument('--cdc_ep_num_notification', type=int, default=0,
3838
help='endpoint number of CDC NOTIFICATION')
@@ -63,6 +63,24 @@
6363
if unknown_hid_devices:
6464
raise ValueError("Unknown HID devices(s)", unknown_hid_devices)
6565

66+
if not args.renumber_endpoints:
67+
if 'CDC' in args.devices:
68+
if (args.cdc_ep_num_notification == 0 or args.cdc_ep_num_data_out == 0 or
69+
args.cdc_ep_num_data_in == 0):
70+
raise ValueError("Endpoint address must not be 0")
71+
72+
if 'MSC' in args.devices:
73+
if args.msc_ep_num_out == 0 or args.msc_ep_num_in == 0:
74+
raise ValueError("Endpoint address must not be 0")
75+
76+
if 'HID' in args.devices:
77+
if args.hid_ep_num_in == 0:
78+
raise ValueError("Endpoint address must not be 0")
79+
80+
if 'AUDIO' in args.devices:
81+
if args.midi_ep_num_out == 0 or args.midi_ep_num_in == 0:
82+
raise ValueError("Endpoint address must not be 0")
83+
6684
class StringIndex:
6785
"""Assign a monotonically increasing index to each unique string. Start with 0."""
6886
string_to_index = {}
@@ -323,15 +341,10 @@ def strings_in_order(cls):
323341
if 'AUDIO' in args.devices:
324342
interfaces_to_join.append(audio_interfaces)
325343

326-
if args.relative_ep_num:
327-
# util.join_interfaces() will renumber the endpoints to make them unique across descriptors,
328-
# and renumber the interfaces in order. But we still need to fix up certain
329-
# interface cross-references.
330-
interfaces = util.join_interfaces(*interfaces_to_join)
331-
else:
332-
# util.renumbers_interfaces() will renumber the interfaces in order. But we still need to
333-
# fix up certain interface cross-references.
334-
interfaces = util.renumbers_interfaces(*interfaces_to_join)
344+
# util.join_interfaces() will renumber the endpoints to make them unique across descriptors,
345+
# and renumber the interfaces in order. But we still need to fix up certain
346+
# interface cross-references.
347+
interfaces = util.join_interfaces(interfaces_to_join, renumber_endpoints=args.renumber_endpoints)
335348

336349
# Now adjust the CDC interface cross-references.
337350

0 commit comments

Comments
 (0)