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 
10 FILE_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 */
51 struct usb_hid {
52  /** USB function */
53  struct usb_function *func;
54  /** Interrupt IN endpoint */
55  struct usb_endpoint in;
56  /** Interrupt OUT endpoint (optional) */
57  struct usb_endpoint out;
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  */
68 static inline __attribute__ (( always_inline )) void
69 usbhid_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  */
88 static inline __attribute__ (( always_inline )) int
89 usbhid_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  */
105 static inline __attribute__ (( always_inline )) int
106 usbhid_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  */
125 static inline __attribute__ (( always_inline )) int
126 usbhid_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 
134 extern int usbhid_open ( struct usb_hid *hid );
135 extern void usbhid_close ( struct usb_hid *hid );
136 extern int usbhid_refill ( struct usb_hid *hid );
137 extern int usbhid_describe ( struct usb_hid *hid,
138  struct usb_configuration_descriptor *config );
139 
140 #endif /* _IPXE_USBHID_H */
#define __attribute__(x)
Definition: compiler.h:10
__be32 in[4]
Definition: CIB_PRM.h:35
struct usb_endpoint in
Interrupt IN endpoint.
Definition: usbhid.h:55
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:783
__be32 out[4]
Definition: CIB_PRM.h:36
void usbhid_close(struct usb_hid *hid)
Close USB human interface device.
Definition: usbhid.c:83
#define USBHID_SET_PROTOCOL
Set protocol.
Definition: usbhid.h:21
A USB endpoint.
Definition: usb.h:389
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
An object interface.
Definition: interface.h:124
int usbhid_refill(struct usb_hid *hid)
Refill USB human interface device endpoints.
Definition: usbhid.c:99
FILE_LICENCE(GPL2_OR_LATER_OR_UBDL)
#define USBHID_SET_REPORT
Set report.
Definition: usbhid.h:37
A USB device.
Definition: usb.h:708
u16 duration
Microseconds to reserve link.
Definition: ieee80211.h:15
static int usbhid_set_protocol(struct usb_device *usb, unsigned int interface, unsigned int protocol)
Set protocol.
Definition: usbhid.h:89
A USB human interface device.
Definition: usbhid.h:51
struct usb_device * usb
USB device.
Definition: usb.h:663
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:525
A USB configuration descriptor.
Definition: usb.h:195
uint32_t len
Length.
Definition: ena.h:14
uint32_t type
Operating system type.
Definition: ena.h:12
Universal Serial Bus (USB)
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
int usbhid_describe(struct usb_hid *hid, struct usb_configuration_descriptor *config)
Describe USB human interface device.
Definition: usbhid.c:120
uint8_t data[48]
Additional event data.
Definition: ena.h:22
int usbhid_open(struct usb_hid *hid)
Open USB human interface device.
Definition: usbhid.c:43
uint16_t protocol
Protocol ID.
Definition: stp.h:18
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
struct usb_function * func
USB function.
Definition: usbhid.h:53
USB endpoint driver operations.
Definition: usb.h:474
A USB function.
Definition: usb.h:659
#define NULL
NULL pointer (VOID *)
Definition: Base.h:321
#define USBHID_SET_IDLE
Set idle time.
Definition: usbhid.h:32