embassy-usb-host

Crates

git

Versions

default

Flavors

GipDevice

Trait GipDevice 

Source
pub trait GipDevice: Sized {
    // Required methods
    fn try_new(vendor_id: u16, product_id: u16) -> Option<Self>;
    fn init_packets(&self) -> &'static [&'static [u8]];

    // Provided methods
    fn parse_input(&self, data: &[u8]) -> Option<GamepadReport> { ... }
    fn parse_guide_button(&self, data: &[u8]) -> Option<bool> { ... }
    fn build_rumble(
        &self,
        buf: &mut [u8; 64],
        seq: u8,
        cmd: &RumbleCommand,
    ) -> usize { ... }
}
Expand description

Trait for GIP device-specific behavior.

Different Xbox One–family controllers require different initialization sequences and may have variant input report formats (e.g., Elite paddle data, Share button location). Implement this trait to add support for a specific controller or family.

The built-in XboxOneSGamepad handles the Xbox One S and is broadly compatible with most standard GIP gamepads.

Required Methods§

Source

fn try_new(vendor_id: u16, product_id: u16) -> Option<Self>

Attempt to create a device handler for the given USB device.

Returns None if this implementation does not support the device. Implementations may capture VID/PID to vary behavior at runtime (e.g., selecting init packets based on product ID).

Source

fn init_packets(&self) -> &'static [&'static [u8]]

GIP init packets sent in response to the device’s Hello message.

Each entry is a complete GIP message (header + payload). The driver patches byte 2 (sequence number) with an incrementing value before transmission.

Provided Methods§

Source

fn parse_input(&self, data: &[u8]) -> Option<GamepadReport>

Parse a GIP input report (message type 0x20) into a GamepadReport.

data is the full GIP packet including the 4-byte header. Return None to silently drop the message.

The default delegates to parse_standard_input.

Source

fn parse_guide_button(&self, data: &[u8]) -> Option<bool>

Parse a virtual key report (message type 0x07) into a guide button state.

The default reads bits 0–1 of byte 4.

Source

fn build_rumble( &self, buf: &mut [u8; 64], seq: u8, cmd: &RumbleCommand, ) -> usize

Build a rumble command packet into buf.

Returns the total number of bytes written. The default delegates to build_standard_rumble.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§