# USB Subsystem

## Composite USB Device

The Beyond MCU enumerates as a composite USB device with multiple interfaces:

| Interface | Class | Purpose |
|-----------|-------|---------|
| HID | Human Interface Device | Command/control channel (64-byte reports) |
| Audio | USB Audio Class | Microphone audio streaming |
| CDC | Communications Device Class | Virtual COM port (debug) |

**USB Identifiers:**

| Mode | Vendor ID | Product ID | Manufacturer | Product |
|------|-----------|------------|--------------|---------|
| Application | 0x35BD | 0x0101 | Bigscreen | Beyond |
| Bootloader | 0x35BD | 0x4004 | — | — |

### HID Endpoint Quirk

Due to limited endpoints on the ATSAMG55, the PC-to-HMD direction uses **HID feature reports** (on default control endpoint 0) instead of standard reports. This frees up an endpoint for the audio interface. HMD-to-PC communication uses standard HID reports on a dedicated endpoint.

This means host software must use `send_feature_report()` instead of `write()` when sending commands.

**Source files:** `src/usbhid_interface.c/h`, `src/config/conf_usb.h`

## USB Hub Management

### BS1 Configuration

Single **USB3803** hub with downstream ports for internal peripherals.

### BS2 Configuration

Triple **USB3803** hub configuration:
- 1 primary hub
- 2 secondary hubs
- Provides additional downstream ports for eye-tracking cameras and Bluetooth

### USB3803 Hub Driver

- I2C-based configuration at startup
- Self-powered vs bus-powered mode selection
- Hub reset and reconfiguration support
- Configuration written to non-volatile hub registers

#### Upstream PHY Boost and Sensitivity (v0.3.15+)

The primary hub (upstream to linkbox) supports configurable signaling parameters, both stored as nonvolatile config tags:

- **PHY Boost** (`USB3803_BOOST_UP3` register `0xF6`): Increases USB 2.0 signaling current on the upstream port. Available levels: -5%, default, 5% (factory default), 10%, 15%, 20%, 30%. Configured via config tag, applied only to the first hub.
- **Receiver Sensitivity** (`USB3803_VARISENSE_UP3` register `0xF4`): Lowers the squelch threshold for better signal detection on marginal cables. Configured via config tag.

PHY boost was tested at 30% (v0.3.17) but later reverted (v0.3.18) as an external USB booster board made it unnecessary.

### USB2517 Hub (Deprecated)

- Previously used on BS1 for Bluetooth connectivity (v0.2.4A)
- Removed in v0.3.3 in favor of USB3803-only design
- Was used for board version detection (BS1 vs BS2) — BS2 detected by absence of USB2517

**Source files:** `src/Devices/usb3803.c/h`, `src/Devices/usb2517.c/h` (deprecated)

### Hub Version History

| Version | Change |
|---------|--------|
| v0.2.4A | Added second USB hub for Bluetooth |
| v0.3.1 | BS2 support with USB2517, board detection |
| v0.3.2 | USB2517 driver bugfix |
| v0.3.3 | Removed USB2517, added triple USB3803 for BS2 |
| v0.3.5 | Unified BS1/BS2 builds |

## USB-C Multiplexing

A USB-C crossbar switch handles signal routing for the Type-C connector:
- Controlled by the MCU based on cable orientation
- CC pin ADC monitoring determines plug orientation
- Testable via hardware self-test (`HW_TEST` sub-command `S`)

**Source files:** `src/Devices/usbc_mux.c/h`

## VBUS Monitoring

- VBUS presence detection via GPIO
- Used to determine if the headset is connected to a powered USB port
- Configured in `conf_board.h`

## Windows Driver

Windows CDC driver files included in the repository:
- `atmel_devices_cdc.inf` — Driver information file
- `atmel_devices_cdc.cat` — Driver catalog (signed)
