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