hid.h 2.8 KB

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