Skip to main content

HidClass

Struct HidClass 

Source
pub struct HidClass<'a, B: UsbBus, D> { /* private fields */ }
Expand description

USB HID class — the transport for a HidDevice.

Allocates one interface, an interrupt IN endpoint for input reports and, if the device’s HidSpec asks for one, an interrupt OUT endpoint. The endpoint sizes and the interface class/protocol come from the device’s spec.

Implementations§

Source§

impl<'a, B: UsbBus, D: HidDevice<B>> HidClass<'a, B, D>

Source

pub fn new(alloc: &'a UsbBusAllocator<B>, device: D) -> Self

Create a HID class for device, allocating its interface and endpoints.

Must be called before the UsbBusAllocator is frozen by building the device.

Source

pub fn device(&self) -> &D

The wrapped HID function.

Source

pub fn device_mut(&mut self) -> &mut D

The wrapped HID function, to update its state from the main loop.

Source

pub fn is_configured(&self) -> bool

true once the host has configured the device.

Source

pub fn interface(&self) -> InterfaceNumber

Interface number allocated for this function.

Source

pub fn report_descriptor(&self) -> &'static [u8]

Report descriptor served to the host.

Source

pub fn send_input(&self, report: &[u8]) -> UsbResult<()>

Send an input report to the host.

report is the raw report, including the report ID byte when the descriptor uses report IDs. Returns WouldBlock when the previous report has not been collected yet — the caller retries later.

Source

pub fn flush(&mut self)

Let the device send the input reports it queued.

Called automatically from every UsbClass::poll, so calling it is only useful to shorten the latency by one loop iteration.

Trait Implementations§

Source§

impl<B: UsbBus, D: HidDevice<B>> UsbClass<B> for HidClass<'_, B, D>

Source§

fn configuration_descriptors( &self, w: &mut DescriptorWriter<'_>, ) -> UsbResult<()>

Append this class’s interface and endpoint descriptors.
Source§

fn control_in(&mut self, xfer: ControlIn<'_, B>)

Handle a control IN transfer. Accept, reject, or pass (drop without acting).
Source§

fn control_out(&mut self, xfer: ControlOut<'_, B>)

Handle a control OUT transfer. Accept, reject, or pass (drop without acting).
Source§

fn endpoint_out(&mut self, addr: EndpointAddress)

Called when endpoint addr received an OUT packet.
Source§

fn configure(&mut self)

Called when the host sends SET_CONFIGURATION(1).
Source§

fn deconfigure(&mut self)

Called when the host sends SET_CONFIGURATION(0) or on reset.
Source§

fn reset(&mut self)

Called after a USB bus reset.
Source§

fn poll(&mut self)

Called unconditionally on every UsbDevice::poll.
Source§

fn string(&self, index: StringIndex, lang_id: u16) -> Option<&str>

Return the string for a previously allocated StringIndex, or None.
Source§

fn endpoint_in_complete(&mut self, addr: EndpointAddress)

Called when endpoint addr completed an IN transfer.
Source§

fn endpoint_setup(&mut self, addr: EndpointAddress)

Called when endpoint addr received a SETUP packet (non-EP0 control).
Source§

fn alt_setting(&mut self, interface: InterfaceNumber) -> Option<u8>

Return the current alternate setting for interface, or None.
Source§

fn set_alt_setting(&mut self, interface: InterfaceNumber, alt: u8) -> bool

Set the alternate setting for interface. Return true if handled.

Auto Trait Implementations§

§

impl<'a, B, D> Forget for HidClass<'a, B, D>

§

impl<'a, B, D> Freeze for HidClass<'a, B, D>
where Endpoint<'a, B, In>: Freeze, Option<Endpoint<'a, B, Out>>: Freeze, D: Freeze,

§

impl<'a, B, D> Move for HidClass<'a, B, D>

§

impl<'a, B, D> RefUnwindSafe for HidClass<'a, B, D>

§

impl<'a, B, D> Send for HidClass<'a, B, D>
where D: Send, Endpoint<'a, B, In>: Send, Option<Endpoint<'a, B, Out>>: Send,

§

impl<'a, B, D> Sync for HidClass<'a, B, D>
where D: Sync, Endpoint<'a, B, In>: Sync, Option<Endpoint<'a, B, Out>>: Sync,

§

impl<'a, B, D> Unpin for HidClass<'a, B, D>
where D: Unpin, Endpoint<'a, B, In>: Unpin, Option<Endpoint<'a, B, Out>>: Unpin,

§

impl<'a, B, D> UnsafeUnpin for HidClass<'a, B, D>

§

impl<'a, B, D> UnwindSafe for HidClass<'a, B, D>
where Endpoint<'a, B, In>: UnwindSafe, Option<Endpoint<'a, B, Out>>: UnwindSafe, D: UnwindSafe,

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.