Skip to content

Commit d005b12

Browse files
committed
WIP: seems to be done
1 parent c00b25e commit d005b12

6 files changed

Lines changed: 158 additions & 31 deletions

File tree

ports/atmel-samd/asf4_conf/samd21/hpl_usb_config.h

Lines changed: 63 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,62 @@
22
#ifndef HPL_USB_CONFIG_H
33
#define HPL_USB_CONFIG_H
44

5+
// CIRCUITPY:
6+
7+
// Use 64-byte USB buffers for endpoint directions that are in use. They're set to 0 below otherwise.
8+
9+
#include "genhdr/autogen_usb_descriptor.h"
10+
11+
#if defined(USB_ENDPOINT_1_OUT_USED) && USB_ENDPOINT_1_OUT_USED
12+
#define CONF_USB_EP1_CACHE 64
13+
#endif
14+
#if defined(USB_ENDPOINT_1_IN_USED) && USB_ENDPOINT_1_IN_USED
15+
#define CONF_USB_EP1_I_CACHE 64
16+
#endif
17+
18+
#if defined(USB_ENDPOINT_2_OUT_USED) && USB_ENDPOINT_2_OUT_USED
19+
#define CONF_USB_EP2_CACHE 64
20+
#endif
21+
#if defined(USB_ENDPOINT_2_IN_USED) && USB_ENDPOINT_2_IN_USED
22+
#define CONF_USB_EP2_I_CACHE 64
23+
#endif
24+
25+
#if defined(USB_ENDPOINT_3_OUT_USED) && USB_ENDPOINT_3_OUT_USED
26+
#define CONF_USB_EP3_CACHE 64
27+
#endif
28+
#if defined(USB_ENDPOINT_3_IN_USED) && USB_ENDPOINT_3_IN_USED
29+
#define CONF_USB_EP3_I_CACHE 64
30+
#endif
31+
32+
#if defined(USB_ENDPOINT_4_OUT_USED) && USB_ENDPOINT_4_OUT_USED
33+
#define CONF_USB_EP4_CACHE 64
34+
#endif
35+
#if defined(USB_ENDPOINT_4_IN_USED) && USB_ENDPOINT_4_IN_USED
36+
#define CONF_USB_EP4_I_CACHE 64
37+
#endif
38+
39+
#if defined(USB_ENDPOINT_5_OUT_USED) && USB_ENDPOINT_5_OUT_USED
40+
#define CONF_USB_EP5_CACHE 64
41+
#endif
42+
#if defined(USB_ENDPOINT_5_IN_USED) && USB_ENDPOINT_5_IN_USED
43+
#define CONF_USB_EP5_I_CACHE 64
44+
#endif
45+
46+
#if defined(USB_ENDPOINT_6_OUT_USED) && USB_ENDPOINT_6_OUT_USED
47+
#define CONF_USB_EP6_CACHE 64
48+
#endif
49+
#if defined(USB_ENDPOINT_6_IN_USED) && USB_ENDPOINT_6_IN_USED
50+
#define CONF_USB_EP6_I_CACHE 64
51+
#endif
52+
53+
#if defined(USB_ENDPOINT_7_OUT_USED) && USB_ENDPOINT_7_OUT_USED
54+
#define CONF_USB_EP7_CACHE 64
55+
#endif
56+
#if defined(USB_ENDPOINT_7_IN_USED) && USB_ENDPOINT_7_IN_USED
57+
#define CONF_USB_EP7_I_CACHE 64
58+
#endif
59+
60+
561
// <<< Use Configuration Wizard in Context Menu >>>
662

763
#define CONF_USB_N_0 0
@@ -28,6 +84,8 @@
2884

2985
// <y> Max number of endpoints supported
3086
// <i> Limits the number of endpoints (described by EP address) can be used in app.
87+
// NOTE(tannewt): This not only limits the number of endpoints but also the
88+
// addresses. In other words, even if you use endpoint 6 you need to set this to 11.
3189
// <CONF_USB_N_1"> 1 (EP0 only)
3290
// <CONF_USB_N_2"> 2 (EP0 + 1 endpoint)
3391
// <CONF_USB_N_3"> 3 (EP0 + 2 endpoints)
@@ -100,7 +158,7 @@
100158
// <1024=> Cached by 1024 bytes buffer (interrupt or isochronous EP)
101159
// <id> usb_arch_ep1_cache
102160
#ifndef CONF_USB_EP1_CACHE
103-
#define CONF_USB_EP1_CACHE 64
161+
#define CONF_USB_EP1_CACHE 0
104162
#endif
105163

106164
// <o> Cache buffer size for EP1 IN
@@ -138,7 +196,7 @@
138196
// <1024=> Cached by 1024 bytes buffer (interrupt or isochronous EP)
139197
// <id> usb_arch_ep2_cache
140198
#ifndef CONF_USB_EP2_CACHE
141-
#define CONF_USB_EP2_CACHE 64
199+
#define CONF_USB_EP2_CACHE 0
142200
#endif
143201

144202
// <o> Cache buffer size for EP2 IN
@@ -156,7 +214,7 @@
156214
// <1024=> Cached by 1024 bytes buffer (interrupt or isochronous EP)
157215
// <id> usb_ep2_I_CACHE
158216
#ifndef CONF_USB_EP2_I_CACHE
159-
#define CONF_USB_EP2_I_CACHE 64
217+
#define CONF_USB_EP2_I_CACHE 0
160218
#endif
161219
// </h>
162220

@@ -194,7 +252,7 @@
194252
// <1024=> Cached by 1024 bytes buffer (interrupt or isochronous EP)
195253
// <id> usb_ep3_I_CACHE
196254
#ifndef CONF_USB_EP3_I_CACHE
197-
#define CONF_USB_EP3_I_CACHE 64
255+
#define CONF_USB_EP3_I_CACHE 0
198256
#endif
199257
// </h>
200258

@@ -214,7 +272,7 @@
214272
// <1024=> Cached by 1024 bytes buffer (interrupt or isochronous EP)
215273
// <id> usb_arch_ep4_cache
216274
#ifndef CONF_USB_EP4_CACHE
217-
#define CONF_USB_EP4_CACHE 64
275+
#define CONF_USB_EP4_CACHE 0
218276
#endif
219277

220278
// <o> Cache buffer size for EP4 IN

ports/atmel-samd/asf4_conf/samd51/hpl_usb_config.h

Lines changed: 65 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,62 @@
22
#ifndef HPL_USB_CONFIG_H
33
#define HPL_USB_CONFIG_H
44

5+
// CIRCUITPY:
6+
7+
// Use 64-byte USB buffers for endpoint directions that are in use. They're set to 0 below otherwise.
8+
9+
#include "genhdr/autogen_usb_descriptor.h"
10+
11+
#if defined(USB_ENDPOINT_1_OUT_USED) && USB_ENDPOINT_1_OUT_USED
12+
#define CONF_USB_EP1_CACHE 64
13+
#endif
14+
#if defined(USB_ENDPOINT_1_IN_USED) && USB_ENDPOINT_1_IN_USED
15+
#define CONF_USB_EP1_I_CACHE 64
16+
#endif
17+
18+
#if defined(USB_ENDPOINT_2_OUT_USED) && USB_ENDPOINT_2_OUT_USED
19+
#define CONF_USB_EP2_CACHE 64
20+
#endif
21+
#if defined(USB_ENDPOINT_2_IN_USED) && USB_ENDPOINT_2_IN_USED
22+
#define CONF_USB_EP2_I_CACHE 64
23+
#endif
24+
25+
#if defined(USB_ENDPOINT_3_OUT_USED) && USB_ENDPOINT_3_OUT_USED
26+
#define CONF_USB_EP3_CACHE 64
27+
#endif
28+
#if defined(USB_ENDPOINT_3_IN_USED) && USB_ENDPOINT_3_IN_USED
29+
#define CONF_USB_EP3_I_CACHE 64
30+
#endif
31+
32+
#if defined(USB_ENDPOINT_4_OUT_USED) && USB_ENDPOINT_4_OUT_USED
33+
#define CONF_USB_EP4_CACHE 64
34+
#endif
35+
#if defined(USB_ENDPOINT_4_IN_USED) && USB_ENDPOINT_4_IN_USED
36+
#define CONF_USB_EP4_I_CACHE 64
37+
#endif
38+
39+
#if defined(USB_ENDPOINT_5_OUT_USED) && USB_ENDPOINT_5_OUT_USED
40+
#define CONF_USB_EP5_CACHE 64
41+
#endif
42+
#if defined(USB_ENDPOINT_5_IN_USED) && USB_ENDPOINT_5_IN_USED
43+
#define CONF_USB_EP5_I_CACHE 64
44+
#endif
45+
46+
#if defined(USB_ENDPOINT_6_OUT_USED) && USB_ENDPOINT_6_OUT_USED
47+
#define CONF_USB_EP6_CACHE 64
48+
#endif
49+
#if defined(USB_ENDPOINT_6_IN_USED) && USB_ENDPOINT_6_IN_USED
50+
#define CONF_USB_EP6_I_CACHE 64
51+
#endif
52+
53+
#if defined(USB_ENDPOINT_7_OUT_USED) && USB_ENDPOINT_7_OUT_USED
54+
#define CONF_USB_EP7_CACHE 64
55+
#endif
56+
#if defined(USB_ENDPOINT_7_IN_USED) && USB_ENDPOINT_7_IN_USED
57+
#define CONF_USB_EP7_I_CACHE 64
58+
#endif
59+
60+
561
// <<< Use Configuration Wizard in Context Menu >>>
662

763
#define CONF_USB_N_0 0
@@ -102,7 +158,7 @@
102158
// <1024=> Cached by 1024 bytes buffer (interrupt or isochronous EP)
103159
// <id> usb_arch_ep1_cache
104160
#ifndef CONF_USB_EP1_CACHE
105-
#define CONF_USB_EP1_CACHE 64
161+
#define CONF_USB_EP1_CACHE 0
106162
#endif
107163

108164
// <o> Cache buffer size for EP1 IN
@@ -140,7 +196,7 @@
140196
// <1024=> Cached by 1024 bytes buffer (interrupt or isochronous EP)
141197
// <id> usb_arch_ep2_cache
142198
#ifndef CONF_USB_EP2_CACHE
143-
#define CONF_USB_EP2_CACHE 64
199+
#define CONF_USB_EP2_CACHE 0
144200
#endif
145201

146202
// <o> Cache buffer size for EP2 IN
@@ -158,7 +214,7 @@
158214
// <1024=> Cached by 1024 bytes buffer (interrupt or isochronous EP)
159215
// <id> usb_ep2_I_CACHE
160216
#ifndef CONF_USB_EP2_I_CACHE
161-
#define CONF_USB_EP2_I_CACHE 64
217+
#define CONF_USB_EP2_I_CACHE 0
162218
#endif
163219
// </h>
164220

@@ -178,7 +234,7 @@
178234
// <1024=> Cached by 1024 bytes buffer (interrupt or isochronous EP)
179235
// <id> usb_arch_ep3_cache
180236
#ifndef CONF_USB_EP3_CACHE
181-
#define CONF_USB_EP3_CACHE 64
237+
#define CONF_USB_EP3_CACHE 0
182238
#endif
183239

184240
// <o> Cache buffer size for EP3 IN
@@ -216,7 +272,7 @@
216272
// <1024=> Cached by 1024 bytes buffer (interrupt or isochronous EP)
217273
// <id> usb_arch_ep4_cache
218274
#ifndef CONF_USB_EP4_CACHE
219-
#define CONF_USB_EP4_CACHE 64
275+
#define CONF_USB_EP4_CACHE 0
220276
#endif
221277

222278
// <o> Cache buffer size for EP4 IN
@@ -254,7 +310,7 @@
254310
// <1024=> Cached by 1024 bytes buffer (interrupt or isochronous EP)
255311
// <id> usb_arch_ep5_cache
256312
#ifndef CONF_USB_EP5_CACHE
257-
#define CONF_USB_EP5_CACHE 64
313+
#define CONF_USB_EP5_CACHE 0
258314
#endif
259315

260316
// <o> Cache buffer size for EP5 IN
@@ -292,7 +348,7 @@
292348
// <1024=> Cached by 1024 bytes buffer (interrupt or isochronous EP)
293349
// <id> usb_arch_ep6_cache
294350
#ifndef CONF_USB_EP6_CACHE
295-
#define CONF_USB_EP6_CACHE 64
351+
#define CONF_USB_EP6_CACHE 0
296352
#endif
297353

298354
// <o> Cache buffer size for EP6 IN
@@ -310,7 +366,7 @@
310366
// <1024=> Cached by 1024 bytes buffer (interrupt or isochronous EP)
311367
// <id> usb_ep6_I_CACHE
312368
#ifndef CONF_USB_EP6_I_CACHE
313-
#define CONF_USB_EP6_I_CACHE 64
369+
#define CONF_USB_EP6_I_CACHE 0
314370
#endif
315371
// </h>
316372

@@ -330,7 +386,7 @@
330386
// <1024=> Cached by 1024 bytes buffer (interrupt or isochronous EP)
331387
// <id> usb_arch_ep7_cache
332388
#ifndef CONF_USB_EP7_CACHE
333-
#define CONF_USB_EP7_CACHE 64
389+
#define CONF_USB_EP7_CACHE 0
334390
#endif
335391

336392
// <o> Cache buffer size for EP7 IN

ports/atmel-samd/tools/gen_usb_descriptor.py

Lines changed: 26 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@
119119
hid_max_report_length = max(hid_report_lengths.values())
120120

121121
# ASF4 expects keyboard and generic devices to have both in and out endpoints,
122-
# and will fail in mysterious ways if you only supply one.
122+
# and will fail (possibly silently) if both are not supplied.
123123
hid_endpoint_in_descriptor = standard.EndpointDescriptor(
124124
description="HID in",
125125
bEndpointAddress=0x0 | standard.EndpointDescriptor.DIRECTION_IN,
@@ -144,19 +144,12 @@
144144
hid_endpoint_out_descriptor,
145145
]
146146
),
147-
# bInterfaceClass = hid.HID_CLASS,
148-
# bInterfaceSubClass = hid.HID_SUBCLASS_NOBOOT,
149-
# bInterfaceProtocol=hid.HID_PROTOCOL_MOUSE,
150-
# subdescriptors=[
151-
# hid.HIDDescriptor(wDescriptorLength=len(bytes(hid_report_descriptor))),
152-
# hid_endpoint_descriptor,
153-
# ]
154-
# ),
155147
]
156148

157149
# This will renumber the endpoints to make them unique across descriptors.
158-
#interfaces = util.join_interfaces(cdc_interfaces, msc_interfaces, hid_interfaces)
159-
interfaces = util.join_interfaces(cdc_interfaces, hid_interfaces)
150+
interfaces = util.join_interfaces(cdc_interfaces, msc_interfaces, hid_interfaces)
151+
#interfaces = util.join_interfaces(cdc_interfaces, hid_interfaces, msc_interfaces)
152+
#interfaces = util.join_interfaces(cdc_interfaces, hid_interfaces)
160153

161154
cdc_function = standard.InterfaceAssociationDescriptor(
162155
description="CDC function",
@@ -167,7 +160,7 @@
167160
bFunctionProtocol=0x1) # Common AT Commands
168161

169162
configuration = standard.ConfigurationDescriptor(
170-
description="CDC configuration",
163+
description="Composite configuration",
171164
wTotalLength=(standard.ConfigurationDescriptor.bLength +
172165
cdc_function.bLength +
173166
sum([len(bytes(x)) for x in interfaces])),
@@ -186,6 +179,8 @@
186179
187180
#include "{H_FILE_NAME}"
188181
182+
#include "usb/device/usbdc.h"
183+
189184
""".format(H_FILE_NAME=h_file.name))
190185

191186
c_file.write("""\
@@ -227,9 +222,6 @@
227222
#ifndef MICROPY_INCLUDED_AUTOGEN_USB_DESCRIPTOR_H
228223
#define MICROPY_INCLUDED_AUTOGEN_USB_DESCRIPTOR_H
229224
230-
#include "usb/device/usbdc.h"
231-
232-
struct usbd_descriptors descriptor_bounds;
233225
#define SERIAL_NUMBER_OFFSET {SERIAL_NUMBER_OFFSET}
234226
#define SERIAL_NUMBER_LENGTH {SERIAL_NUMBER_LENGTH}
235227
uint8_t* serial_number;
@@ -245,20 +237,39 @@
245237
HID_ENDPOINT_IN_ADDRESS=hex(hid_endpoint_in_descriptor.bEndpointAddress),
246238
HID_ENDPOINT_OUT_ADDRESS=hex(hid_endpoint_out_descriptor.bEndpointAddress)))
247239

240+
# Write out #define's that declare which endpoints are in use.
241+
# These provide information for declaring cache sizes and perhaps other things at compile time
242+
for interface in interfaces:
243+
for subdescriptor in interface.subdescriptors:
244+
if isinstance(subdescriptor, standard.EndpointDescriptor):
245+
endpoint_num = subdescriptor.bEndpointAddress & standard.EndpointDescriptor.NUMBER_MASK
246+
endpoint_in = ((subdescriptor.bEndpointAddress & standard.EndpointDescriptor.DIRECTION_MASK) ==
247+
standard.EndpointDescriptor.DIRECTION_IN)
248+
h_file.write("""\
249+
#define USB_ENDPOINT_{NUMBER}_{DIRECTION}_USED 1
250+
""".format(NUMBER=endpoint_num,
251+
DIRECTION="IN" if endpoint_in else "OUT"))
252+
253+
h_file.write("\n")
254+
248255
# #define the report ID's used in the combined HID descriptor
249256
for name, id in hid_report_ids.items():
250257
h_file.write("""\
251258
#define USB_HID_REPORT_ID_{NAME} {ID}
252259
""".format(NAME=name,
253260
ID = id))
254261

262+
h_file.write("\n")
263+
255264
# #define the report sizes used in the combined HID descriptor
256265
for name, length in hid_report_lengths.items():
257266
h_file.write("""\
258267
#define USB_HID_REPORT_LENGTH_{NAME} {LENGTH}
259268
""".format(NAME=name,
260269
LENGTH=length))
261270

271+
h_file.write("\n")
272+
262273
h_file.write("""\
263274
#define USB_HID_NUM_DEVICES {NUM_DEVICES}
264275
#define USB_HID_MAX_REPORT_LENGTH {MAX_LENGTH}

ports/atmel-samd/usb.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@
4848

4949
#include "supervisor/shared/autoreload.h"
5050

51+
extern struct usbd_descriptors descriptor_bounds;
52+
5153
// Store received characters on our own so that we can filter control characters
5254
// and act immediately on CTRL-C for example.
5355

0 commit comments

Comments
 (0)