[PATCH] ukbd.c cleanup and mba iso support

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

[PATCH] ukbd.c cleanup and mba iso support

William Orr-2
Hey,

This implements some of Alexey's comments as well as munging the grave key for
macbook airs. Tested on a mba with a WELLSPRING ANSI keyboard.

Thanks,
William Orr

Index: sys/dev/usb/ukbd.c
===================================================================
RCS file: /cvs/src/sys/dev/usb/ukbd.c,v
retrieving revision 1.70
diff -u -b -w -p -r1.70 ukbd.c
--- sys/dev/usb/ukbd.c 19 Jan 2015 20:16:10 -0000 1.70
+++ sys/dev/usb/ukbd.c 4 Feb 2015 05:18:47 -0000
@@ -182,6 +182,11 @@ void ukbd_gdium_munge(void *, uint8_t *,
 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
@@ -244,14 +249,16 @@ ukbd_attach(struct device *parent, struc
  case USB_PRODUCT_APPLE_GEYSER_ISO:
  sc->sc_munge = ukbd_apple_iso_munge;
  break;
- case USB_PRODUCT_APPLE_WELLSPRING4A_ANSI:
  case USB_PRODUCT_APPLE_WELLSPRING4A_ISO:
+ case USB_PRODUCT_APPLE_WELLSPRING4_ISO:
+ case USB_PRODUCT_APPLE_WELLSPRING_ISO:
+ sc->sc_munge = ukbd_apple_iso_mba_munge;
+ break;
+ case USB_PRODUCT_APPLE_WELLSPRING4A_ANSI:
  case USB_PRODUCT_APPLE_WELLSPRING4A_JIS:
  case USB_PRODUCT_APPLE_WELLSPRING4_ANSI:
- case USB_PRODUCT_APPLE_WELLSPRING4_ISO:
  case USB_PRODUCT_APPLE_WELLSPRING4_JIS:
  case USB_PRODUCT_APPLE_WELLSPRING_ANSI:
- case USB_PRODUCT_APPLE_WELLSPRING_ISO:
  case USB_PRODUCT_APPLE_WELLSPRING_JIS:
  sc->sc_munge = ukbd_apple_mba_munge;
  break;
@@ -461,12 +468,28 @@ ukbd_translate(const struct ukbd_transla
 }
 
 void
-ukbd_apple_munge(void *vsc, uint8_t *ibuf, u_int ilen)
+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 */
@@ -499,23 +522,14 @@ ukbd_apple_munge(void *vsc, uint8_t *ibu
  if (!hid_get_data(ibuf, ilen, &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;
- }
+ 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;
- struct hidkbd *kbd = &sc->sc_kbd;
- uint8_t *pos, *spos, *epos, xlat;
 
  static const struct ukbd_translation apple_fn_trans[] = {
  { 40, 73 }, /* return -> insert */
@@ -545,40 +559,34 @@ ukbd_apple_mba_munge(void *vsc, uint8_t
  if (!hid_get_data(ibuf, ilen, &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;
- }
+ 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)
 {
- struct ukbd_softc *sc = vsc;
- struct hidkbd *kbd = &sc->sc_kbd;
- uint8_t *pos, *spos, *epos, xlat;
-
  static const struct ukbd_translation apple_iso_trans[] = {
  { 53, 100 }, /* less -> grave */
  { 100, 53 },
  };
 
- spos = ibuf + kbd->sc_keycodeloc.pos / 8;
- epos = spos + kbd->sc_nkeycode;
-
- for (pos = spos; pos != epos; pos++) {
- xlat = ukbd_translate(apple_iso_trans,
-    nitems(apple_iso_trans), *pos);
- if (xlat != 0)
- *pos = xlat;
+ ukbd_apple_translate(vsc, ibuf, ilen, apple_iso_trans,
+                     nitems(apple_iso_trans));
+ ukbd_apple_munge(vsc, ibuf, ilen);
  }
 
- 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__

Reply | Threaded
Open this post in threaded view
|

Re: [PATCH] ukbd.c cleanup and mba iso support

William Orr-2
Hey,

Any interest?

Thanks,
William Orr

On 2/4/15 9:37 AM, William Orr wrote:

> Hey,
>
> This implements some of Alexey's comments as well as munging the grave key for
> macbook airs. Tested on a mba with a WELLSPRING ANSI keyboard.
>
> Thanks,
> William Orr
>
> Index: sys/dev/usb/ukbd.c
> ===================================================================
> RCS file: /cvs/src/sys/dev/usb/ukbd.c,v
> retrieving revision 1.70
> diff -u -b -w -p -r1.70 ukbd.c
> --- sys/dev/usb/ukbd.c 19 Jan 2015 20:16:10 -0000 1.70
> +++ sys/dev/usb/ukbd.c 4 Feb 2015 05:18:47 -0000
> @@ -182,6 +182,11 @@ void ukbd_gdium_munge(void *, uint8_t *,
>  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
> @@ -244,14 +249,16 @@ ukbd_attach(struct device *parent, struc
>   case USB_PRODUCT_APPLE_GEYSER_ISO:
>   sc->sc_munge = ukbd_apple_iso_munge;
>   break;
> - case USB_PRODUCT_APPLE_WELLSPRING4A_ANSI:
>   case USB_PRODUCT_APPLE_WELLSPRING4A_ISO:
> + case USB_PRODUCT_APPLE_WELLSPRING4_ISO:
> + case USB_PRODUCT_APPLE_WELLSPRING_ISO:
> + sc->sc_munge = ukbd_apple_iso_mba_munge;
> + break;
> + case USB_PRODUCT_APPLE_WELLSPRING4A_ANSI:
>   case USB_PRODUCT_APPLE_WELLSPRING4A_JIS:
>   case USB_PRODUCT_APPLE_WELLSPRING4_ANSI:
> - case USB_PRODUCT_APPLE_WELLSPRING4_ISO:
>   case USB_PRODUCT_APPLE_WELLSPRING4_JIS:
>   case USB_PRODUCT_APPLE_WELLSPRING_ANSI:
> - case USB_PRODUCT_APPLE_WELLSPRING_ISO:
>   case USB_PRODUCT_APPLE_WELLSPRING_JIS:
>   sc->sc_munge = ukbd_apple_mba_munge;
>   break;
> @@ -461,12 +468,28 @@ ukbd_translate(const struct ukbd_transla
>  }
>  
>  void
> -ukbd_apple_munge(void *vsc, uint8_t *ibuf, u_int ilen)
> +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 */
> @@ -499,23 +522,14 @@ ukbd_apple_munge(void *vsc, uint8_t *ibu
>   if (!hid_get_data(ibuf, ilen, &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;
> - }
> + 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;
> - struct hidkbd *kbd = &sc->sc_kbd;
> - uint8_t *pos, *spos, *epos, xlat;
>  
>   static const struct ukbd_translation apple_fn_trans[] = {
>   { 40, 73 }, /* return -> insert */
> @@ -545,40 +559,34 @@ ukbd_apple_mba_munge(void *vsc, uint8_t
>   if (!hid_get_data(ibuf, ilen, &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;
> - }
> + 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)
>  {
> - struct ukbd_softc *sc = vsc;
> - struct hidkbd *kbd = &sc->sc_kbd;
> - uint8_t *pos, *spos, *epos, xlat;
> -
>   static const struct ukbd_translation apple_iso_trans[] = {
>   { 53, 100 }, /* less -> grave */
>   { 100, 53 },
>   };
>  
> - spos = ibuf + kbd->sc_keycodeloc.pos / 8;
> - epos = spos + kbd->sc_nkeycode;
> -
> - for (pos = spos; pos != epos; pos++) {
> - xlat = ukbd_translate(apple_iso_trans,
> -    nitems(apple_iso_trans), *pos);
> - if (xlat != 0)
> - *pos = xlat;
> + ukbd_apple_translate(vsc, ibuf, ilen, apple_iso_trans,
> +                     nitems(apple_iso_trans));
> + ukbd_apple_munge(vsc, ibuf, ilen);
>   }
>  
> - 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__
>


signature.asc (836 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: [PATCH] ukbd.c cleanup and mba iso support

Joerg Jung
On Wed, Feb 18, 2015 at 10:33:57PM -0800, William Orr wrote:
> Hey,
>
> Any interest?

I'm interested in this. Your diff looks reasonable, so I applied it and
it compiled fine, but the less and grave keys are still wrong exchanged
on my MacBookAir4,2. Looks like usbdevs says I have a
USB_PRODUCT_APPLE_WELLSPRING6_ISO:

   port 2 addr 7: full speed, power 40 mA, config 1, Apple Internal
      Keyboard / Trackpad(0x024d), Apple Inc.(0x05ac), rev 2.09  

So I guess some more case's are required in the diff below?
 

> Thanks,
> William Orr
>
> On 2/4/15 9:37 AM, William Orr wrote:
> > Hey,
> >
> > This implements some of Alexey's comments as well as munging the grave key for
> > macbook airs. Tested on a mba with a WELLSPRING ANSI keyboard.
> >
> > Thanks,
> > William Orr
> >
> > Index: sys/dev/usb/ukbd.c
> > ===================================================================
> > RCS file: /cvs/src/sys/dev/usb/ukbd.c,v
> > retrieving revision 1.70
> > diff -u -b -w -p -r1.70 ukbd.c
> > --- sys/dev/usb/ukbd.c 19 Jan 2015 20:16:10 -0000 1.70
> > +++ sys/dev/usb/ukbd.c 4 Feb 2015 05:18:47 -0000
> > @@ -182,6 +182,11 @@ void ukbd_gdium_munge(void *, uint8_t *,
> >  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
> > @@ -244,14 +249,16 @@ ukbd_attach(struct device *parent, struc
> >   case USB_PRODUCT_APPLE_GEYSER_ISO:
> >   sc->sc_munge = ukbd_apple_iso_munge;
> >   break;
> > - case USB_PRODUCT_APPLE_WELLSPRING4A_ANSI:
> >   case USB_PRODUCT_APPLE_WELLSPRING4A_ISO:
> > + case USB_PRODUCT_APPLE_WELLSPRING4_ISO:
> > + case USB_PRODUCT_APPLE_WELLSPRING_ISO:
> > + sc->sc_munge = ukbd_apple_iso_mba_munge;
> > + break;
> > + case USB_PRODUCT_APPLE_WELLSPRING4A_ANSI:
> >   case USB_PRODUCT_APPLE_WELLSPRING4A_JIS:
> >   case USB_PRODUCT_APPLE_WELLSPRING4_ANSI:
> > - case USB_PRODUCT_APPLE_WELLSPRING4_ISO:
> >   case USB_PRODUCT_APPLE_WELLSPRING4_JIS:
> >   case USB_PRODUCT_APPLE_WELLSPRING_ANSI:
> > - case USB_PRODUCT_APPLE_WELLSPRING_ISO:
> >   case USB_PRODUCT_APPLE_WELLSPRING_JIS:
> >   sc->sc_munge = ukbd_apple_mba_munge;
> >   break;
> > @@ -461,12 +468,28 @@ ukbd_translate(const struct ukbd_transla
> >  }
> >  
> >  void
> > -ukbd_apple_munge(void *vsc, uint8_t *ibuf, u_int ilen)
> > +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 */
> > @@ -499,23 +522,14 @@ ukbd_apple_munge(void *vsc, uint8_t *ibu
> >   if (!hid_get_data(ibuf, ilen, &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;
> > - }
> > + 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;
> > - struct hidkbd *kbd = &sc->sc_kbd;
> > - uint8_t *pos, *spos, *epos, xlat;
> >  
> >   static const struct ukbd_translation apple_fn_trans[] = {
> >   { 40, 73 }, /* return -> insert */
> > @@ -545,40 +559,34 @@ ukbd_apple_mba_munge(void *vsc, uint8_t
> >   if (!hid_get_data(ibuf, ilen, &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;
> > - }
> > + 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)
> >  {
> > - struct ukbd_softc *sc = vsc;
> > - struct hidkbd *kbd = &sc->sc_kbd;
> > - uint8_t *pos, *spos, *epos, xlat;
> > -
> >   static const struct ukbd_translation apple_iso_trans[] = {
> >   { 53, 100 }, /* less -> grave */
> >   { 100, 53 },
> >   };
> >  
> > - spos = ibuf + kbd->sc_keycodeloc.pos / 8;
> > - epos = spos + kbd->sc_nkeycode;
> > -
> > - for (pos = spos; pos != epos; pos++) {
> > - xlat = ukbd_translate(apple_iso_trans,
> > -    nitems(apple_iso_trans), *pos);
> > - if (xlat != 0)
> > - *pos = xlat;
> > + ukbd_apple_translate(vsc, ibuf, ilen, apple_iso_trans,
> > +                     nitems(apple_iso_trans));
> > + ukbd_apple_munge(vsc, ibuf, ilen);
> >   }
> >  
> > - 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__
> >
>



Reply | Threaded
Open this post in threaded view
|

Re: [PATCH] ukbd.c cleanup and mba iso support

Joerg Jung
Hi,

...back on this topic.

On Thu, Aug 06, 2015 at 09:58:56PM +0200, Joerg Jung wrote:

> On Wed, Feb 18, 2015 at 10:33:57PM -0800, William Orr wrote:
> >
> > Any interest?
>
> I'm interested in this. Your diff looks reasonable, so I applied it and
> it compiled fine, but the less and grave keys are still wrong exchanged
> on my MacBookAir4,2. Looks like usbdevs says I have a
> USB_PRODUCT_APPLE_WELLSPRING6_ISO:
>
>    port 2 addr 7: full speed, power 40 mA, config 1, Apple Internal
>       Keyboard / Trackpad(0x024d), Apple Inc.(0x05ac), rev 2.09  
>
> So I guess some more case's are required in the diff below?
>  
> > On 2/4/15 9:37 AM, William Orr wrote:
> > >
> > > This implements some of Alexey's comments as well as munging the grave key for
> > > macbook airs. Tested on a mba with a WELLSPRING ANSI keyboard.

Please find below an updated diff which also includes a case for the ISO
keyboard found in my older MacbookAir4,2.

This newer diff also includes some minor KNF and whitespace cleanup.

I would really like to commit this, as this fixes a real bug (exchanged
grave/less key). So no longer fiddling with xmodmap required.

OK, anyone?

Thanks,
Regards,
Joerg


Index: sys/dev/usb/ukbd.c
===================================================================
RCS file: /cvs/src/sys/dev/usb/ukbd.c,v
retrieving revision 1.71
diff -u -p -r1.71 ukbd.c
--- sys/dev/usb/ukbd.c 14 Mar 2015 03:38:50 -0000 1.71
+++ sys/dev/usb/ukbd.c 8 Dec 2015 20:39:31 -0000
@@ -158,13 +158,13 @@ const struct wskbd_accessops ukbd_access
  ukbd_ioctl,
 };
 
-int ukbd_match(struct device *, void *, void *);
-void ukbd_attach(struct device *, struct device *, void *);
-int ukbd_detach(struct device *, int);
-
-struct cfdriver ukbd_cd = {
- NULL, "ukbd", DV_DULL
-};
+int ukbd_match(struct device *, void *, void *);
+void ukbd_attach(struct device *, struct device *, void *);
+int ukbd_detach(struct device *, int);
+
+struct cfdriver ukbd_cd = {
+ NULL, "ukbd", DV_DULL
+};
 
 const struct cfattach ukbd_ca = {
  sizeof(struct ukbd_softc), ukbd_match, ukbd_attach, ukbd_detach
@@ -181,6 +181,9 @@ void ukbd_gdium_munge(void *, uint8_t *,
 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
@@ -243,14 +246,17 @@ ukbd_attach(struct device *parent, struc
  case USB_PRODUCT_APPLE_GEYSER_ISO:
  sc->sc_munge = ukbd_apple_iso_munge;
  break;
- case USB_PRODUCT_APPLE_WELLSPRING4A_ANSI:
+ case USB_PRODUCT_APPLE_WELLSPRING6_ISO:
  case USB_PRODUCT_APPLE_WELLSPRING4A_ISO:
+ case USB_PRODUCT_APPLE_WELLSPRING4_ISO:
+ case USB_PRODUCT_APPLE_WELLSPRING_ISO:
+ sc->sc_munge = ukbd_apple_iso_mba_munge;
+ break;
+ case USB_PRODUCT_APPLE_WELLSPRING4A_ANSI:
  case USB_PRODUCT_APPLE_WELLSPRING4A_JIS:
  case USB_PRODUCT_APPLE_WELLSPRING4_ANSI:
- case USB_PRODUCT_APPLE_WELLSPRING4_ISO:
  case USB_PRODUCT_APPLE_WELLSPRING4_JIS:
  case USB_PRODUCT_APPLE_WELLSPRING_ANSI:
- case USB_PRODUCT_APPLE_WELLSPRING_ISO:
  case USB_PRODUCT_APPLE_WELLSPRING_JIS:
  sc->sc_munge = ukbd_apple_mba_munge;
  break;
@@ -431,15 +437,14 @@ ukbd_cnpollc(void *v, int on)
 }
 
 void
-ukbd_cnbell(void *v, u_int pitch, u_int period, u_int volume)
+ukbd_cnbell(void *v, u_int pitch, u_int period, u_int volume)
 {
  hidkbd_bell(pitch, period, volume, 1);
-}
+}
 
 int
 ukbd_cnattach(void)
 {
-
  /*
  * XXX USB requires too many parts of the kernel to be running
  * XXX in order to work, so we can't do much for the console
@@ -460,12 +465,28 @@ ukbd_translate(const struct ukbd_transla
 }
 
 void
-ukbd_apple_munge(void *vsc, uint8_t *ibuf, u_int ilen)
+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 */
@@ -498,23 +519,14 @@ ukbd_apple_munge(void *vsc, uint8_t *ibu
  if (!hid_get_data(ibuf, ilen, &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;
- }
+ 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;
- struct hidkbd *kbd = &sc->sc_kbd;
- uint8_t *pos, *spos, *epos, xlat;
 
  static const struct ukbd_translation apple_fn_trans[] = {
  { 40, 73 }, /* return -> insert */
@@ -544,40 +556,34 @@ ukbd_apple_mba_munge(void *vsc, uint8_t
  if (!hid_get_data(ibuf, ilen, &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;
- }
+ 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)
 {
- struct ukbd_softc *sc = vsc;
- struct hidkbd *kbd = &sc->sc_kbd;
- uint8_t *pos, *spos, *epos, xlat;
-
  static const struct ukbd_translation apple_iso_trans[] = {
  { 53, 100 }, /* less -> grave */
  { 100, 53 },
  };
 
- spos = ibuf + kbd->sc_keycodeloc.pos / 8;
- epos = spos + kbd->sc_nkeycode;
+ ukbd_apple_translate(vsc, ibuf, ilen, apple_iso_trans,
+    nitems(apple_iso_trans));
+ ukbd_apple_munge(vsc, ibuf, ilen);
+}
 
- for (pos = spos; pos != epos; pos++) {
- xlat = ukbd_translate(apple_iso_trans,
-    nitems(apple_iso_trans), *pos);
- if (xlat != 0)
- *pos = xlat;
- }
+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_munge(vsc, ibuf, ilen);
+ ukbd_apple_translate(vsc, ibuf, ilen, apple_iso_trans,
+    nitems(apple_iso_trans));
+ ukbd_apple_mba_munge(vsc, ibuf, ilen);
 }
 
 #ifdef __loongson__

Reply | Threaded
Open this post in threaded view
|

Re: [PATCH] ukbd.c cleanup and mba iso support

Joerg Jung
On Tue, Dec 08, 2015 at 10:12:38PM +0100, Joerg Jung wrote:

> On Thu, Aug 06, 2015 at 09:58:56PM +0200, Joerg Jung wrote:
> > On Wed, Feb 18, 2015 at 10:33:57PM -0800, William Orr wrote:
> > >
> > > Any interest?
> >
> > I'm interested in this. Your diff looks reasonable, so I applied it and
> > it compiled fine, but the less and grave keys are still wrong exchanged
> > on my MacBookAir4,2. Looks like usbdevs says I have a
> > USB_PRODUCT_APPLE_WELLSPRING6_ISO:
> >
> >    port 2 addr 7: full speed, power 40 mA, config 1, Apple Internal
> >       Keyboard / Trackpad(0x024d), Apple Inc.(0x05ac), rev 2.09  
> >
> > So I guess some more case's are required in the diff below?
> >  
> > > On 2/4/15 9:37 AM, William Orr wrote:
> > > >
> > > > This implements some of Alexey's comments as well as munging the grave key for
> > > > macbook airs. Tested on a mba with a WELLSPRING ANSI keyboard.
>
> Please find below an updated diff which also includes a case for the ISO
> keyboard found in my older MacbookAir4,2.
>
> This newer diff also includes some minor KNF and whitespace cleanup.
>
> I would really like to commit this, as this fixes a real bug (exchanged
> grave/less key). So no longer fiddling with xmodmap required.

Slightly updated diff below, sorting the switch cases in the same order
as found in usbdevs.
 
OK, anyone?


Index: sys/dev/usb/ukbd.c
===================================================================
RCS file: /cvs/src/sys/dev/usb/ukbd.c,v
retrieving revision 1.71
diff -u -p -r1.71 ukbd.c
--- sys/dev/usb/ukbd.c 14 Mar 2015 03:38:50 -0000 1.71
+++ sys/dev/usb/ukbd.c 8 Dec 2015 22:40:12 -0000
@@ -158,13 +158,13 @@ const struct wskbd_accessops ukbd_access
  ukbd_ioctl,
 };
 
-int ukbd_match(struct device *, void *, void *);
-void ukbd_attach(struct device *, struct device *, void *);
-int ukbd_detach(struct device *, int);
-
-struct cfdriver ukbd_cd = {
- NULL, "ukbd", DV_DULL
-};
+int ukbd_match(struct device *, void *, void *);
+void ukbd_attach(struct device *, struct device *, void *);
+int ukbd_detach(struct device *, int);
+
+struct cfdriver ukbd_cd = {
+ NULL, "ukbd", DV_DULL
+};
 
 const struct cfattach ukbd_ca = {
  sizeof(struct ukbd_softc), ukbd_match, ukbd_attach, ukbd_detach
@@ -181,6 +181,9 @@ void ukbd_gdium_munge(void *, uint8_t *,
 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
@@ -241,17 +244,20 @@ ukbd_attach(struct device *parent, struc
  switch (uha->uaa->product) {
  case USB_PRODUCT_APPLE_FOUNTAIN_ISO:
  case USB_PRODUCT_APPLE_GEYSER_ISO:
+ case USB_PRODUCT_APPLE_WELLSPRING6_ISO:
  sc->sc_munge = ukbd_apple_iso_munge;
  break;
- case USB_PRODUCT_APPLE_WELLSPRING4A_ANSI:
- case USB_PRODUCT_APPLE_WELLSPRING4A_ISO:
- case USB_PRODUCT_APPLE_WELLSPRING4A_JIS:
- case USB_PRODUCT_APPLE_WELLSPRING4_ANSI:
+ case USB_PRODUCT_APPLE_WELLSPRING_ISO:
  case USB_PRODUCT_APPLE_WELLSPRING4_ISO:
- case USB_PRODUCT_APPLE_WELLSPRING4_JIS:
+ case USB_PRODUCT_APPLE_WELLSPRING4A_ISO:
+ sc->sc_munge = ukbd_apple_iso_mba_munge;
+ break;
  case USB_PRODUCT_APPLE_WELLSPRING_ANSI:
- case USB_PRODUCT_APPLE_WELLSPRING_ISO:
  case USB_PRODUCT_APPLE_WELLSPRING_JIS:
+ case USB_PRODUCT_APPLE_WELLSPRING4_ANSI:
+ 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;
  break;
  default:
@@ -431,15 +437,14 @@ ukbd_cnpollc(void *v, int on)
 }
 
 void
-ukbd_cnbell(void *v, u_int pitch, u_int period, u_int volume)
+ukbd_cnbell(void *v, u_int pitch, u_int period, u_int volume)
 {
  hidkbd_bell(pitch, period, volume, 1);
-}
+}
 
 int
 ukbd_cnattach(void)
 {
-
  /*
  * XXX USB requires too many parts of the kernel to be running
  * XXX in order to work, so we can't do much for the console
@@ -460,12 +465,28 @@ ukbd_translate(const struct ukbd_transla
 }
 
 void
-ukbd_apple_munge(void *vsc, uint8_t *ibuf, u_int ilen)
+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 */
@@ -498,23 +519,14 @@ ukbd_apple_munge(void *vsc, uint8_t *ibu
  if (!hid_get_data(ibuf, ilen, &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;
- }
+ 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;
- struct hidkbd *kbd = &sc->sc_kbd;
- uint8_t *pos, *spos, *epos, xlat;
 
  static const struct ukbd_translation apple_fn_trans[] = {
  { 40, 73 }, /* return -> insert */
@@ -544,40 +556,34 @@ ukbd_apple_mba_munge(void *vsc, uint8_t
  if (!hid_get_data(ibuf, ilen, &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;
- }
+ 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)
 {
- struct ukbd_softc *sc = vsc;
- struct hidkbd *kbd = &sc->sc_kbd;
- uint8_t *pos, *spos, *epos, xlat;
-
  static const struct ukbd_translation apple_iso_trans[] = {
  { 53, 100 }, /* less -> grave */
  { 100, 53 },
  };
 
- spos = ibuf + kbd->sc_keycodeloc.pos / 8;
- epos = spos + kbd->sc_nkeycode;
+ ukbd_apple_translate(vsc, ibuf, ilen, apple_iso_trans,
+    nitems(apple_iso_trans));
+ ukbd_apple_munge(vsc, ibuf, ilen);
+}
 
- for (pos = spos; pos != epos; pos++) {
- xlat = ukbd_translate(apple_iso_trans,
-    nitems(apple_iso_trans), *pos);
- if (xlat != 0)
- *pos = xlat;
- }
+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_munge(vsc, ibuf, ilen);
+ ukbd_apple_translate(vsc, ibuf, ilen, apple_iso_trans,
+    nitems(apple_iso_trans));
+ ukbd_apple_mba_munge(vsc, ibuf, ilen);
 }
 
 #ifdef __loongson__