tech-kern archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[PATCH] ISO abd JIS for ADB (Was: two keys with same keycode on ADB)
Here is my proposed patch to proprely handle ISO and JIS keyboard
layouts for ADB.
Wee change sysctl machdep.adbkbdX.emulate_usb from boolean to int:
0: no emulation (like with false previously)
1: ANSI emulation (like with true previously)
2: ISO emulation
3: JIS emulation
The value is automatically set from keyboard handler id but can
be modified afterwards.
I have been able to test ISO, but input would be welcome from
someone that has access from a japanese keyboard.
I am also a bit puzzled that in our historical code, ANSI ADB
scancode 42, which is supposed to be backslash (the key is between
backspace and return), is converted into USB scancode 50, which
is non US hash. I did not change it, but here again, input from
someone that has access to that keyboard would help.
--
Emmanuel Dreyfus
manu%netbsd.org@localhost
Index: sys/dev/adb/adb_kbd.c
===================================================================
RCS file: /cvsroot/src/sys/dev/adb/adb_kbd.c,v
retrieving revision 1.32
diff -U4 -r1.32 adb_kbd.c
--- sys/dev/adb/adb_kbd.c 7 Aug 2021 16:19:09 -0000 1.32
+++ sys/dev/adb/adb_kbd.c 13 May 2022 01:10:05 -0000
@@ -92,9 +92,9 @@
uint32_t sc_timestamp;
#ifdef WSDISPLAY_COMPAT_RAWKBD
int sc_rawkbd;
#endif
- bool sc_emul_usb;
+ int sc_emul_usb;
bool sc_power_dbg;
uint32_t sc_power;
uint8_t sc_buffer[16];
@@ -234,9 +234,9 @@
* needs it
*/
sc->sc_power = 0xffff;
sc->sc_timestamp = 0;
- sc->sc_emul_usb = FALSE;
+ sc->sc_emul_usb = ADB_EMUL_USB_NONE;
#ifdef ADBKBD_POWER_DDB
sc->sc_power_dbg = TRUE;
#else
sc->sc_power_dbg = FALSE;
@@ -385,10 +385,56 @@
sc->sc_wskbddev = config_found(self, &a, wskbddevprint,
CFARGS(.iattr = "wskbddev"));
#ifdef ADBKBD_EMUL_USB
- sc->sc_emul_usb = TRUE;
- wskbd_set_evtrans(sc->sc_wskbddev, adb_to_usb, 128);
+ /* Values from Linux's drivers/macintosh/adbhud.c */
+ switch (sc->sc_adbdev->handler_id) {
+ case ADB_ISOKBD: /* FALLTHROUGH */
+ case ADB_EXTISOKBD: /* FALLTHROUGH */
+ case 0x07: /* FALLTHROUGH */
+ case ADB_ISOKBDII: /* FALLTHROUGH */
+ case ADB_PBISOKBD: /* FALLTHROUGH */
+ case ADB_ADJISOKBD: /* FALLTHROUGH */
+ case ADB_PBEXTISOKBD: /* FALLTHROUGH */
+ case 0x19: /* FALLTHROUGH */
+ case 0x1d: /* FALLTHROUGH */
+ case 0xc1: /* FALLTHROUGH */
+ case ADB_IBOOKKBD: /* FALLTHROUGH */
+ case 0xc7:
+ sc->sc_emul_usb = ADB_EMUL_USB_ISO;
+ wskbd_set_evtrans(sc->sc_wskbddev, adb_to_usb_iso, 128);
+ break;
+ case ADB_ADJJAPKBD: /* FALLTHROUGH */
+ case ADB_PBEXTJAPKBD: /* FALLTHROUGH */
+ case ADB_JPKBDII: /* FALLTHROUGH */
+ case 0x17: /* FALLTHROUGH */
+ case 0x1a: /* FALLTHROUGH */
+ case ADB_PBJPKBD: /* FALLTHROUGH */
+ case 0xc2: /* FALLTHROUGH */
+ case 0xc5: /* FALLTHROUGH */
+ case 0xc8: /* FALLTHROUGH */
+ case 0xc9:
+ sc->sc_emul_usb = ADB_EMUL_USB_JIS;
+ wskbd_set_evtrans(sc->sc_wskbddev, adb_to_usb_jis, 128);
+ break;
+ case ADB_STDKBD: /* FALLTHROUGH */
+ case ADB_EXTKBD: /* FALLTHROUGH */
+ case 0x03: /* FALLTHROUGH */
+ case 0x06: /* FALLTHROUGH */
+ case ADB_KBDII: /* FALLTHROUGH */
+ case ADB_PBKBD: /* FALLTHROUGH */
+ case ADB_ADJKBD: /* FALLTHROUGH */
+ case ADB_PBEXTKBD: /* FALLTHROUGH */
+ case ADB_DESIGNKBD: /* FALLTHROUGH */
+ case 0x1c: /* FALLTHROUGH */
+ case 0xc0: /* FALLTHROUGH */
+ case ADB_PBG3KBD: /* FALLTHROUGH */
+ case 0xc6: /* FALLTHROUGH */
+ default: /* default to ANSI for unknown values */
+ sc->sc_emul_usb = ADB_EMUL_USB_ANSI;
+ wskbd_set_evtrans(sc->sc_wskbddev, adb_to_usb_ansi, 128);
+ break;
+ }
#endif /* ADBKBD_EMUL_USB */
#if NWSMOUSE > 0
/* attach the mouse device */
@@ -632,9 +678,9 @@
switch (cmd) {
case WSKBDIO_GTYPE:
- if (sc->sc_emul_usb) {
+ if (sc->sc_emul_usb != ADB_EMUL_USB_NONE) {
*(int *)data = WSKBD_TYPE_USB;
} else {
*(int *)data = WSKBD_TYPE_ADB;
}
@@ -797,23 +843,37 @@
{
struct sysctlnode node = *rnode;
struct adbkbd_softc *sc=(struct adbkbd_softc *)node.sysctl_data;
const int *np = newp;
- bool reg;
+ int 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 {
+ sc->sc_emul_usb = *(int *)node.sysctl_data;
+ switch (sc->sc_emul_usb) {
+ case ADB_EMUL_USB_NONE:
wskbd_set_evtrans(sc->sc_wskbddev, NULL, 0);
+ break;
+ case ADB_EMUL_USB_ANSI:
+ wskbd_set_evtrans(sc->sc_wskbddev,
+ adb_to_usb_ansi, 128);
+ break;
+ case ADB_EMUL_USB_ISO:
+ wskbd_set_evtrans(sc->sc_wskbddev,
+ adb_to_usb_iso, 128);
+ break;
+ case ADB_EMUL_USB_JIS:
+ wskbd_set_evtrans(sc->sc_wskbddev,
+ adb_to_usb_jis, 128);
+ break;
+ default:
+ return EINVAL;
+ break;
}
return 0;
}
return EINVAL;
@@ -864,9 +924,9 @@
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",
+ CTLTYPE_INT, "emulate_usb", "USB keyboard emulation",
adbkbd_sysctl_usb, 1, (void *)sc, 0, CTL_MACHDEP,
me->sysctl_num, CTL_CREATE, CTL_EOL);
ret = sysctl_createv(NULL, 0, NULL,
(void *)&node,
Index: sys/dev/adb/adb_keymap.h
===================================================================
RCS file: /cvsroot/src/sys/dev/adb/adb_keymap.h,v
retrieving revision 1.9
diff -U4 -r1.9 adb_keymap.h
--- sys/dev/adb/adb_keymap.h 6 Apr 2022 17:14:42 -0000 1.9
+++ sys/dev/adb/adb_keymap.h 13 May 2022 01:10:05 -0000
@@ -491,5 +491,12 @@
#undef KBD_MAP
#undef KC
-extern keysym_t adb_to_usb[];
+#define ADB_EMUL_USB_NONE 0
+#define ADB_EMUL_USB_ANSI 1
+#define ADB_EMUL_USB_ISO 2
+#define ADB_EMUL_USB_JIS 3
+
+extern keysym_t adb_to_usb_ansi[];
+extern keysym_t adb_to_usb_iso[];
+extern keysym_t adb_to_usb_jis[];
Index: sys/dev/adb/adb_usb_map.c
===================================================================
RCS file: /cvsroot/src/sys/dev/adb/adb_usb_map.c,v
retrieving revision 1.2
diff -U4 -r1.2 adb_usb_map.c
--- sys/dev/adb/adb_usb_map.c 8 Nov 2014 16:52:35 -0000 1.2
+++ sys/dev/adb/adb_usb_map.c 13 May 2022 01:10:05 -0000
@@ -33,9 +33,29 @@
#include <sys/device.h>
#include <dev/wscons/wsksymvar.h>
-keysym_t adb_to_usb[] = {
+/*
+ * Explanation of the differences between ANSI, ISO and JIS:
+ * https://github.com/tmk/tmk_keyboard/blob/master/converter/adb_usb/matrix.c
+ * Summary:
+ * ADB scan code USB usage
+ * ANSI ISO JIS ANSI ISO JIS
+ * 50 10 50 GRAVE/53 GRAVE/53 GRAVE/53
+ * ---- 50 ---- ---- NUBS/100 ----
+ * 42 112 42 BSLS/49 NUHS/50 NUHS/50
+ * ---- ---- 93 ---- ---- JPY/137
+ * ---- ---- 94 ---- ---- RO/135
+ *
+ * With:
+ * NUBS = Non-US Backslash
+ * NUHS = Non-US Hash
+ * BSLS = Backslash
+ * JPY = Japaneese Yen
+ * RO = ?
+ */
+
+keysym_t adb_to_usb_ansi[] = {
/* 0, KS_a */ 4,
/* 1, KS_s */ 22,
/* 2, KS_d */ 7,
/* 3, KS_f */ 9,
@@ -163,4 +183,267 @@
/* 125, KS_Control_R */ 228,
/* 126 */ 0,
/* 127, KS_Cmd_Debugger */ 102
};
+
+keysym_t adb_to_usb_iso[] = {
+/* 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 */ 100,
+/* 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,
+/* 60, KS_Right */ 79,
+/* 61, KS_Down */ 81,
+/* 62, KS_Up */ 82,
+/* 63 */ 0,
+/* 64 */ 0,
+/* 65, KS_KP_Decimal */ 99,
+/* 66 */ 0,
+/* 67, KS_KP_Multiply */ 85,
+/* 68 */ 0,
+/* 69, KS_KP_Add */ 87,
+/* 70 */ 0,
+/* 71, KS_Num_Lock */ 83,
+/* 72 */ 0,
+/* 73 */ 0,
+/* 74 */ 0,
+/* 75, KS_KP_Divide */ 84,
+/* 76, KS_KP_Enter */ 88,
+/* 77 */ 0,
+/* 78, KS_KP_Subtract */ 86,
+/* 79 */ 0,
+/* 80 */ 0,
+/* 81, KS_KP_Equal */ 46, /* no KP_EQUAL on USB? */
+/* 82, KS_KP_Insert, 0 */ 98,
+/* 83, KS_KP_End, 1 */ 89,
+/* 84, KS_KP_Down, 2 */ 90,
+/* 85, KS_KP_Next, 3 */ 91,
+/* 86, KS_KP_Left, 4 */ 92,
+/* 87, KS_KP_Begin 5 */ 93,
+/* 88, KS_KP_Right 6 */ 94,
+/* 89, KS_KP_Home 7 */ 95,
+/* 90 */ 0,
+/* 91, KS_KP_Up 8 */ 96,
+/* 92, KS_KP_Prior 9 */ 97,
+/* 93, KS_backslash */ 100,
+/* 94, KS_underscore */ 45,
+/* 95, KS_KP_Delete . */ 99,
+/* 96, KS_f5 */ 62,
+/* 97, KS_f6 */ 63,
+/* 98, KS_f7 */ 64,
+/* 99, KS_f3 */ 60,
+/* 100, KS_f8 */ 65,
+/* 101, KS_f9 */ 66,
+/* 102 */ 0,
+/* 103, KS_f11 */ 68,
+/* 104 */ 0,
+/* 105, KS_Print_Screen */ 70,
+/* 106, KS_KP_Enter */ 88,
+/* 107, KS_Hold_Screen */ 71,
+/* 108 */ 0,
+/* 109, KS_f10 */ 67,
+/* 110 */ 0,
+/* 111, KS_f12 */ 69,
+/* 112 */ 0,
+/* 113, KS_Pause */ 72,
+/* 114, KS_Insert */ 73,
+/* 115, KS_Home */ 74,
+/* 116, KS_Prior */ 75,
+/* 117, KS_BackSpace */ 76,
+/* 118, KS_f4 */ 61,
+/* 119, KS_End */ 77,
+/* 120, KS_f2 */ 59,
+/* 121, KS_Next */ 78,
+/* 122, KS_f1 */ 58,
+/* 123, KS_Shift_R */ 229,
+/* 124, KS_Alt_R */ 230,
+/* 125, KS_Control_R */ 228,
+/* 126 */ 0,
+/* 127, KS_Cmd_Debugger */ 102
+};
+
+keysym_t adb_to_usb_jis[] = { /* XXX not updated from ansi yet */
+/* 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,
+/* 60, KS_Right */ 79,
+/* 61, KS_Down */ 81,
+/* 62, KS_Up */ 82,
+/* 63 */ 0,
+/* 64 */ 0,
+/* 65, KS_KP_Decimal */ 99,
+/* 66 */ 0,
+/* 67, KS_KP_Multiply */ 85,
+/* 68 */ 0,
+/* 69, KS_KP_Add */ 87,
+/* 70 */ 0,
+/* 71, KS_Num_Lock */ 83,
+/* 72 */ 0,
+/* 73 */ 0,
+/* 74 */ 0,
+/* 75, KS_KP_Divide */ 84,
+/* 76, KS_KP_Enter */ 88,
+/* 77 */ 0,
+/* 78, KS_KP_Subtract */ 86,
+/* 79 */ 0,
+/* 80 */ 0,
+/* 81, KS_KP_Equal */ 46, /* no KP_EQUAL on USB? */
+/* 82, KS_KP_Insert, 0 */ 98,
+/* 83, KS_KP_End, 1 */ 89,
+/* 84, KS_KP_Down, 2 */ 90,
+/* 85, KS_KP_Next, 3 */ 91,
+/* 86, KS_KP_Left, 4 */ 92,
+/* 87, KS_KP_Begin 5 */ 93,
+/* 88, KS_KP_Right 6 */ 94,
+/* 89, KS_KP_Home 7 */ 95,
+/* 90 */ 0,
+/* 91, KS_KP_Up 8 */ 96,
+/* 92, KS_KP_Prior 9 */ 97,
+/* 93, KS_backslash */ 137, /* JPY */
+/* 94, KS_underscore */ 135, /* RO */
+/* 95, KS_KP_Delete . */ 99,
+/* 96, KS_f5 */ 62,
+/* 97, KS_f6 */ 63,
+/* 98, KS_f7 */ 64,
+/* 99, KS_f3 */ 60,
+/* 100, KS_f8 */ 65,
+/* 101, KS_f9 */ 66,
+/* 102 */ 0,
+/* 103, KS_f11 */ 68,
+/* 104 */ 0,
+/* 105, KS_Print_Screen */ 70,
+/* 106, KS_KP_Enter */ 88,
+/* 107, KS_Hold_Screen */ 71,
+/* 108 */ 0,
+/* 109, KS_f10 */ 67,
+/* 110 */ 0,
+/* 111, KS_f12 */ 69,
+/* 112 */ 0,
+/* 113, KS_Pause */ 72,
+/* 114, KS_Insert */ 73,
+/* 115, KS_Home */ 74,
+/* 116, KS_Prior */ 75,
+/* 117, KS_BackSpace */ 76,
+/* 118, KS_f4 */ 61,
+/* 119, KS_End */ 77,
+/* 120, KS_f2 */ 59,
+/* 121, KS_Next */ 78,
+/* 122, KS_f1 */ 58,
+/* 123, KS_Shift_R */ 229,
+/* 124, KS_Alt_R */ 230,
+/* 125, KS_Control_R */ 228,
+/* 126 */ 0,
+/* 127, KS_Cmd_Debugger */ 102
+};
+
Home |
Main Index |
Thread Index |
Old Index