Skip to content

Commit 93e09e7

Browse files
authored
Merge pull request #738 from dhalbert/3.0_hid
3.0 hid
2 parents 9672f38 + 1e87a78 commit 93e09e7

File tree

19 files changed

+549
-353
lines changed

19 files changed

+549
-353
lines changed

main.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -286,12 +286,12 @@ int __attribute__((used)) main(void) {
286286
#endif
287287

288288
// Reset to remove any state that boot.py setup. It should only be used to
289-
// change internal state thats not in the heap.
289+
// change internal state that's not in the heap.
290290
reset_port();
291291
reset_mp();
292292
}
293293

294-
// Start serial after giving boot.py a chance to tweak behavior.
294+
// Start serial and HID after giving boot.py a chance to tweak behavior.
295295
serial_init();
296296

297297
// Boot script is finished, so now go into REPL/main mode.

ports/atmel-samd/Makefile

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ BASE_CFLAGS = \
7272
-Wnested-externs \
7373
-Wunreachable-code \
7474
-Wcast-align \
75+
-Wno-error=lto-type-mismatch \
7576
-D__$(CHIP_VARIANT)__ \
7677
-ffunction-sections \
7778
-fdata-sections \
@@ -81,6 +82,7 @@ BASE_CFLAGS = \
8182
-DCIRCUITPY_SAFE_RESTART_WORD=0xDEADBEEF \
8283
--param max-inline-insns-single=500
8384

85+
8486
# NDEBUG disables assert() statements. This reduces code size pretty dramatically, per tannewt.
8587

8688
ifeq ($(CHIP_FAMILY), samd21)
@@ -95,8 +97,8 @@ endif
9597
ifeq ($(DEBUG), 1)
9698
# Turn on Python modules useful for debugging (e.g. uheap, ustack).
9799
CFLAGS += -ggdb
98-
CFLAGS += -flto
99-
## CFLAGS += -fno-inline
100+
## CFLAGS += -flto
101+
CFLAGS += -fno-inline -fno-ipa-sra
100102
ifeq ($(CHIP_FAMILY), samd21)
101103
CFLAGS += -DENABLE_MICRO_TRACE_BUFFER
102104
endif
@@ -192,6 +194,7 @@ SRC_ASF := \
192194
hpl/systick/hpl_systick.c \
193195
hpl/usb/hpl_usb.c \
194196
usb/class/cdc/device/cdcdf_acm.c \
197+
usb/class/hid/device/hiddf_generic.c \
195198
usb/class/msc/device/mscdf.c \
196199
usb/device/usbdc.c \
197200
usb/usb_protocol.c \
@@ -281,6 +284,8 @@ SRC_COMMON_HAL = \
281284
pulseio/PulseIn.c \
282285
pulseio/PulseOut.c \
283286
pulseio/PWMOut.c \
287+
usb_hid/__init__.c \
288+
usb_hid/Device.c
284289
# audiobusio/__init__.c \
285290
audiobusio/PDMIn.c \
286291
audioio/__init__.c \
@@ -289,8 +294,6 @@ SRC_COMMON_HAL = \
289294
nvm/ByteArray.c \
290295
touchio/__init__.c \
291296
touchio/TouchIn.c \
292-
usb_hid/__init__.c \
293-
usb_hid/Device.c
294297
295298
ifeq ($(INTERNAL_LIBM),1)
296299
SRC_LIBM = $(addprefix lib/,\
@@ -378,14 +381,19 @@ $(BUILD)/firmware.uf2: $(BUILD)/firmware.bin
378381
$(ECHO) "Create $@"
379382
python2 $(TOP)/tools/uf2/utils/uf2conv.py -b $(BOOTLOADER_SIZE) -c -o $@ $^
380383

381-
$(BUILD)/autogen_usb_descriptor.c: tools/gen_usb_descriptor.py Makefile
384+
$(BUILD)/autogen_usb_descriptor.c $(BUILD)/genhdr/autogen_usb_descriptor.h: autogen_usb_descriptor.intermediate
385+
386+
.INTERMEDIATE: autogen_usb_descriptor.intermediate
387+
388+
autogen_usb_descriptor.intermediate: tools/gen_usb_descriptor.py Makefile
382389
install -d $(BUILD)
383390
python3 tools/gen_usb_descriptor.py \
384391
--manufacturer $(USB_MANUFACTURER)\
385392
--product $(USB_PRODUCT)\
386393
--vid $(USB_VID)\
387394
--pid $(USB_PID)\
388-
$@
395+
--output_c_file $(BUILD)/autogen_usb_descriptor.c\
396+
--output_h_file $(BUILD)/genhdr/autogen_usb_descriptor.h
389397

390398
deploy: $(BUILD)/firmware.bin
391399
$(ECHO) "Writing $< to the board"

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

0 commit comments

Comments
 (0)