pub struct HidHost<D: UsbHostDriver> { /* private fields */ }Expand description
HID host driver.
Provides report reading and optional class request access to a USB HID device.
Implementations§
Source§impl<D: UsbHostDriver> HidHost<D>
impl<D: UsbHostDriver> HidHost<D>
Sourcepub fn new(
driver: &D,
config_desc: &[u8],
device_address: u8,
max_packet_size_0: u16,
) -> Result<Self, HidError>
pub fn new( driver: &D, config_desc: &[u8], device_address: u8, max_packet_size_0: u16, ) -> Result<Self, HidError>
Create a new HID host driver.
Parses the config descriptor to find the HID interface and its interrupt IN endpoint, then allocates the necessary channels.
Sourcepub async fn fetch_report_descriptor<'a>(
&mut self,
buf: &'a mut [u8],
) -> Result<&'a [u8], HidError>
pub async fn fetch_report_descriptor<'a>( &mut self, buf: &'a mut [u8], ) -> Result<&'a [u8], HidError>
Fetch the HID Report Descriptor from the device into buf.
Returns the descriptor bytes as a slice. Pass the result to
ReportDescriptor::parse to decode it:
let mut buf = [0u8; 256];
let desc = hid.fetch_report_descriptor(&mut buf).await?;
let report: ReportDescriptor<32> = ReportDescriptor::parse(desc);buf should be at least HidInfo::report_descriptor_len bytes; any
excess is unused.
Sourcepub async fn set_idle(
&mut self,
report_id: u8,
idle_duration: u8,
) -> Result<(), HidError>
pub async fn set_idle( &mut self, report_id: u8, idle_duration: u8, ) -> Result<(), HidError>
Set the idle rate for a report.
report_id = 0 applies to all reports. idle_duration = 0 disables idle repeat.
Note: SET_IDLE is optional; some devices STALL this request. A STALL is treated as success per the HID specification.
Sourcepub async fn set_protocol(&mut self, protocol: u8) -> Result<(), HidError>
pub async fn set_protocol(&mut self, protocol: u8) -> Result<(), HidError>
Set the protocol (boot or report).
Sourcepub async fn read(&mut self, buf: &mut [u8]) -> Result<usize, HidError>
pub async fn read(&mut self, buf: &mut [u8]) -> Result<usize, HidError>
Read a raw input report from the interrupt IN endpoint.
Returns the number of bytes received.
Sourcepub async fn read_keyboard(
&mut self,
) -> Result<Option<KeyboardReport>, HidError>
pub async fn read_keyboard( &mut self, ) -> Result<Option<KeyboardReport>, HidError>
Read and parse a boot-protocol keyboard report.
Call HidHost::set_protocol with PROTOCOL_BOOT first.
Returns None if the report is malformed (shorter than 8 bytes).
Sourcepub async fn read_mouse(&mut self) -> Result<Option<MouseReport>, HidError>
pub async fn read_mouse(&mut self) -> Result<Option<MouseReport>, HidError>
Read and parse a boot-protocol mouse report.
Call HidHost::set_protocol with PROTOCOL_BOOT first.
Returns None if the report is malformed (shorter than 3 bytes).