Adding buttons on the Linkit Smart

Here’s what I found out while trying to add buttons to the OpenWrt based Linkit Smart.

The flow is:

  • Keys are defined in target/linux/ramips/dts/LINKIT7688.dts

    • gpio-button-hotplug emulates gpio-keys-polled and generates uevents.

      • The uevent is received onver netlink by procd in plug/hotplug.c

        • The event is dispatched via /etc/hotplug.json

          • The standard dispatch rule calls /etc/rc.buttons/$BUTTON

          The DTS fragment is:

          gpio-keys-polled {
          ...
          btn2 {
              label = "btn2";
              gpios = <&gpio0 2 1>;
              linux,code = <0x102>;
          };
          

          where the <&#038;gpio0 2 1> picks the second pin from the zeroth port i.e. GPIO 2 and

          maps it to BTN_2. See uapi/linux/input.h for the other key codes.

          gpio-button-hotplug supports a limited number of keys. See the source for the

          current list, which is BTN_0 to BTN_9, power, reset, rfkill, wps, and wwan.

          Also, the LinkIt uses a binary wifi driver which seems to be very sensitive to

          the kernel version. I ended up reverting 363508bcabd8e9205f5fffc8ff282439e61d618f

          to bring OpenWrt back to 3.18.21 to stop it crashing when the interface comes up.

Avatar
Michael Hope
Software Engineer