summaryrefslogtreecommitdiff
path: root/examples/device/mtp/README.md
diff options
context:
space:
mode:
authorhathach <[email protected]>2026-06-29 10:16:25 +0700
committerhathach <[email protected]>2026-06-29 10:16:25 +0700
commit4b1c8d16f72bb5d8f2eb8a2e8dde35abdd2f2a88 (patch)
tree3db175aa3d96c92a44fab764dba59f473096c4b4 /examples/device/mtp/README.md
parent0a25cc27d7d3699536f6df01e80af3eb0423ce58 (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/mtp/README.md')
-rw-r--r--examples/device/mtp/README.md85
1 files changed, 85 insertions, 0 deletions
diff --git a/examples/device/mtp/README.md b/examples/device/mtp/README.md
new file mode 100644
index 000000000..eafbe8061
--- /dev/null
+++ b/examples/device/mtp/README.md
@@ -0,0 +1,85 @@
+# MTP
+
+A USB Media Transfer Protocol device backed by a small in-RAM filesystem that the host can browse, read from and write to.
+
+## What it does
+
+- Presents a single MTP storage preloaded with two read-only objects: `readme.txt` and `tinyusb.png`.
+- Supports core MTP operations: get device info, open/close session, get storage IDs and storage info, enumerate object handles, get object info, get object and get partial object, and a device property (device friendly name).
+- Lets the host upload one additional object (SendObjectInfo / SendObject) into a 4 KB RAM buffer and delete objects (unless built read-only).
+- Handles MTP class control requests: cancel, device reset and get device status.
+- LED blink rate indicates bus state (not mounted / mounted / suspended).
+
+## USB Descriptors
+
+| Interface | Class driver |
+|-----------|--------------|
+| 0 | MTP |
+
+## Configuration
+
+Notable `tusb_config.h` settings:
+
+```c
+#define CFG_TUD_MTP 1
+#define CFG_TUD_MTP_EP_BUFSIZE 512
+#define CFG_TUD_MTP_EP_CONTROL_BUFSIZE 16 // should be enough to hold data in MTP control request
+
+// MTP device info
+#define CFG_TUD_MTP_DEVICEINFO_EXTENSIONS "microsoft.com: 1.0; "
+#define CFG_TUD_MTP_DEVICEINFO_SUPPORTED_OPERATIONS \
+ MTP_OP_GET_DEVICE_INFO, \
+ MTP_OP_OPEN_SESSION, \
+ MTP_OP_CLOSE_SESSION, \
+ MTP_OP_GET_STORAGE_IDS, \
+ MTP_OP_GET_STORAGE_INFO, \
+ MTP_OP_GET_OBJECT_HANDLES, \
+ MTP_OP_GET_OBJECT_INFO, \
+ MTP_OP_GET_OBJECT, \
+ MTP_OP_GET_PARTIAL_OBJECT, \
+ MTP_OP_DELETE_OBJECT, \
+ MTP_OP_SEND_OBJECT_INFO, \
+ MTP_OP_SEND_OBJECT, \
+ MTP_OP_RESET_DEVICE, \
+ MTP_OP_GET_DEVICE_PROP_DESC, \
+ MTP_OP_GET_DEVICE_PROP_VALUE, \
+ MTP_OP_SET_DEVICE_PROP_VALUE
+
+#define CFG_TUD_MTP_DEVICEINFO_SUPPORTED_EVENTS \
+ MTP_EVENT_OBJECT_ADDED
+
+#define CFG_TUD_MTP_DEVICEINFO_SUPPORTED_DEVICE_PROPERTIES \
+ MTP_DEV_PROP_DEVICE_FRIENDLY_NAME
+
+#define CFG_TUD_MTP_DEVICEINFO_CAPTURE_FORMATS \
+ MTP_OBJ_FORMAT_UNDEFINED, \
+ MTP_OBJ_FORMAT_ASSOCIATION, \
+ MTP_OBJ_FORMAT_TEXT, \
+ MTP_OBJ_FORMAT_PNG
+
+#define CFG_TUD_MTP_DEVICEINFO_PLAYBACK_FORMATS \
+ MTP_OBJ_FORMAT_UNDEFINED, \
+ MTP_OBJ_FORMAT_ASSOCIATION, \
+ MTP_OBJ_FORMAT_TEXT, \
+ MTP_OBJ_FORMAT_PNG
+```
+
+## Building
+
+CMake:
+
+```bash
+mkdir build && cd build
+cmake -DBOARD=raspberry_pi_pico ..
+cmake --build .
+```
+
+Make:
+
+```bash
+make BOARD=raspberry_pi_pico all
+```
+
+## Try it
+
+The device enumerates as an MTP device and shows up in a file browser (e.g. the Files/Explorer app, or `mtp-detect` / `mtp-files` from libmtp). You should see `readme.txt` and `tinyusb.png`; you can copy a small file onto the device and delete files.