iPXE
usbhid.h
Go to the documentation of this file.
1#ifndef _IPXE_USBHID_H
2#define _IPXE_USBHID_H
3
4/** @file
5 *
6 * USB human interface devices (HID)
7 *
8 */
9
10FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
11
12#include <ipxe/usb.h>
13
14/** Class code for human interface devices */
15#define USB_CLASS_HID 3
16
17/** Subclass code for boot devices */
18#define USB_SUBCLASS_HID_BOOT 1
19
20/** Set protocol */
21#define USBHID_SET_PROTOCOL \
22 ( USB_DIR_OUT | USB_TYPE_CLASS | USB_RECIP_INTERFACE | \
23 USB_REQUEST_TYPE ( 0x0b ) )
24
25/** Boot protocol */
26#define USBHID_PROTOCOL_BOOT 0
27
28/** Report protocol */
29#define USBHID_PROTOCOL_REPORT 1
30
31/** Set idle time */
32#define USBHID_SET_IDLE \
33 ( USB_DIR_OUT | USB_TYPE_CLASS | USB_RECIP_INTERFACE | \
34 USB_REQUEST_TYPE ( 0x0a ) )
35
36/** Set report */
37#define USBHID_SET_REPORT \
38 ( USB_DIR_OUT | USB_TYPE_CLASS | USB_RECIP_INTERFACE | \
39 USB_REQUEST_TYPE ( 0x09 ) )
40
41/** Input report type */
42#define USBHID_REPORT_INPUT 0x01
43
44/** Output report type */
45#define USBHID_REPORT_OUTPUT 0x02
46
47/** Feature report type */
48#define USBHID_REPORT_FEATURE 0x03
49
50/** A USB human interface device */
51struct usb_hid {
52 /** USB function */
54 /** Interrupt IN endpoint */
56 /** Interrupt OUT endpoint (optional) */
58};
59
60/**
61 * Initialise USB human interface device
62 *
63 * @v hid USB human interface device
64 * @v func USB function
65 * @v in Interrupt IN endpoint operations
66 * @v out Interrupt OUT endpoint operations (or NULL)
67 */
68static inline __attribute__ (( always_inline )) void
69usbhid_init ( struct usb_hid *hid, struct usb_function *func,
72 struct usb_device *usb = func->usb;
73
74 hid->func = func;
75 usb_endpoint_init ( &hid->in, usb, in );
76 if ( out )
77 usb_endpoint_init ( &hid->out, usb, out );
78}
79
80/**
81 * Set protocol
82 *
83 * @v usb USB device
84 * @v interface Interface number
85 * @v protocol HID protocol
86 * @ret rc Return status code
87 */
88static inline __attribute__ (( always_inline )) int
89usbhid_set_protocol ( struct usb_device *usb, unsigned int interface,
90 unsigned int protocol ) {
91
93 NULL, 0 );
94}
95
96/**
97 * Set idle time
98 *
99 * @v usb USB device
100 * @v interface Interface number
101 * @v report Report ID
102 * @v duration Duration (in 4ms units)
103 * @ret rc Return status code
104 */
105static inline __attribute__ (( always_inline )) int
106usbhid_set_idle ( struct usb_device *usb, unsigned int interface,
107 unsigned int report, unsigned int duration ) {
108
109 return usb_control ( usb, USBHID_SET_IDLE,
110 ( ( duration << 8 ) | report ),
111 interface, NULL, 0 );
112}
113
114/**
115 * Set report
116 *
117 * @v usb USB device
118 * @v interface Interface number
119 * @v type Report type
120 * @v report Report ID
121 * @v data Report data
122 * @v len Length of report data
123 * @ret rc Return status code
124 */
125static inline __attribute__ (( always_inline )) int
126usbhid_set_report ( struct usb_device *usb, unsigned int interface,
127 unsigned int type, unsigned int report, void *data,
128 size_t len ) {
129
130 return usb_control ( usb, USBHID_SET_REPORT, ( ( type << 8 ) | report ),
131 interface, data, len );
132}
133
134extern int usbhid_open ( struct usb_hid *hid );
135extern void usbhid_close ( struct usb_hid *hid );
136extern int usbhid_refill ( struct usb_hid *hid );
137extern int usbhid_describe ( struct usb_hid *hid,
138 struct usb_configuration_descriptor *config );
139
140#endif /* _IPXE_USBHID_H */
#define NULL
NULL pointer (VOID *)
Definition Base.h:322
__be32 in[4]
Definition CIB_PRM.h:7
__be32 out[4]
Definition CIB_PRM.h:8
ring len
Length.
Definition dwmac.h:226
uint32_t type
Operating system type.
Definition ena.h:1
uint8_t data[48]
Additional event data.
Definition ena.h:11
#define FILE_LICENCE(_licence)
Declare a particular licence as applying to a file.
Definition compiler.h:896
u16 duration
Microseconds to reserve link.
Definition ieee80211.h:1
#define __attribute__(x)
Definition compiler.h:10
Universal Serial Bus (USB)
static void usb_endpoint_init(struct usb_endpoint *ep, struct usb_device *usb, struct usb_endpoint_driver_operations *driver)
Initialise USB endpoint.
Definition usb.h:540
uint16_t protocol
Protocol ID.
Definition stp.h:7
An object interface.
Definition interface.h:125
A USB configuration descriptor.
Definition usb.h:210
A USB device.
Definition usb.h:723
USB endpoint driver operations.
Definition usb.h:489
A USB endpoint.
Definition usb.h:404
A USB function.
Definition usb.h:674
struct usb_device * usb
USB device.
Definition usb.h:678
A USB human interface device.
Definition usbhid.h:51
struct usb_endpoint in
Interrupt IN endpoint.
Definition usbhid.h:55
struct usb_function * func
USB function.
Definition usbhid.h:53
struct usb_endpoint out
Interrupt OUT endpoint (optional)
Definition usbhid.h:57
int usb_control(struct usb_device *usb, unsigned int request, unsigned int value, unsigned int index, void *data, size_t len)
Issue USB control transaction.
Definition usb.c:784
int usbhid_refill(struct usb_hid *hid)
Refill USB human interface device endpoints.
Definition usbhid.c:99
int usbhid_describe(struct usb_hid *hid, struct usb_configuration_descriptor *config)
Describe USB human interface device.
Definition usbhid.c:120
static int usbhid_set_idle(struct usb_device *usb, unsigned int interface, unsigned int report, unsigned int duration)
Set idle time.
Definition usbhid.h:106
static int usbhid_set_protocol(struct usb_device *usb, unsigned int interface, unsigned int protocol)
Set protocol.
Definition usbhid.h:89
#define USBHID_SET_PROTOCOL
Set protocol.
Definition usbhid.h:21
static int usbhid_set_report(struct usb_device *usb, unsigned int interface, unsigned int type, unsigned int report, void *data, size_t len)
Set report.
Definition usbhid.h:126
static void usbhid_init(struct usb_hid *hid, struct usb_function *func, struct usb_endpoint_driver_operations *in, struct usb_endpoint_driver_operations *out)
Initialise USB human interface device.
Definition usbhid.h:69
void usbhid_close(struct usb_hid *hid)
Close USB human interface device.
Definition usbhid.c:83
#define USBHID_SET_REPORT
Set report.
Definition usbhid.h:37
int usbhid_open(struct usb_hid *hid)
Open USB human interface device.
Definition usbhid.c:43
#define USBHID_SET_IDLE
Set idle time.
Definition usbhid.h:32