MTK外部按键新增

提示:文章写完后,目录可以自动生成,如何生成可参考右边的帮助文档

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;
+            }
         }

相关推荐
似霰9 分钟前
安卓智能指针sp、wp、RefBase浅析
android·c++·binder
大风起兮云飞扬丶9 分钟前
Android——网络请求
android
干一行,爱一行12 分钟前
android camera data -> surface 显示
android
WaaTong21 分钟前
《重学Java设计模式》之 原型模式
java·设计模式·原型模式
m0_7430484421 分钟前
初识Java EE和Spring Boot
java·java-ee
AskHarries23 分钟前
Java字节码增强库ByteBuddy
java·后端
断墨先生28 分钟前
uniapp—android原生插件开发(3Android真机调试)
android·uni-app
小灰灰__43 分钟前
IDEA加载通义灵码插件及使用指南
java·ide·intellij-idea
夜雨翦春韭1 小时前
Java中的动态代理
java·开发语言·aop·动态代理
程序媛小果1 小时前
基于java+SpringBoot+Vue的宠物咖啡馆平台设计与实现
java·vue.js·spring boot