mirror of
https://github.com/hathach/tinyusb.git
synced 2026-08-19 03:29:13 +00:00
Class drivers: skip and account the SS endpoint companion descriptor in every descriptor walk (hid, midi, midi2, ecm_rndis, printer, mtp, usbtmc), via a shared usbd_skip_ss_ep_companion() helper in usbd_pvt.h (cdc/ncm already handled; vendor/dfu naturally tolerant). usbtmc buffer grows to 1024 at SS to satisfy its packet-multiple assert. bth/audio/video are left FS/HS-only (ISO-centric; ISO is unsupported on the CH569 dcd). usbd.h: new SS template macros TUD_HID_SS_DESCRIPTOR(+INOUT), TUD_MIDI_SS_DESCRIPTOR (+ DESC_EP_SS part), TUD_MIDI2_DESC_ALT1_EP_SS, TUD_PRINTER_SS_DESCRIPTOR, TUD_MTP_SS_DESCRIPTOR, TUD_USBTMC_BULK_SS_DESCRIPTORS/INT_SS_DESCRIPTOR, with _SS_DESC_LEN counterparts (bulk endpoints hardcode 1024, companion after every EP). Examples: 17 bulk/interrupt examples gain the full SS descriptor set (EP0 512/64 clamp, SS device descriptor bcdUSB 3.20 mps0=2^9, SS config with companions, BOS caps, speed-switched callbacks): cdc_dual_ports, cdc_msc_freertos, dfu, dfu_runtime, dynamic_configuration, hid_boot_interface, hid_composite(+freertos), hid_generic_inout, hid_multiple_interface, midi_test(+freertos), midi2_device, msc_dual_lun, mtp, printer_to_cdc, usbtmc, webusb_serial. msc_dual_lun is un-skipped for CH569 using read-only flash disks (16KB RAM can't hold two 8KB RAM disks, same as ch32v10x/v20x boards). Validation: full example sweep green for hydrausb3_v1 (SPEED=super, 19 device ELFs) and raspberry_pi_pico; wTotalLength == sizeof() verified for every SS configuration array in the built ELFs; ceedling 65/65; pre-commit clean; code-size delta +0.0% on rp2040 (SS code folds out on non-SS builds). Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_019MRGjBT2NBkCoWwyDT4LaE
Printer to CDC
This example demonstrates a USB composite device with a Printer class interface and a CDC serial interface. Data flows bidirectionally between the two:
- Data sent to the Printer (from host) is forwarded to the CDC serial port
- Data sent to the CDC serial port (from host) is forwarded to the Printer IN endpoint
This is useful for debugging printer class communication or as a reference for implementing printer class devices.
USB Descriptors
| Interface | Class | Description |
|---|---|---|
| 0 | CDC ACM | Virtual serial port |
| 2 | Printer | USB Printer (bidirectional, protocol 2) |
Configuration
Notable tusb_config.h settings:
#define CFG_TUD_CDC 1
#define CFG_TUD_PRINTER 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_PRINTER_RX_BUFSIZE (TUD_OPT_HIGH_SPEED ? 512 : 64)
#define CFG_TUD_PRINTER_TX_BUFSIZE (TUD_OPT_HIGH_SPEED ? 512 : 64)
How to Test
The device exposes two endpoints on the host:
/dev/ttyACM0(CDC serial port)/dev/usb/lp0(USB printer)
Note: the actual device numbers may vary depending on your system.
Prerequisites (Linux):
# Load the USB printer kernel module if not already loaded
sudo modprobe usblp
# Check devices exist
ls /dev/ttyACM* /dev/usb/lp*
Test Printer to CDC (host writes to printer, reads from CDC):
# Terminal 1: read from CDC
cat /dev/ttyACM0
# Terminal 2: write to printer
echo "hello from printer" > /dev/usb/lp0
# "hello from printer" appears in Terminal 1
Test CDC to Printer (host writes to CDC, reads from printer):
# Terminal 1: read from printer IN endpoint
cat /dev/usb/lp0
# Terminal 2: write to CDC
echo "hello from cdc" > /dev/ttyACM0
# "hello from cdc" appears in Terminal 1
Interactive bidirectional test:
# Terminal 1: open CDC serial port
minicom -D /dev/ttyACM0
# Terminal 2: send to printer
echo "tinyusb print example" > /dev/usb/lp0
# Text appears in minicom. Type in minicom to send data back through printer TX.
IEEE 1284 Device ID
The device responds to GET_DEVICE_ID requests with:
MFG:TinyUSB;MDL:Printer to CDC;CMD:PS;CLS:PRINTER;
Verify with:
cat /sys/class/usbmisc/lp0/device/ieee1284_id