Skip to content

Commit f0564b4

Browse files
committed
merge from upstream; complicated webusb merge
2 parents 1b7f3d1 + 2061097 commit f0564b4

File tree

96 files changed

+2509
-1104
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

96 files changed

+2509
-1104
lines changed

.github/workflows/build.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,7 @@ jobs:
208208
- "datum_imu"
209209
- "datum_light"
210210
- "datum_weather"
211+
- "dynalora_usb"
211212
- "dynossat_edu_eps"
212213
- "dynossat_edu_obc"
213214
- "electronut_labs_blip"

WEBUSB_README.md

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
<!--
2+
SPDX-FileCopyrightText: 2014 MicroPython & CircuitPython contributors (https://github.com/adafruit/circuitpython/graphs/contributors)
3+
4+
SPDX-License-Identifier: MIT
5+
-->
6+
7+
# WebUSB Serial Support
8+
9+
To date, this has only been tested on one port (esp32s2), on one board (espressif_kaluga_1).
10+
11+
## What it does
12+
13+
If you have ever used CircuitPython on a platform with a graphical LCD display, you have probably
14+
already seen multiple "consoles" in use (although the LCD console is "output only").
15+
16+
New compile-time option CIRCUITPY_USB_VENDOR enables an additional "console" that can be used in
17+
parallel with the original (CDC) serial console.
18+
19+
Web pages that support the WebUSB standard can connect to the "vendor" interface and activate
20+
this WebUSB serial console at any time.
21+
22+
You can type into either console, and CircuitPython output is sent to all active consoles.
23+
24+
One example of a web page you can use to test drive this feature can be found at:
25+
26+
https://adafruit.github.io/Adafruit_TinyUSB_Arduino/examples/webusb-serial/index.html
27+
28+
## How to enable
29+
30+
Update your platform's mpconfigboard.mk file to enable and disable specific types of USB interfaces.
31+
32+
CIRCUITPY_USB_HID = xxx
33+
CIRCUITPY_USB_MIDI = xxx
34+
CIRCUITPY_USB_VENDOR = xxx
35+
36+
On at least some of the hardware platforms, the maximum number of USB endpoints is fixed.
37+
For example, on the ESP32S2, you must pick only one of the above 3 interfaces to be enabled.
38+
39+
Original espressif_kaluga_1 mpconfigboard.mk settings:
40+
41+
CIRCUITPY_USB_HID = 1
42+
CIRCUITPY_USB_MIDI = 0
43+
CIRCUITPY_USB_VENDOR = 0
44+
45+
Settings to enable WebUSB instead:
46+
47+
CIRCUITPY_USB_HID = 0
48+
CIRCUITPY_USB_MIDI = 0
49+
CIRCUITPY_USB_VENDOR = 1
50+
51+
Notice that to enable VENDOR on ESP32-S2, we had to give up HID. There may be platforms that can have both, or even all three.
52+
53+
## Implementation Notes
54+
55+
CircuitPython uses the tinyusb library.
56+
57+
The tinyusb library already has support for WebUSB serial.
58+
The tinyusb examples already include a "WebUSB serial" example.
59+
60+
Sidenote - The use of the term "vendor" instead of "WebUSB" was done to match tinyusb.
61+
62+
Basically, this feature was ported into CircuitPython by pulling code snippets out of the
63+
tinyusb example, and putting them where they best belonged in the CircuitPython codebase.
64+
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.

docs/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ Full Table of Contents
4646
../BUILDING
4747
../CODE_OF_CONDUCT
4848
../license.rst
49+
../WEBUSB_README
4950

5051
Indices and tables
5152
==================

locale/ID.po

Lines changed: 29 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -642,6 +642,10 @@ msgstr ""
642642
"Tidak dapat melakukan reset ke bootloader karena tidak ada bootloader yang "
643643
"terisi"
644644

645+
#: ports/esp32s2/common-hal/socketpool/Socket.c
646+
msgid "Cannot set socket options"
647+
msgstr ""
648+
645649
#: shared-bindings/digitalio/DigitalInOut.c
646650
msgid "Cannot set value when direction is input."
647651
msgstr "Tidak dapat menetapkan nilai saat arah input."
@@ -884,7 +888,7 @@ msgstr "Channel EXTINT sedang digunakan"
884888
msgid "Error in regex"
885889
msgstr "Error pada regex"
886890

887-
#: shared-bindings/socketpool/Socket.c
891+
#: shared-bindings/socketpool/Socket.c shared-bindings/ssl/SSLSocket.c
888892
msgid "Error: Failure to bind"
889893
msgstr ""
890894

@@ -943,7 +947,7 @@ msgstr "FFT didefinisikan hanya untuk ndarrays"
943947
msgid "FFT is implemented for linear arrays only"
944948
msgstr ""
945949

946-
#: ports/esp32s2/common-hal/socketpool/Socket.c
950+
#: ports/esp32s2/common-hal/ssl/SSLSocket.c
947951
msgid "Failed SSL handshake"
948952
msgstr ""
949953

@@ -1316,18 +1320,14 @@ msgstr "security_mode tidak valid"
13161320
msgid "Invalid size"
13171321
msgstr ""
13181322

1319-
#: ports/esp32s2/common-hal/socketpool/Socket.c
1323+
#: ports/esp32s2/common-hal/ssl/SSLContext.c
13201324
msgid "Invalid socket for TLS"
13211325
msgstr ""
13221326

13231327
#: ports/esp32s2/bindings/espidf/__init__.c ports/esp32s2/esp_error.c
13241328
msgid "Invalid state"
13251329
msgstr ""
13261330

1327-
#: ports/esp32s2/common-hal/socketpool/Socket.c
1328-
msgid "Invalid use of TLS Socket"
1329-
msgstr ""
1330-
13311331
#: shared-bindings/audiomixer/Mixer.c
13321332
msgid "Invalid voice"
13331333
msgstr "Suara tidak valid"
@@ -1344,10 +1344,6 @@ msgstr "File wave tidak valid"
13441344
msgid "Invalid word/bit length"
13451345
msgstr "Panjang kata/bit tidak valid"
13461346

1347-
#: ports/esp32s2/common-hal/socketpool/Socket.c
1348-
msgid "Issue setting SO_REUSEADDR"
1349-
msgstr ""
1350-
13511347
#: shared-bindings/aesio/aes.c
13521348
msgid "Key must be 16, 24, or 32 bytes long"
13531349
msgstr "Panjang kunci harus 16, 24, atau 32 byte"
@@ -1560,6 +1556,12 @@ msgstr ""
15601556
msgid "No out in program"
15611557
msgstr ""
15621558

1559+
#: ports/atmel-samd/common-hal/busio/I2C.c ports/esp32s2/common-hal/busio/I2C.c
1560+
#: ports/mimxrt10xx/common-hal/busio/I2C.c ports/nrf/common-hal/busio/I2C.c
1561+
#: ports/raspberrypi/common-hal/busio/I2C.c
1562+
msgid "No pull up found on SDA or SCL; check your wiring"
1563+
msgstr ""
1564+
15631565
#: shared-module/touchio/TouchIn.c
15641566
msgid "No pulldown on pin; 1Mohm recommended"
15651567
msgstr "Tidak ada pull-down pada pin; 1Mohm direkomendasikan"
@@ -1674,7 +1676,7 @@ msgstr ""
16741676
msgid "Out of memory"
16751677
msgstr ""
16761678

1677-
#: ports/esp32s2/common-hal/socketpool/Socket.c
1679+
#: ports/esp32s2/common-hal/socketpool/SocketPool.c
16781680
msgid "Out of sockets"
16791681
msgstr ""
16801682

@@ -1825,13 +1827,18 @@ msgstr "Kesalahan DeInit RNG"
18251827
msgid "RNG Init Error"
18261828
msgstr "Kesalahan Init RNG"
18271829

1830+
#: ports/nrf/common-hal/busio/UART.c
1831+
msgid "RS485 Not yet supported on this device"
1832+
msgstr ""
1833+
18281834
#: ports/esp32s2/common-hal/busio/UART.c
18291835
#: ports/mimxrt10xx/common-hal/busio/UART.c
18301836
msgid "RS485 inversion specified when not in RS485 mode"
18311837
msgstr "Pembalikan RS485 ditentukan saat tidak dalam mode RS485"
18321838

18331839
#: ports/cxd56/common-hal/rtc/RTC.c ports/esp32s2/common-hal/rtc/RTC.c
18341840
#: ports/mimxrt10xx/common-hal/rtc/RTC.c ports/nrf/common-hal/rtc/RTC.c
1841+
#: ports/raspberrypi/common-hal/rtc/RTC.c
18351842
msgid "RTC calibration is not supported on this board"
18361843
msgstr "Kalibrasi RTC tidak didukung pada board ini"
18371844

@@ -1840,7 +1847,7 @@ msgid "RTC is not supported on this board"
18401847
msgstr "RTC tidak didukung di board ini"
18411848

18421849
#: ports/atmel-samd/common-hal/busio/UART.c ports/cxd56/common-hal/busio/UART.c
1843-
#: ports/nrf/common-hal/busio/UART.c ports/stm/common-hal/busio/UART.c
1850+
#: ports/stm/common-hal/busio/UART.c
18441851
msgid "RTS/CTS/RS485 Not yet supported on this device"
18451852
msgstr "RTS/CTS/RS485 Belum didukung pada perangkat ini"
18461853

@@ -1898,12 +1905,6 @@ msgstr ""
18981905
msgid "SD card CSD format not supported"
18991906
msgstr ""
19001907

1901-
#: ports/atmel-samd/common-hal/busio/I2C.c ports/esp32s2/common-hal/busio/I2C.c
1902-
#: ports/mimxrt10xx/common-hal/busio/I2C.c ports/nrf/common-hal/busio/I2C.c
1903-
#: ports/raspberrypi/common-hal/busio/I2C.c
1904-
msgid "SDA or SCL needs a pull up"
1905-
msgstr "SDA atau SCL membutuhkan pull up"
1906-
19071908
#: ports/stm/common-hal/sdioio/SDCard.c
19081909
#, c-format
19091910
msgid "SDIO GetCardInfo Error %d"
@@ -2203,7 +2204,7 @@ msgstr ""
22032204
msgid "Unexpected nrfx uuid type"
22042205
msgstr "Tipe urf nrfx tak sesuai"
22052206

2206-
#: ports/esp32s2/common-hal/socketpool/Socket.c
2207+
#: ports/esp32s2/common-hal/ssl/SSLSocket.c
22072208
#, c-format
22082209
msgid "Unhandled ESP TLS error %d %d %x %d"
22092210
msgstr ""
@@ -2512,7 +2513,7 @@ msgstr ""
25122513
msgid "buffer too small"
25132514
msgstr ""
25142515

2515-
#: shared-bindings/socketpool/Socket.c
2516+
#: shared-bindings/socketpool/Socket.c shared-bindings/ssl/SSLSocket.c
25162517
msgid "buffer too small for requested bytes"
25172518
msgstr ""
25182519

@@ -3673,6 +3674,10 @@ msgstr "Muncul dari PulseIn yang kosong"
36733674
msgid "pop from empty %q"
36743675
msgstr ""
36753676

3677+
#: shared-bindings/socketpool/Socket.c shared-bindings/ssl/SSLSocket.c
3678+
msgid "port must be >= 0"
3679+
msgstr ""
3680+
36763681
#: py/objint_mpz.c
36773682
msgid "pow() 3rd argument cannot be 0"
36783683
msgstr ""
@@ -4202,6 +4207,9 @@ msgstr ""
42024207
msgid "zi must be of shape (n_section, 2)"
42034208
msgstr ""
42044209

4210+
#~ msgid "SDA or SCL needs a pull up"
4211+
#~ msgstr "SDA atau SCL membutuhkan pull up"
4212+
42054213
#~ msgid "%d address pins and %d rgb pins indicate a height of %d, not %d"
42064214
#~ msgstr "pin alamat %d dan pin rgb %d menunjukkan tinggi %d, bukan %d"
42074215

locale/circuitpython.pot

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -629,6 +629,10 @@ msgstr ""
629629
msgid "Cannot reset into bootloader because no bootloader is present."
630630
msgstr ""
631631

632+
#: ports/esp32s2/common-hal/socketpool/Socket.c
633+
msgid "Cannot set socket options"
634+
msgstr ""
635+
632636
#: shared-bindings/digitalio/DigitalInOut.c
633637
msgid "Cannot set value when direction is input."
634638
msgstr ""
@@ -865,7 +869,7 @@ msgstr ""
865869
msgid "Error in regex"
866870
msgstr ""
867871

868-
#: shared-bindings/socketpool/Socket.c
872+
#: shared-bindings/socketpool/Socket.c shared-bindings/ssl/SSLSocket.c
869873
msgid "Error: Failure to bind"
870874
msgstr ""
871875

@@ -924,7 +928,7 @@ msgstr ""
924928
msgid "FFT is implemented for linear arrays only"
925929
msgstr ""
926930

927-
#: ports/esp32s2/common-hal/socketpool/Socket.c
931+
#: ports/esp32s2/common-hal/ssl/SSLSocket.c
928932
msgid "Failed SSL handshake"
929933
msgstr ""
930934

@@ -1295,18 +1299,14 @@ msgstr ""
12951299
msgid "Invalid size"
12961300
msgstr ""
12971301

1298-
#: ports/esp32s2/common-hal/socketpool/Socket.c
1302+
#: ports/esp32s2/common-hal/ssl/SSLContext.c
12991303
msgid "Invalid socket for TLS"
13001304
msgstr ""
13011305

13021306
#: ports/esp32s2/bindings/espidf/__init__.c ports/esp32s2/esp_error.c
13031307
msgid "Invalid state"
13041308
msgstr ""
13051309

1306-
#: ports/esp32s2/common-hal/socketpool/Socket.c
1307-
msgid "Invalid use of TLS Socket"
1308-
msgstr ""
1309-
13101310
#: shared-bindings/audiomixer/Mixer.c
13111311
msgid "Invalid voice"
13121312
msgstr ""
@@ -1323,10 +1323,6 @@ msgstr ""
13231323
msgid "Invalid word/bit length"
13241324
msgstr ""
13251325

1326-
#: ports/esp32s2/common-hal/socketpool/Socket.c
1327-
msgid "Issue setting SO_REUSEADDR"
1328-
msgstr ""
1329-
13301326
#: shared-bindings/aesio/aes.c
13311327
msgid "Key must be 16, 24, or 32 bytes long"
13321328
msgstr ""
@@ -1539,6 +1535,12 @@ msgstr ""
15391535
msgid "No out in program"
15401536
msgstr ""
15411537

1538+
#: ports/atmel-samd/common-hal/busio/I2C.c ports/esp32s2/common-hal/busio/I2C.c
1539+
#: ports/mimxrt10xx/common-hal/busio/I2C.c ports/nrf/common-hal/busio/I2C.c
1540+
#: ports/raspberrypi/common-hal/busio/I2C.c
1541+
msgid "No pull up found on SDA or SCL; check your wiring"
1542+
msgstr ""
1543+
15421544
#: shared-module/touchio/TouchIn.c
15431545
msgid "No pulldown on pin; 1Mohm recommended"
15441546
msgstr ""
@@ -1647,7 +1649,7 @@ msgstr ""
16471649
msgid "Out of memory"
16481650
msgstr ""
16491651

1650-
#: ports/esp32s2/common-hal/socketpool/Socket.c
1652+
#: ports/esp32s2/common-hal/socketpool/SocketPool.c
16511653
msgid "Out of sockets"
16521654
msgstr ""
16531655

@@ -1870,12 +1872,6 @@ msgstr ""
18701872
msgid "SD card CSD format not supported"
18711873
msgstr ""
18721874

1873-
#: ports/atmel-samd/common-hal/busio/I2C.c ports/esp32s2/common-hal/busio/I2C.c
1874-
#: ports/mimxrt10xx/common-hal/busio/I2C.c ports/nrf/common-hal/busio/I2C.c
1875-
#: ports/raspberrypi/common-hal/busio/I2C.c
1876-
msgid "SDA or SCL needs a pull up"
1877-
msgstr ""
1878-
18791875
#: ports/stm/common-hal/sdioio/SDCard.c
18801876
#, c-format
18811877
msgid "SDIO GetCardInfo Error %d"
@@ -2167,7 +2163,7 @@ msgstr ""
21672163
msgid "Unexpected nrfx uuid type"
21682164
msgstr ""
21692165

2170-
#: ports/esp32s2/common-hal/socketpool/Socket.c
2166+
#: ports/esp32s2/common-hal/ssl/SSLSocket.c
21712167
#, c-format
21722168
msgid "Unhandled ESP TLS error %d %d %x %d"
21732169
msgstr ""
@@ -2466,7 +2462,7 @@ msgstr ""
24662462
msgid "buffer too small"
24672463
msgstr ""
24682464

2469-
#: shared-bindings/socketpool/Socket.c
2465+
#: shared-bindings/socketpool/Socket.c shared-bindings/ssl/SSLSocket.c
24702466
msgid "buffer too small for requested bytes"
24712467
msgstr ""
24722468

@@ -3626,6 +3622,10 @@ msgstr ""
36263622
msgid "pop from empty %q"
36273623
msgstr ""
36283624

3625+
#: shared-bindings/socketpool/Socket.c shared-bindings/ssl/SSLSocket.c
3626+
msgid "port must be >= 0"
3627+
msgstr ""
3628+
36293629
#: py/objint_mpz.c
36303630
msgid "pow() 3rd argument cannot be 0"
36313631
msgstr ""

0 commit comments

Comments
 (0)