usbh_hid.h 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. /*
  2. * Copyright (c) 2022, sakumisu
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. */
  6. #ifndef USBH_HID_H
  7. #define USBH_HID_H
  8. #include "usb_hid.h"
  9. #ifndef CONFIG_USB_HID_MAX_REPORT_ITEMS
  10. #define CONFIG_USB_HID_MAX_REPORT_ITEMS 16
  11. #endif
  12. #define USBH_HID_REPORTITEM_TYPE_INPUT 0
  13. #define USBH_HID_REPORTITEM_TYPE_OUTPUT 1
  14. #define USBH_HID_REPORTITEM_TYPE_FEATURE 2
  15. struct usbh_hid_report_item_attribute {
  16. uint16_t usage_page;
  17. uint16_t usage_min;
  18. uint16_t usage_max;
  19. int32_t logical_min;
  20. int32_t logical_max;
  21. uint32_t physical_min;
  22. uint32_t physical_max;
  23. uint32_t unit_exponent;
  24. uint32_t unit;
  25. uint32_t report_count;
  26. uint8_t report_size;
  27. uint8_t report_id;
  28. };
  29. struct usbh_hid_report_item {
  30. uint8_t report_type; /* input, output, feature */
  31. uint16_t report_flags;
  32. uint32_t report_bit_offset;
  33. struct usbh_hid_report_item_attribute attribute;
  34. };
  35. struct usbh_hid_report_info {
  36. struct usbh_hid_report_item report_items[CONFIG_USB_HID_MAX_REPORT_ITEMS];
  37. uint32_t report_item_count;
  38. bool using_report_id;
  39. };
  40. struct usbh_hid {
  41. struct usbh_hubport *hport;
  42. struct usb_endpoint_descriptor *intin; /* INTR IN endpoint */
  43. struct usb_endpoint_descriptor *intout; /* INTR OUT endpoint */
  44. struct usbh_urb intin_urb; /* INTR IN urb */
  45. struct usbh_urb intout_urb; /* INTR OUT urb */
  46. uint16_t report_size;
  47. uint8_t protocol;
  48. uint8_t intf; /* interface number */
  49. uint8_t minor;
  50. void *user_data;
  51. };
  52. #ifdef __cplusplus
  53. extern "C" {
  54. #endif
  55. int usbh_hid_get_report_descriptor(struct usbh_hid *hid_class, uint8_t *buffer, uint32_t buflen);
  56. int usbh_hid_set_idle(struct usbh_hid *hid_class, uint8_t report_id, uint8_t duration);
  57. int usbh_hid_get_idle(struct usbh_hid *hid_class, uint8_t *buffer);
  58. int usbh_hid_set_protocol(struct usbh_hid *hid_class, uint8_t protocol);
  59. int usbh_hid_get_protocol(struct usbh_hid *hid_class, uint8_t *protocol);
  60. int usbh_hid_set_report(struct usbh_hid *hid_class, uint8_t report_type, uint8_t report_id, uint8_t *buffer, uint32_t buflen);
  61. int usbh_hid_get_report(struct usbh_hid *hid_class, uint8_t report_type, uint8_t report_id, uint8_t *buffer, uint32_t buflen);
  62. int usbh_hid_parse_report_descriptor(const uint8_t *report_data, uint32_t report_size, struct usbh_hid_report_info *report_info);
  63. void usbh_hid_run(struct usbh_hid *hid_class);
  64. void usbh_hid_stop(struct usbh_hid *hid_class);
  65. int lshid(int argc, char **argv);
  66. #ifdef __cplusplus
  67. }
  68. #endif
  69. #endif /* USBH_HID_H */