• MTK外部按键新增


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


    前言

    总的来说就是,加驱动,加点击事件


    一、添加驱动

    这种不同平台的按照文档添加即可

    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
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47
    • 48
    • 49
    • 50
    • 51
    • 52
    • 53
    • 54
    • 55
    • 56
    • 57
    • 58
    • 59
    • 60
    • 61
    • 62
    • 63
    • 64
    • 65
    • 66
    • 67
    • 68
    • 69
    • 70
    • 71
    • 72
    • 73
    • 74
    • 75

    二、修改framework

    1.增加按键定义

    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;
             }
             
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47
    • 48
    • 49
    • 50
    • 51
    • 52
    • 53
    • 54
    • 55
    • 56
    • 57
    • 58
    • 59
    • 60
    • 61
    • 62
    • 63
    • 64
    • 65
    • 66
    • 67
    • 68
    • 69
    • 70
    • 71
    • 72

    2.PhoneWindowManager处理点击事件

    interceptKeyBeforeQueueing中

    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;
    +            }
             }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19

  • 相关阅读:
    重载和重写什么区别?
    “益路同行”栏目专访第11期——柳州市雨花敬老服务中心陈勇梅
    文件安全外发,墨门云防范共享泄密
    如何通过EasyCVR接口监测日志观察平台拉流情况?
    38.红黑树(王道第7章查找补充知识)
    x86汇编代码学习-计算机工作原理2
    怎样做ChatGPT应用开发?
    基于Java+SpringBoot+Vue民宿管理系统的设计与实现 前后端分离【Java毕业设计·文档报告·代码讲解·安装调试】
    UE4 C++设计模式:状态模式(State Pattern)
    第一期 微信云开发小程序介绍-生活智打卡
  • 原文地址:https://blog.csdn.net/xuyewen288/article/details/133882577