Skip to main content

CustomHid

Struct CustomHid 

Source
pub struct CustomHid { /* private fields */ }
Expand description

A HID function defined entirely by its report descriptor.

Input reports are sent as-is with HidClass::send_input. Output and feature reports written by the host are buffered — in the same layout the device sends (report_id first when the spec uses report IDs) — and read with read_report. Get Report echoes the last buffered report back.

ⓘ
static DESCRIPTOR: &[u8] = &[/* … */];

let spec = HidSpec::new(DESCRIPTOR, 8).out_report_size(8).report_ids(true);
let mut hid = HidClass::new(&alloc, CustomHid::new(spec));

loop {
    usb_dev.poll(&mut [&mut hid]);
    let mut buf = [0u8; 8];
    if let Some(len) = hid.device_mut().read_report(&mut buf) {
        // host wrote a report
    }
}

Implementations§

Source§

impl CustomHid

Source

pub const fn new(spec: HidSpec) -> Self

Create a function from a report descriptor and its endpoint geometry.

Set HidSpec::out_report_size for a device that receives output or feature reports.

Source

pub fn read_report(&mut self, buf: &mut [u8]) -> Option<usize>

Read the last report written by the host and return its length.

None when nothing has arrived since the previous call.

Trait Implementations§

Source§

impl<B: UsbBus> HidDevice<B> for CustomHid

Source§

fn spec(&self) -> HidSpec

Report descriptor, endpoint sizes and interface class/protocol.
Source§

fn get_report( &mut self, _report_type: ReportType, _report_id: u8, buf: &mut [u8], ) -> Option<usize>

Get Report — copy the report selected by report_type and report_id into buf and return its length, including the report ID byte when the spec declares report IDs. Read more
Source§

fn set_report( &mut self, report_type: ReportType, report_id: u8, data: &[u8], ) -> bool

Set Report — handle a report written by the host. Read more
Source§

fn output_report(&mut self, report_id: u8, data: &[u8])

Output report received on the interrupt OUT endpoint. Read more
Source§

fn reset(&mut self)

Called after a USB bus reset.
Source§

fn configure(&mut self)

Called when the host configures the device. Read more
Source§

fn deconfigure(&mut self)

Called when the host de-configures the device.
Source§

fn poll(&mut self, _input: &EndpointIn<'_, B>)

Called on every device poll while configured. Read more

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> 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.