32
32
help = 'devices to include in descriptor (AUDIO includes MIDI support)' )
33
33
parser .add_argument ('--hid_devices' , type = lambda l : tuple (l .split (',' )), default = DEFAULT_HID_DEVICES ,
34
34
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))' )
37
35
parser .add_argument ('--msc_max_packet_size' , type = int , default = 64 ,
38
36
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' )
39
57
parser .add_argument ('--output_c_file' , type = argparse .FileType ('w' ), required = True )
40
58
parser .add_argument ('--output_h_file' , type = argparse .FileType ('w' ), required = True )
41
59
49
67
if unknown_hid_devices :
50
68
raise ValueError ("Unknown HID devices(s)" , unknown_hid_devices )
51
69
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" )
55
96
56
97
class StringIndex :
57
98
"""Assign a monotonically increasing index to each unique string. Start with 0."""
@@ -122,7 +163,7 @@ def strings_in_order(cls):
122
163
cdc_union ,
123
164
standard .EndpointDescriptor (
124
165
description = "CDC comm in" ,
125
- bEndpointAddress = 0x0 | standard .EndpointDescriptor .DIRECTION_IN ,
166
+ bEndpointAddress = args . cdc_ep_num_notification | standard .EndpointDescriptor .DIRECTION_IN ,
126
167
bmAttributes = standard .EndpointDescriptor .TYPE_INTERRUPT ,
127
168
wMaxPacketSize = 0x0040 ,
128
169
bInterval = 0x10 )
@@ -135,11 +176,11 @@ def strings_in_order(cls):
135
176
subdescriptors = [
136
177
standard .EndpointDescriptor (
137
178
description = "CDC data out" ,
138
- bEndpointAddress = 0x0 | standard .EndpointDescriptor .DIRECTION_OUT ,
179
+ bEndpointAddress = args . cdc_ep_num_data_out | standard .EndpointDescriptor .DIRECTION_OUT ,
139
180
bmAttributes = standard .EndpointDescriptor .TYPE_BULK ),
140
181
standard .EndpointDescriptor (
141
182
description = "CDC data in" ,
142
- bEndpointAddress = 0x0 | standard .EndpointDescriptor .DIRECTION_IN ,
183
+ bEndpointAddress = args . cdc_ep_num_data_in | standard .EndpointDescriptor .DIRECTION_IN ,
143
184
bmAttributes = standard .EndpointDescriptor .TYPE_BULK ),
144
185
])
145
186
@@ -155,15 +196,13 @@ def strings_in_order(cls):
155
196
subdescriptors = [
156
197
standard .EndpointDescriptor (
157
198
description = "MSC in" ,
158
- bEndpointAddress = 0x0 | standard .EndpointDescriptor .DIRECTION_IN ,
199
+ bEndpointAddress = args . msc_ep_num_in | standard .EndpointDescriptor .DIRECTION_IN ,
159
200
bmAttributes = standard .EndpointDescriptor .TYPE_BULK ,
160
201
bInterval = 0 ,
161
202
wMaxPacketSize = args .msc_max_packet_size ),
162
203
standard .EndpointDescriptor (
163
204
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 ),
167
206
bmAttributes = standard .EndpointDescriptor .TYPE_BULK ,
168
207
bInterval = 0 ,
169
208
wMaxPacketSize = args .msc_max_packet_size )
@@ -201,13 +240,13 @@ def strings_in_order(cls):
201
240
# and will fail (possibly silently) if both are not supplied.
202
241
hid_endpoint_in_descriptor = standard .EndpointDescriptor (
203
242
description = "HID in" ,
204
- bEndpointAddress = 0x0 | standard .EndpointDescriptor .DIRECTION_IN ,
243
+ bEndpointAddress = args . hid_ep_num_in | standard .EndpointDescriptor .DIRECTION_IN ,
205
244
bmAttributes = standard .EndpointDescriptor .TYPE_INTERRUPT ,
206
245
bInterval = 8 )
207
246
208
247
hid_endpoint_out_descriptor = standard .EndpointDescriptor (
209
248
description = "HID out" ,
210
- bEndpointAddress = 0x0 | standard .EndpointDescriptor .DIRECTION_OUT ,
249
+ bEndpointAddress = args . hid_ep_num_out | standard .EndpointDescriptor .DIRECTION_OUT ,
211
250
bmAttributes = standard .EndpointDescriptor .TYPE_INTERRUPT ,
212
251
bInterval = 8 )
213
252
@@ -271,12 +310,12 @@ def strings_in_order(cls):
271
310
),
272
311
standard .EndpointDescriptor (
273
312
description = "MIDI data out to CircuitPython" ,
274
- bEndpointAddress = 0x0 | standard .EndpointDescriptor .DIRECTION_OUT ,
313
+ bEndpointAddress = args . midi_ep_num_out | standard .EndpointDescriptor .DIRECTION_OUT ,
275
314
bmAttributes = standard .EndpointDescriptor .TYPE_BULK ),
276
315
midi .DataEndpointDescriptor (baAssocJack = [midi_in_jack_emb ]),
277
316
standard .EndpointDescriptor (
278
317
description = "MIDI data in from CircuitPython" ,
279
- bEndpointAddress = 0x0 | standard .EndpointDescriptor .DIRECTION_IN ,
318
+ bEndpointAddress = args . midi_ep_num_in | standard .EndpointDescriptor .DIRECTION_IN ,
280
319
bmAttributes = standard .EndpointDescriptor .TYPE_BULK ,
281
320
bInterval = 0x0 ),
282
321
midi .DataEndpointDescriptor (baAssocJack = [midi_out_jack_emb ]),
@@ -320,7 +359,7 @@ def strings_in_order(cls):
320
359
# util.join_interfaces() will renumber the endpoints to make them unique across descriptors,
321
360
# and renumber the interfaces in order. But we still need to fix up certain
322
361
# interface cross-references.
323
- interfaces = util .join_interfaces (* interfaces_to_join )
362
+ interfaces = util .join_interfaces (interfaces_to_join , renumber_endpoints = args . renumber_endpoints )
324
363
325
364
# Now adjust the CDC interface cross-references.
326
365
0 commit comments