hid.h 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. #pragma once
  2. #include <common/stddef.h>
  3. #define __HID_USAGE_TABLE_SIZE 64 // usage stack的大小
  4. #define HID_MAX_REPORT 300 // 最大允许的hid report数目(包括feature、input、output)
  5. #define HID_MAX_PATH_SIZE 16 // maximum depth for path
  6. /**
  7. * @brief 描述hid path中的一个节点
  8. *
  9. */
  10. struct hid_node_t
  11. {
  12. int u_page;
  13. int usage;
  14. };
  15. /**
  16. * @brief 描述一条hid path
  17. *
  18. */
  19. struct hid_path_t
  20. {
  21. int size; // 路径中的节点数目
  22. struct hid_node_t node[HID_MAX_PATH_SIZE];
  23. };
  24. /**
  25. * @brief Describe a HID Data with its location in report
  26. *
  27. */
  28. struct hid_data_t
  29. {
  30. int value; // hid对象的值
  31. struct hid_path_t path; // hid path
  32. int report_count; // count of reports for this usage type
  33. int offset; // offset of data in report
  34. int size; // size of data in bits
  35. uint8_t report_id; // report id(from incoming report)
  36. uint8_t type; // 数据类型:FEATURE / INPUT / OUTPUT
  37. uint8_t attribute; // report field attribute. (2 = (Data,Var,Abs,No Wrap,Linear,Preferred State,No Null Position))
  38. // (6 = (Data,Var,Rel,No Wrap,Linear,Preferred State,No Null Position))
  39. int8_t unit_exp; // unit exponent;
  40. uint32_t unit; // HID unit
  41. int logical_min; // Logical min
  42. int logical_max; // Logical max
  43. int phys_min; // Physical min
  44. int phys_max; // Physical max
  45. };
  46. /**
  47. * @brief hid解析器
  48. *
  49. */
  50. struct hid_parser
  51. {
  52. const uint8_t *report_desc; // 指向report descriptor的指针
  53. int report_desc_size; // report descriptor的大小(字节)
  54. int pos; // report_desc中,当前正在处理的位置
  55. uint8_t item; // 暂存当前的item
  56. uint32_t value; // 暂存当前的值
  57. struct hid_data_t data; // 存储当前的环境
  58. int offset_table[HID_MAX_REPORT][3]; // 存储 hid report的ID、type、offset
  59. int report_count; // hid report的数量
  60. int count; // local items的计数
  61. uint32_t u_page;
  62. struct hid_node_t usage_table[__HID_USAGE_TABLE_SIZE]; // Usage stack
  63. int usage_size; // usage的数量
  64. int usage_min;
  65. int usage_max;
  66. int cnt_objects; // report descriptor中的对象数目
  67. int cnt_report // report desc中的report数目
  68. };
  69. struct hid_usage_types_string
  70. {
  71. int value;
  72. const char *string;
  73. };
  74. struct hid_usage_pages_string
  75. {
  76. int value;
  77. struct hid_usage_types_string * types;
  78. const char * string;
  79. };
  80. int hid_parse_report(const void *report_data, const int len);