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
impl CustomHid
Sourcepub const fn new(spec: HidSpec) -> Self
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.
Sourcepub fn read_report(&mut self, buf: &mut [u8]) -> Option<usize>
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
impl<B: UsbBus> HidDevice<B> for CustomHid
Source§fn get_report(
&mut self,
_report_type: ReportType,
_report_id: u8,
buf: &mut [u8],
) -> Option<usize>
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 moreSource§fn set_report(
&mut self,
report_type: ReportType,
report_id: u8,
data: &[u8],
) -> bool
fn set_report( &mut self, report_type: ReportType, report_id: u8, data: &[u8], ) -> bool
Set Report — handle a report written by the host. Read moreSource§fn output_report(&mut self, report_id: u8, data: &[u8])
fn output_report(&mut self, report_id: u8, data: &[u8])
Output report received on the interrupt OUT endpoint. Read more
Source§fn deconfigure(&mut self)
fn deconfigure(&mut self)
Called when the host de-configures the device.
Source§fn poll(&mut self, _input: &EndpointIn<'_, B>)
fn poll(&mut self, _input: &EndpointIn<'_, B>)
Called on every device poll while configured. Read more
Auto Trait Implementations§
impl Forget for CustomHid
impl Freeze for CustomHid
impl Move for CustomHid
impl RefUnwindSafe for CustomHid
impl Send for CustomHid
impl Sync for CustomHid
impl Unpin for CustomHid
impl UnsafeUnpin for CustomHid
impl UnwindSafe for CustomHid
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more