Hi,

the diff below makes the brightness keys work on apple powerbooks > 5,6
where the keyboard attaches via ukbd(4).
I'm wondering if it would be better to go through wskbd as is done with
audio, but we don't have keycodes allocated for brightness up/down.

Thoughts? ok?

Index: ukbd.c
===================================================================
RCS file: /cvs/src/sys/dev/usb/ukbd.c,v
retrieving revision 1.79
diff -u -p -r1.79 ukbd.c
--- ukbd.c      23 Aug 2020 11:08:02 -0000      1.79
+++ ukbd.c      26 Oct 2020 23:10:05 -0000
@@ -71,6 +71,7 @@
 #include <dev/usb/ukbdvar.h>
 
 #include <dev/wscons/wsconsio.h>
+#include <dev/wscons/wsdisplayvar.h>
 #include <dev/wscons/wskbdvar.h>
 #include <dev/wscons/wsksymdef.h>
 #include <dev/wscons/wsksymvar.h>
@@ -86,6 +87,10 @@ int  ukbddebug = 0;
 #define DPRINTFN(n,x)
 #endif
 
+#define UKBD_PARAM             (1 << 15)
+#define UKBD_BRIGHTNESS_UP     0x1
+#define UKBD_BRIGHTNESS_DOWN   0x2
+
 const kbd_t ukbd_countrylayout[1 + HCC_MAX] = {
        (kbd_t)-1,
        (kbd_t)-1,      /* arabic */
@@ -159,6 +164,7 @@ void        ukbd_db_enter(void *);
 int    ukbd_enable(void *, int);
 void   ukbd_set_leds(void *, int);
 int    ukbd_ioctl(void *, u_long, caddr_t, int, struct proc *);
+void   ukbd_set_display_param(int);
 
 const struct wskbd_accessops ukbd_accessops = {
        ukbd_enable,
@@ -180,7 +186,7 @@ const struct cfattach ukbd_ca = {
 
 struct ukbd_translation {
        uint8_t original;
-       uint8_t translation;
+       uint16_t translation;
 };
 
 #ifdef __loongson__
@@ -192,7 +198,7 @@ void        ukbd_apple_iso_munge(void *, uint8_
 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);
+uint16_t       ukbd_translate(const struct ukbd_translation *, size_t, 
uint8_t);
 
 int
 ukbd_match(struct device *parent, void *match, void *aux)
@@ -511,7 +517,7 @@ ukbd_cnattach(void)
        return (0);
 }
 
-uint8_t
+uint16_t
 ukbd_translate(const struct ukbd_translation *table, size_t tsize,
     uint8_t keycode)
 {
@@ -527,13 +533,19 @@ ukbd_apple_translate(void *vsc, uint8_t 
 {
        struct ukbd_softc *sc = vsc;
        struct hidkbd *kbd = &sc->sc_kbd;
-       uint8_t *pos, *spos, *epos, xlat;
+       uint8_t *pos, *spos, *epos;
+       uint16_t 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 & UKBD_PARAM) {
+                       ukbd_set_display_param(xlat & ~UKBD_PARAM);
+                       *pos = 0;
+                       return;
+               }
                if (xlat != 0)
                        *pos = xlat;
        }
@@ -548,8 +560,6 @@ ukbd_apple_munge(void *vsc, uint8_t *ibu
                { 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 */
@@ -559,6 +569,8 @@ ukbd_apple_munge(void *vsc, uint8_t *ibu
                { 66, 0 },      /* F9 -> audio next */
 #endif
 #ifdef __macppc__
+               { 58, UKBD_PARAM | UKBD_BRIGHTNESS_DOWN },      /* F1 -> screen 
brightness down */
+               { 59, UKBD_PARAM | UKBD_BRIGHTNESS_UP  },       /* F2 -> screen 
brightness up */
                { 60, 127 },    /* F3 -> audio mute */
                { 61, 129 },    /* F4 -> audio lower */
                { 62, 128 },    /* F5 -> audio raise */
@@ -641,6 +653,21 @@ ukbd_apple_iso_mba_munge(void *vsc, uint
        ukbd_apple_translate(vsc, ibuf, ilen, apple_iso_trans,
            nitems(apple_iso_trans));
        ukbd_apple_mba_munge(vsc, ibuf, ilen);
+}
+
+void
+ukbd_set_display_param(int num)
+{
+       switch(num) {
+       case UKBD_BRIGHTNESS_UP:
+               wsdisplay_brightness_step(NULL, 1);
+               break;
+       case UKBD_BRIGHTNESS_DOWN:
+               wsdisplay_brightness_step(NULL, -1);
+               break;
+       default:
+               break;
+       }
 }
 
 #ifdef __loongson__

Reply via email to