On 14/09/22 17:21 +0200, Tobias Heider wrote: > On Wed, Sep 14, 2022 at 11:56:48AM +0000, Miod Vallat wrote: > > > Hey, > > > > > > the diff below adds FN key combos for Page Up, Page Down and some more > > > on the M2 keyboard. Most of the logic was copied from ukbd. > > > > This means most of the munging logic should move from ukbd into hidkbd, > > but that can be done later. > > Right, that was also my idea. For now I'd be happy to have them working > at all.
I've also had a look because I wanted this on the M1 macbook as well and decided to move things out to hidkbd as miod suggested. Works fine for me. Index: arch/arm64/dev/apldc.c =================================================================== RCS file: /cvs/src/sys/arch/arm64/dev/apldc.c,v retrieving revision 1.3 diff -u -p -u -r1.3 apldc.c --- arch/arm64/dev/apldc.c 15 Sep 2022 14:45:49 -0000 1.3 +++ arch/arm64/dev/apldc.c 16 Sep 2022 11:58:41 -0000 @@ -37,6 +37,7 @@ #include <dev/hid/hid.h> #include <dev/hid/hidkbdsc.h> +#include <dev/hid/hidkbdtrans.h> #include <dev/hid/hidmsvar.h> #include <arm64/dev/rtkit.h> @@ -1066,22 +1067,6 @@ struct apldckbd_softc { struct apldchidev_softc *sc_hidev; struct hidkbd sc_kbd; int sc_spl; - struct hid_location sc_fn; - int sc_has_fn; -}; - -struct apldckbd_translation { - uint8_t original; - uint8_t translation; -}; - -static const struct apldckbd_translation apldckbd_trans_table[] = { - { 40, 73 }, /* return -> insert */ - { 42, 76 }, /* backspace -> delete */ - { 79, 77 }, /* right -> end */ - { 80, 74 }, /* left -> home */ - { 81, 78 }, /* down -> page down */ - { 82, 75 } /* up -> page up */ }; void apldckbd_cngetc(void *, u_int *, int *); @@ -1138,8 +1123,9 @@ apldckbd_attach(struct device *parent, s printf("\n"); - sc->sc_has_fn = hid_locate(aa->aa_desc, aa->aa_desclen, - HID_USAGE2(HUP_APPLE, HUG_FN_KEY), 1, hid_input, &sc->sc_fn, NULL); + if (hid_locate(aa->aa_desc, aa->aa_desclen, HID_USAGE2(HUP_APPLE, HUG_FN_KEY), + 1, hid_input, &kbd->sc_fn, NULL)) + kbd->sc_munge = hidkbd_apple_munge; if (kbd->sc_console_keyboard) { extern struct wskbd_mapdata ukbd_keymapdata; @@ -1153,40 +1139,13 @@ apldckbd_attach(struct device *parent, s } void -apldckbd_munge(void *v, uint8_t *ibuf, size_t ilen) -{ - struct apldckbd_softc *sc = v; - struct hidkbd *kbd = &sc->sc_kbd; - uint8_t *pos, *spos, *epos; - const struct apldckbd_translation *tbl; - size_t tsize; - - if (!hid_get_data(ibuf, ilen, &sc->sc_fn)) - return; - - spos = ibuf + kbd->sc_keycodeloc.pos / 8; - epos = spos + kbd->sc_nkeycode; - - for (pos = spos; pos != epos; pos++) { - tbl = apldckbd_trans_table; - tsize = nitems(apldckbd_trans_table); - for (; tsize != 0; tbl++, tsize--) - if (tbl->original == *pos) - *pos = tbl->translation; - } -} - -void apldckbd_intr(struct device *self, uint8_t *packet, size_t packetlen) { struct apldckbd_softc *sc = (struct apldckbd_softc *)self; struct hidkbd *kbd = &sc->sc_kbd; - if (kbd->sc_enabled) { - if (sc->sc_has_fn) - apldckbd_munge(sc, &packet[1], packetlen - 1); + if (kbd->sc_enabled) hidkbd_input(kbd, &packet[1], packetlen - 1); - } } int Index: arch/arm64/dev/aplhidev.c =================================================================== RCS file: /cvs/src/sys/arch/arm64/dev/aplhidev.c,v retrieving revision 1.6 diff -u -p -u -r1.6 aplhidev.c --- arch/arm64/dev/aplhidev.c 6 Apr 2022 18:59:26 -0000 1.6 +++ arch/arm64/dev/aplhidev.c 16 Sep 2022 11:58:41 -0000 @@ -40,6 +40,7 @@ #include <dev/hid/hid.h> #include <dev/hid/hidkbdsc.h> +#include <dev/hid/hidkbdtrans.h> #include <dev/hid/hidmsvar.h> #include "aplhidev.h" @@ -458,6 +459,10 @@ aplkbd_attach(struct device *parent, str return; printf("\n"); + + if (hid_locate(aa->aa_desc, aa->aa_desclen, HID_USAGE2(HUP_APPLE, HUG_FN_KEY), + 1, hid_input, &kbd->sc_fn, NULL)) + kbd->sc_munge = hidkbd_apple_munge; if (kbd->sc_console_keyboard) { extern struct wskbd_mapdata ukbd_keymapdata; Index: dev/hid/hidkbd.c =================================================================== RCS file: /cvs/src/sys/dev/hid/hidkbd.c,v retrieving revision 1.6 diff -u -p -u -r1.6 hidkbd.c --- dev/hid/hidkbd.c 2 Nov 2020 19:45:18 -0000 1.6 +++ dev/hid/hidkbd.c 16 Sep 2022 11:58:42 -0000 @@ -50,6 +50,7 @@ #include <dev/hid/hid.h> #include <dev/hid/hidkbdsc.h> +#include <dev/hid/hidkbdtrans.h> #ifdef HIDKBD_DEBUG #define DPRINTF(x) do { if (hidkbddebug) printf x; } while (0) @@ -236,11 +237,119 @@ hidkbd_detach(struct hidkbd *kbd, int fl return (rv); } +uint8_t +hidkbd_translate(const struct hidkbd_translation *table, size_t tsize, + uint8_t keycode) +{ + for (; tsize != 0; table++, tsize--) + if (table->original == keycode) + return table->translation; + return 0; +} + +void +hidkbd_apple_translate(void *vsc, uint8_t *ibuf, u_int ilen, + const struct hidkbd_translation* trans, u_int tlen) +{ + struct hidkbd *kbd = vsc; + uint8_t *pos, *spos, *epos, xlat; + + spos = ibuf + kbd->sc_keycodeloc.pos / 8; + epos = spos + kbd->sc_nkeycode; + + for (pos = spos; pos != epos; pos++) { + xlat = hidkbd_translate(trans, tlen, *pos); + if (xlat != 0) + *pos = xlat; + } +} + +void +hidkbd_apple_munge(void *vsc, uint8_t *ibuf, u_int ilen) +{ + struct hidkbd *kbd = vsc; + + if (!hid_get_data(ibuf, ilen, &kbd->sc_fn)) + return; + + hidkbd_apple_translate(vsc, ibuf, ilen, apple_fn_trans, + nitems(apple_fn_trans)); +} + +void +hidkbd_apple_iso_munge(void *vsc, uint8_t *ibuf, u_int ilen) +{ + hidkbd_apple_translate(vsc, ibuf, ilen, apple_iso_trans, + nitems(apple_iso_trans)); +} + +void +hidkbd_apple_mba_munge(void *vsc, uint8_t *ibuf, u_int ilen) +{ + struct hidkbd *kbd = vsc; + + if (!hid_get_data(ibuf, ilen, &kbd->sc_fn)) + return; + + hidkbd_apple_translate(vsc, ibuf, ilen, apple_mba_trans, + nitems(apple_mba_trans)); +} + +void +hidkbd_apple_iso_mba_munge(void *vsc, uint8_t *ibuf, u_int ilen) +{ + hidkbd_apple_translate(vsc, ibuf, ilen, apple_iso_mba_trans, + nitems(apple_iso_mba_trans)); +} + +#ifdef __loongson__ +#define GDIUM_FN_CODE 0x82 +void +hidkbd_gdium_munge(void *vsc, uint8_t *ibuf, u_int ilen) +{ + struct hidkbd *kbd = vsc; + uint8_t *pos, *spos, *epos, xlat; + int fn; + + spos = ibuf + kbd->sc_keycodeloc.pos / 8; + epos = spos + kbd->sc_nkeycode; + + /* + * Check for Fn key being down and remove it from the report. + */ + + fn = 0; + for (pos = spos; pos != epos; pos++) + if (*pos == GDIUM_FN_CODE) { + fn = 1; + *pos = 0; + break; + } + + /* + * Rewrite keycodes on the fly to perform Fn-key translation. + * Keycodes without a translation are passed unaffected. + */ + + if (fn != 0) + for (pos = spos; pos != epos; pos++) { + xlat = hidkbd_translate(gdium_fn_trans, + nitems(gdium_fn_trans), *pos); + if (xlat != 0) + *pos = xlat; + } + +} +#endif + void hidkbd_input(struct hidkbd *kbd, uint8_t *data, u_int len) { struct hidkbd_data *ud = &kbd->sc_ndata; int i; + + if (kbd->sc_munge != NULL) + (*kbd->sc_munge)(kbd, (uint8_t *)data, len); #ifdef HIDKBD_DEBUG if (hidkbddebug > 5) { Index: dev/hid/hidkbdsc.h =================================================================== RCS file: /cvs/src/sys/dev/hid/hidkbdsc.h,v retrieving revision 1.1 diff -u -p -u -r1.1 hidkbdsc.h --- dev/hid/hidkbdsc.h 8 Jan 2016 15:54:13 -0000 1.1 +++ dev/hid/hidkbdsc.h 16 Sep 2022 11:58:42 -0000 @@ -67,6 +67,7 @@ struct hidkbd { struct hid_location sc_capsloc; struct hid_location sc_scroloc; struct hid_location sc_compose; + struct hid_location sc_fn; int sc_leds; /* state information */ @@ -88,6 +89,13 @@ struct hidkbd { int sc_polling; int sc_npollchar; u_int16_t sc_pollchars[MAXKEYS]; + + void (*sc_munge)(void *, uint8_t *, u_int); +}; + +struct hidkbd_translation { + uint8_t original; + uint8_t translation; }; int hidkbd_attach(struct device *, struct hidkbd *, int, uint32_t, @@ -98,6 +106,7 @@ void hidkbd_bell(u_int, u_int, u_int, in void hidkbd_cngetc(struct hidkbd *, u_int *, int *); int hidkbd_detach(struct hidkbd *, int); int hidkbd_enable(struct hidkbd *, int); +void hidkbd_munge(void *, uint8_t *, u_int); void hidkbd_input(struct hidkbd *, uint8_t *, u_int); int hidkbd_ioctl(struct hidkbd *, u_long, caddr_t, int, struct proc *); int hidkbd_set_leds(struct hidkbd *, int, uint8_t *); Index: dev/hid/hidkbdtrans.h =================================================================== RCS file: dev/hid/hidkbdtrans.h diff -N dev/hid/hidkbdtrans.h --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ dev/hid/hidkbdtrans.h 16 Sep 2022 11:58:42 -0000 @@ -0,0 +1,123 @@ +/* $OpenBSD$ */ +/* + * Copyright (c) 2022 Robert Nagy <rob...@openbsd.org> + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +static const struct hidkbd_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__ + { 58, 233 }, /* F1 -> screen brightness down */ + { 59, 232 }, /* F2 -> screen brightness up */ + { 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 */ +}; + +static const struct hidkbd_translation apple_mba_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 */ + { 63, 0 }, /* F6 -> audio back */ + { 64, 0 }, /* F7 -> audio pause/play */ + { 65, 0 }, /* F8 -> audio next */ +#endif + { 66, 127 }, /* F9 -> audio mute */ + { 67, 129 }, /* F10 -> audio lower */ + { 68, 128 }, /* F11 -> audio raise */ +#ifdef notyet + { 69, 0 }, /* F12 -> eject */ +#endif + { 79, 77 }, /* right -> end */ + { 80, 74 }, /* left -> home */ + { 81, 78 }, /* down -> page down */ + { 82, 75 } /* up -> page up */ +}; + +static const struct hidkbd_translation apple_iso_trans[] = { + { 53, 100 }, /* less -> grave */ + { 100, 53 } +}; + +static const struct hidkbd_translation apple_iso_mba_trans[] = { + { 53, 100 }, /* less -> grave */ + { 100, 53 } +}; + +#ifdef __loongson__ +/* + * Software Fn- translation for Gdium Liberty keyboard. + */ +static const struct hidkbd_translation gdium_fn_trans[] = { +#ifdef notyet + { 58, 0 }, /* F1 -> toggle camera */ + { 59, 0 }, /* F2 -> toggle wireless */ +#endif + { 60, 127 }, /* F3 -> audio mute */ + { 61, 128 }, /* F4 -> audio raise */ + { 62, 129 }, /* F5 -> audio lower */ +#ifdef notyet + { 63, 0 }, /* F6 -> toggle ext. video */ + { 64, 0 }, /* F7 -> toggle mouse */ + { 65, 0 }, /* F8 -> brightness up */ + { 66, 0 }, /* F9 -> brightness down */ + { 67, 0 }, /* F10 -> suspend */ + { 68, 0 }, /* F11 -> user1 */ + { 69, 0 }, /* F12 -> user2 */ + { 70, 0 }, /* print screen -> sysrq */ +#endif + { 76, 71 }, /* delete -> scroll lock */ + { 81, 78 }, /* down -> page down */ + { 82, 75 } /* up -> page up */ +}; +#endif + +uint8_t hidkbd_translate(const struct hidkbd_translation *, size_t, uint8_t); +void hidkbd_apple_translate(void *, uint8_t *, u_int, + const struct hidkbd_translation*, u_int); + +#ifdef __loongson__ +void hidkbd_gdium_munge(void *, uint8_t *, u_int); +#endif + +void hidkbd_apple_munge(void *, uint8_t *, u_int); +void hidkbd_apple_iso_munge(void *, uint8_t *, u_int); +void hidkbd_apple_mba_munge(void *, uint8_t *, u_int); +void hidkbd_apple_iso_mba_munge(void *, uint8_t *, u_int); Index: dev/usb/ukbd.c =================================================================== RCS file: /cvs/src/sys/dev/usb/ukbd.c,v retrieving revision 1.86 diff -u -p -u -r1.86 ukbd.c --- dev/usb/ukbd.c 9 Jan 2022 05:43:00 -0000 1.86 +++ dev/usb/ukbd.c 16 Sep 2022 11:58:42 -0000 @@ -76,6 +76,7 @@ #include <dev/wscons/wsksymvar.h> #include <dev/hid/hidkbdsc.h> +#include <dev/hid/hidkbdtrans.h> #ifdef UKBD_DEBUG #define DPRINTF(x) do { if (ukbddebug) printf x; } while (0) @@ -132,7 +133,6 @@ struct ukbd_softc { struct hidkbd sc_kbd; int sc_spl; struct hid_location sc_apple_fn; - void (*sc_munge)(void *, uint8_t *, u_int); #ifdef DDB struct timeout sc_ddb; /* for entering DDB */ @@ -183,17 +183,6 @@ struct ukbd_translation { uint8_t translation; }; -#ifdef __loongson__ -void ukbd_gdium_munge(void *, uint8_t *, u_int); -#endif -void ukbd_apple_munge(void *, uint8_t *, u_int); -void ukbd_apple_mba_munge(void *, uint8_t *, u_int); -void ukbd_apple_iso_munge(void *, uint8_t *, u_int); -void ukbd_apple_iso_mba_munge(void *, uint8_t *, u_int); -void ukbd_apple_translate(void *, uint8_t *, u_int, - const struct ukbd_translation *, u_int); -uint8_t ukbd_translate(const struct ukbd_translation *, size_t, uint8_t); - int ukbd_match(struct device *parent, void *match, void *aux) { @@ -263,12 +252,12 @@ ukbd_attach(struct device *parent, struc case USB_PRODUCT_APPLE_GEYSER3_ISO: case USB_PRODUCT_APPLE_WELLSPRING6_ISO: case USB_PRODUCT_APPLE_WELLSPRING8_ISO: - sc->sc_munge = ukbd_apple_iso_munge; + kbd->sc_munge = hidkbd_apple_iso_munge; break; case USB_PRODUCT_APPLE_WELLSPRING_ISO: case USB_PRODUCT_APPLE_WELLSPRING4_ISO: case USB_PRODUCT_APPLE_WELLSPRING4A_ISO: - sc->sc_munge = ukbd_apple_iso_mba_munge; + kbd->sc_munge = hidkbd_apple_iso_mba_munge; break; case USB_PRODUCT_APPLE_WELLSPRING_ANSI: case USB_PRODUCT_APPLE_WELLSPRING_JIS: @@ -276,10 +265,10 @@ ukbd_attach(struct device *parent, struc case USB_PRODUCT_APPLE_WELLSPRING4_JIS: case USB_PRODUCT_APPLE_WELLSPRING4A_ANSI: case USB_PRODUCT_APPLE_WELLSPRING4A_JIS: - sc->sc_munge = ukbd_apple_mba_munge; + kbd->sc_munge = hidkbd_apple_mba_munge; break; default: - sc->sc_munge = ukbd_apple_munge; + kbd->sc_munge = hidkbd_apple_munge; break; } } @@ -315,7 +304,7 @@ ukbd_attach(struct device *parent, struc #ifdef __loongson__ if (uha->uaa->vendor == USB_VENDOR_CYPRESS && uha->uaa->product == USB_PRODUCT_CYPRESS_LPRDK) - sc->sc_munge = ukbd_gdium_munge; + sc->sc_munge = hidkbd_gdium_munge; #endif if (kbd->sc_console_keyboard) { @@ -362,11 +351,8 @@ ukbd_intr(struct uhidev *addr, void *ibu struct ukbd_softc *sc = (struct ukbd_softc *)addr; struct hidkbd *kbd = &sc->sc_kbd; - if (kbd->sc_enabled != 0) { - if (sc->sc_munge != NULL) - (*sc->sc_munge)(sc, (uint8_t *)ibuf, len); + if (kbd->sc_enabled != 0) hidkbd_input(kbd, (uint8_t *)ibuf, len); - } } int @@ -514,204 +500,3 @@ ukbd_cnattach(void) return (0); } - -uint8_t -ukbd_translate(const struct ukbd_translation *table, size_t tsize, - uint8_t keycode) -{ - for (; tsize != 0; table++, tsize--) - if (table->original == keycode) - return table->translation; - return 0; -} - -void -ukbd_apple_translate(void *vsc, uint8_t *ibuf, u_int ilen, - const struct ukbd_translation* trans, u_int tlen) -{ - struct ukbd_softc *sc = vsc; - struct hidkbd *kbd = &sc->sc_kbd; - uint8_t *pos, *spos, *epos, xlat; - - spos = ibuf + kbd->sc_keycodeloc.pos / 8; - epos = spos + kbd->sc_nkeycode; - - for (pos = spos; pos != epos; pos++) { - xlat = ukbd_translate(trans, tlen, *pos); - if (xlat != 0) - *pos = xlat; - } -} - -void -ukbd_apple_munge(void *vsc, uint8_t *ibuf, u_int ilen) -{ - struct ukbd_softc *sc = vsc; - - 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__ - { 58, 233 }, /* F1 -> screen brightness down */ - { 59, 232 }, /* F2 -> screen brightness up */ - { 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, ilen, &sc->sc_apple_fn)) - return; - - ukbd_apple_translate(vsc, ibuf, ilen, apple_fn_trans, - nitems(apple_fn_trans)); -} - -void -ukbd_apple_mba_munge(void *vsc, uint8_t *ibuf, u_int ilen) -{ - struct ukbd_softc *sc = vsc; - - 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 */ - { 63, 0 }, /* F6 -> audio back */ - { 64, 0 }, /* F7 -> audio pause/play */ - { 65, 0 }, /* F8 -> audio next */ -#endif - { 66, 127 }, /* F9 -> audio mute */ - { 67, 129 }, /* F10 -> audio lower */ - { 68, 128 }, /* F11 -> audio raise */ -#ifdef notyet - { 69, 0 }, /* F12 -> eject */ -#endif - { 79, 77 }, /* right -> end */ - { 80, 74 }, /* left -> home */ - { 81, 78 }, /* down -> page down */ - { 82, 75 } /* up -> page up */ - }; - - if (!hid_get_data(ibuf, ilen, &sc->sc_apple_fn)) - return; - - ukbd_apple_translate(vsc, ibuf, ilen, apple_fn_trans, - nitems(apple_fn_trans)); -} - -void -ukbd_apple_iso_munge(void *vsc, uint8_t *ibuf, u_int ilen) -{ - static const struct ukbd_translation apple_iso_trans[] = { - { 53, 100 }, /* less -> grave */ - { 100, 53 }, - }; - - ukbd_apple_translate(vsc, ibuf, ilen, apple_iso_trans, - nitems(apple_iso_trans)); - ukbd_apple_munge(vsc, ibuf, ilen); -} - -void -ukbd_apple_iso_mba_munge(void *vsc, uint8_t *ibuf, u_int ilen) -{ - static const struct ukbd_translation apple_iso_trans[] = { - { 53, 100 }, /* less -> grave */ - { 100, 53 }, - }; - - ukbd_apple_translate(vsc, ibuf, ilen, apple_iso_trans, - nitems(apple_iso_trans)); - ukbd_apple_mba_munge(vsc, ibuf, ilen); -} - -#ifdef __loongson__ -/* - * Software Fn- translation for Gdium Liberty keyboard. - */ -#define GDIUM_FN_CODE 0x82 -void -ukbd_gdium_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; - int fn; - - static const struct ukbd_translation gdium_fn_trans[] = { -#ifdef notyet - { 58, 0 }, /* F1 -> toggle camera */ - { 59, 0 }, /* F2 -> toggle wireless */ -#endif - { 60, 127 }, /* F3 -> audio mute */ - { 61, 128 }, /* F4 -> audio raise */ - { 62, 129 }, /* F5 -> audio lower */ -#ifdef notyet - { 63, 0 }, /* F6 -> toggle ext. video */ - { 64, 0 }, /* F7 -> toggle mouse */ - { 65, 0 }, /* F8 -> brightness up */ - { 66, 0 }, /* F9 -> brightness down */ - { 67, 0 }, /* F10 -> suspend */ - { 68, 0 }, /* F11 -> user1 */ - { 69, 0 }, /* F12 -> user2 */ - { 70, 0 }, /* print screen -> sysrq */ -#endif - { 76, 71 }, /* delete -> scroll lock */ - { 81, 78 }, /* down -> page down */ - { 82, 75 } /* up -> page up */ - }; - - spos = ibuf + kbd->sc_keycodeloc.pos / 8; - epos = spos + kbd->sc_nkeycode; - - /* - * Check for Fn key being down and remove it from the report. - */ - - fn = 0; - for (pos = spos; pos != epos; pos++) - if (*pos == GDIUM_FN_CODE) { - fn = 1; - *pos = 0; - break; - } - - /* - * Rewrite keycodes on the fly to perform Fn-key translation. - * Keycodes without a translation are passed unaffected. - */ - - if (fn != 0) - for (pos = spos; pos != epos; pos++) { - xlat = ukbd_translate(gdium_fn_trans, - nitems(gdium_fn_trans), *pos); - if (xlat != 0) - *pos = xlat; - } - -} -#endif