当前位置:   article > 正文

RK3588 Android13自定义一个按键实现长按短按_rk3588 gpio-keys

rk3588 gpio-keys

一、kernel修改

  1. diff --git a/arch/arm64/boot/dts/rockchip/rk3588-nvr-demo.dtsi b/arch/arm64/boot/dts/rockchip/rk3588-nvr-demo.dtsi
  2. index 5aae5c613825..4cc1223f9cbf 100755
  3. --- a/arch/arm64/boot/dts/rockchip/rk3588-nvr-demo.dtsi
  4. +++ b/arch/arm64/boot/dts/rockchip/rk3588-nvr-demo.dtsi
  5. +
  6. + gpio-keys {
  7. + status = "okay";
  8. + compatible = "gpio-keys";
  9. + autorepeat;
  10. + userf1 {
  11. + label = "GPIO user key";
  12. + linux,code = <KEY_USERKEY>;
  13. + gpios = <&gpio1 RK_PA3 GPIO_ACTIVE_LOW>;
  14. + debounce-interval = <100>;
  15. + };
  16. + userf1_lp {
  17. + label = "GPIO user key lp";
  18. + linux,code = <KEY_USERKEY_LP>;
  19. + gpios = <&gpio1 RK_PD0 GPIO_ACTIVE_LOW>;
  20. + debounce-interval = <100>;
  21. + };
  22. + };
  23. };
  24. diff --git a/drivers/input/keyboard/gpio_keys.c b/drivers/input/keyboard/gpio_keys.c
  25. old mode 100644
  26. new mode 100755
  27. index f2d4e4daa818..9e95f3465620
  28. --- a/drivers/input/keyboard/gpio_keys.c
  29. +++ b/drivers/input/keyboard/gpio_keys.c
  30. @@ -29,6 +29,8 @@
  31. #include <linux/spinlock.h>
  32. #include <dt-bindings/input/gpio-keys.h>
  33. +static unsigned long start_time = 0;
  34. +
  35. struct gpio_button_data {
  36. const struct gpio_keys_button *button;
  37. struct input_dev *input;
  38. @@ -359,7 +361,8 @@ static void gpio_keys_gpio_report_event(struct gpio_button_data *bdata)
  39. struct input_dev *input = bdata->input;
  40. unsigned int type = button->type ?: EV_KEY;
  41. int state;
  42. -
  43. + unsigned long press_time = 0;
  44. +
  45. state = gpiod_get_value_cansleep(bdata->gpiod);
  46. if (state < 0) {
  47. dev_err(input->dev.parent,
  48. @@ -371,7 +374,27 @@ static void gpio_keys_gpio_report_event(struct gpio_button_data *bdata)
  49. if (state)
  50. input_event(input, type, button->code, button->value);
  51. } else {
  52. - input_event(input, type, *bdata->code, state);
  53. + if (*bdata->code == 744) {
  54. + if (state) {
  55. + start_time = jiffies;
  56. + } else {
  57. + press_time = jiffies_to_msecs(jiffies - start_time);
  58. + printk(KERN_INFO "Button pressed for %lu milliseconds\n", press_time);
  59. + if (press_time >= 5000) {
  60. + printk("factoryreset \n");
  61. + input_event(input, type, 745, 1);
  62. + input_sync(input);
  63. + input_event(input, type, 745, state);
  64. + } else {
  65. + input_event(input, type, 744, 1);
  66. + input_sync(input);
  67. + input_event(input, type, 744, state);
  68. + }
  69. + }
  70. + } else {
  71. + input_event(input, type, *bdata->code, state);
  72. + }
  73. + printk("gpio_keys_gpio_report_event input_event *bdata->code=%d,state = %d\n",*bdata->code, state);
  74. }
  75. input_sync(input);
  76. }
  77. @@ -405,6 +428,7 @@ static irqreturn_t gpio_keys_gpio_isr(int irq, void *dev_id)
  78. * handler to run.
  79. */
  80. input_report_key(bdata->input, button->code, 1);
  81. + printk("gpio_keys_gpio_isr input_report_key *bdata->code=%d\n",button->code);
  82. }
  83. }
  84. @@ -424,6 +448,7 @@ static void gpio_keys_irq_timer(struct timer_list *t)
  85. spin_lock_irqsave(&bdata->lock, flags);
  86. if (bdata->key_pressed) {
  87. input_event(input, EV_KEY, *bdata->code, 0);
  88. + printk("gpio_keys_irq_timer input_event *bdata->code=%d\n",*bdata->code);
  89. input_sync(input);
  90. bdata->key_pressed = false;
  91. }
  92. @@ -445,10 +470,12 @@ static irqreturn_t gpio_keys_irq_isr(int irq, void *dev_id)
  93. pm_wakeup_event(bdata->input->dev.parent, 0);
  94. input_event(input, EV_KEY, *bdata->code, 1);
  95. + printk("gpio_keys_irq_isr input_event *bdata->code=%d\n",*bdata->code);
  96. input_sync(input);
  97. if (!bdata->release_delay) {
  98. input_event(input, EV_KEY, *bdata->code, 0);
  99. + printk("gpio_keys_irq_isr !bdata->release_delay input_event *bdata->code=%d\n",*bdata->code);
  100. input_sync(input);
  101. goto out;
  102. }
  103. diff --git a/include/dt-bindings/input/rk-input.h b/include/dt-bindings/input/rk-input.h
  104. index 00b412927890..06c66d7c6bd4 100644
  105. --- a/include/dt-bindings/input/rk-input.h
  106. +++ b/include/dt-bindings/input/rk-input.h
  107. @@ -578,6 +578,9 @@
  108. #define KEY_BRIGHTNESS_MIN 0x250 /* Set Brightness to Minimum */
  109. #define KEY_BRIGHTNESS_MAX 0x251 /* Set Brightness to Maximum */
  110. +#define KEY_USERKEY 0x2e8
  111. +#define KEY_USERKEY_LP 0x2e9
  112. +
  113. #define BTN_TRIGGER_HAPPY 0x2c0
  114. #define BTN_TRIGGER_HAPPY1 0x2c0
  115. #define BTN_TRIGGER_HAPPY2 0x2c1
  116. diff --git a/include/uapi/linux/input-event-codes.h b/include/uapi/linux/input-event-codes.h
  117. index 7989d9483ea7..1064395e72c3 100644
  118. --- a/include/uapi/linux/input-event-codes.h
  119. +++ b/include/uapi/linux/input-event-codes.h
  120. @@ -778,6 +778,8 @@
  121. #define BTN_TRIGGER_HAPPY38 0x2e5
  122. #define BTN_TRIGGER_HAPPY39 0x2e6
  123. #define BTN_TRIGGER_HAPPY40 0x2e7
  124. +#define KEY_USERKEY 0x2e8
  125. +#define KEY_USERKEY_LP 0x2e9

二、framework修改

  1. diff --git a/core/api/current.txt b/core/api/current.txt
  2. index 1d610ab7536b..15e5b6487d13 100644
  3. --- a/core/api/current.txt
  4. +++ b/core/api/current.txt
  5. @@ -48634,6 +48634,8 @@ package android.view {
  6. field public static final int KEYCODE_TV_ZOOM_MODE = 255; // 0xff
  7. field public static final int KEYCODE_U = 49; // 0x31
  8. field public static final int KEYCODE_UNKNOWN = 0; // 0x0
  9. + field public static final int KEYCODE_USERKEY = 305; // 0x131
  10. + field public static final int KEYCODE_USERKEY_LP = 306; // 0x132
  11. field public static final int KEYCODE_V = 50; // 0x32
  12. field public static final int KEYCODE_VIDEO_APP_1 = 289; // 0x121
  13. field public static final int KEYCODE_VIDEO_APP_2 = 290; // 0x122
  14. diff --git a/core/java/android/view/KeyEvent.java b/core/java/android/view/KeyEvent.java
  15. index c3a638c4c36a..e5a21e3f3e06 100644
  16. --- a/core/java/android/view/KeyEvent.java
  17. +++ b/core/java/android/view/KeyEvent.java
  18. @@ -866,6 +866,8 @@ public class KeyEvent extends InputEvent implements Parcelable {
  19. public static final int KEYCODE_DEMO_APP_3 = 303;
  20. /** Key code constant: Demo Application key #4. */
  21. public static final int KEYCODE_DEMO_APP_4 = 304;
  22. + public static final int KEYCODE_USERKEY = 305;
  23. + public static final int KEYCODE_USERKEY_LP = 306;
  24. /**
  25. * Integer value of the last KEYCODE. Increases as new keycodes are added to KeyEvent.
  26. diff --git a/core/res/res/values/attrs.xml b/core/res/res/values/attrs.xml
  27. index d86aa1122d3a..fb3bccc7fd80 100644
  28. --- a/core/res/res/values/attrs.xml
  29. +++ b/core/res/res/values/attrs.xml
  30. @@ -2004,7 +2004,9 @@
  31. <enum name="KEYCODE_DEMO_APP_1" value="301" />
  32. <enum name="KEYCODE_DEMO_APP_2" value="302" />
  33. <enum name="KEYCODE_DEMO_APP_3" value="303" />
  34. - <enum name="KEYCODE_DEMO_APP_4" value="304" />
  35. + <enum name="KEYCODE_DEMO_APP_4" value="304" />
  36. + <enum name="KEYCODE_USERKEY" value="305" />
  37. + <enum name="KEYCODE_USERKEY_LP" value="306" />
  38. </attr>
  39. <!-- ***************************************************************** -->
  40. diff --git a/data/keyboards/Generic.kl b/data/keyboards/Generic.kl
  41. index c81473ddcfc6..0096266539a4 100644
  42. --- a/data/keyboards/Generic.kl
  43. +++ b/data/keyboards/Generic.kl
  44. @@ -410,6 +410,8 @@ key 580 APP_SWITCH
  45. key 582 VOICE_ASSIST
  46. # Linux KEY_ASSISTANT
  47. key 583 ASSIST
  48. +key 744 USERKEY
  49. +key 745 USERKEY_LP
  50. # Keys defined by HID usages
  51. key usage 0x0c0067 WINDOW
  52. diff --git a/services/core/java/com/android/server/policy/PhoneWindowManager.java b/services/core/java/com/android/server/policy/PhoneWindowManager.java
  53. old mode 100644
  54. new mode 100755
  55. index 40643f638ac0..3f573a8a52de
  56. --- a/services/core/java/com/android/server/policy/PhoneWindowManager.java
  57. +++ b/services/core/java/com/android/server/policy/PhoneWindowManager.java
  58. @@ -182,6 +182,8 @@ import android.view.accessibility.AccessibilityManager;
  59. import android.view.animation.Animation;
  60. import android.view.animation.AnimationUtils;
  61. import android.view.autofill.AutofillManagerInternal;
  62. +import android.os.UserManager;
  63. +import android.os.RecoverySystem;
  64. import com.android.internal.R;
  65. import com.android.internal.accessibility.AccessibilityShortcutController;
  66. @@ -3031,6 +3033,27 @@ public class PhoneWindowManager implements WindowManagerPolicy {
  67. case KeyEvent.KEYCODE_DEMO_APP_4:
  68. Slog.wtf(TAG, "KEYCODE_APP_X should be handled in interceptKeyBeforeQueueing");
  69. return key_consumed;
  70. + case KeyEvent.KEYCODE_USERKEY:
  71. + //do nothing
  72. + PowerManager pm = (PowerManager) mContext.getSystemService(Context.POWER_SERVICE);
  73. + pm.reboot(null);
  74. + Slog.wtf(TAG, "KeyEvent.KEYCODE_USERKEY in interceptKeyBeforeQueueing");
  75. + break;
  76. + case KeyEvent.KEYCODE_USERKEY_LP:
  77. + // 检查是否允许当前用户执行恢复出厂设置操作
  78. + UserManager um = mContext.getSystemService(UserManager.class);
  79. + if (um.hasUserRestriction(UserManager.DISALLOW_FACTORY_RESET)) {
  80. + throw new SecurityException("Factory reset is not allowed for this user.");
  81. + }
  82. +
  83. + // 执行恢复出厂设置操作
  84. + try {
  85. + RecoverySystem.rebootWipeUserData(mContext);
  86. + } catch (IOException e) {
  87. + // 处理异常
  88. + }
  89. + Slog.wtf(TAG, "KeyEvent.KEYCODE_USERKEY_LP in interceptKeyBeforeQueueing");
  90. + break;
  91. case KeyEvent.KEYCODE_BRIGHTNESS_UP:
  92. case KeyEvent.KEYCODE_BRIGHTNESS_DOWN:
  93. if (down) {
  94. diff --git a/include/android/keycodes.h b/include/android/keycodes.h
  95. index 3357660f5c..52750f400e 100644
  96. --- a/include/android/keycodes.h
  97. +++ b/include/android/keycodes.h
  98. @@ -809,7 +809,8 @@ enum {
  99. AKEYCODE_DEMO_APP_3 = 303,
  100. /** Demo Application key #4. */
  101. AKEYCODE_DEMO_APP_4 = 304,
  102. -
  103. + AKEYCODE_USERKEY = 305,
  104. + AKEYCODE_USERKEY_LP = 306,
  105. // NOTE: If you add a new keycode here you must also add it to several other files.
  106. // Refer to frameworks/base/core/java/android/view/KeyEvent.java for the full list.
  107. };
  108. diff --git a/libs/input/InputEventLabels.cpp b/libs/input/InputEventLabels.cpp
  109. index 2d768ce573..9cd92a7bef 100644
  110. --- a/libs/input/InputEventLabels.cpp
  111. +++ b/libs/input/InputEventLabels.cpp
  112. @@ -330,7 +330,9 @@ namespace android {
  113. DEFINE_KEYCODE(DEMO_APP_1), \
  114. DEFINE_KEYCODE(DEMO_APP_2), \
  115. DEFINE_KEYCODE(DEMO_APP_3), \
  116. - DEFINE_KEYCODE(DEMO_APP_4)
  117. + DEFINE_KEYCODE(DEMO_APP_4), \
  118. + DEFINE_KEYCODE(USERKEY), \
  119. + DEFINE_KEYCODE(USERKEY_LP)
  120. // NOTE: If you add a new axis here you must also add it to several other files.

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/菜鸟追梦旅行/article/detail/704611
推荐阅读
相关标签
  

闽ICP备14008679号