今天给大家介绍一下如何运用Android已有的框架去添加按键.首先,我们来看一下按键的现象!
将DragonBoard 410c开发板连接到ubuntu, 输入以下命令:
$ adb root
$ adb shell
# getevent
在板子上分别按下电源键,音量+, 音量- 时,会看到有事件上报,如图1所示:
图1
现在来给大家详细介绍下如何在410c板子上添加一个按键,当输入上面的命令时按下该按键也能看到有事件上报.
1) 根据410c硬件原理图,如图2所示,选择一个合适的GPIO(支持中断),如GPIO_13.
图2
2)在msm8916-pinctrl.dtsi中添加GPIO13
tlmm_gpio_key {
// qcom,pins = <&gp 107>, <&gp 108>, <&gp 109>;
qcom,pins = <&gp 107>, <&gp 108>, <&gp 109>, <&gp 13>;
qcom,pin-func = <0>;
// qcom,num-grp-pins = <3>;
qcom,num-grp-pins = <4>;
label = "tlmm_gpio_key";
gpio_key_active: gpio_key_active {
drive-strength = <2>;
bias-pull-up;
};
gpio_key_suspend: gpio_key_suspend {
drive-strength = <2>;
bias-pull-up;
};
};
3) 查看kernel/include/uapi/linux/input.h文件,选择一个合适的键值(未被使用),如147,然后在apq8016-***c.dtsi中添加相应的节点,如:
gpio_keys {
compatible = "gpio-keys";
input-name = "gpio-keys";
pinctrl-names = "tlmm_gpio_key_active","tlmm_gpio_key_suspend";
pinctrl-0 = <&gpio_key_active>;
pinctrl-1 = <&gpio_key_suspend>;
camera_focus {
label = "camera_focus";
gpios = <&msm_gpio 108 0x1>;
linux,input-type = <1>;
linux,code = <0x210>;
gpio-key,wakeup;
debounce-interval = <15>;
};
camera_snapshot {
label = "camera_snapshot";
gpios = <&msm_gpio 109 0x1>;
linux,input-type = <1>;
linux,code = <0x2fe>;
gpio-key,wakeup;
debounce-interval = <15>;
};
vol_up {
label = "volume_up";
gpios = <&msm_gpio 107 0x1>;
linux,input-type = <1>;
linux,code = <115>;
gpio-key,wakeup;
debounce-interval = <15>;
};
my_key {
label = "my_key";
gpios = <&msm_gpio 13 0x1>;
linux,input-type = <1>;
linux,code = <147>;
gpio-key,wakeup;
debounce-interval = <15>;
};
};
4) 编译bootimage,并烧写到开发板就可以实现了,按下所添加的按键会看到有事件上报,如图3所示:
图3
以上就是添加按键的全部过程.至于上报的 0001 0093 00000001 表示什么含义,我将会在往后的blog进行讲解,敬请期待!
|