Vendor-specific¶
The device driver provides bulk, and optionally interrupt or isochronous, transfers for a vendor-defined interface. There is no generic vendor protocol: the device descriptors, request semantics, framing, and host software are part of the product’s protocol.
Device¶
Enable CFG_TUD_VENDOR and add TUD_VENDOR_DESCRIPTOR for the usual pair
of bulk endpoints. Buffered mode is the practical default.
Option |
Default |
What it controls |
|---|---|---|
|
Device bulk maximum |
Software FIFO bytes. Setting either to zero selects direct mode for both directions. |
|
Device bulk maximum |
Bulk endpoint transfer buffer sizes. Each must be at least the
endpoint’s |
|
|
Disables automatic receive arming at open and transfer completion.
Use |
|
|
Allows multi-packet receive termination by a zero-length packet; enable
only when the custom host protocol sends that terminator. RX transfers
then can request up to |
|
|
Enables optional direct interrupt endpoints. Their buffer-size options default to 64 bytes. |
|
|
Enables optional direct isochronous endpoints. They require alternate settings; their buffers default to 64 bytes. |
|
|
Enables alternate-setting tracking. It requires direct mode and is required by the optional isochronous endpoints. |
Use tud_vendor_available()/tud_vendor_read() for OUT data and
tud_vendor_write()/tud_vendor_write_flush() for IN data. In buffered
mode, tud_vendor_rx_cb() is only a notification; read the FIFO rather than
using its null buffer argument.
For direct transfers, configure zero RX/TX FIFO sizes and follow the ownership
rules in vendor_device.h. Optional interrupt, isochronous, and alternate
setting support is controlled by CFG_TUD_VENDOR_EP_* and
CFG_TUD_VENDOR_ALT_SETTINGS. Interrupt and isochronous OUT endpoints must
be explicitly re-armed after their receive callbacks.
API or callback |
What it does |
|---|---|
|
Tests whether an instance has any configured bulk, interrupt, or isochronous endpoint open. |
|
Reports and removes bulk OUT FIFO bytes in buffered mode. |
|
Reports room and copies as many bulk IN bytes as fit. In direct mode the copy is limited to one endpoint buffer. |
|
Starts a short buffered IN transfer and returns the number of bytes submitted. |
|
Announces received data or completed output. In direct mode, consume or copy the receive pointer before returning from the callback. |
|
Arms one optional OUT transfer; re-arm after each receive callback. |
|
Copies and queues at most one optional endpoint buffer and returns the accepted byte count. |
|
Returns the host-selected alternate setting when support is enabled. |
Handle vendor control requests in tud_vendor_control_xfer_cb() and perform
the data/status stage with tud_control_xfer() or
tud_control_status(). Validate bmRequestType, bRequest,
wIndex, wValue, and wLength before accepting a request.
The WebUSB Serial example combines a vendor bulk interface with WebUSB and Microsoft OS 2.0 descriptors.
Host¶
A host cannot interpret an arbitrary vendor interface from its class code.
TinyUSB does not currently offer a supported, protocol-neutral
tuh_vendor_* application API. For a simple fixed device, enable
CFG_TUH_API_EDPT_XFER and use the descriptor/endpoint APIs demonstrated by
Host: Bare API. For a reusable protocol, implement a
custom host class driver that matches devices by descriptors and VID/PID and
owns their enumeration and transfer state.
Define framing, version negotiation, maximum message lengths, timeouts, and error recovery before deploying a vendor protocol. Never cast unvalidated wire data directly to an application structure.