iPXE
usbhid.h
Go to the documentation of this file.
00001 #ifndef _IPXE_USBHID_H
00002 #define _IPXE_USBHID_H
00003 
00004 /** @file
00005  *
00006  * USB human interface devices (HID)
00007  *
00008  */
00009 
00010 FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
00011 
00012 #include <ipxe/usb.h>
00013 
00014 /** Class code for human interface devices */
00015 #define USB_CLASS_HID 3
00016 
00017 /** Subclass code for boot devices */
00018 #define USB_SUBCLASS_HID_BOOT 1
00019 
00020 /** Set protocol */
00021 #define USBHID_SET_PROTOCOL                                             \
00022         ( USB_DIR_OUT | USB_TYPE_CLASS | USB_RECIP_INTERFACE |          \
00023           USB_REQUEST_TYPE ( 0x0b ) )
00024 
00025 /** Boot protocol */
00026 #define USBHID_PROTOCOL_BOOT 0
00027 
00028 /** Report protocol */
00029 #define USBHID_PROTOCOL_REPORT 1
00030 
00031 /** Set idle time */
00032 #define USBHID_SET_IDLE                                                 \
00033         ( USB_DIR_OUT | USB_TYPE_CLASS | USB_RECIP_INTERFACE |          \
00034           USB_REQUEST_TYPE ( 0x0a ) )
00035 
00036 /** Set report */
00037 #define USBHID_SET_REPORT                                               \
00038         ( USB_DIR_OUT | USB_TYPE_CLASS | USB_RECIP_INTERFACE |          \
00039           USB_REQUEST_TYPE ( 0x09 ) )
00040 
00041 /** Input report type */
00042 #define USBHID_REPORT_INPUT 0x01
00043 
00044 /** Output report type */
00045 #define USBHID_REPORT_OUTPUT 0x02
00046 
00047 /** Feature report type */
00048 #define USBHID_REPORT_FEATURE 0x03
00049 
00050 /** A USB human interface device */
00051 struct usb_hid {
00052         /** USB function */
00053         struct usb_function *func;
00054         /** Interrupt IN endpoint */
00055         struct usb_endpoint in;
00056         /** Interrupt OUT endpoint (optional) */
00057         struct usb_endpoint out;
00058 };
00059 
00060 /**
00061  * Initialise USB human interface device
00062  *
00063  * @v hid               USB human interface device
00064  * @v func              USB function
00065  * @v in                Interrupt IN endpoint operations
00066  * @v out               Interrupt OUT endpoint operations (or NULL)
00067  */
00068 static inline __attribute__ (( always_inline )) void
00069 usbhid_init ( struct usb_hid *hid, struct usb_function *func,
00070               struct usb_endpoint_driver_operations *in,
00071               struct usb_endpoint_driver_operations *out ) {
00072         struct usb_device *usb = func->usb;
00073 
00074         hid->func = func;
00075         usb_endpoint_init ( &hid->in, usb, in );
00076         if ( out )
00077                 usb_endpoint_init ( &hid->out, usb, out );
00078 }
00079 
00080 /**
00081  * Set protocol
00082  *
00083  * @v usb               USB device
00084  * @v interface         Interface number
00085  * @v protocol          HID protocol
00086  * @ret rc              Return status code
00087  */
00088 static inline __attribute__ (( always_inline )) int
00089 usbhid_set_protocol ( struct usb_device *usb, unsigned int interface,
00090                       unsigned int protocol ) {
00091 
00092         return usb_control ( usb, USBHID_SET_PROTOCOL, protocol, interface,
00093                              NULL, 0 );
00094 }
00095 
00096 /**
00097  * Set idle time
00098  *
00099  * @v usb               USB device
00100  * @v interface         Interface number
00101  * @v report            Report ID
00102  * @v duration          Duration (in 4ms units)
00103  * @ret rc              Return status code
00104  */
00105 static inline __attribute__ (( always_inline )) int
00106 usbhid_set_idle ( struct usb_device *usb, unsigned int interface,
00107                   unsigned int report, unsigned int duration ) {
00108 
00109         return usb_control ( usb, USBHID_SET_IDLE,
00110                              ( ( duration << 8 ) | report ),
00111                              interface, NULL, 0 );
00112 }
00113 
00114 /**
00115  * Set report
00116  *
00117  * @v usb               USB device
00118  * @v interface         Interface number
00119  * @v type              Report type
00120  * @v report            Report ID
00121  * @v data              Report data
00122  * @v len               Length of report data
00123  * @ret rc              Return status code
00124  */
00125 static inline __attribute__ (( always_inline )) int
00126 usbhid_set_report ( struct usb_device *usb, unsigned int interface,
00127                     unsigned int type, unsigned int report, void *data,
00128                     size_t len ) {
00129 
00130         return usb_control ( usb, USBHID_SET_REPORT, ( ( type << 8 ) | report ),
00131                              interface, data, len );
00132 }
00133 
00134 extern int usbhid_open ( struct usb_hid *hid );
00135 extern void usbhid_close ( struct usb_hid *hid );
00136 extern int usbhid_refill ( struct usb_hid *hid );
00137 extern int usbhid_describe ( struct usb_hid *hid,
00138                              struct usb_configuration_descriptor *config );
00139 
00140 #endif /* _IPXE_USBHID_H */