summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMartin Pieuchot <mpi@cvs.openbsd.org>2011-12-04 15:09:36 +0000
committerMartin Pieuchot <mpi@cvs.openbsd.org>2011-12-04 15:09:36 +0000
commit18c69ef820ce62c51b9abe064d2504dd8e12a3f7 (patch)
tree1f13e7da44805069c64a8bbd16916f6bff56fecd
parent941756471e3d04f78a6ab2965cfdd430f28cbe9f (diff)
Add support for Apple fn keys
based on a diff from jcs@, ok miod@
-rw-r--r--sys/dev/usb/ukbd.c63
-rw-r--r--sys/dev/usb/usbhid.h4
2 files changed, 65 insertions, 2 deletions
diff --git a/sys/dev/usb/ukbd.c b/sys/dev/usb/ukbd.c
index 1fffac497bb..f99b8246411 100644
--- a/sys/dev/usb/ukbd.c
+++ b/sys/dev/usb/ukbd.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: ukbd.c,v 1.55 2011/07/03 15:47:17 matthew Exp $ */
+/* $OpenBSD: ukbd.c,v 1.56 2011/12/04 15:09:35 mpi Exp $ */
/* $NetBSD: ukbd.c,v 1.85 2003/03/11 16:44:00 augustss Exp $ */
/*
@@ -132,6 +132,8 @@ struct ukbd_softc {
u_char sc_dying;
+ struct hid_location sc_apple_fn;
+
void (*sc_munge)(void *, uint8_t *, u_int);
};
@@ -182,6 +184,7 @@ struct ukbd_translation {
#ifdef __loongson__
void ukbd_gdium_munge(void *, uint8_t *, u_int);
#endif
+void ukbd_apple_munge(void *, uint8_t *, u_int);
uint8_t ukbd_translate(const struct ukbd_translation *, size_t, uint8_t);
int
@@ -227,6 +230,14 @@ ukbd_attach(struct device *parent, struct device *self, void *aux)
if (hidkbd_attach(self, kbd, 1, qflags, repid, desc, dlen) != 0)
return;
+ if (uha->uaa->vendor == USB_VENDOR_APPLE) {
+ if (hid_locate(desc, dlen, HID_USAGE2(HUP_APPLE, HUG_FN_KEY),
+ uha->reportid, hid_input, &sc->sc_apple_fn, &qflags)) {
+ if (qflags & HIO_VARIABLE)
+ sc->sc_munge = ukbd_apple_munge;
+ }
+ }
+
if (uha->uaa->vendor == USB_VENDOR_TOPRE &&
uha->uaa->product == USB_PRODUCT_TOPRE_HHKB) {
/* ignore country code on purpose */
@@ -439,6 +450,56 @@ ukbd_translate(const struct ukbd_translation *table, size_t tsize,
return 0;
}
+void
+ukbd_apple_munge(void *vsc, uint8_t *ibuf, u_int ilen)
+{
+ struct ukbd_softc *sc = vsc;
+ struct hidkbd *kbd = &sc->sc_kbd;
+ uint8_t *pos, *spos, *epos, xlat;
+
+ static const struct ukbd_translation apple_fn_trans[] = {
+ { 40, 73 }, /* return -> insert */
+ { 42, 76 }, /* backspace -> delete */
+#ifdef notyet
+ { 58, 0 }, /* F1 -> screen brightness down */
+ { 59, 0 }, /* F2 -> screen brightness up */
+ { 60, 0 }, /* F3 */
+ { 61, 0 }, /* F4 */
+ { 62, 0 }, /* F5 -> keyboard backlight down */
+ { 63, 0 }, /* F6 -> keyboard backlight up */
+ { 64, 0 }, /* F7 -> audio back */
+ { 65, 0 }, /* F8 -> audio pause/play */
+ { 66, 0 }, /* F9 -> audio next */
+#endif
+#ifdef __macppc__
+ { 60, 127 }, /* F3 -> audio mute */
+ { 61, 129 }, /* F4 -> audio lower */
+ { 62, 128 }, /* F5 -> audio raise */
+#else
+ { 67, 127 }, /* F10 -> audio mute */
+ { 68, 129 }, /* F11 -> audio lower */
+ { 69, 128 }, /* F12 -> audio raise */
+#endif
+ { 79, 77 }, /* right -> end */
+ { 80, 74 }, /* left -> home */
+ { 81, 78 }, /* down -> page down */
+ { 82, 75 } /* up -> page up */
+ };
+
+ if (!hid_get_data(ibuf, &sc->sc_apple_fn))
+ return;
+
+ spos = ibuf + kbd->sc_keycodeloc.pos / 8;
+ epos = spos + kbd->sc_nkeycode;
+
+ for (pos = spos; pos != epos; pos++) {
+ xlat = ukbd_translate(apple_fn_trans,
+ nitems(apple_fn_trans), *pos);
+ if (xlat != 0)
+ *pos = xlat;
+ }
+}
+
#ifdef __loongson__
/*
* Software Fn- translation for Gdium Liberty keyboard.
diff --git a/sys/dev/usb/usbhid.h b/sys/dev/usb/usbhid.h
index 8866e141d9a..af05a2c9ee6 100644
--- a/sys/dev/usb/usbhid.h
+++ b/sys/dev/usb/usbhid.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: usbhid.h,v 1.13 2009/12/09 21:27:19 matthieu Exp $ */
+/* $OpenBSD: usbhid.h,v 1.14 2011/12/04 15:09:35 mpi Exp $ */
/* $NetBSD: usbhid.h,v 1.11 2001/12/28 00:20:24 augustss Exp $ */
/* $FreeBSD: src/sys/dev/usb/usbhid.h,v 1.7 1999/11/17 22:33:51 n_hibma Exp $ */
@@ -88,11 +88,13 @@ typedef struct usb_hid_descriptor {
#define HUP_SCALE 0x008c
#define HUP_CAMERA_CONTROL 0x0090
#define HUP_ARCADE 0x0091
+#define HUP_APPLE 0x00ff
#define HUP_MICROSOFT 0xff00
/* Usages, generic desktop */
#define HUG_POINTER 0x0001
#define HUG_MOUSE 0x0002
+#define HUG_FN_KEY 0x0003
#define HUG_JOYSTICK 0x0004
#define HUG_GAME_PAD 0x0005
#define HUG_KEYBOARD 0x0006