Skip to main content

HidSpec

Struct HidSpec 

Source
pub struct HidSpec {
    pub report_descriptor: &'static [u8],
    pub in_report_size: u16,
    pub out_report_size: u16,
    pub subclass: u8,
    pub protocol: u8,
    pub poll_interval_ms: u8,
    pub report_ids: bool,
}
Expand description

Static description of a HID function.

Everything a HidClass needs to allocate its endpoints and write its descriptors, plus the two facts about the reports that cannot be derived from the report descriptor itself (its size and whether it declares report IDs).

ⓘ
use my_hal_usb::class::hid::{HidSpec, hid_protocol, hid_subclass};

static MY_DESCRIPTOR: &[u8] = &[0x05, 0x01, 0x09, 0x06, 0xA1, 0x01, 0xC0];

const SPEC: HidSpec = HidSpec::new(MY_DESCRIPTOR, 8)
    .subclass(hid_subclass::BOOT)
    .protocol(hid_protocol::KEYBOARD)
    .out_report_size(1)
    .poll_interval_ms(8);

Fields§

§report_descriptor: &'static [u8]

Report descriptor, served for Get Descriptor (HID Report).

§in_report_size: u16

Size of the interrupt IN endpoint — at least the largest input report, including its report ID byte when report IDs are used.

§out_report_size: u16

Size of the interrupt OUT endpoint, or 0 for a function without one.

§subclass: u8

HID subclass: 0 (none) or hid_subclass::BOOT.

§protocol: u8

HID protocol: 0 (none) or a boot protocol.

§poll_interval_ms: u8

Interrupt endpoint polling interval, in milliseconds.

§report_ids: bool

true when the report descriptor declares report IDs.

Output reports on the interrupt OUT endpoint then carry the report ID as their first byte (HID 1.11 §7.2.2), whereas Set Report passes it in wValue and leaves it out of the data.

Implementations§

Source§

impl HidSpec

Source

pub const fn new(report_descriptor: &'static [u8], in_report_size: u16) -> Self

A spec with no subclass, no protocol, no OUT endpoint, a 10 ms poll interval and no report IDs.

Source

pub const fn subclass(self, subclass: u8) -> Self

Set the HID subclass (and, for boot devices, the protocol).

Source

pub const fn protocol(self, protocol: u8) -> Self

Set the HID protocol reported in the interface descriptor.

Source

pub const fn out_report_size(self, size: u16) -> Self

Allocate an interrupt OUT endpoint of size bytes.

Source

pub const fn poll_interval_ms(self, interval: u8) -> Self

Set the interrupt endpoint polling interval, in milliseconds.

Source

pub const fn report_ids(self, report_ids: bool) -> Self

Declare that the report descriptor uses report IDs.

Trait Implementations§

Source§

impl Clone for HidSpec

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Copy for HidSpec

Source§

impl Debug for HidSpec

Source§

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

Formats the value using the given formatter. Read more
Source§

impl Eq for HidSpec

Source§

impl PartialEq for HidSpec

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for HidSpec

Auto Trait Implementations§

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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 = !

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

fn try_from(value: U) -> Result<T, !>

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.