xref: /openbsd/sys/dev/hid/hidkbdsc.h (revision 73471bf0)
1 /*	$OpenBSD: hidkbdsc.h,v 1.1 2016/01/08 15:54:13 jcs Exp $	*/
2 /*      $NetBSD: ukbd.c,v 1.85 2003/03/11 16:44:00 augustss Exp $        */
3 
4 /*
5  * Copyright (c) 1998 The NetBSD Foundation, Inc.
6  * All rights reserved.
7  *
8  * This code is derived from software contributed to The NetBSD Foundation
9  * by Lennart Augustsson (lennart@augustsson.net) at
10  * Carlstedt Research & Technology.
11  *
12  * Redistribution and use in source and binary forms, with or without
13  * modification, are permitted provided that the following conditions
14  * are met:
15  * 1. Redistributions of source code must retain the above copyright
16  *    notice, this list of conditions and the following disclaimer.
17  * 2. Redistributions in binary form must reproduce the above copyright
18  *    notice, this list of conditions and the following disclaimer in the
19  *    documentation and/or other materials provided with the distribution.
20  *
21  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
22  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
23  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
24  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
25  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
26  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31  * POSSIBILITY OF SUCH DAMAGE.
32  */
33 
34 #define MAXKEYCODE 6
35 #define MAXVARS 128
36 
37 #define MAXKEYS (MAXVARS+2*MAXKEYCODE)
38 
39 /* quirks */
40 #define HIDKBD_SPUR_BUT_UP 0x001 /* spurious button up events */
41 
42 struct hidkbd_variable {
43 	struct hid_location loc;
44 	u_int8_t	mask;
45 	u_int8_t	key;
46 };
47 
48 struct hidkbd_data {
49 	u_int8_t	keycode[MAXKEYCODE];
50 	u_int8_t	var[MAXVARS];
51 };
52 
53 struct hidkbd {
54 	/* stored data */
55 	struct hidkbd_data sc_ndata;
56 	struct hidkbd_data sc_odata;
57 
58 	/* input reports */
59 	u_int sc_nvar;
60 	struct hidkbd_variable *sc_var;
61 
62 	struct hid_location sc_keycodeloc;
63 	u_int sc_nkeycode;
64 
65 	/* output reports */
66 	struct hid_location sc_numloc;
67 	struct hid_location sc_capsloc;
68 	struct hid_location sc_scroloc;
69 	struct hid_location sc_compose;
70 	int sc_leds;
71 
72 	/* state information */
73 	struct device *sc_device;
74 	struct device *sc_wskbddev;
75 	char sc_enabled;
76 
77 	char sc_console_keyboard;	/* we are the console keyboard */
78 
79 	char sc_debounce;		/* for quirk handling */
80 	struct timeout sc_delay;	/* for quirk handling */
81 	struct hidkbd_data sc_data;	/* for quirk handling */
82 
83 	/* key repeat logic */
84 #if defined(WSDISPLAY_COMPAT_RAWKBD)
85 	int sc_rawkbd;
86 #endif /* defined(WSDISPLAY_COMPAT_RAWKBD) */
87 
88 	int sc_polling;
89 	int sc_npollchar;
90 	u_int16_t sc_pollchars[MAXKEYS];
91 };
92 
93 int	hidkbd_attach(struct device *, struct hidkbd *, int, uint32_t,
94 	    int, void *, int);
95 void	hidkbd_attach_wskbd(struct hidkbd *, kbd_t,
96 	    const struct wskbd_accessops *);
97 void	hidkbd_bell(u_int, u_int, u_int, int);
98 void	hidkbd_cngetc(struct hidkbd *, u_int *, int *);
99 int	hidkbd_detach(struct hidkbd *, int);
100 int	hidkbd_enable(struct hidkbd *, int);
101 void	hidkbd_input(struct hidkbd *, uint8_t *, u_int);
102 int	hidkbd_ioctl(struct hidkbd *, u_long, caddr_t, int, struct proc *);
103 int	hidkbd_set_leds(struct hidkbd *, int, uint8_t *);
104 
105 extern int hidkbd_is_console;
106