3232 help = 'devices to include in descriptor (AUDIO includes MIDI support)' )
3333parser .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 ('--msc_num_endpoint_pairs' , type = int , default = 1 ,
36- help = 'Use 1 or 2 endpoint pairs for MSC (1 bidirectional, or 1 input + 1 output (required by SAMD21))' )
3735parser .add_argument ('--msc_max_packet_size' , type = int , default = 64 ,
3836 help = 'Max packet size for MSC' )
37+ parser .add_argument ('--no-renumber_endpoints' , dest = 'renumber_endpoints' , action = 'store_false' ,
38+ help = 'use to not renumber endpoint' )
39+ parser .add_argument ('--cdc_ep_num_notification' , type = int , default = 0 ,
40+ help = 'endpoint number of CDC NOTIFICATION' )
41+ parser .add_argument ('--cdc_ep_num_data_out' , type = int , default = 0 ,
42+ help = 'endpoint number of CDC DATA OUT' )
43+ parser .add_argument ('--cdc_ep_num_data_in' , type = int , default = 0 ,
44+ help = 'endpoint number of CDC DATA IN' )
45+ parser .add_argument ('--msc_ep_num_out' , type = int , default = 0 ,
46+ help = 'endpoint number of MSC OUT' )
47+ parser .add_argument ('--msc_ep_num_in' , type = int , default = 0 ,
48+ help = 'endpoint number of MSC IN' )
49+ parser .add_argument ('--hid_ep_num_out' , type = int , default = 0 ,
50+ help = 'endpoint number of HID OUT' )
51+ parser .add_argument ('--hid_ep_num_in' , type = int , default = 0 ,
52+ help = 'endpoint number of HID IN' )
53+ parser .add_argument ('--midi_ep_num_out' , type = int , default = 0 ,
54+ help = 'endpoint number of MIDI OUT' )
55+ parser .add_argument ('--midi_ep_num_in' , type = int , default = 0 ,
56+ help = 'endpoint number of MIDI IN' )
3957parser .add_argument ('--output_c_file' , type = argparse .FileType ('w' ), required = True )
4058parser .add_argument ('--output_h_file' , type = argparse .FileType ('w' ), required = True )
4159
4967if unknown_hid_devices :
5068 raise ValueError ("Unknown HID devices(s)" , unknown_hid_devices )
5169
52- if args .msc_num_endpoint_pairs not in (1 , 2 ):
53- raise ValueError ("--msc_num_endpoint_pairs must be 1 or 2" )
54-
70+ if not args .renumber_endpoints :
71+ if 'CDC' in args .devices :
72+ if args .cdc_ep_num_notification == 0 :
73+ raise ValueError ("CDC notification endpoint number must not be 0" )
74+ elif args .cdc_ep_num_data_out == 0 :
75+ raise ValueError ("CDC data OUT endpoint number must not be 0" )
76+ elif args .cdc_ep_num_data_in == 0 :
77+ raise ValueError ("CDC data IN endpoint number must not be 0" )
78+
79+ if 'MSC' in args .devices :
80+ if args .msc_ep_num_out == 0 :
81+ raise ValueError ("MSC endpoint OUT number must not be 0" )
82+ elif args .msc_ep_num_in == 0 :
83+ raise ValueError ("MSC endpoint IN number must not be 0" )
84+
85+ if 'HID' in args .devices :
86+ if args .args .hid_ep_num_out == 0 :
87+ raise ValueError ("HID endpoint OUT number must not be 0" )
88+ elif args .hid_ep_num_in == 0 :
89+ raise ValueError ("HID endpoint IN number must not be 0" )
90+
91+ if 'AUDIO' in args .devices :
92+ if args .args .midi_ep_num_out == 0 :
93+ raise ValueError ("MIDI endpoint OUT number must not be 0" )
94+ elif args .midi_ep_num_in == 0 :
95+ raise ValueError ("MIDI endpoint IN number must not be 0" )
5596
5697class StringIndex :
5798 """Assign a monotonically increasing index to each unique string. Start with 0."""
@@ -122,7 +163,7 @@ def strings_in_order(cls):
122163 cdc_union ,
123164 standard .EndpointDescriptor (
124165 description = "CDC comm in" ,
125- bEndpointAddress = 0x0 | standard .EndpointDescriptor .DIRECTION_IN ,
166+ bEndpointAddress = args . cdc_ep_num_notification | standard .EndpointDescriptor .DIRECTION_IN ,
126167 bmAttributes = standard .EndpointDescriptor .TYPE_INTERRUPT ,
127168 wMaxPacketSize = 0x0040 ,
128169 bInterval = 0x10 )
@@ -135,11 +176,11 @@ def strings_in_order(cls):
135176 subdescriptors = [
136177 standard .EndpointDescriptor (
137178 description = "CDC data out" ,
138- bEndpointAddress = 0x0 | standard .EndpointDescriptor .DIRECTION_OUT ,
179+ bEndpointAddress = args . cdc_ep_num_data_out | standard .EndpointDescriptor .DIRECTION_OUT ,
139180 bmAttributes = standard .EndpointDescriptor .TYPE_BULK ),
140181 standard .EndpointDescriptor (
141182 description = "CDC data in" ,
142- bEndpointAddress = 0x0 | standard .EndpointDescriptor .DIRECTION_IN ,
183+ bEndpointAddress = args . cdc_ep_num_data_in | standard .EndpointDescriptor .DIRECTION_IN ,
143184 bmAttributes = standard .EndpointDescriptor .TYPE_BULK ),
144185 ])
145186
@@ -155,15 +196,13 @@ def strings_in_order(cls):
155196 subdescriptors = [
156197 standard .EndpointDescriptor (
157198 description = "MSC in" ,
158- bEndpointAddress = 0x0 | standard .EndpointDescriptor .DIRECTION_IN ,
199+ bEndpointAddress = args . msc_ep_num_in | standard .EndpointDescriptor .DIRECTION_IN ,
159200 bmAttributes = standard .EndpointDescriptor .TYPE_BULK ,
160201 bInterval = 0 ,
161202 wMaxPacketSize = args .msc_max_packet_size ),
162203 standard .EndpointDescriptor (
163204 description = "MSC out" ,
164- # SAMD21 needs to use a separate pair of endpoints for MSC.
165- bEndpointAddress = ((0x1 if args .msc_num_endpoint_pairs == 2 else 0x0 ) |
166- standard .EndpointDescriptor .DIRECTION_OUT ),
205+ bEndpointAddress = (args .msc_ep_num_out | standard .EndpointDescriptor .DIRECTION_OUT ),
167206 bmAttributes = standard .EndpointDescriptor .TYPE_BULK ,
168207 bInterval = 0 ,
169208 wMaxPacketSize = args .msc_max_packet_size )
@@ -201,13 +240,13 @@ def strings_in_order(cls):
201240# and will fail (possibly silently) if both are not supplied.
202241hid_endpoint_in_descriptor = standard .EndpointDescriptor (
203242 description = "HID in" ,
204- bEndpointAddress = 0x0 | standard .EndpointDescriptor .DIRECTION_IN ,
243+ bEndpointAddress = args . hid_ep_num_in | standard .EndpointDescriptor .DIRECTION_IN ,
205244 bmAttributes = standard .EndpointDescriptor .TYPE_INTERRUPT ,
206245 bInterval = 8 )
207246
208247hid_endpoint_out_descriptor = standard .EndpointDescriptor (
209248 description = "HID out" ,
210- bEndpointAddress = 0x0 | standard .EndpointDescriptor .DIRECTION_OUT ,
249+ bEndpointAddress = args . hid_ep_num_out | standard .EndpointDescriptor .DIRECTION_OUT ,
211250 bmAttributes = standard .EndpointDescriptor .TYPE_INTERRUPT ,
212251 bInterval = 8 )
213252
@@ -271,12 +310,12 @@ def strings_in_order(cls):
271310 ),
272311 standard .EndpointDescriptor (
273312 description = "MIDI data out to CircuitPython" ,
274- bEndpointAddress = 0x0 | standard .EndpointDescriptor .DIRECTION_OUT ,
313+ bEndpointAddress = args . midi_ep_num_out | standard .EndpointDescriptor .DIRECTION_OUT ,
275314 bmAttributes = standard .EndpointDescriptor .TYPE_BULK ),
276315 midi .DataEndpointDescriptor (baAssocJack = [midi_in_jack_emb ]),
277316 standard .EndpointDescriptor (
278317 description = "MIDI data in from CircuitPython" ,
279- bEndpointAddress = 0x0 | standard .EndpointDescriptor .DIRECTION_IN ,
318+ bEndpointAddress = args . midi_ep_num_in | standard .EndpointDescriptor .DIRECTION_IN ,
280319 bmAttributes = standard .EndpointDescriptor .TYPE_BULK ,
281320 bInterval = 0x0 ),
282321 midi .DataEndpointDescriptor (baAssocJack = [midi_out_jack_emb ]),
@@ -320,7 +359,7 @@ def strings_in_order(cls):
320359# util.join_interfaces() will renumber the endpoints to make them unique across descriptors,
321360# and renumber the interfaces in order. But we still need to fix up certain
322361# interface cross-references.
323- interfaces = util .join_interfaces (* interfaces_to_join )
362+ interfaces = util .join_interfaces (interfaces_to_join , renumber_endpoints = args . renumber_endpoints )
324363
325364# Now adjust the CDC interface cross-references.
326365
0 commit comments