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))' )
35
+ parser .add_argument ('--msc_max_packet_size' , type = int , default = 64 ,
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' )
37
57
parser .add_argument ('--output_c_file' , type = argparse .FileType ('w' ), required = True )
38
58
parser .add_argument ('--output_h_file' , type = argparse .FileType ('w' ), required = True )
39
59
47
67
if unknown_hid_devices :
48
68
raise ValueError ("Unknown HID devices(s)" , unknown_hid_devices )
49
69
50
- if args .msc_num_endpoint_pairs not in (1 , 2 ):
51
- raise ValueError ("--msc_num_endpoint_pairs must be 1 or 2" )
52
-
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" )
53
96
54
97
class StringIndex :
55
98
"""Assign a monotonically increasing index to each unique string. Start with 0."""
@@ -120,7 +163,7 @@ def strings_in_order(cls):
120
163
cdc_union ,
121
164
standard .EndpointDescriptor (
122
165
description = "CDC comm in" ,
123
- bEndpointAddress = 0x0 | standard .EndpointDescriptor .DIRECTION_IN ,
166
+ bEndpointAddress = args . cdc_ep_num_notification | standard .EndpointDescriptor .DIRECTION_IN ,
124
167
bmAttributes = standard .EndpointDescriptor .TYPE_INTERRUPT ,
125
168
wMaxPacketSize = 0x0040 ,
126
169
bInterval = 0x10 )
@@ -133,11 +176,11 @@ def strings_in_order(cls):
133
176
subdescriptors = [
134
177
standard .EndpointDescriptor (
135
178
description = "CDC data out" ,
136
- bEndpointAddress = 0x0 | standard .EndpointDescriptor .DIRECTION_OUT ,
179
+ bEndpointAddress = args . cdc_ep_num_data_out | standard .EndpointDescriptor .DIRECTION_OUT ,
137
180
bmAttributes = standard .EndpointDescriptor .TYPE_BULK ),
138
181
standard .EndpointDescriptor (
139
182
description = "CDC data in" ,
140
- bEndpointAddress = 0x0 | standard .EndpointDescriptor .DIRECTION_IN ,
183
+ bEndpointAddress = args . cdc_ep_num_data_in | standard .EndpointDescriptor .DIRECTION_IN ,
141
184
bmAttributes = standard .EndpointDescriptor .TYPE_BULK ),
142
185
])
143
186
@@ -153,16 +196,16 @@ def strings_in_order(cls):
153
196
subdescriptors = [
154
197
standard .EndpointDescriptor (
155
198
description = "MSC in" ,
156
- bEndpointAddress = 0x0 | standard .EndpointDescriptor .DIRECTION_IN ,
199
+ bEndpointAddress = args . msc_ep_num_in | standard .EndpointDescriptor .DIRECTION_IN ,
157
200
bmAttributes = standard .EndpointDescriptor .TYPE_BULK ,
158
- bInterval = 0 ),
201
+ bInterval = 0 ,
202
+ wMaxPacketSize = args .msc_max_packet_size ),
159
203
standard .EndpointDescriptor (
160
204
description = "MSC out" ,
161
- # SAMD21 needs to use a separate pair of endpoints for MSC.
162
- bEndpointAddress = ((0x1 if args .msc_num_endpoint_pairs == 2 else 0x0 ) |
163
- standard .EndpointDescriptor .DIRECTION_OUT ),
205
+ bEndpointAddress = (args .msc_ep_num_out | standard .EndpointDescriptor .DIRECTION_OUT ),
164
206
bmAttributes = standard .EndpointDescriptor .TYPE_BULK ,
165
- bInterval = 0 )
207
+ bInterval = 0 ,
208
+ wMaxPacketSize = args .msc_max_packet_size )
166
209
]
167
210
)
168
211
]
@@ -197,13 +240,13 @@ def strings_in_order(cls):
197
240
# and will fail (possibly silently) if both are not supplied.
198
241
hid_endpoint_in_descriptor = standard .EndpointDescriptor (
199
242
description = "HID in" ,
200
- bEndpointAddress = 0x0 | standard .EndpointDescriptor .DIRECTION_IN ,
243
+ bEndpointAddress = args . hid_ep_num_in | standard .EndpointDescriptor .DIRECTION_IN ,
201
244
bmAttributes = standard .EndpointDescriptor .TYPE_INTERRUPT ,
202
245
bInterval = 8 )
203
246
204
247
hid_endpoint_out_descriptor = standard .EndpointDescriptor (
205
248
description = "HID out" ,
206
- bEndpointAddress = 0x0 | standard .EndpointDescriptor .DIRECTION_OUT ,
249
+ bEndpointAddress = args . hid_ep_num_out | standard .EndpointDescriptor .DIRECTION_OUT ,
207
250
bmAttributes = standard .EndpointDescriptor .TYPE_INTERRUPT ,
208
251
bInterval = 8 )
209
252
@@ -267,12 +310,12 @@ def strings_in_order(cls):
267
310
),
268
311
standard .EndpointDescriptor (
269
312
description = "MIDI data out to CircuitPython" ,
270
- bEndpointAddress = 0x0 | standard .EndpointDescriptor .DIRECTION_OUT ,
313
+ bEndpointAddress = args . midi_ep_num_out | standard .EndpointDescriptor .DIRECTION_OUT ,
271
314
bmAttributes = standard .EndpointDescriptor .TYPE_BULK ),
272
315
midi .DataEndpointDescriptor (baAssocJack = [midi_in_jack_emb ]),
273
316
standard .EndpointDescriptor (
274
317
description = "MIDI data in from CircuitPython" ,
275
- bEndpointAddress = 0x0 | standard .EndpointDescriptor .DIRECTION_IN ,
318
+ bEndpointAddress = args . midi_ep_num_in | standard .EndpointDescriptor .DIRECTION_IN ,
276
319
bmAttributes = standard .EndpointDescriptor .TYPE_BULK ,
277
320
bInterval = 0x0 ),
278
321
midi .DataEndpointDescriptor (baAssocJack = [midi_out_jack_emb ]),
@@ -316,7 +359,7 @@ def strings_in_order(cls):
316
359
# util.join_interfaces() will renumber the endpoints to make them unique across descriptors,
317
360
# and renumber the interfaces in order. But we still need to fix up certain
318
361
# interface cross-references.
319
- interfaces = util .join_interfaces (* interfaces_to_join )
362
+ interfaces = util .join_interfaces (interfaces_to_join , renumber_endpoints = args . renumber_endpoints )
320
363
321
364
# Now adjust the CDC interface cross-references.
322
365
0 commit comments