embassy-usb-host

Crates

git

Versions

default

Flavors

HidHost

Struct HidHost 

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

Source

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.

Source

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.

Source

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.

Source

pub async fn set_protocol(&mut self, protocol: u8) -> Result<(), HidError>

Set the protocol (boot or report).

Source

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.

Source

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

Source

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

Source

pub async fn get_report( &mut self, report_type: u8, report_id: u8, buf: &mut [u8], ) -> Result<usize, HidError>

Issue a GET_REPORT control request.

report_type: 1=Input, 2=Output, 3=Feature. report_id: 0 if the device uses a single report.

Returns the number of bytes received.

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