embassy-usb-host

Crates

git

Versions

default

Flavors

ReportDescriptor

Struct ReportDescriptor 

Source
pub struct ReportDescriptor<const N: usize> {
    pub has_report_ids: bool,
    /* private fields */
}
Expand description

Parsed HID report descriptor.

N is the maximum number of input fields to store. A typical gamepad descriptor produces 8–20 fields; 32 is sufficient for most devices.

Obtain one by calling ReportDescriptor::parse.

Fields§

§has_report_ids: bool

true when the descriptor uses Report ID items. Each packet from the device will then begin with a one-byte report ID.

Implementations§

Source§

impl<const N: usize> ReportDescriptor<N>

Source

pub fn parse(descriptor: &[u8]) -> Self

Parse a raw HID report descriptor byte slice.

Fields beyond the N-th are silently dropped — increase N if needed.

Source

pub fn fields(&self) -> impl Iterator<Item = &ReportField>

Iterate over all parsed Input fields (skips empty slots).

Source

pub fn find( &self, report_id: u8, page: u16, usage: u16, ) -> Option<(&ReportField, usize)>

Find the Input field whose usage range contains usage on the given usage_page, for the given report_id.

Returns a reference to the field and the element index within it.

Source

pub fn extract_i32( &self, report: &[u8], report_id: u8, page: u16, usage: u16, ) -> Option<i32>

Extract a signed value for the given usage from a complete report packet.

report is the full packet received from the interrupt IN endpoint, including the leading report-ID byte if has_report_ids is true.

Returns None if the field is not found, the buffer is too short, or (when has_report_ids) report[0] does not match report_id.

Source

pub fn extract_u32( &self, report: &[u8], report_id: u8, page: u16, usage: u16, ) -> Option<u32>

Extract an unsigned value for the given usage. See extract_i32 for details.

Source

pub fn extract_bool( &self, report: &[u8], report_id: u8, page: u16, usage: u16, ) -> Option<bool>

Extract a boolean value for the given usage (non-zero ⇒ true). Convenient for button fields.

Trait Implementations§

Source§

impl<const N: usize> Debug for ReportDescriptor<N>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<const N: usize> Freeze for ReportDescriptor<N>

§

impl<const N: usize> RefUnwindSafe for ReportDescriptor<N>

§

impl<const N: usize> Send for ReportDescriptor<N>

§

impl<const N: usize> Sync for ReportDescriptor<N>

§

impl<const N: usize> Unpin for ReportDescriptor<N>

§

impl<const N: usize> UnwindSafe for ReportDescriptor<N>

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.