notro / fbtft_tools

27 stars 17 forks source link

Raspberry PI 2/3 pullup support #11

Closed whitty closed 7 years ago

whitty commented 7 years ago

Verified with raspberry-pi 3 with PiTFT GPIO buttons:

sudo insmod gpio_keys_device.ko  keys=22:108,27:105,17:106,23:103  pullup=1 active_low=1

Lovingly ripped from rpi_power_switch

notro commented 7 years ago

This will stop working when we switch to Linux 4.9 in a month or so. Only CONFIG_ARCH_BCM2835 will be defined for Pi1, 2 and 3. Which one is determined at runtime.

I suggest you use a device tree overlay instead. Something like this:

/dts-v1/;
/plugin/;

/ {
    compatible = "brcm,bcm2835";

    fragment@0 {
        target = <&gpio>;
        __overlay__ {
            keypad_pins: keypad_pins {
                brcm,pins = <4 17 22 23 27>;
                brcm,function = <0>; /* in */
                brcm,pull = <1>; /* down */
            };
        };
    };

    /*
     * Values for input event code is found under the
     * 'Keys and buttons' heading in include/uapi/linux/input.h
     */
    fragment@1 {
        target-path = "/soc";
        __overlay__ {
            keypad: keypad {
                compatible = "gpio-keys";
                #address-cells = <1>;
                #size-cells = <0>;
                pinctrl-names = "default";
                pinctrl-0 = <&keypad_pins>;
                autorepeat;

                button@17 {
                    label = "GPIO KEY_UP";
                    linux,code = <103>;
                    gpios = <&gpio 17 0>;
                };
                button@22 {
                    label = "GPIO KEY_DOWN";
                    linux,code = <108>;
                    gpios = <&gpio 22 0>;
                };
                button@27 {
                    label = "GPIO KEY_LEFT";
                    linux,code = <105>;
                    gpios = <&gpio 27 0>;
                };
                button@23 {
                    label = "GPIO KEY_RIGHT";
                    linux,code = <106>;
                    gpios = <&gpio 23 0>;
                };
                button@4 {
                    label = "GPIO KEY_ENTER";
                    linux,code = <28>;
                    gpios = <&gpio 4 0>;
                };
            };
        };
    };
};

Example is taken from: https://github.com/raspberrypi/linux/blob/rpi-4.9.y/arch/arm/boot/dts/overlays/tinylcd35-overlay.dts

Howto: