提示:文章写完后,目录可以自动生成,如何生成可参考右边的帮助文档
MTK外部按键新增
前言
总的来说就是,加驱动,加点击事件
一、添加驱动
这种不同平台的按照文档添加即可
java
diff --git a/alps/kernel-4.14/arch/arm64/boot/dts/mediatek/xxxxx.dts b/alps/kernel-4.14/arch/arm64/boot/dts/mediatek/xxxxx.dts
index bf4f48fdc8..b8f9465236 100755
--- a/alps/kernel-4.14/arch/arm64/boot/dts/mediatek/xxxxx.dts
+++ b/alps/kernel-4.14/arch/arm64/boot/dts/mediatek/xxxxx.dts
@@ -10,6 +10,7 @@
* GNU General Public License for more details.
*/
+#include <dt-bindings/input/input.h>
#include <generated/autoconf.h>
/dts-v1/;
@@ -102,6 +103,22 @@ ROOT_NODE {
enable-active-high;
regulator-always-on;
};
+
+ key_net: key_net {
+ compatible = "gpio-keys";
+ autorepeat;
+
+ pinctrl-names = "default";
+ pinctrl-0 = <&net_key_pins_default>;
+ status = "okay";
+
+ net {
+ label = "GPIO NET";
+ linux,code = <KEY_NET>;
+ gpios = <&pio 131 GPIO_ACTIVE_LOW>;
+ debounce-interval = <5>;
+ };
+ };
};
&accdet {
@@ -1098,6 +1115,13 @@ ROOT_NODE {
bias-pull-up = <MTK_PUPD_SET_R1R0_01>;
};
};
+
+ net_key_pins_default: net_key {
+ pins_cmd_dat {
+ pinmux = <MT8168_PIN_131_TDM_TX_MCK__FUNC_GPIO131>;
+ };
+ };
+
};
&spi {
diff --git a/alps/kernel-4.14/drivers/input/keyboard/Kconfig b/alps/kernel-4.14/drivers/input/keyboard/Kconfig
index bd56c5d545..b743824bdc 100644
--- a/alps/kernel-4.14/drivers/input/keyboard/Kconfig
+++ b/alps/kernel-4.14/drivers/input/keyboard/Kconfig
@@ -214,6 +214,7 @@ config KEYBOARD_EP93XX
config KEYBOARD_GPIO
tristate "GPIO Buttons"
depends on GPIOLIB || COMPILE_TEST
+ default y
help
This driver implements support for buttons connected
to GPIO pins of various CPUs (and some other chips).
diff --git a/alps/kernel-4.14/include/uapi/linux/input-event-codes.h b/alps/kernel-4.14/include/uapi/linux/input-event-codes.h
index 61769d4b7d..235a2ba1a6 100644
--- a/alps/kernel-4.14/include/uapi/linux/input-event-codes.h
+++ b/alps/kernel-4.14/include/uapi/linux/input-event-codes.h
@@ -337,6 +337,8 @@
#define KEY_MICMUTE 248 /* Mute / unmute the microphone */
+#define KEY_NET 249 /* 配网键 add by het-will-Zhangw */
+
/* Code 255 is reserved for special needs of AT keyboard driver */
#define BTN_MISC 0x100
二、修改framework
1.增加按键定义
java
diff --git a/alps/frameworks/native/include/android/keycodes.h b/alps/frameworks/native/include/android/keycodes.h
index 214559d683..939bede4ff 100644
--- a/alps/frameworks/native/include/android/keycodes.h
+++ b/alps/frameworks/native/include/android/keycodes.h
@@ -776,7 +776,9 @@ enum {
AKEYCODE_THUMBS_DOWN = 287,
/** Used to switch current account that is consuming content.
* May be consumed by system to switch current viewer profile. */
- AKEYCODE_PROFILE_SWITCH = 288
+ AKEYCODE_PROFILE_SWITCH = 288,
+
+ AKEYCODE_NET = 289 //
// NOTE: If you add a new keycode here you must also add it to several other files.
// Refer to frameworks/base/core/java/android/view/KeyEvent.java for the full list.
diff --git a/alps/frameworks/native/include/input/InputEventLabels.h b/alps/frameworks/native/include/input/InputEventLabels.h
index 59d16d15af..7f78e2bd24 100644
--- a/alps/frameworks/native/include/input/InputEventLabels.h
+++ b/alps/frameworks/native/include/input/InputEventLabels.h
@@ -328,6 +328,7 @@ static const InputEventLabel KEYCODES[] = {
DEFINE_KEYCODE(THUMBS_UP),
DEFINE_KEYCODE(THUMBS_DOWN),
DEFINE_KEYCODE(PROFILE_SWITCH),
+ DEFINE_KEYCODE(NET),
{ nullptr, 0 }
};
diff --git a/alps/frameworks/base/data/keyboards/Generic.kl b/alps/frameworks/base/data/keyboards/Generic.kl
index 8699cb491d..1f7af8d7b6 100644
--- a/alps/frameworks/base/data/keyboards/Generic.kl
+++ b/alps/frameworks/base/data/keyboards/Generic.kl
@@ -247,6 +247,8 @@ key 224 BRIGHTNESS_DOWN
key 225 BRIGHTNESS_UP
key 226 HEADSETHOOK
+key 249 NET
+
key 256 BUTTON_1
key 257 BUTTON_2
key 258 BUTTON_3
diff --git a/alps/frameworks/base/core/java/android/view/KeyEvent.java b/alps/frameworks/base/core/java/android/view/KeyEvent.java
index 87dd5b47c4..5dcf3e4752 100644
--- a/alps/frameworks/base/core/java/android/view/KeyEvent.java
+++ b/alps/frameworks/base/core/java/android/view/KeyEvent.java
@@ -823,13 +823,16 @@ public class KeyEvent extends InputEvent implements Parcelable {
* consuming content. May be consumed by system to set account globally.
*/
public static final int KEYCODE_PROFILE_SWITCH = 288;
+
+ public static final int KEYCODE_NET = 289; // add by het-will-Zhang
/**
* Integer value of the last KEYCODE. Increases as new keycodes are added to KeyEvent.
* @hide
*/
+
@TestApi
- public static final int LAST_KEYCODE = KEYCODE_PROFILE_SWITCH;
+ public static final int LAST_KEYCODE = KEYCODE_NET;
// NOTE: If you add a new keycode here you must also add it to:
// isSystem()
@@ -1924,6 +1927,7 @@ public class KeyEvent extends InputEvent implements Parcelable {
case KeyEvent.KEYCODE_SYSTEM_NAVIGATION_DOWN:
case KeyEvent.KEYCODE_SYSTEM_NAVIGATION_LEFT:
case KeyEvent.KEYCODE_SYSTEM_NAVIGATION_RIGHT:
+ case KeyEvent.KEYCODE_NET: //
return true;
}
2.PhoneWindowManager处理点击事件
interceptKeyBeforeQueueing中
java
diff --git a/alps/frameworks/base/services/core/java/com/android/server/policy/PhoneWindowManager.java b/alps/frameworks/base/services/core/java/com/android/server/policy/PhoneWindowManager.java
index 5c51d75d0d..dec20e3b51 100644
--- a/alps/frameworks/base/services/core/java/com/android/server/policy/PhoneWindowManager.java
+++ b/alps/frameworks/base/services/core/java/com/android/server/policy/PhoneWindowManager.java
@@ -4056,6 +4056,25 @@ public class PhoneWindowManager implements WindowManagerPolicy {
}
break;
}
+ case KeyEvent.KEYCODE_NET: {
+ result &= ~ACTION_PASS_TO_USER;//是否继续传递到用户处理,否
+ if (down) {//按键按下
+ } else { //按键抬起
+ }
+
+ break;
+ }
}