Skip to content

Commit c26e49c

Browse files
committed
wip: starting to try to compile
1 parent 9d1fcc3 commit c26e49c

File tree

17 files changed

+149
-2383
lines changed

17 files changed

+149
-2383
lines changed

WEBUSB_README.md

Lines changed: 1 addition & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -62,33 +62,4 @@ The tinyusb examples already include a "WebUSB serial" example.
6262
Basically, this feature was ported into CircuitPython by pulling code snippets out of the
6363
tinyusb example, and putting them where they best belonged in the CircuitPython codebase.
6464

65-
There was one complication:
66-
67-
tinyusb uses C preprocessor macros to define things like USB descriptors.
68-
69-
CircuitPython uses a Python program (tools/gen_usb_descriptor.py) to create USB descriptors (etc.)
70-
using "helper objects" from another repo (adafruit_usb_descriptor). This means some of the example
71-
code had to be adapted to the new programing model, and gen_usb_descriptor gained new command-line
72-
options to control the generated code.
73-
74-
The generated files go into the "build" directory, look for autogen_usb_descriptor.c and
75-
genhdr/autogen_usb_descriptor.h.
76-
77-
78-
Also worth pointing out - the re-use of the CDC connect/disconnect mechanism is not actually part
79-
of the WebUSB standard, it's more of "common idiom". We make use of it here because we need to know
80-
when we should be paying attention to the WebUSB serial interface, and when we should ignore it..
81-
82-
## Possible future work areas
83-
84-
The current code uses the existing Python infrastructure to create the Interface descriptor, but
85-
simply outputs the code snippets from the original tinyusb demo code to create the WEBUSB_URL,
86-
BOS, and MS_OS_20 descriptors. I suppose additional work could be done to add these to the
87-
adafruit_usb_descriptor project, and then gen_usb_descriptor.py could be modified to make use
88-
of them.
89-
90-
Program gen_usb_descriptor.py creates objects for most interface types, regardless of whether or
91-
not they are actually enabled. This increases the size of a generated string table. I made the
92-
new vendor-interface-related code not do this (because some of the ARM platforms would no longer
93-
build), but I did not go back and do this for the other interface types (CDC, MIDI, HID, etc.)
94-
Some FLASH savings are probably possible if this is done.
65+
### TODO: This needs to be reworked for dynamic USB descriptors.

main.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -518,7 +518,6 @@ STATIC void __attribute__ ((noinline)) run_boot_py(safe_mode_t safe_mode) {
518518
}
519519
#endif
520520

521-
// TODO(tannewt): Allocate temporary space to hold custom usb descriptors.
522521
filesystem_flush();
523522
supervisor_allocation* heap = allocate_remaining_memory();
524523
start_mp(heap);
@@ -535,6 +534,12 @@ STATIC void __attribute__ ((noinline)) run_boot_py(safe_mode_t safe_mode) {
535534
boot_output_file = NULL;
536535
#endif
537536

537+
#if CIRCUITPY_USB
538+
// Remember USB settings done during boot.py.
539+
// Call this before the boot.py heap is destroyed.
540+
usb_post_boot_py();
541+
#endif
542+
538543
cleanup_after_vm(heap);
539544
}
540545
}
@@ -588,6 +593,7 @@ int __attribute__((used)) main(void) {
588593
// Port-independent devices, like CIRCUITPY_BLEIO_HCI.
589594
reset_devices();
590595
reset_board();
596+
reset_usb();
591597

592598
// This is first time we are running CircuitPython after a reset or power-up.
593599
supervisor_set_run_reason(RUN_REASON_STARTUP);

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

Lines changed: 2 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -2,60 +2,29 @@
22
#ifndef HPL_USB_CONFIG_H
33
#define HPL_USB_CONFIG_H
44

5-
// CIRCUITPY:
5+
// CIRCUITPY: Since we have dynamic USB descriptors, we may end up using all endpoints.
6+
// So provide cache space for all of them.
67

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
128
#define CONF_USB_EP1_CACHE 64
13-
#endif
14-
#if defined(USB_ENDPOINT_1_IN_USED) && USB_ENDPOINT_1_IN_USED
159
#define CONF_USB_EP1_I_CACHE 64
16-
#endif
1710

18-
#if defined(USB_ENDPOINT_2_OUT_USED) && USB_ENDPOINT_2_OUT_USED
1911
#define CONF_USB_EP2_CACHE 64
20-
#endif
21-
#if defined(USB_ENDPOINT_2_IN_USED) && USB_ENDPOINT_2_IN_USED
2212
#define CONF_USB_EP2_I_CACHE 64
23-
#endif
2413

25-
#if defined(USB_ENDPOINT_3_OUT_USED) && USB_ENDPOINT_3_OUT_USED
2614
#define CONF_USB_EP3_CACHE 64
27-
#endif
28-
#if defined(USB_ENDPOINT_3_IN_USED) && USB_ENDPOINT_3_IN_USED
2915
#define CONF_USB_EP3_I_CACHE 64
30-
#endif
3116

32-
#if defined(USB_ENDPOINT_4_OUT_USED) && USB_ENDPOINT_4_OUT_USED
3317
#define CONF_USB_EP4_CACHE 64
34-
#endif
35-
#if defined(USB_ENDPOINT_4_IN_USED) && USB_ENDPOINT_4_IN_USED
3618
#define CONF_USB_EP4_I_CACHE 64
37-
#endif
3819

39-
#if defined(USB_ENDPOINT_5_OUT_USED) && USB_ENDPOINT_5_OUT_USED
4020
#define CONF_USB_EP5_CACHE 64
41-
#endif
42-
#if defined(USB_ENDPOINT_5_IN_USED) && USB_ENDPOINT_5_IN_USED
4321
#define CONF_USB_EP5_I_CACHE 64
44-
#endif
4522

46-
#if defined(USB_ENDPOINT_6_OUT_USED) && USB_ENDPOINT_6_OUT_USED
4723
#define CONF_USB_EP6_CACHE 64
48-
#endif
49-
#if defined(USB_ENDPOINT_6_IN_USED) && USB_ENDPOINT_6_IN_USED
5024
#define CONF_USB_EP6_I_CACHE 64
51-
#endif
5225

53-
#if defined(USB_ENDPOINT_7_OUT_USED) && USB_ENDPOINT_7_OUT_USED
5426
#define CONF_USB_EP7_CACHE 64
55-
#endif
56-
#if defined(USB_ENDPOINT_7_IN_USED) && USB_ENDPOINT_7_IN_USED
5727
#define CONF_USB_EP7_I_CACHE 64
58-
#endif
5928

6029

6130
// <<< Use Configuration Wizard in Context Menu >>>

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

Lines changed: 2 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -2,60 +2,29 @@
22
#ifndef HPL_USB_CONFIG_H
33
#define HPL_USB_CONFIG_H
44

5-
// CIRCUITPY:
5+
// CIRCUITPY: Since we have dynamic USB descriptors, we may end up using all endpoints.
6+
// So provide cache space for all of them.
67

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
128
#define CONF_USB_EP1_CACHE 64
13-
#endif
14-
#if defined(USB_ENDPOINT_1_IN_USED) && USB_ENDPOINT_1_IN_USED
159
#define CONF_USB_EP1_I_CACHE 64
16-
#endif
1710

18-
#if defined(USB_ENDPOINT_2_OUT_USED) && USB_ENDPOINT_2_OUT_USED
1911
#define CONF_USB_EP2_CACHE 64
20-
#endif
21-
#if defined(USB_ENDPOINT_2_IN_USED) && USB_ENDPOINT_2_IN_USED
2212
#define CONF_USB_EP2_I_CACHE 64
23-
#endif
2413

25-
#if defined(USB_ENDPOINT_3_OUT_USED) && USB_ENDPOINT_3_OUT_USED
2614
#define CONF_USB_EP3_CACHE 64
27-
#endif
28-
#if defined(USB_ENDPOINT_3_IN_USED) && USB_ENDPOINT_3_IN_USED
2915
#define CONF_USB_EP3_I_CACHE 64
30-
#endif
3116

32-
#if defined(USB_ENDPOINT_4_OUT_USED) && USB_ENDPOINT_4_OUT_USED
3317
#define CONF_USB_EP4_CACHE 64
34-
#endif
35-
#if defined(USB_ENDPOINT_4_IN_USED) && USB_ENDPOINT_4_IN_USED
3618
#define CONF_USB_EP4_I_CACHE 64
37-
#endif
3819

39-
#if defined(USB_ENDPOINT_5_OUT_USED) && USB_ENDPOINT_5_OUT_USED
4020
#define CONF_USB_EP5_CACHE 64
41-
#endif
42-
#if defined(USB_ENDPOINT_5_IN_USED) && USB_ENDPOINT_5_IN_USED
4321
#define CONF_USB_EP5_I_CACHE 64
44-
#endif
4522

46-
#if defined(USB_ENDPOINT_6_OUT_USED) && USB_ENDPOINT_6_OUT_USED
4723
#define CONF_USB_EP6_CACHE 64
48-
#endif
49-
#if defined(USB_ENDPOINT_6_IN_USED) && USB_ENDPOINT_6_IN_USED
5024
#define CONF_USB_EP6_I_CACHE 64
51-
#endif
5225

53-
#if defined(USB_ENDPOINT_7_OUT_USED) && USB_ENDPOINT_7_OUT_USED
5426
#define CONF_USB_EP7_CACHE 64
55-
#endif
56-
#if defined(USB_ENDPOINT_7_IN_USED) && USB_ENDPOINT_7_IN_USED
5727
#define CONF_USB_EP7_I_CACHE 64
58-
#endif
5928

6029

6130
// <<< Use Configuration Wizard in Context Menu >>>

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

Lines changed: 2 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -2,60 +2,29 @@
22
#ifndef HPL_USB_CONFIG_H
33
#define HPL_USB_CONFIG_H
44

5-
// CIRCUITPY:
5+
// CIRCUITPY: Since we have dynamic USB descriptors, we may end up using all endpoints.
6+
// So provide cache space for all of them.
67

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
128
#define CONF_USB_EP1_CACHE 64
13-
#endif
14-
#if defined(USB_ENDPOINT_1_IN_USED) && USB_ENDPOINT_1_IN_USED
159
#define CONF_USB_EP1_I_CACHE 64
16-
#endif
1710

18-
#if defined(USB_ENDPOINT_2_OUT_USED) && USB_ENDPOINT_2_OUT_USED
1911
#define CONF_USB_EP2_CACHE 64
20-
#endif
21-
#if defined(USB_ENDPOINT_2_IN_USED) && USB_ENDPOINT_2_IN_USED
2212
#define CONF_USB_EP2_I_CACHE 64
23-
#endif
2413

25-
#if defined(USB_ENDPOINT_3_OUT_USED) && USB_ENDPOINT_3_OUT_USED
2614
#define CONF_USB_EP3_CACHE 64
27-
#endif
28-
#if defined(USB_ENDPOINT_3_IN_USED) && USB_ENDPOINT_3_IN_USED
2915
#define CONF_USB_EP3_I_CACHE 64
30-
#endif
3116

32-
#if defined(USB_ENDPOINT_4_OUT_USED) && USB_ENDPOINT_4_OUT_USED
3317
#define CONF_USB_EP4_CACHE 64
34-
#endif
35-
#if defined(USB_ENDPOINT_4_IN_USED) && USB_ENDPOINT_4_IN_USED
3618
#define CONF_USB_EP4_I_CACHE 64
37-
#endif
3819

39-
#if defined(USB_ENDPOINT_5_OUT_USED) && USB_ENDPOINT_5_OUT_USED
4020
#define CONF_USB_EP5_CACHE 64
41-
#endif
42-
#if defined(USB_ENDPOINT_5_IN_USED) && USB_ENDPOINT_5_IN_USED
4321
#define CONF_USB_EP5_I_CACHE 64
44-
#endif
4522

46-
#if defined(USB_ENDPOINT_6_OUT_USED) && USB_ENDPOINT_6_OUT_USED
4723
#define CONF_USB_EP6_CACHE 64
48-
#endif
49-
#if defined(USB_ENDPOINT_6_IN_USED) && USB_ENDPOINT_6_IN_USED
5024
#define CONF_USB_EP6_I_CACHE 64
51-
#endif
5225

53-
#if defined(USB_ENDPOINT_7_OUT_USED) && USB_ENDPOINT_7_OUT_USED
5426
#define CONF_USB_EP7_CACHE 64
55-
#endif
56-
#if defined(USB_ENDPOINT_7_IN_USED) && USB_ENDPOINT_7_IN_USED
5727
#define CONF_USB_EP7_I_CACHE 64
58-
#endif
5928

6029

6130
// <<< Use Configuration Wizard in Context Menu >>>

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

Lines changed: 2 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -2,60 +2,29 @@
22
#ifndef HPL_USB_CONFIG_H
33
#define HPL_USB_CONFIG_H
44

5-
// CIRCUITPY:
5+
// CIRCUITPY: Since we have dynamic USB descriptors, we may end up using all endpoints.
6+
// So provide cache space for all of them.
67

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
128
#define CONF_USB_EP1_CACHE 64
13-
#endif
14-
#if defined(USB_ENDPOINT_1_IN_USED) && USB_ENDPOINT_1_IN_USED
159
#define CONF_USB_EP1_I_CACHE 64
16-
#endif
1710

18-
#if defined(USB_ENDPOINT_2_OUT_USED) && USB_ENDPOINT_2_OUT_USED
1911
#define CONF_USB_EP2_CACHE 64
20-
#endif
21-
#if defined(USB_ENDPOINT_2_IN_USED) && USB_ENDPOINT_2_IN_USED
2212
#define CONF_USB_EP2_I_CACHE 64
23-
#endif
2413

25-
#if defined(USB_ENDPOINT_3_OUT_USED) && USB_ENDPOINT_3_OUT_USED
2614
#define CONF_USB_EP3_CACHE 64
27-
#endif
28-
#if defined(USB_ENDPOINT_3_IN_USED) && USB_ENDPOINT_3_IN_USED
2915
#define CONF_USB_EP3_I_CACHE 64
30-
#endif
3116

32-
#if defined(USB_ENDPOINT_4_OUT_USED) && USB_ENDPOINT_4_OUT_USED
3317
#define CONF_USB_EP4_CACHE 64
34-
#endif
35-
#if defined(USB_ENDPOINT_4_IN_USED) && USB_ENDPOINT_4_IN_USED
3618
#define CONF_USB_EP4_I_CACHE 64
37-
#endif
3819

39-
#if defined(USB_ENDPOINT_5_OUT_USED) && USB_ENDPOINT_5_OUT_USED
4020
#define CONF_USB_EP5_CACHE 64
41-
#endif
42-
#if defined(USB_ENDPOINT_5_IN_USED) && USB_ENDPOINT_5_IN_USED
4321
#define CONF_USB_EP5_I_CACHE 64
44-
#endif
4522

46-
#if defined(USB_ENDPOINT_6_OUT_USED) && USB_ENDPOINT_6_OUT_USED
4723
#define CONF_USB_EP6_CACHE 64
48-
#endif
49-
#if defined(USB_ENDPOINT_6_IN_USED) && USB_ENDPOINT_6_IN_USED
5024
#define CONF_USB_EP6_I_CACHE 64
51-
#endif
5225

53-
#if defined(USB_ENDPOINT_7_OUT_USED) && USB_ENDPOINT_7_OUT_USED
5426
#define CONF_USB_EP7_CACHE 64
55-
#endif
56-
#if defined(USB_ENDPOINT_7_IN_USED) && USB_ENDPOINT_7_IN_USED
5727
#define CONF_USB_EP7_I_CACHE 64
58-
#endif
5928

6029

6130
// <<< Use Configuration Wizard in Context Menu >>>

py/circuitpy_mpconfig.mk

Lines changed: 22 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -308,6 +308,9 @@ CFLAGS += -DCIRCUITPY_STRUCT=$(CIRCUITPY_STRUCT)
308308
CIRCUITPY_SUPERVISOR ?= 1
309309
CFLAGS += -DCIRCUITPY_SUPERVISOR=$(CIRCUITPY_SUPERVISOR)
310310

311+
CIRCUITPY_SYNTHIO ?= $(CIRCUITPY_AUDIOCORE)
312+
CFLAGS += -DCIRCUITPY_SYNTHIO=$(CIRCUITPY_SYNTHIO)
313+
311314
CIRCUITPY_TERMINALIO ?= $(CIRCUITPY_DISPLAYIO)
312315
CFLAGS += -DCIRCUITPY_TERMINALIO=$(CIRCUITPY_TERMINALIO)
313316

@@ -325,39 +328,34 @@ CFLAGS += -DCIRCUITPY_TOUCHIO=$(CIRCUITPY_TOUCHIO)
325328
CIRCUITPY_UHEAP ?= 0
326329
CFLAGS += -DCIRCUITPY_UHEAP=$(CIRCUITPY_UHEAP)
327330

328-
# Secondary CDC is usually available if there are at least 8 endpoints.
329-
CIRCUITPY_USB_CDC ?= $(shell expr $(USB_NUM_EP) '>=' 8)
331+
CIRCUITPY_USB ?= 1
332+
CFLAGS += -DCIRCUITPY_USB=$(CIRCUITPY_USB)
333+
334+
# If you need to count endpoints, do:
335+
# $(shell expr $(USB_NUM_EP) '>=' 8)
336+
337+
CIRCUITPY_USB_CDC ?= 1
330338
CFLAGS += -DCIRCUITPY_USB_CDC=$(CIRCUITPY_USB_CDC)
339+
CIRCUITPY_USB_CDC_REPL_ENABLED ?= 1
340+
CFLAGS += -DCIRCUITPY_USB_CDC_DATA_ENABLED_DEFAULT=$(CIRCUITPY_USB_CDC_DATA_ENABLED_DEFAULT)
341+
CIRCUITPY_USB_CDC_DATA_ENABLED ?= 0
342+
CFLAGS += -DCIRCUITPY_USB_CDC_DATA_ENABLED_DEFAULT=$(CIRCUITPY_USB_CDC_DATA_ENABLED_DEFAULT)
331343

332344
CIRCUITPY_USB_HID ?= 1
333345
CFLAGS += -DCIRCUITPY_USB_HID=$(CIRCUITPY_USB_HID)
346+
CIRCUITPY_USB_HID_ENABLED_DEFAULT = $(CIRCUITPY_USB_HID)
347+
CFLAGS += -DCIRCUITPY_USB_HID_ENABLED_DEFAULT=$(CIRCUITPY_USB_HID_ENABLED_DEFAULT)
334348

335-
CIRCUITPY_USB_HID_CONSUMER ?= 1
336-
CFLAGS += -DCIRCUITPY_USB_HID_CONSUMER=$(CIRCUITPY_USB_HID_CONSUMER)
337-
338-
CIRCUITPY_USB_HID_DIGITIZER ?= 0
339-
CFLAGS += -DCIRCUITPY_USB_HID_DIGITIZER=$(CIRCUITPY_USB_HID_DIGITIZER)
340-
341-
CIRCUITPY_USB_HID_GAMEPAD ?= 1
342-
CFLAGS += -DCIRCUITPY_USB_HID_GAMEPAD=$(CIRCUITPY_USB_HID_GAMEPAD)
343-
344-
CIRCUITPY_USB_HID_KEYBOARD ?= 1
345-
CFLAGS += -DCIRCUITPY_USB_HID_KEYBOARD=$(CIRCUITPY_USB_HID_KEYBOARD)
346-
347-
CIRCUITPY_USB_HID_MOUSE ?= 1
348-
CFLAGS += -DCIRCUITPY_USB_HID_MOUSE=$(CIRCUITPY_USB_HID_MOUSE)
349-
350-
CIRCUITPY_USB_HID_SYS_CONTROL ?= 0
351-
CFLAGS += -DCIRCUITPY_USB_HID_SYS_CONTROL=$(CIRCUITPY_USB_HID_SYS_CONTROL)
352-
353-
CIRCUITPY_USB_HID_XAC_COMPATIBLE_GAMEPAD ?= 0
354-
CFLAGS += -DCIRCUITPY_USB_HID_XAC_COMPATIBLE_GAMEPAD=$(CIRCUITPY_USB_HID_XAC_COMPATIBLE_GAMEPAD)
355-
356-
CIRCUITPY_USB_MIDI ?= 1
349+
# MIDI is usually available if there are at least 8 endpoints.
350+
CIRCUITPY_USB_MIDI ?= $(shell expr $(USB_NUM_EP) '>=' 8)
357351
CFLAGS += -DCIRCUITPY_USB_MIDI=$(CIRCUITPY_USB_MIDI)
352+
CIRCUITPY_USB_MIDI_ENABLED_DEFAULT = $(CIRCUITPY_USB_MIDI)
353+
CFLAGS += -DCIRCUITPY_USB_MIDI_ENABLED_DEFAULT=$(CIRCUITPY_USB_MIDI_ENABLED_DEFAULT)
358354

359355
CIRCUITPY_USB_MSC ?= 1
360356
CFLAGS += -DCIRCUITPY_USB_MSC=$(CIRCUITPY_USB_MSC)
357+
CIRCUITPY_USB_MSC_ENABLED_DEFAULT = $(CIRCUITPY_USB_MSC)
358+
CFLAGS += -DCIRCUITPY_USB_MSC_ENABLED_DEFAULT=$(CIRCUITPY_USB_MSC_ENABLED_DEFAULT)
361359

362360
# Defaulting this to OFF initially because it has only been tested on a
363361
# limited number of platforms, and the other platforms do not have this

0 commit comments

Comments
 (0)