embassy-usb

Crates

git

Versions

default

Flavors

Skip to main content

HidHost

Struct HidHost 

Source
pub struct HidHost<'d, A: UsbHostAllocator<'d>> { /* private fields */ }
Expand description

HID host driver.

Provides report reading and optional class request access to a USB HID device.

Implementations§

Source§

impl<'d, A: UsbHostAllocator<'d>> HidHost<'d, A>

Source

pub fn new( alloc: &A, config_desc: &[u8], enum_info: &EnumerationInfo, ) -> 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 fn new_with_info( alloc: &A, info: HidInfo, enum_info: &EnumerationInfo, ) -> Result<Self, HidError>

Allocate pipes from an already-probed HidInfo.

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: HidProtocolMode, ) -> 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 HidProtocolMode::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 HidProtocolMode::Boot first. Returns None if the report is malformed (shorter than 3 bytes).

Source

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

Issue a GET_REPORT control request.

Use report ID 0 if the device uses a single report.

Returns the number of bytes received.

Source

pub async fn set_report( &mut self, report: ReportId, buf: &[u8], ) -> Result<(), HidError>

Issue a SET_REPORT control request.

Use report ID 0 if the device uses a single report; buf is the report body.

Trait Implementations§

Source§

impl<'d, A: UsbHostAllocator<'d>> HostClass<'d, A> for HidHost<'d, A>

Source§

const NAME: &'static str = "HID"

Human-readable class name, used for logging.
Source§

type Info = HidInfo

Cheap, owned description of the interface(s) and endpoints to use. Read more
Source§

fn probe(_enum_info: &EnumerationInfo, cfg: &[u8]) -> Option<Self::Info>

Find the class in an enumerated device. Returns None when the class is not present. This must not allocate pipes or issue control requests. Read more
Source§

async fn open( alloc: &A, _cfg: &[u8], info: Self::Info, enum_info: &EnumerationInfo, ) -> Result<Self, ClassError>

Allocate pipes and perform any class-specific setup.
Source§

fn is_present(enum_info: &EnumerationInfo, cfg: &[u8]) -> bool

Convenience wrapper around probe.

Auto Trait Implementations§

§

impl<'d, A> Forget for HidHost<'d, A>

§

impl<'d, A> Freeze for HidHost<'d, A>

§

impl<'d, A> Move for HidHost<'d, A>

§

impl<'d, A> RefUnwindSafe for HidHost<'d, A>

§

impl<'d, A> Send for HidHost<'d, A>

§

impl<'d, A> Sync for HidHost<'d, A>

§

impl<'d, A> Unpin for HidHost<'d, A>

§

impl<'d, A> UnsafeUnpin for HidHost<'d, A>

§

impl<'d, A> UnwindSafe for HidHost<'d, A>

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.