xref: /plan9/sys/src/cmd/usb/kb/hid.h (revision d40255d87ccd1acd15b87823a96efd7b6296fadd)
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	= 16,	/* 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	= 8,
87 	MaxIfc	= 8,
88 };
89 
90 struct HidInterface {
91 	ulong	v[MaxVals];	/* one ulong per val should be enough */
92 	int	kind[MaxVals];
93 	int	nbits;
94 	int	count;
95 };
96 
97 struct HidRepTempl{
98 	int	nifcs;
99 	HidInterface ifcs[MaxIfc];
100 };
101 
102 enum {
103 	/* report types */
104 	HidTypeUsgPg	= 0x05,
105 	HidPgButts	= 0x09,
106 
107 	HidTypeRepSz	= 0x75,
108 	HidTypeCnt	= 0x95,
109 
110 	HidTypeUsg	= 0x09,
111 	HidPtr		= 0x01,
112 	HidX		= 0x30,
113 	HidY		= 0x31,
114 	HidWheel	= 0x38,
115 
116 	HidInput	= 0x81,
117 	HidReportId	= 0x85,
118 
119 	HidEnd		= 0x0c,
120 };
121 
122 void	dumpreport(HidRepTempl *templ);
123 int	hidifcval(HidRepTempl *templ, int kind, int n);
124 int	parsereport(HidRepTempl *templ, Chain *rep);
125 int	parsereportdesc(HidRepTempl *temp, uchar *repdesc, int repsz);
126