diff options
| author | hathach <[email protected]> | 2026-06-29 10:16:25 +0700 |
|---|---|---|
| committer | hathach <[email protected]> | 2026-06-29 10:16:25 +0700 |
| commit | 4b1c8d16f72bb5d8f2eb8a2e8dde35abdd2f2a88 (patch) | |
| tree | 3db175aa3d96c92a44fab764dba59f473096c4b4 /examples/device/webusb_serial/README.md | |
| parent | 0a25cc27d7d3699536f6df01e80af3eb0423ce58 (diff) | |
docs: add build-doc tooling and a README for every example
Documentation tooling:
- Add the `build-doc` skill and `tools/build_doc.py` wrapper for local
Sphinx builds (clean / -W / open).
- Enable Markdown (MyST) in conf.py and auto-collect
examples/{device,host,dual}/*/README.md into a 3-level Examples nav
(Examples > Device/Host/Dual > example), noting each page's source
location and normalizing headings to a single H1.
- Remove the stale `.claude/commands/build-doc.md`; point the AGENTS.md
Documentation section at the skill.
Example docs:
- Add a README.md for every device/host/dual example: what it does, USB
interface table, notable tusb_config.h settings, generic CMake + Make
build steps, and how to try it.
- Fold each *_freertos variant into its base README, noting the FreeRTOS
source path and any RTOS-specific behavior.
Generated docs/examples/ output is git-ignored. Builds clean with
`sphinx-build -W`.
Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Diffstat (limited to 'examples/device/webusb_serial/README.md')
| -rw-r--r-- | examples/device/webusb_serial/README.md | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/examples/device/webusb_serial/README.md b/examples/device/webusb_serial/README.md new file mode 100644 index 000000000..5ca70f909 --- /dev/null +++ b/examples/device/webusb_serial/README.md @@ -0,0 +1,54 @@ +# WebUSB Serial + +A WebUSB device that acts as a web serial bridge, reachable directly from a WebUSB-capable browser (e.g. Chrome). It also exposes a standard CDC virtual serial port, and bridges traffic between the two. + +## What it does + +- Exposes a Vendor (WebUSB) interface plus a CDC virtual serial port. +- Echoes any data received on either the WebUSB or the CDC interface back to **both** of them. +- Serves a WebUSB landing-page URL (`example.tinyusb.org/webusb-serial/index.html`) via a BOS descriptor, so a supporting browser can offer to open the page. +- Provides a Microsoft OS 2.0 descriptor so Windows auto-binds the WinUSB driver to the WebUSB interface. +- Treats a vendor control request as a connect/disconnect signal from the browser; lights the on-board LED solid while the web serial is connected. +- Blinks the on-board LED to reflect bus state: 250 ms unmounted, 1000 ms mounted, 2500 ms suspended. + +## USB Descriptors + +| Interface | Class driver | +|-----------|--------------| +| 0–1 | CDC (virtual serial) | +| 2 | Vendor (WebUSB) | + +## Configuration + +Notable `tusb_config.h` settings: + +```c +#define CFG_TUD_CDC 1 +#define CFG_TUD_VENDOR 1 +#define CFG_TUD_CDC_RX_BUFSIZE (TUD_OPT_HIGH_SPEED ? 512 : 64) +#define CFG_TUD_CDC_TX_BUFSIZE (TUD_OPT_HIGH_SPEED ? 512 : 64) +#define CFG_TUD_VENDOR_RX_BUFSIZE (TUD_OPT_HIGH_SPEED ? 512 : 64) +#define CFG_TUD_VENDOR_TX_BUFSIZE (TUD_OPT_HIGH_SPEED ? 512 : 64) +``` + +## Building + +CMake: + +```bash +mkdir build && cd build +cmake -DBOARD=raspberry_pi_pico .. +cmake --build . +``` + +Make: + +```bash +make BOARD=raspberry_pi_pico all +``` + +## Try it + +After flashing, open the landing page (`https://example.tinyusb.org/webusb-serial/index.html`) in a WebUSB-capable browser such as Chrome, click **Connect**, and select the device — the on-board LED lights solid once connected. Characters typed in the web page are echoed back, and are also mirrored to the CDC serial port (e.g. `/dev/ttyACM0`) and vice versa. + +On Linux/macOS you may need to install the udev rules from `examples/device/99-tinyusb.rules` for the browser to access the device. |
