Wed Aug 29 02:38:31 2012 UTC ()
support an optional table to translate scancodes when in event mode


(macallan)
diff -r1.131 -r1.132 src/sys/dev/wscons/wskbd.c
diff -r1.17 -r1.18 src/sys/dev/wscons/wskbdvar.h

cvs diff -r1.131 -r1.132 src/sys/dev/wscons/wskbd.c (expand / switch to unified diff)

--- src/sys/dev/wscons/wskbd.c 2012/03/13 18:40:34 1.131
+++ src/sys/dev/wscons/wskbd.c 2012/08/29 02:38:31 1.132
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: wskbd.c,v 1.131 2012/03/13 18:40:34 elad Exp $ */ 1/* $NetBSD: wskbd.c,v 1.132 2012/08/29 02:38:31 macallan Exp $ */
2 2
3/* 3/*
4 * Copyright (c) 1996, 1997 Christopher G. Demetriou. All rights reserved. 4 * Copyright (c) 1996, 1997 Christopher G. Demetriou. All rights reserved.
5 * 5 *
6 * Redistribution and use in source and binary forms, with or without 6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions 7 * modification, are permitted provided that the following conditions
8 * are met: 8 * are met:
9 * 1. Redistributions of source code must retain the above copyright 9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer. 10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright 11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the 12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution. 13 * documentation and/or other materials provided with the distribution.
14 * 3. All advertising materials mentioning features or use of this software 14 * 3. All advertising materials mentioning features or use of this software
@@ -95,27 +95,27 @@ @@ -95,27 +95,27 @@
95 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 95 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
96 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 96 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
97 * SUCH DAMAGE. 97 * SUCH DAMAGE.
98 * 98 *
99 * @(#)kbd.c 8.2 (Berkeley) 10/30/93 99 * @(#)kbd.c 8.2 (Berkeley) 10/30/93
100 */ 100 */
101 101
102/* 102/*
103 * Keyboard driver (/dev/wskbd*). Translates incoming bytes to ASCII or 103 * Keyboard driver (/dev/wskbd*). Translates incoming bytes to ASCII or
104 * to `wscons_events' and passes them up to the appropriate reader. 104 * to `wscons_events' and passes them up to the appropriate reader.
105 */ 105 */
106 106
107#include <sys/cdefs.h> 107#include <sys/cdefs.h>
108__KERNEL_RCSID(0, "$NetBSD: wskbd.c,v 1.131 2012/03/13 18:40:34 elad Exp $"); 108__KERNEL_RCSID(0, "$NetBSD: wskbd.c,v 1.132 2012/08/29 02:38:31 macallan Exp $");
109 109
110#include "opt_ddb.h" 110#include "opt_ddb.h"
111#include "opt_kgdb.h" 111#include "opt_kgdb.h"
112#include "opt_wsdisplay_compat.h" 112#include "opt_wsdisplay_compat.h"
113 113
114#include "wsdisplay.h" 114#include "wsdisplay.h"
115#include "wskbd.h" 115#include "wskbd.h"
116#include "wsmux.h" 116#include "wsmux.h"
117 117
118#include <sys/param.h> 118#include <sys/param.h>
119#include <sys/conf.h> 119#include <sys/conf.h>
120#include <sys/device.h> 120#include <sys/device.h>
121#include <sys/ioctl.h> 121#include <sys/ioctl.h>
@@ -197,26 +197,30 @@ struct wskbd_softc { @@ -197,26 +197,30 @@ struct wskbd_softc {
197 int sc_repeat_value; 197 int sc_repeat_value;
198 198
199 int sc_translating; /* xlate to chars for emulation */ 199 int sc_translating; /* xlate to chars for emulation */
200 200
201 int sc_maplen; /* number of entries in sc_map */ 201 int sc_maplen; /* number of entries in sc_map */
202 struct wscons_keymap *sc_map; /* current translation map */ 202 struct wscons_keymap *sc_map; /* current translation map */
203 kbd_t sc_layout; /* current layout */ 203 kbd_t sc_layout; /* current layout */
204 204
205 int sc_refcnt; 205 int sc_refcnt;
206 u_char sc_dying; /* device is being detached */ 206 u_char sc_dying; /* device is being detached */
207 207
208 wskbd_hotkey_plugin *sc_hotkey; 208 wskbd_hotkey_plugin *sc_hotkey;
209 void *sc_hotkeycookie; 209 void *sc_hotkeycookie;
 210
 211 /* optional table to translate scancodes in event mode */
 212 int sc_evtrans_len;
 213 keysym_t *sc_evtrans;
210}; 214};
211 215
212#define MOD_SHIFT_L (1 << 0) 216#define MOD_SHIFT_L (1 << 0)
213#define MOD_SHIFT_R (1 << 1) 217#define MOD_SHIFT_R (1 << 1)
214#define MOD_SHIFTLOCK (1 << 2) 218#define MOD_SHIFTLOCK (1 << 2)
215#define MOD_CAPSLOCK (1 << 3) 219#define MOD_CAPSLOCK (1 << 3)
216#define MOD_CONTROL_L (1 << 4) 220#define MOD_CONTROL_L (1 << 4)
217#define MOD_CONTROL_R (1 << 5) 221#define MOD_CONTROL_R (1 << 5)
218#define MOD_META_L (1 << 6) 222#define MOD_META_L (1 << 6)
219#define MOD_META_R (1 << 7) 223#define MOD_META_R (1 << 7)
220#define MOD_MODESHIFT (1 << 8) 224#define MOD_MODESHIFT (1 << 8)
221#define MOD_NUMLOCK (1 << 9) 225#define MOD_NUMLOCK (1 << 9)
222#define MOD_COMPOSE (1 << 10) 226#define MOD_COMPOSE (1 << 10)
@@ -408,26 +412,28 @@ wskbd_match(device_t parent, cfdata_t ma @@ -408,26 +412,28 @@ wskbd_match(device_t parent, cfdata_t ma
408void 412void
409wskbd_attach(device_t parent, device_t self, void *aux) 413wskbd_attach(device_t parent, device_t self, void *aux)
410{ 414{
411 struct wskbd_softc *sc = device_private(self); 415 struct wskbd_softc *sc = device_private(self);
412 struct wskbddev_attach_args *ap = aux; 416 struct wskbddev_attach_args *ap = aux;
413#if NWSMUX > 0 417#if NWSMUX > 0
414 int mux, error; 418 int mux, error;
415#endif 419#endif
416 420
417 sc->sc_base.me_dv = self; 421 sc->sc_base.me_dv = self;
418 sc->sc_isconsole = ap->console; 422 sc->sc_isconsole = ap->console;
419 sc->sc_hotkey = NULL; 423 sc->sc_hotkey = NULL;
420 sc->sc_hotkeycookie = NULL; 424 sc->sc_hotkeycookie = NULL;
 425 sc->sc_evtrans_len = 0;
 426 sc->sc_evtrans = NULL;
421 427
422#if NWSMUX > 0 || NWSDISPLAY > 0 428#if NWSMUX > 0 || NWSDISPLAY > 0
423 sc->sc_base.me_ops = &wskbd_srcops; 429 sc->sc_base.me_ops = &wskbd_srcops;
424#endif 430#endif
425#if NWSMUX > 0 431#if NWSMUX > 0
426 mux = device_cfdata(sc->sc_base.me_dv)->wskbddevcf_mux; 432 mux = device_cfdata(sc->sc_base.me_dv)->wskbddevcf_mux;
427 if (ap->console) { 433 if (ap->console) {
428 /* Ignore mux for console; it always goes to the console mux. */ 434 /* Ignore mux for console; it always goes to the console mux. */
429 /* printf(" (mux %d ignored for console)", mux); */ 435 /* printf(" (mux %d ignored for console)", mux); */
430 mux = -1; 436 mux = -1;
431 } 437 }
432 if (mux >= 0) 438 if (mux >= 0)
433 aprint_normal(" mux %d", mux); 439 aprint_normal(" mux %d", mux);
@@ -734,27 +740,37 @@ wskbd_deliver_event(struct wskbd_softc * @@ -734,27 +740,37 @@ wskbd_deliver_event(struct wskbd_softc *
734 if (evar == NULL) { 740 if (evar == NULL) {
735 DPRINTF(("wskbd_input: not open\n")); 741 DPRINTF(("wskbd_input: not open\n"));
736 return; 742 return;
737 } 743 }
738 744
739#ifdef DIAGNOSTIC 745#ifdef DIAGNOSTIC
740 if (evar->q == NULL) { 746 if (evar->q == NULL) {
741 printf("wskbd_input: evar->q=NULL\n"); 747 printf("wskbd_input: evar->q=NULL\n");
742 return; 748 return;
743 } 749 }
744#endif 750#endif
745 751
746 event.type = type; 752 event.type = type;
747 event.value = value; 753 event.value = 0;
 754 DPRINTF(("%d ->", value));
 755 if (sc->sc_evtrans_len > 0) {
 756 if (sc->sc_evtrans_len > value) {
 757 DPRINTF(("%d", sc->sc_evtrans[value]));
 758 event.value = sc->sc_evtrans[value];
 759 }
 760 } else {
 761 event.value = value;
 762 }
 763 DPRINTF(("\n"));
748 if (wsevent_inject(evar, &event, 1) != 0) 764 if (wsevent_inject(evar, &event, 1) != 0)
749 log(LOG_WARNING, "%s: event queue overflow\n", 765 log(LOG_WARNING, "%s: event queue overflow\n",
750 device_xname(sc->sc_base.me_dv)); 766 device_xname(sc->sc_base.me_dv));
751} 767}
752 768
753#ifdef WSDISPLAY_COMPAT_RAWKBD 769#ifdef WSDISPLAY_COMPAT_RAWKBD
754void 770void
755wskbd_rawinput(device_t dev, u_char *tbuf, int len) 771wskbd_rawinput(device_t dev, u_char *tbuf, int len)
756{ 772{
757#if NWSDISPLAY > 0 773#if NWSDISPLAY > 0
758 struct wskbd_softc *sc = device_private(dev); 774 struct wskbd_softc *sc = device_private(dev);
759 int i; 775 int i;
760 776
@@ -1868,13 +1884,23 @@ wskbd_translate(struct wskbd_internal *i @@ -1868,13 +1884,23 @@ wskbd_translate(struct wskbd_internal *i
1868 if (MOD_ONESET(id, MOD_ANYMETA)) { 1884 if (MOD_ONESET(id, MOD_ANYMETA)) {
1869 if (id->t_flags & WSKFL_METAESC) { 1885 if (id->t_flags & WSKFL_METAESC) {
1870 id->t_symbols[0] = KS_Escape; 1886 id->t_symbols[0] = KS_Escape;
1871 id->t_symbols[1] = res; 1887 id->t_symbols[1] = res;
1872 return (2); 1888 return (2);
1873 } else 1889 } else
1874 res |= 0x80; 1890 res |= 0x80;
1875 } 1891 }
1876 } 1892 }
1877 1893
1878 id->t_symbols[0] = res; 1894 id->t_symbols[0] = res;
1879 return (1); 1895 return (1);
1880} 1896}
 1897
 1898void
 1899wskbd_set_evtrans(device_t dev, keysym_t *tab, int len)
 1900{
 1901 struct wskbd_softc *sc = device_private(dev);
 1902
 1903 sc->sc_evtrans_len = len;
 1904 sc->sc_evtrans = tab;
 1905}
 1906

cvs diff -r1.17 -r1.18 src/sys/dev/wscons/wskbdvar.h (expand / switch to unified diff)

--- src/sys/dev/wscons/wskbdvar.h 2010/10/26 05:12:34 1.17
+++ src/sys/dev/wscons/wskbdvar.h 2012/08/29 02:38:31 1.18
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: wskbdvar.h,v 1.17 2010/10/26 05:12:34 jruoho Exp $ */ 1/* $NetBSD: wskbdvar.h,v 1.18 2012/08/29 02:38:31 macallan Exp $ */
2 2
3/* 3/*
4 * Copyright (c) 1996, 1997 Christopher G. Demetriou. All rights reserved. 4 * Copyright (c) 1996, 1997 Christopher G. Demetriou. All rights reserved.
5 * 5 *
6 * Redistribution and use in source and binary forms, with or without 6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions 7 * modification, are permitted provided that the following conditions
8 * are met: 8 * are met:
9 * 1. Redistributions of source code must retain the above copyright 9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer. 10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright 11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the 12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution. 13 * documentation and/or other materials provided with the distribution.
14 * 3. All advertising materials mentioning features or use of this software 14 * 3. All advertising materials mentioning features or use of this software
@@ -93,18 +93,25 @@ void wskbd_input(device_t, u_int, int); @@ -93,18 +93,25 @@ void wskbd_input(device_t, u_int, int);
93void wskbd_rawinput(device_t, u_char *, int); 93void wskbd_rawinput(device_t, u_char *, int);
94 94
95/* 95/*
96 * Callbacks for (ACPI) hotkey drivers which generate 96 * Callbacks for (ACPI) hotkey drivers which generate
97 * keycodes. 97 * keycodes.
98 */ 98 */
99struct wskbd_softc; 99struct wskbd_softc;
100typedef int (wskbd_hotkey_plugin)(struct wskbd_softc *, void *, u_int, int); 100typedef int (wskbd_hotkey_plugin)(struct wskbd_softc *, void *, u_int, int);
101 101
102device_t wskbd_hotkey_register(device_t, void *, wskbd_hotkey_plugin *); 102device_t wskbd_hotkey_register(device_t, void *, wskbd_hotkey_plugin *);
103void wskbd_hotkey_deregister(device_t); 103void wskbd_hotkey_deregister(device_t);
104 104
105/* 105/*
 106 * set a translation table for scancodes in event mode
 107 * parameters are a pointer to the table and its length
 108 * pass length zero to turn translation off
 109 */
 110void wskbd_set_evtrans(device_t, keysym_t *, int);
 111
 112/*
106 * Console interface. 113 * Console interface.
107 */ 114 */
108int wskbd_cngetc(dev_t); 115int wskbd_cngetc(dev_t);
109void wskbd_cnpollc(dev_t, int); 116void wskbd_cnpollc(dev_t, int);
110void wskbd_cnbell(dev_t, u_int, u_int, u_int); 117void wskbd_cnbell(dev_t, u_int, u_int, u_int);