usb-if

USB Interface definitions for CrabUSB


License
MIT

Documentation

CrabUSB πŸ¦€

A high-performance, asynchronous USB Host driver implementation written in Rust for embedded systems and operating system kernels.

πŸš€ Features

Core Capabilities

  • πŸ”„ Async/Await Support: Built from the ground up with async primitives for non-blocking USB operations
  • ⚑ Lock-Free Design: Ring-based architecture using TRB (Transfer Request Block) for zero-lock async operations
  • 🎯 xHCI Controller Support: Complete implementation of the xHCI (Extensible Host Controller Interface) specification
  • πŸ“± USB Standards Compliance: Full support for USB 1.1, 2.0, and 3.x devices (Full, High, and SuperSpeed)
  • πŸ”§ No-STD Compatible: Designed for #![no_std] environments with minimal memory footprint
  • πŸ–₯️ User-Space libusb Backend: Optional libusb backend for testing and development in user-space environments

Transfer Types

  • Control Transfers: Device setup, configuration, and standard requests
  • Bulk Transfers: High-throughput data transfer for storage devices
  • Interrupt Transfers: Periodic data transfer for HID devices
  • Isochronous Transfers: Real-time streaming for audio/video devices

Device Management

  • πŸ” Device Enumeration: Automatic discovery and enumeration of connected USB devices
  • πŸ“‹ Descriptor Parsing: Complete parsing of device, configuration, interface, and endpoint descriptors
  • πŸ”Œ Interface Management: Easy interface claiming and endpoint access
  • 🏷️ String Descriptors: Full support for manufacturer, product, and serial number strings

Architecture Highlights

  • Executor Agnostic: Works with any async executor or can be used synchronously
  • DMA-Aware: Efficient memory management with DMA coherency support
  • Event-Driven: Interrupt-based event handling for optimal performance
  • Modular Design: Clean separation between host controller and USB interface layers
  • Multi-Backend Support: Supports both direct hardware access (xHCI) and user-space testing (libusb)

πŸ—οΈ Architecture

CrabUSB uses an innovative lock-free design based on TRB rings where each TRB represents an async task. The future queries the ring to obtain async results without requiring a specific executor, making it highly flexible and performant.

The driver supports multiple backends:

  • xHCI Backend: Direct hardware access for embedded systems and OS kernels
  • libusb Backend: User-space testing and development using libusb (enable with libusb feature)
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚   Application   │◄──►│   USB Interface  │◄──►│    Backend      β”‚
β”‚                 β”‚    β”‚     (usb-if)     β”‚    β”‚   Selection     β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                              β”‚                          β”‚
                              β–Ό                          β–Ό
                       β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”         β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
                       β”‚ Descriptors  β”‚         β”‚ xHCI / libusbβ”‚
                       β”‚ & Transfers  β”‚         β”‚   Drivers    β”‚
                       β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜         β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜