hid.h 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. /*
  2. * USB keyboard/mouse constants
  3. */
  4. typedef struct Chain Chain;
  5. typedef struct HidInterface HidInterface;
  6. typedef struct HidRepTempl HidRepTempl;
  7. enum {
  8. Stack = 32 * 1024,
  9. /* HID class subclass protocol ids */
  10. PtrCSP = 0x020103, /* mouse.boot.hid */
  11. KbdCSP = 0x010103, /* keyboard.boot.hid */
  12. /* Requests */
  13. Getproto = 0x03,
  14. Setidle = 0x0a,
  15. Setproto = 0x0b,
  16. /* protocols for SET_PROTO request */
  17. Bootproto = 0,
  18. Reportproto = 1,
  19. };
  20. enum {
  21. /* keyboard modifier bits */
  22. Mlctrl = 0,
  23. Mlshift = 1,
  24. Mlalt = 2,
  25. Mlgui = 3,
  26. Mrctrl = 4,
  27. Mrshift = 5,
  28. Mralt = 6,
  29. Mrgui = 7,
  30. /* masks for byte[0] */
  31. Mctrl = 1<<Mlctrl | 1<<Mrctrl,
  32. Mshift = 1<<Mlshift | 1<<Mrshift,
  33. Malt = 1<<Mlalt | 1<<Mralt,
  34. Mcompose = 1<<Mlalt,
  35. Maltgr = 1<<Mralt,
  36. Mgui = 1<<Mlgui | 1<<Mrgui,
  37. MaxAcc = 3, /* max. ptr acceleration */
  38. PtrMask= 0xf, /* 4 buttons: should allow for more. */
  39. };
  40. /*
  41. * Plan 9 keyboard driver constants.
  42. */
  43. enum {
  44. /* Scan codes (see kbd.c) */
  45. SCesc1 = 0xe0, /* first of a 2-character sequence */
  46. SCesc2 = 0xe1,
  47. SClshift = 0x2a,
  48. SCrshift = 0x36,
  49. SCctrl = 0x1d,
  50. SCcompose = 0x38,
  51. Keyup = 0x80, /* flag bit */
  52. Keymask = 0x7f, /* regular scan code bits */
  53. };
  54. int kbmain(Dev *d, int argc, char*argv[]);
  55. enum{
  56. MaxChLen = 64, /* bytes */
  57. };
  58. struct Chain {
  59. int b; /* offset start in bits, (first full) */
  60. int e; /* offset end in bits (first empty) */
  61. uchar buf[MaxChLen];
  62. };
  63. #define MSK(nbits) ((1UL << (nbits)) - 1)
  64. #define IsCut(bbits, ebits) (((ebits)/8 - (bbits)/8) > 0)
  65. enum {
  66. KindPad = 0,
  67. KindButtons,
  68. KindX,
  69. KindY,
  70. KindWheel,
  71. MaxVals = 16,
  72. MaxIfc = 8,
  73. };
  74. struct HidInterface {
  75. ulong v[MaxVals]; /* one ulong per val should be enough */
  76. uchar kind[MaxVals];
  77. int nbits;
  78. int count;
  79. };
  80. struct HidRepTempl{
  81. int id; /* id which may not be present */
  82. uint sz; /* in bytes */
  83. int nifcs;
  84. HidInterface ifcs[MaxIfc];
  85. };
  86. enum {
  87. /* report types */
  88. HidReportApp = 0x01,
  89. HidTypeUsgPg = 0x05,
  90. HidPgButts = 0x09,
  91. HidTypeRepSz = 0x75,
  92. HidTypeCnt = 0x95,
  93. HidCollection = 0xa1,
  94. HidTypeUsg = 0x09,
  95. HidPtr = 0x01,
  96. HidX = 0x30,
  97. HidY = 0x31,
  98. HidZ = 0x32,
  99. HidWheel = 0x38,
  100. HidInput = 0x81,
  101. HidReportId = 0x85,
  102. HidReportIdPtr = 0x01,
  103. HidEnd = 0xc0,
  104. };
  105. void dumpreport(HidRepTempl *templ);
  106. int hidifcval(HidRepTempl *templ, int kind, int n);
  107. int parsereport(HidRepTempl *templ, Chain *rep);
  108. int parsereportdesc(HidRepTempl *temp, uchar *repdesc, int repsz);