I am trying to use a gpio-keys interrupt to wake up the screen after it goes to sleep. I am using Raspberry Pi 3 and Lineage OS 14.1. I have been able to successfully configure the gpio-keys where it registers input device events upon receiving an interrupt. However, I cannot get it to wake up the screen when it goes off. My device tree overlay file for my gpio-keys device is below:
/dts-v1/;
/plugin/;
/ {
compatible = "brcm,bcm2835", "brcm,bcm2708", "brcm,bcm2709";
fragment@0 {
// Configure the gpio pin controller
target = <&gpio>;
__overlay__ {
pin_state: key_pins@0 {
brcm,pins = <17>; // gpio number
brcm,function = <0>; // 0 = input, 1 = output
brcm,pull = <2>; // 0 = none, 1 = pull down, 2 = pull up
};
};
};
fragment@1 {
target-path = "/";
__overlay__ {
keypad: proximity@0 {
compatible = "gpio-keys";
#address-cells = <1>;
#size-cells = <0>;
key: proximity {
label = "proximity detection";
linux,code = <61>; // F3 Key
gpios = <&gpio 17 1>; // GPIO 17
wakeup-source;
};
};
};
};
};
As you see in the file, I added the property wakeup-source but I believe perhaps it wakes up the system from a CPU sleep and not necessarily the screen itself when the screen is sleeping.
As you also see, my gpio-keys is tied to KEY F3. If I press F3 on the keyboard, it wakes up the monitor. However, if I generate an interrupt on the GPIO17 pin, it doesn't wake up the monitor even though it registers as a KEY F3 event. Any suggestions as how to wake up the monitor from gpio-keys? Thanks!
I found a much better solution than my previous answer. I'm leaving my previous answer as a post as it is a working solution (although it's not the most ideal solution).
Anyways, what you have to do is create (or modify) a key layout file. For this key layout file to register with a certain device, the key layout filename must follow a particular naming convention corresponding to details about the device you want to use (gpio-keys in my case). More details about this here: https://source.android.com/devices/input/key-layout-files. In my case, I decided for my key layout filename to match the device name. The device name in my case was gpio-keys, which you define in the device tree overlay file. You can also find the device name if you have access to an Android local terminal by typing into the command line cat /proc/bus/input/devices
. A snippet of my gpio-keys overlay file is shown below:
fragment@1 {
target-path = "/";
__overlay__ {
keypad: gpio-keys {
compatible = "gpio-keys";
#address-cells = <1>;
#size-cells = <0>;
key: proximity {
label = "proximity-detection";
linux,code = <29>; // KEY_LEFTCTRL
linux,input-type = <1>; // EV_KEY
gpios = <&gpio 17 0>; // GPIO 17
wakeup-source;
};
};
};
};
As you can see above next to keypad:, the device name gpio-keys is set. You can write other names here as well. Therefore, I named my key layout file gpio-keys.kl. I placed my gpio-keys.kl file in the /system/usr/keylayout/ directory in Android. The gpio-keys.kl file is shown below:
# Key layout used for gpio-keys
key 29 CTRL_LEFT WAKE
As my gpio-key (GPIO17) is tied to the Linux keycode 29 or KEY_LEFTCTRL, my key layout file associates the Linux keycode 29 (or KEY_LEFTCTRL) to the corresponding Android keycode CTRL_LEFT. Then I add the term WAKE on this same line as shown above. Linux keycodes and their matching Android keycodes can be found here: https://source.android.com/devices/input/keyboard-devices.
This allows for my screen to wake when GPIO17 receives an interrupt, as desired. This is a better solution than just using the Linux keycode for WAKEUP as you may want to write an Android app where you have several different gpio-keys that you want to treat differently. If each gpio-key is tied to a different keycode, you'll be able to distinguish them from each other. If they all have the same keycode, I think distinguishing between these different keys would be much more difficult.