You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

usbhid.h 2.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. #ifndef _IPXE_USBHID_H
  2. #define _IPXE_USBHID_H
  3. /** @file
  4. *
  5. * USB human interface devices (HID)
  6. *
  7. */
  8. FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
  9. #include <ipxe/usb.h>
  10. /** Class code for human interface devices */
  11. #define USB_CLASS_HID 3
  12. /** Subclass code for boot devices */
  13. #define USB_SUBCLASS_HID_BOOT 1
  14. /** Set protocol */
  15. #define USBHID_SET_PROTOCOL \
  16. ( USB_DIR_OUT | USB_TYPE_CLASS | USB_RECIP_INTERFACE | \
  17. USB_REQUEST_TYPE ( 0x0b ) )
  18. /** Boot protocol */
  19. #define USBHID_PROTOCOL_BOOT 0
  20. /** Report protocol */
  21. #define USBHID_PROTOCOL_REPORT 1
  22. /** Set idle time */
  23. #define USBHID_SET_IDLE \
  24. ( USB_DIR_OUT | USB_TYPE_CLASS | USB_RECIP_INTERFACE | \
  25. USB_REQUEST_TYPE ( 0x0a ) )
  26. /** A USB human interface device */
  27. struct usb_hid {
  28. /** USB function */
  29. struct usb_function *func;
  30. /** Interrupt IN endpoint */
  31. struct usb_endpoint in;
  32. /** Interrupt OUT endpoint (optional) */
  33. struct usb_endpoint out;
  34. };
  35. /**
  36. * Initialise USB human interface device
  37. *
  38. * @v hid USB human interface device
  39. * @v func USB function
  40. * @v in Interrupt IN endpoint operations
  41. * @v out Interrupt OUT endpoint operations (or NULL)
  42. */
  43. static inline __attribute__ (( always_inline )) void
  44. usbhid_init ( struct usb_hid *hid, struct usb_function *func,
  45. struct usb_endpoint_driver_operations *in,
  46. struct usb_endpoint_driver_operations *out ) {
  47. struct usb_device *usb = func->usb;
  48. hid->func = func;
  49. usb_endpoint_init ( &hid->in, usb, in );
  50. if ( out )
  51. usb_endpoint_init ( &hid->out, usb, out );
  52. }
  53. /**
  54. * Set protocol
  55. *
  56. * @v usb USB device
  57. * @v interface Interface number
  58. * @v protocol HID protocol
  59. * @ret rc Return status code
  60. */
  61. static inline __attribute__ (( always_inline )) int
  62. usbhid_set_protocol ( struct usb_device *usb, unsigned int interface,
  63. unsigned int protocol ) {
  64. return usb_control ( usb, USBHID_SET_PROTOCOL, protocol, interface,
  65. NULL, 0 );
  66. }
  67. /**
  68. * Set idle time
  69. *
  70. * @v usb USB device
  71. * @v interface Interface number
  72. * @v report Report ID
  73. * @v duration Duration (in 4ms units)
  74. * @ret rc Return status code
  75. */
  76. static inline __attribute__ (( always_inline )) int
  77. usbhid_set_idle ( struct usb_device *usb, unsigned int interface,
  78. unsigned int report, unsigned int duration ) {
  79. return usb_control ( usb, USBHID_SET_IDLE,
  80. ( ( duration << 8 ) | report ),
  81. interface, NULL, 0 );
  82. }
  83. extern int usbhid_open ( struct usb_hid *hid );
  84. extern void usbhid_close ( struct usb_hid *hid );
  85. extern int usbhid_refill ( struct usb_hid *hid );
  86. extern int usbhid_describe ( struct usb_hid *hid,
  87. struct usb_configuration_descriptor *config );
  88. #endif /* _IPXE_USBHID_H */