Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys/dev/adb when in event mode, optionally pretend to be a U...
details: https://anonhg.NetBSD.org/src/rev/254144811eaf
branches: trunk
changeset: 781231:254144811eaf
user: macallan <macallan%NetBSD.org@localhost>
date: Wed Aug 29 02:44:07 2012 +0000
description:
when in event mode, optionally pretend to be a USB keyboard
with this USB and ADB keyboards can coexist at the same mux, with X just
listening to /dev/wskbd instead of having to open each one separately
this can be controlled via sysctl, defaults to off for now
needs testing with non-US keyboards
diffstat:
sys/dev/adb/adb_kbd.c | 117 +++++++++++++++++++++++---------
sys/dev/adb/adb_keymap.h | 3 +-
sys/dev/adb/adb_usb_map.c | 166 ++++++++++++++++++++++++++++++++++++++++++++++
sys/dev/adb/files.adb | 3 +-
4 files changed, 253 insertions(+), 36 deletions(-)
diffs (truncated from 387 to 300 lines):
diff -r 4d1b0b12bc0a -r 254144811eaf sys/dev/adb/adb_kbd.c
--- a/sys/dev/adb/adb_kbd.c Wed Aug 29 02:38:31 2012 +0000
+++ b/sys/dev/adb/adb_kbd.c Wed Aug 29 02:44:07 2012 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: adb_kbd.c,v 1.17 2012/06/02 21:36:43 dsl Exp $ */
+/* $NetBSD: adb_kbd.c,v 1.18 2012/08/29 02:44:07 macallan Exp $ */
/*
* Copyright (C) 1998 Colin Wood
@@ -32,7 +32,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: adb_kbd.c,v 1.17 2012/06/02 21:36:43 dsl Exp $");
+__KERNEL_RCSID(0, "$NetBSD: adb_kbd.c,v 1.18 2012/08/29 02:44:07 macallan Exp $");
#include <sys/param.h>
#include <sys/device.h>
@@ -86,6 +86,8 @@
#ifdef WSDISPLAY_COMPAT_RAWKBD
int sc_rawkbd;
#endif
+ bool sc_emul_usb;
+
uint8_t sc_buffer[16];
uint8_t sc_pollbuf[16];
uint8_t sc_us;
@@ -151,6 +153,7 @@
static int adbkbd_sysctl_mid(SYSCTLFN_ARGS);
static int adbkbd_sysctl_right(SYSCTLFN_ARGS);
+static int adbkbd_sysctl_usb(SYSCTLFN_ARGS);
static void adbkbd_setup_sysctl(struct adbkbd_softc *);
#endif /* NWSMOUSE > 0 */
@@ -215,6 +218,7 @@
sc->sc_trans[2] = 111; /* F12 */
sc->sc_power = 0x7f;
sc->sc_timestamp = 0;
+ sc->sc_emul_usb = FALSE;
printf(" addr %d: ", sc->sc_adbdev->current_addr);
@@ -340,9 +344,8 @@
sc->sc_wsmousedev = config_found_ia(self, "wsmousedev", &am,
wsmousedevprint);
- if (sc->sc_wsmousedev != NULL)
- adbkbd_setup_sysctl(sc);
#endif
+ adbkbd_setup_sysctl(sc);
/* finally register the power button */
sysmon_task_queue_init();
@@ -573,7 +576,11 @@
switch (cmd) {
case WSKBDIO_GTYPE:
- *(int *)data = WSKBD_TYPE_ADB;
+ if (sc->sc_emul_usb) {
+ *(int *)data = WSKBD_TYPE_USB;
+ } else {
+ *(int *)data = WSKBD_TYPE_ADB;
+ }
return 0;
case WSKBDIO_SETLEDS:
adbkbd_set_leds(sc, *(int *)data);
@@ -674,34 +681,6 @@
{
}
-static void
-adbkbd_setup_sysctl(struct adbkbd_softc *sc)
-{
- const struct sysctlnode *me, *node;
- int ret;
-
- DPRINTF("%s: sysctl setup\n", device_xname(sc->sc_dev));
- ret = sysctl_createv(NULL, 0, NULL, &me,
- CTLFLAG_READWRITE,
- CTLTYPE_NODE, device_xname(sc->sc_dev), NULL,
- NULL, 0, NULL, 0,
- CTL_MACHDEP, CTL_CREATE, CTL_EOL);
-
- ret = sysctl_createv(NULL, 0, NULL,
- (void *)&node,
- CTLFLAG_READWRITE | CTLFLAG_OWNDESC,
- CTLTYPE_INT, "middle", "middle mouse button", adbkbd_sysctl_mid,
- 1, (void *)sc, 0, CTL_MACHDEP, me->sysctl_num, CTL_CREATE,
- CTL_EOL);
-
- ret = sysctl_createv(NULL, 0, NULL,
- (void *)&node,
- CTLFLAG_READWRITE | CTLFLAG_OWNDESC,
- CTLTYPE_INT, "right", "right mouse button", adbkbd_sysctl_right,
- 2, (void *)sc, 0, CTL_MACHDEP, me->sysctl_num, CTL_CREATE,
- CTL_EOL);
-}
-
static int
adbkbd_sysctl_mid(SYSCTLFN_ARGS)
{
@@ -754,6 +733,77 @@
}
}
+#endif /* NWSMOUSE > 0 */
+
+static int
+adbkbd_sysctl_usb(SYSCTLFN_ARGS)
+{
+ struct sysctlnode node = *rnode;
+ struct adbkbd_softc *sc=(struct adbkbd_softc *)node.sysctl_data;
+ const int *np = newp;
+ bool reg;
+
+ DPRINTF("%s\n", __func__);
+ reg = sc->sc_emul_usb;
+ if (np) {
+ /* we're asked to write */
+ node.sysctl_data = ®
+ if (sysctl_lookup(SYSCTLFN_CALL(&node)) == 0) {
+
+ sc->sc_emul_usb = *(bool *)node.sysctl_data;
+ if (sc->sc_emul_usb) {
+ wskbd_set_evtrans(sc->sc_wskbddev,
+ adb_to_usb, 128);
+ } else {
+ wskbd_set_evtrans(sc->sc_wskbddev, NULL, 0);
+ }
+ return 0;
+ }
+ return EINVAL;
+ } else {
+ node.sysctl_data = ®
+ node.sysctl_size = sizeof(reg);
+ return (sysctl_lookup(SYSCTLFN_CALL(&node)));
+ }
+}
+
+static void
+adbkbd_setup_sysctl(struct adbkbd_softc *sc)
+{
+ const struct sysctlnode *me, *node;
+ int ret;
+
+ DPRINTF("%s: sysctl setup\n", device_xname(sc->sc_dev));
+ ret = sysctl_createv(NULL, 0, NULL, &me,
+ CTLFLAG_READWRITE,
+ CTLTYPE_NODE, device_xname(sc->sc_dev), NULL,
+ NULL, 0, NULL, 0,
+ CTL_MACHDEP, CTL_CREATE, CTL_EOL);
+ ret = sysctl_createv(NULL, 0, NULL,
+ (void *)&node,
+ CTLFLAG_READWRITE | CTLFLAG_OWNDESC,
+ CTLTYPE_BOOL, "emulate_usb", "USB keyboard emulation",
+ adbkbd_sysctl_usb, 1, (void *)sc, 0, CTL_MACHDEP,
+ me->sysctl_num, CTL_CREATE, CTL_EOL);
+#if NWSMOUSE > 0
+ if (sc->sc_wsmousedev != NULL) {
+ ret = sysctl_createv(NULL, 0, NULL,
+ (void *)&node,
+ CTLFLAG_READWRITE | CTLFLAG_OWNDESC,
+ CTLTYPE_INT, "middle", "middle mouse button",
+ adbkbd_sysctl_mid, 1, (void *)sc, 0, CTL_MACHDEP,
+ me->sysctl_num, CTL_CREATE, CTL_EOL);
+
+ ret = sysctl_createv(NULL, 0, NULL,
+ (void *)&node,
+ CTLFLAG_READWRITE | CTLFLAG_OWNDESC,
+ CTLTYPE_INT, "right", "right mouse button",
+ adbkbd_sysctl_right, 2, (void *)sc, 0, CTL_MACHDEP,
+ me->sysctl_num, CTL_CREATE, CTL_EOL);
+ }
+#endif /* NWSMOUSE > 0 */
+}
+
SYSCTL_SETUP(sysctl_adbkbdtrans_setup, "adbkbd translator setup")
{
@@ -763,4 +813,3 @@
NULL, 0, NULL, 0,
CTL_MACHDEP, CTL_EOL);
}
-#endif /* NWSMOUSE > 0 */
diff -r 4d1b0b12bc0a -r 254144811eaf sys/dev/adb/adb_keymap.h
--- a/sys/dev/adb/adb_keymap.h Wed Aug 29 02:38:31 2012 +0000
+++ b/sys/dev/adb/adb_keymap.h Wed Aug 29 02:44:07 2012 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: adb_keymap.h,v 1.3 2008/04/28 20:23:47 martin Exp $ */
+/* $NetBSD: adb_keymap.h,v 1.4 2012/08/29 02:44:07 macallan Exp $ */
/*-
* Copyright (c) 1997 The NetBSD Foundation, Inc.
@@ -421,3 +421,4 @@
#undef KBD_MAP
#undef KC
+extern keysym_t adb_to_usb[];
diff -r 4d1b0b12bc0a -r 254144811eaf sys/dev/adb/adb_usb_map.c
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/dev/adb/adb_usb_map.c Wed Aug 29 02:44:07 2012 +0000
@@ -0,0 +1,166 @@
+/* $NetBSD: adb_usb_map.c,v 1.1 2012/08/29 02:44:07 macallan Exp $ */
+
+/*-
+ * Copyright (c) 2006 Michael Lorenz
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <sys/cdefs.h>
+__KERNEL_RCSID(0, "$NetBSD: adb_usb_map.c,v 1.1 2012/08/29 02:44:07 macallan Exp $");
+
+#include <sys/param.h>
+#include <sys/device.h>
+
+#include <dev/wscons/wsksymvar.h>
+
+keysym_t adb_to_usb[] = {
+/* 0, KS_a */ 4,
+/* 1, KS_s */ 22,
+/* 2, KS_d */ 7,
+/* 3, KS_f */ 9,
+/* 4, KS_h */ 11,
+/* 5, KS_g */ 10,
+/* 6, KS_z */ 29,
+/* 7, KS_x */ 27,
+/* 8, KS_c */ 6,
+/* 9, KS_v */ 25,
+/* 10, KS_paragraph */ 53,
+/* 11, KS_b */ 5,
+/* 12, KS_q */ 20,
+/* 13, KS_w */ 26,
+/* 14, KS_e */ 8,
+/* 15, KS_r */ 21,
+/* 16, KS_y */ 28,
+/* 17, KS_t */ 23,
+/* 18, KS_1 */ 30,
+/* 19, KS_2 */ 31,
+/* 20, KS_3 */ 32,
+/* 21, KS_4 */ 33,
+/* 22, KS_6 */ 35,
+/* 23, KS_5 */ 34,
+/* 24, KS_equal */ 46,
+/* 25, KS_9 */ 38,
+/* 26, KS_7 */ 36,
+/* 27, KS_minus */ 45,
+/* 28, KS_8 */ 37,
+/* 29, KS_0 */ 39,
+/* 30, KS_bracketright */ 48,
+/* 31, KS_o */ 18,
+/* 32, KS_u */ 24,
+/* 33, KS_bracketleft */ 47,
+/* 34, KS_i */ 12,
+/* 35, KS_p */ 19,
+/* 36, KS_Return */ 40,
+/* 37, KS_l */ 15,
+/* 38, KS_j */ 13,
+/* 39, KS_apostrophe */ 52,
+/* 40, KS_k */ 14,
+/* 41, KS_semicolon */ 51,
+/* 42, KS_backslash */ 50,
+/* 43, KS_comma */ 54,
+/* 44, KS_slash */ 56,
+/* 45, KS_n */ 17,
+/* 46, KS_m */ 16,
+/* 47, KS_period */ 55,
+/* 48, KS_Tab */ 43,
+/* 49, KS_space */ 44,
+/* 50, KS_grave */ 53,
+/* 51, KS_Delete */ 42,
+/* 52, KS_KP_Enter */ 88,
+/* 53, KS_Escape */ 41,
+/* 54, KS_Control_L */ 224,
+/* 55, KS_Cmd */ 227, /* left meta */
+/* 56, KS_Shift_L */ 225,
+/* 57, KS_Caps_Lock */ 57,
+/* 58, KS_Option */ 226,
+/* 59, KS_Left */ 80,
Home |
Main Index |
Thread Index |
Old Index