2 * Copyright (C) 2015 Michael Brown <mbrown@fensystems.co.uk>.
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License as
6 * published by the Free Software Foundation; either version 2 of the
7 * License, or (at your option) any later version.
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
19 * You can also choose to distribute this program under the terms of
20 * the Unmodified Binary Distribution Licence (as given in the file
21 * COPYING.UBDL), provided that you have satisfied its requirements.
24 FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL
);
29 #include <ipxe/usbhid.h>
33 * USB human interface devices (HID)
38 * Open USB human interface device
40 * @v hid USB human interface device
41 * @ret rc Return status code
43 int usbhid_open ( struct usb_hid
*hid
) {
46 /* Open interrupt IN endpoint */
47 if ( ( rc
= usb_endpoint_open ( &hid
->in
) ) != 0 ) {
48 DBGC ( hid
, "HID %s could not open interrupt IN: %s\n",
49 hid
->func
->name
, strerror ( rc
) );
53 /* Refill interrupt IN endpoint */
54 if ( ( rc
= usb_refill ( &hid
->in
) ) != 0 ) {
55 DBGC ( hid
, "HID %s could not refill interrupt IN: %s\n",
56 hid
->func
->name
, strerror ( rc
) );
60 /* Open interrupt OUT endpoint, if applicable */
62 ( ( rc
= usb_endpoint_open ( &hid
->out
) ) != 0 ) ) {
63 DBGC ( hid
, "HID %s could not open interrupt OUT: %s\n",
64 hid
->func
->name
, strerror ( rc
) );
70 usb_endpoint_close ( &hid
->out
);
73 usb_endpoint_close ( &hid
->in
);
79 * Close USB human interface device
81 * @v hid USB human interface device
83 void usbhid_close ( struct usb_hid
*hid
) {
85 /* Close interrupt OUT endpoint, if applicable */
87 usb_endpoint_close ( &hid
->out
);
89 /* Close interrupt IN endpoint */
90 usb_endpoint_close ( &hid
->in
);
94 * Refill USB human interface device endpoints
96 * @v hid USB human interface device
97 * @ret rc Return status code
99 int usbhid_refill ( struct usb_hid
*hid
) {
102 /* Refill interrupt IN endpoint */
103 if ( ( rc
= usb_refill ( &hid
->in
) ) != 0 )
106 /* Refill interrupt OUT endpoint, if applicable */
107 if ( hid
->out
.usb
&& ( ( rc
= usb_refill ( &hid
->out
) ) != 0 ) )
114 * Describe USB human interface device
116 * @v hid USB human interface device
117 * @v config Configuration descriptor
118 * @ret rc Return status code
120 int usbhid_describe ( struct usb_hid
*hid
,
121 struct usb_configuration_descriptor
*config
) {
122 struct usb_interface_descriptor
*desc
;
125 /* Locate interface descriptor */
126 desc
= usb_interface_descriptor ( config
, hid
->func
->interface
[0], 0 );
128 DBGC ( hid
, "HID %s has no interface descriptor\n",
133 /* Describe interrupt IN endpoint */
134 if ( ( rc
= usb_endpoint_described ( &hid
->in
, config
, desc
,
135 USB_INTERRUPT_IN
, 0 ) ) != 0 ) {
136 DBGC ( hid
, "HID %s could not describe interrupt IN: %s\n",
137 hid
->func
->name
, strerror ( rc
) );
141 /* Describe interrupt OUT endpoint, if applicable */
143 ( ( rc
= usb_endpoint_described ( &hid
->out
, config
, desc
,
144 USB_INTERRUPT_OUT
, 0 ) ) != 0 )){
145 DBGC ( hid
, "HID %s could not describe interrupt OUT: %s\n",
146 hid
->func
->name
, strerror ( rc
) );