embassy-usb-host

Crates

git

Versions

default

Flavors

GipHost

Struct GipHost 

Source
pub struct GipHost<'d, A: UsbHostAllocator<'d>, DEV: GipDevice> { /* private fields */ }
Expand description

GIP host class driver.

Generic over the USB host driver D and a GipDevice implementation that customizes init sequences and input parsing.

§Lifecycle

  1. Register with GipHost::try_register after USB enumeration.
  2. Poll for events with GipHost::poll.
  3. Optionally send rumble with GipHost::set_rumble.

Implementations§

Source§

impl<'d, A: UsbHostAllocator<'d>, DEV: GipDevice> GipHost<'d, A, DEV>

Source

pub async fn try_register( alloc: &A, config_desc: &[u8], enum_info: &EnumerationInfo, ) -> Result<Self, GipError>

Create and initialize a GIP host driver.

Performs the full setup sequence:

  1. Validates the device via GipDevice::try_new.
  2. Locates the GIP data interface in the configuration descriptor.
  3. Allocates interrupt IN and OUT pipes.
  4. Completes the GIP handshake: waits for the device’s Hello message, responds with GipDevice::init_packets, and drains remaining handshake traffic until the controller is active.

On success the driver is ready for poll.

§Errors
Source

pub async fn poll(&mut self) -> Result<GipEvent, GipError>

Poll for the next GIP event.

Reads from the interrupt IN endpoint, parses the GIP header, and dispatches to the GipDevice for interpretation.

Any incoming message with the ACK flag (0x10) set is automatically acknowledged before being processed. This is required by the GIP protocol — controllers stall and stop sending input if the host fails to acknowledge flagged messages.

This method blocks until a meaningful event is available. Protocol messages that don’t produce user-facing events are acknowledged and consumed internally.

Source

pub async fn read_raw(&mut self, buf: &mut [u8]) -> Result<usize, GipError>

Read a raw GIP packet from the device.

Returns the number of bytes received. No parsing or ACK handling is performed; use poll for the high-level interface.

Source

pub async fn set_rumble(&mut self, cmd: &RumbleCommand) -> Result<(), GipError>

Send a rumble command to the controller.

Source

pub async fn stop_rumble(&mut self) -> Result<(), GipError>

Stop all rumble motors.

Source

pub async fn write_raw(&mut self, data: &[u8]) -> Result<(), GipError>

Send a raw GIP packet.

The sequence byte (offset 2) is not patched; the caller is responsible for the full packet contents.

Source

pub fn device(&self) -> &DEV

Get a reference to the underlying GipDevice.

Auto Trait Implementations§

§

impl<'d, A, DEV> Freeze for GipHost<'d, A, DEV>
where <A as UsbHostAllocator<'d>>::Pipe<Interrupt, In>: Freeze, <A as UsbHostAllocator<'d>>::Pipe<Interrupt, Out>: Freeze, DEV: Freeze,

§

impl<'d, A, DEV> RefUnwindSafe for GipHost<'d, A, DEV>

§

impl<'d, A, DEV> Send for GipHost<'d, A, DEV>
where <A as UsbHostAllocator<'d>>::Pipe<Interrupt, In>: Send, <A as UsbHostAllocator<'d>>::Pipe<Interrupt, Out>: Send, DEV: Send,

§

impl<'d, A, DEV> Sync for GipHost<'d, A, DEV>
where <A as UsbHostAllocator<'d>>::Pipe<Interrupt, In>: Sync, <A as UsbHostAllocator<'d>>::Pipe<Interrupt, Out>: Sync, DEV: Sync,

§

impl<'d, A, DEV> Unpin for GipHost<'d, A, DEV>
where <A as UsbHostAllocator<'d>>::Pipe<Interrupt, In>: Unpin, <A as UsbHostAllocator<'d>>::Pipe<Interrupt, Out>: Unpin, DEV: Unpin,

§

impl<'d, A, DEV> UnwindSafe for GipHost<'d, A, DEV>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.