Android 12 按键驱动中增加按键去抖功能

— a/alps/kernel-4.14/drivers/input/keyboard/dw_gpio_key.c
+++ b/alps/kernel-4.14/drivers/input/keyboard/dw_gpio_key.c
@@ -17,16 +17,32 @@ static int key_state; // 按键状态
static int key1_eint; // IRQ
static int key1_eint_gpio; // GPIO

+static int key1_value = 0;
+
+static unsigned long key1_swdebounce;
+static unsigned long key1_hwdebounce;
+static struct delayed_work key1_delaywork;
+
static irqreturn_t gpio_key_irq_handler(int irq, void *dev_id) {

  •   //pr_info("%s,%d-irq=%d", __func__, __LINE__, irq);
    
  •   disable_irq_nosync(irq);
    
  •   schedule_delayed_work(&key1_delaywork,
    
  •           msecs_to_jiffies(key1_swdebounce));
    
  • return IRQ_HANDLED;
    +}

+static void key1_eint_workcb(struct work_struct *work)
+{
int state = gpio_get_value(key1_eint_gpio);

  •   pr_info("%s %d state=%d key_state=%d\n", __func__, __LINE__,state, key_state);
    
  •   state = !state;
    
  •   //pr_info("%s %d state=%d key_state=%d\n", __func__, __LINE__,state, key_state);
    
    if (state != key_state) {
    key_state = state;
  •           pr_info("%s %d MY_KEY_1=%d\n", __func__, __LINE__,MY_KEY_1);
    
  •    input_report_key(input_dev, MY_KEY_1, key_state);  // 报告按键事件
    
  •    input_report_key(input_dev, /*MY_KEY_1*/key1_value, key_state);  // 报告按键事件
       input_sync(input_dev);                             // 同步输入设备
    
    }
  • return IRQ_HANDLED;
  •   enable_irq(key1_eint);
    

}

static int dw_gpio_key_probe(struct platform_device *pdev)
@@ -35,7 +51,8 @@ static int dw_gpio_key_probe(struct platform_device *pdev)
int error;

    struct device_node *node = NULL;
  •   //u32 ints[2] = {0};
    
  •   u32 ints[2] = {0};
    
      pr_info("%s %d E+\n", __func__, __LINE__);
    

@@ -71,6 +88,20 @@ static int dw_gpio_key_probe(struct platform_device *pdev)

            pr_info("%s,%d GPIO IRQ : %d\n", __func__,__LINE__, key1_eint);
            enable_irq_wake(key1_eint);
  •           error = of_property_read_u32_array(node, "key1-debounce",
    
  •                   ints, ARRAY_SIZE(ints));
    
  •           if (!error)
    
  •                   key1_hwdebounce = ints[1];
    
  •           key1_swdebounce = msecs_to_jiffies(100);
    
  •           of_property_read_u32(node, "key1-linux-code", &key1_value);
    
  •           if(!key1_value) {
    
  •                   key1_value = MY_KEY_1;
    
  •           }
    
  •           INIT_DELAYED_WORK(&key1_delaywork, key1_eint_workcb);
      }
    

@@ -86,7 +117,7 @@ static int dw_gpio_key_probe(struct platform_device *pdev)
input_dev->name = “dw_gpio_key”;
input_dev->id.bustype = BUS_HOST;
input_dev->evbit[0] = BIT_MASK(EV_KEY);

  • input_dev->keybit[BIT_WORD(MY_KEY_1)] = BIT_MASK(MY_KEY_1);
  • input_dev->keybit[BIT_WORD(/MY_KEY_1/key1_value)] = BIT_MASK(/MY_KEY_1/key1_value);

    /* 注册输入设备 */
    error = input_register_device(input_dev);

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值