配置和定义

        gpio_power_detect {
                compatible = "quectel,gpio_power_detect";
                pinctrl-names = "default";
                pinctrl-0 = <&gpio_power_detect_active>;
                gpio_power_gpio = <&tlmm 95 0x00>;
                //otg-power-gpios = <&tlmm 18 0>;
                usb-sel-gpios = <&tlmm 66 0>;
                debounce = <15>;
                linux,code = <172>;

        };
 struct gpio_power_detect {
        struct device *dev;
        struct input_dev *p_inputdev;

        unsigned int gpio_power_gpio;
        unsigned int gpio_power_irq_num;

//      struct work_struct power_detect;
        struct workqueue_struct *gpio_power_detect_wq;
        struct work_struct      work;

        unsigned int gpio_usb_sel_gpio;
        atomic_t state;
        unsigned int code;

};

driver 和 dts 块之间的绑定

driver 中的 struct of_device_id 中的 compatible 会和 dts 中的 compatible 进行匹配,吻合的情况下, driver 就能从这个 dts 块中读取相应的数据了。 本文的 dts 是 qm215-qrd.dtsi

static struct of_device_id of_device_sc20_gpio_match_table[] =
{
        {.compatible = "quectel,gpio_power_detect"},
        {},
};
        gpio_power_detect {
                compatible = "quectel,gpio_power_detect";
                ...

        };

driver 配置输入引脚

输入引脚一般需要配置: 引脚方向,中断,上下拉。

  1. 获取 gpio, driver 中通过 dts 中的相同名称,获取到 gpio,然后申请相应的结构体
dev_struct->gpio_power_gpio = of_get_named_gpio(dev_struct->dev->of_node, "gpio_power_gpio", 0);
gpio_request(dev_struct->gpio_power_gpio, "gpio_power_gpio");
        gpio_power_detect {
                ...
                gpio_power_gpio = <&tlmm 95 0x00>;
                ...

        };
  1. 获取中断

    dev_struct->gpio_power_irq_num = gpio_to_irq(dev_struct->gpio_power_gpio);
  2. 设置方向

    gpio_direction_input(dev_struct->gpio_power_gpio);
  3. 设置上下拉,是通过 dts 来配置的,本文实在 msm8917-pinctrl.dtsi 中配置的,然后在 qm215-qrd.dtsi 中进行引用。
                tlmm_gpio_power_detect {
                        gpio_power_detect_active: gpio_power_detect_active {
                                mux {
                                        pins = "gpio95";
                                        drive-strength = <2>;
                                        bias-pull-up;
                                };
                        };
                };
        gpio_power_detect {
                ...
                pinctrl-names = "default";
                pinctrl-0 = <&gpio_power_detect_active>;
                ...

        };
···

# 配置输出引脚
输出引脚配置比较简单,只要获取 gpio 后,配置方向和初始值即可。
1. 获取 gpio
    dev_struct->gpio_usb_sel_gpio = of_get_named_gpio(dev_struct->dev->of_node, "usb-sel-gpios", 0);
    if (dev_struct->gpio_usb_sel_gpio < 0){
            pr_err("%s: get usb_sel_gpio failed\n", __func__);
    return -EINVAL;
    }
    ret = gpio_request(dev_struct->gpio_usb_sel_gpio, "usb-sel-gpios");
    if (ret) {
            pr_err("%s: Unable to request usb_sel_spio [%d]\n", __func__, dev_struct->gpio_usb_sel_gpio);
            return ret;
    }
    gpio_power_detect {
            ...
            usb-sel-gpios = <&tlmm 66 0>;
            ...

    };

2. 配置位输出
    ret = gpio_direction_output(dev_struct->gpio_usb_sel_gpio, 1);
    if (ret) {
            pr_err("%s: Unable to set direction for usb-sel-gpios [%d]\n", __func__, dev_struct->gpio_usb_sel_gpio);
            gpio_free(dev_struct->gpio_usb_sel_gpio);
    }

# 配置按键值上报
1. 获取按键值
    if(of_property_read_u32(dev_struct->dev->of_node, "linux,code", &dev_struct->code)) {
            dev_err(dev_struct->dev, "fail to get linux code\n");
            return (-EINVAL);
    }
    printk("gpio_power_detect probe get key code %d\n", dev_struct->code);

    state = gpio_get_value(dev_struct->gpio_power_gpio);
    if(state < 0) {
            dev_err(dev_struct->dev, "fail to init base_detect state %d\n", state);
            return (-EINVAL);
    }
    atomic_set(&dev_struct->state, state);
    gpio_power_detect {
            ...
            linux,code = <172>;

    };

2. 工作时上报键值
    old_state = atomic_read(&dev_struct->state);
    new_state = gpio_get_value(dev_struct->gpio_power_gpio);
    if (new_state < 0) {
            dev_err(dev_struct->dev,
                    "failed to get bd-gpio state: %d\n", new_state);
            return;
    }

    if(new_state != old_state){
            dev_err(dev_struct->dev, "base_detect update state %d", new_state);
            atomic_set(&dev_struct->state, new_state);
            gpio_set_value(dev_struct->gpio_usb_sel_gpio, new_state);
            input_report_key(dev_struct->p_inputdev, dev_struct->code, new_state);
            input_sync(dev_struct->p_inputdev);
    }


# 注意
本文中使用的 `gpio_request` 属于老的 api,新的 api 一般是 `gpiod` 开头,比如:`gpiod_direction_output`.

如果是按键,为了消抖,dts 中需要考虑 `debounce`,driver 中需要考虑 延迟工作 `struct delayed_work` 。

`DEVICE_ATTR` 可以在 `sys fs` 中添加文件,相关可以参考: https://blog.csdn.net/njuitjf/article/details/16849333

# 参考:
设备树详解  
https://blog.csdn.net/qq_28992301/article/details/53321610  
在Linux驱动中使用gpio子系统  
https://www.jianshu.com/p/f160209bd64b  
Linux内核中的GPIO驱动  
https://blog.csdn.net/vincent1995x/article/details/51581711  
1.1. GPIO设置   
http://developer.rokid.com/docs/7-bspguide/pinmuxji_gpio_she_zhi/gpioshe_zhi.html  
LinuxGPIO中文文档  
https://www.cnblogs.com/bforever/p/10528395.html  
一、初识linux输入子系统  
https://www.cnblogs.com/zhaobinyouth/p/6257662.html  
pm_stay_awake()和pm_relax()的意义  
https://blog.csdn.net/chizhang7815/article/details/100800761  
linux gpio_to_irq()源码分析  
https://blog.csdn.net/MACMACip/article/details/105549516  
of_property_read_u32  
https://biscuitos.github.io/blog/DTS-of_property_read_u32/  
如何在一份驱动中上报键值之理解input子系统设备  
https://blog.csdn.net/weixin_44158983/article/details/106872084?utm_medium=distribute.pc_relevant.none-task-blog-2~default~baidujs_baidulandingword~default-0.no_search_link&spm=1001.2101.3001.4242.1&utm_relevant_index=3  
INPUT子系统学习 evdev  
https://blog.csdn.net/xiaochuan110/article/details/82424237  
高通 gpio控制方式  
https://blog.csdn.net/qq_36781842/article/details/102625088?spm=1001.2101.3001.6650.6&utm_medium=distribute.pc_relevant.none-task-blog-2%7Edefault%7EBlogCommendFromBaidu%7Edefault-6.no_search_link&depth_1-utm_source=distribute.pc_relevant.none-task-blog-2%7Edefault%7EBlogCommendFromBaidu%7Edefault-6.no_search_link  
Android 5.1高通方案增加GPIO按键  
https://blog.csdn.net/tdstds/article/details/50920443?spm=1001.2101.3001.6650.3&utm_medium=distribute.pc_relevant.none-task-blog-2%7Edefault%7ECTRLIST%7Edefault-3.no_search_link&depth_1-utm_source=distribute.pc_relevant.none-task-blog-2%7Edefault%7ECTRLIST%7Edefault-3.no_search_link  
Qualcomm MSM GPIO-KEY device tree  
https://blog.csdn.net/bolanlst/article/details/51385808?spm=1001.2101.3001.6650.2&utm_medium=distribute.pc_relevant.none-task-blog-2%7Edefault%7ECTRLIST%7Edefault-2.no_search_link&depth_1-utm_source=distribute.pc_relevant.none-task-blog-2%7Edefault%7ECTRLIST%7Edefault-2.no_search_link  
android7.1 msm8953通过寄存器拉高gpio电平  
https://blog.csdn.net/zjy764219923/article/details/106243794?spm=1001.2101.3001.6650.15&utm_medium=distribute.pc_relevant.none-task-blog-2%7Edefault%7EBlogCommendFromBaidu%7Edefault-15.no_search_link&depth_1-utm_source=distribute.pc_relevant.none-task-blog-2%7Edefault%7EBlogCommendFromBaidu%7Edefault-15.no_search_link  
msm8996的gpio和irq  
https://blog.csdn.net/lintwins/article/details/50203173?spm=1001.2101.3001.6650.11&utm_medium=distribute.pc_relevant.none-task-blog-2%7Edefault%7ECTRLIST%7Edefault-11.no_search_link&depth_1-utm_source=distribute.pc_relevant.none-task-blog-2%7Edefault%7ECTRLIST%7Edefault-11.no_search_link  
Linux DTS(Device Tree Source)设备树详解之一(背景基础知识篇)  
https://radia.blog.csdn.net/article/details/70800076?spm=1001.2101.3001.6650.6&utm_medium=distribute.pc_relevant.none-task-blog-2%7Edefault%7EBlogCommendFromBaidu%7Edefault-6.no_search_link&depth_1-utm_source=distribute.pc_relevant.none-task-blog-2%7Edefault%7EBlogCommendFromBaidu%7Edefault-6.no_search_link  
高通msm8916 gpio笔记(基于设备树)  
https://blog.csdn.net/hm131415/article/details/54377549?spm=1001.2101.3001.6650.18&utm_medium=distribute.pc_relevant.none-task-blog-2%7Edefault%7EBlogCommendFromBaidu%7Edefault-18.no_search_link&depth_1-utm_source=distribute.pc_relevant.none-task-blog-2%7Edefault%7EBlogCommendFromBaidu%7Edefault-18.no_search_link  
msm8953 申请gpio失败,查看所有的gpio 申请情况。  
https://blog.csdn.net/jlgcumt/article/details/106614870?spm=1001.2101.3001.6650.14&utm_medium=distribute.pc_relevant.none-task-blog-2%7Edefault%7EBlogCommendFromBaidu%7Edefault-14.no_search_link&depth_1-utm_source=distribute.pc_relevant.none-task-blog-2%7Edefault%7EBlogCommendFromBaidu%7Edefault-14.no_search_link  
高通 gpio控制方式  
https://blog.csdn.net/qq_36781842/article/details/102625088?spm=1001.2101.3001.6650.9&utm_medium=distribute.pc_relevant.none-task-blog-2%7Edefault%7EBlogCommendFromBaidu%7Edefault-9.no_search_link&depth_1-utm_source=distribute.pc_relevant.none-task-blog-2%7Edefault%7EBlogCommendFromBaidu%7Edefault-9.no_search_link  
高通msm8916 gpio笔记(基于设备树)  
https://blog.csdn.net/hm131415/article/details/54377549?spm=1001.2101.3001.6650.16&utm_medium=distribute.pc_relevant.none-task-blog-2%7Edefault%7EBlogCommendFromBaidu%7Edefault-16.no_search_link&depth_1-utm_source=distribute.pc_relevant.none-task-blog-2%7Edefault%7EBlogCommendFromBaidu%7Edefault-16.no_search_link  
高通 msm平台GPIO相关的device tree设置  
https://blog.csdn.net/viewsky11/article/details/53402536?spm=1001.2101.3001.6650.1&utm_medium=distribute.pc_relevant.none-task-blog-2%7Edefault%7ECTRLIST%7Edefault-1.no_search_link&depth_1-utm_source=distribute.pc_relevant.none-task-blog-2%7Edefault%7ECTRLIST%7Edefault-1.no_search_link  
配置学习总结高通平台GPIO  
https://blog.csdn.net/Joymine/article/details/48161895?spm=1001.2101.3001.6650.1&utm_medium=distribute.pc_relevant.none-task-blog-2%7Edefault%7ECTRLIST%7Edefault-1.no_search_link&depth_1-utm_source=distribute.pc_relevant.none-task-blog-2%7Edefault%7ECTRLIST%7Edefault-1.no_search_link  
GPIO中断唤醒系统调试方法  
https://blog.csdn.net/jlgcumt/article/details/110480062?spm=1001.2101.3001.6650.4&utm_medium=distribute.pc_relevant.none-task-blog-2%7Edefault%7ECTRLIST%7Edefault-4.no_search_link&depth_1-utm_source=distribute.pc_relevant.none-task-blog-2%7Edefault%7ECTRLIST%7Edefault-4.no_search_link  
Linux休眠后开启中断的方法及中断唤醒过程  
https://blog.csdn.net/mike8825/article/details/98473014  
Android系统下如何通过外设实现GPIO中断触发调用Android程序执行  
https://blog.csdn.net/a499957739/article/details/104425753  
配置学习总结高通平台GPIO  
https://blog.csdn.net/Joymine/article/details/48161895  
Android GPIO 控制方案  
https://blog.csdn.net/WXXGoodJob/article/details/90599925  
android 上层如何控制GPIO  
https://blog.csdn.net/prike/article/details/53216954   
[RK3288]LED亮灯GPIO驱动编写及dts文件架构介绍(基于android8.1使用android studio3.6开发)  
https://blog.csdn.net/a812417530/article/details/107004198  

Android(Linux)控制GPIO的方法及实时性分析  
https://www.cnblogs.com/we-hjb/p/5859479.html  
Android(Linux)控制GPIO方法二  
https://www.cnblogs.com/we-hjb/p/5903366.html  
Android 驱动 (一) GPIO  
https://www.cnblogs.com/tlnshuju/p/7028985.html  

报错

今天在引入 jdsp 这个库是,直接使用 implementation 'com.github.psambit9791:jdsp:1.0.0',结果 androidstudio 报错如下:

Duplicate class org.apache.maven.surefire.report.SafeThrowable found in modules jetified-common-java5-2.19.1 (org.apache.maven.surefire:common-java5:2.19.1) and jetified-surefire-api-2.19.1 (org.apache.maven.surefire:surefire-api:2.19.1)
Duplicate class org.apache.maven.surefire.report.StackTraceWriter found in modules jetified-common-java5-2.19.1 (org.apache.maven.surefire:common-java5:2.19.1) and jetified-surefire-api-2.19.1 (org.apache.maven.surefire:surefire-api:2.19.1)

解决

经过搜索,实验,解决方法在 build.gradle 中修改如下:

android {
...
    packagingOptions {
        exclude 'META-INF/DEPENDENCIES'
        exclude 'META-INF/LICENSE.md'
        exclude 'META-INF/LICENSE-notice.md'
    }

}

dependencies {
...
    implementation('com.github.psambit9791:jdsp:1.0.0') {
        exclude group: 'org.apache.maven.surefire', module: 'common-java5'
        exclude group: 'org.apache.maven.surefire', module: 'surefire-api'
    }

}

参考:

Duplicate class SafeThrowable or StackTraceWriter #11
https://github.com/psambit9791/jDSP/issues/11
Dependency resolution error #5
https://github.com/psambit9791/jDSP/issues/5

查看具体键值

kernel/msm-4.9/include/uapi/linux/input-event-codes.hframeworks/base/data/keyboards/Generic.kl 这个里面都可以看到 home 对应的是 172.

修改 dtsi

vim kernel/msm-4.9/arch/arm64/boot/dts/qcom/sq808-evk/qm215-qrd.dtsi

&soc {
        gpio_keys {

                home {
                        label = "home";
                        gpios = <&tlmm 127 0x1>;
                        linux,input-type = <1>;
                        linux,code = <172>;
                        debounce-interval = <15>;
                        linux,can-disable;
                        gpio-key,wakeup;
                };

        };
}

设置开机唤醒

vim frameworks/base/core/java/android/view/KeyEvent.java

    /** @hide */
    public static final boolean isWakeKey(int keyCode) {
        switch (keyCode) {
            case KeyEvent.KEYCODE_BACK:
            case KeyEvent.KEYCODE_MENU:
            case KeyEvent.KEYCODE_WAKEUP:
            case KeyEvent.KEYCODE_PAIRING:
            case KeyEvent.KEYCODE_STEM_1:
            case KeyEvent.KEYCODE_STEM_2:
            case KeyEvent.KEYCODE_STEM_3:
            case KeyEvent.KEYCODE_HOME:
                return true;
        }
        return false;
    }

参考:

Android添加一个新的按键
https://blog.csdn.net/ccskyer/article/details/10226807?utm_medium=distribute.pc_relevant.none-task-blog-2~default~baidujs_title~default-1.no_search_link&spm=1001.2101.3001.4242.2

android添加按键(二) 添加按键流程、出现问题
https://blog.csdn.net/lintao8613/article/details/82378798?utm_medium=distribute.pc_relevant.none-task-blog-2~default~baidujs_title~default-0.no_search_link&spm=1001.2101.3001.4242.1

Android 10 新增物理按键
https://blog.csdn.net/a546036242/article/details/121012512?spm=1001.2101.3001.6650.1&utm_medium=distribute.pc_relevant.none-task-blog-2%7Edefault%7ECTRLIST%7Edefault-1.no_search_link&depth_1-utm_source=distribute.pc_relevant.none-task-blog-2%7Edefault%7ECTRLIST%7Edefault-1.no_search_link

新增物理按键处理流程-Android
https://blog.csdn.net/qq_34211365/article/details/103169774?spm=1001.2101.3001.6650.1&utm_medium=distribute.pc_relevant.none-task-blog-2%7Edefault%7ECTRLIST%7Edefault-1.no_search_link&depth_1-utm_source=distribute.pc_relevant.none-task-blog-2%7Edefault%7ECTRLIST%7Edefault-1.no_search_link

android8.1 添加物理按键流程
https://blog.csdn.net/tt11212/article/details/87608373

Android 10.0 framework层KeyEvent按键添加流程
https://blog.csdn.net/baidu_41666295/article/details/120262180?spm=1001.2101.3001.6650.13&utm_medium=distribute.pc_relevant.none-task-blog-2%7Edefault%7EOPENSEARCH%7Edefault-13.no_search_link&depth_1-utm_source=distribute.pc_relevant.none-task-blog-2%7Edefault%7EOPENSEARCH%7Edefault-13.no_search_link

Linux下的按键驱动
https://blog.csdn.net/mike8825/article/details/51672975?spm=1001.2101.3001.6650.3&utm_medium=distribute.pc_relevant.none-task-blog-2%7Edefault%7ECTRLIST%7Edefault-3.no_search_link&depth_1-utm_source=distribute.pc_relevant.none-task-blog-2%7Edefault%7ECTRLIST%7Edefault-3.no_search_link

Android Q 按键添加流程详解
https://blog.csdn.net/wjky2014/article/details/111351038?spm=1001.2101.3001.6650.8&utm_medium=distribute.pc_relevant.none-task-blog-2%7Edefault%7EOPENSEARCH%7Edefault-8.no_search_link&depth_1-utm_source=distribute.pc_relevant.none-task-blog-2%7Edefault%7EOPENSEARCH%7Edefault-8.no_search_link

Android下添加自定义按键值
https://blog.csdn.net/u012966861/article/details/77969153?spm=1001.2101.3001.6650.3&utm_medium=distribute.pc_relevant.none-task-blog-2%7Edefault%7ECTRLIST%7Edefault-3.no_search_link&depth_1-utm_source=distribute.pc_relevant.none-task-blog-2%7Edefault%7ECTRLIST%7Edefault-3.no_search_link

Android键值添加和调试
https://blog.csdn.net/u013894427/article/details/78088260?spm=1001.2101.3001.6650.2&utm_medium=distribute.pc_relevant.none-task-blog-2%7Edefault%7ECTRLIST%7Edefault-2.no_search_link&depth_1-utm_source=distribute.pc_relevant.none-task-blog-2%7Edefault%7ECTRLIST%7Edefault-2.no_search_link

安卓添加按键流程
https://blog.csdn.net/qq_50764711/article/details/111352245?utm_medium=distribute.pc_relevant.none-task-blog-2~default~baidujs_title~default-4.no_search_link&spm=1001.2101.3001.4242.3

添加按键
https://blog.csdn.net/qq_20395637/article/details/102777378?spm=1001.2101.3001.6650.1&utm_medium=distribute.pc_relevant.none-task-blog-2%7Edefault%7ECTRLIST%7Edefault-1.no_search_link&depth_1-utm_source=distribute.pc_relevant.none-task-blog-2%7Edefault%7ECTRLIST%7Edefault-1.no_search_link

增加或修改(键盘)按键
https://blog.csdn.net/weixin_38451161/article/details/80291106?spm=1001.2101.3001.6650.1&utm_medium=distribute.pc_relevant.none-task-blog-2%7Edefault%7ECTRLIST%7Edefault-1.no_search_link&depth_1-utm_source=distribute.pc_relevant.none-task-blog-2%7Edefault%7ECTRLIST%7Edefault-1.no_search_link

android定制化软件修改或添加按键驱动的核心操作步骤讲解
https://blog.csdn.net/acm2008/article/details/7065546?spm=1001.2101.3001.6650.1&utm_medium=distribute.pc_relevant.none-task-blog-2%7Edefault%7ECTRLIST%7Edefault-1.no_search_link&depth_1-utm_source=distribute.pc_relevant.none-task-blog-2%7Edefault%7ECTRLIST%7Edefault-1.no_search_link

安卓添加按键驱动
https://blog.csdn.net/jaych/article/details/38065497

android添加按键驱动,android按键驱动开发实例2(增加一个新按键)
https://blog.csdn.net/weixin_33379878/article/details/117618160?spm=1001.2101.3001.6650.2&utm_medium=distribute.pc_relevant.none-task-blog-2%7Edefault%7ECTRLIST%7Edefault-2.no_search_link&depth_1-utm_source=distribute.pc_relevant.none-task-blog-2%7Edefault%7ECTRLIST%7Edefault-2.no_search_link

android系统移植之按键驱动篇
https://blog.csdn.net/armeasy/article/details/6713642?spm=1001.2101.3001.6650.10&utm_medium=distribute.pc_relevant.none-task-blog-2%7Edefault%7ECTRLIST%7Edefault-10.no_search_link&depth_1-utm_source=distribute.pc_relevant.none-task-blog-2%7Edefault%7ECTRLIST%7Edefault-10.no_search_link

Android 增加(键盘)按键
https://www.cnblogs.com/dyufei/p/6612790.html

Android系统input按键处理流程(从驱动到framework)
https://blog.csdn.net/jwq2011/article/details/51234811?spm=1001.2101.3001.6650.9&utm_medium=distribute.pc_relevant.none-task-blog-2%7Edefault%7EBlogCommendFromBaidu%7Edefault-9.no_search_link&depth_1-utm_source=distribute.pc_relevant.none-task-blog-2%7Edefault%7EBlogCommendFromBaidu%7Edefault-9.no_search_link

Android下添加新的自定义键值和按键处理流程
https://blog.csdn.net/tkwxty/article/details/43338921?spm=1001.2101.3001.6650.8&utm_medium=distribute.pc_relevant.none-task-blog-2%7Edefault%7EBlogCommendFromBaidu%7Edefault-8.no_search_link&depth_1-utm_source=distribute.pc_relevant.none-task-blog-2%7Edefault%7EBlogCommendFromBaidu%7Edefault-8.no_search_link

android gpio-keys 按键驱动分析(一) key layout文件
https://blog.csdn.net/clam_zxf/article/details/73849413?utm_medium=distribute.pc_relevant.none-task-blog-2~default~baidujs_title~default-5.no_search_link&spm=1001.2101.3001.4242.4

[RK3288][Android6.0] 系统按键驱动流程分析
https://blog.csdn.net/kris_fei/article/details/77894406?spm=1001.2101.3001.6650.1&utm_medium=distribute.pc_relevant.none-task-blog-2%7Edefault%7ECTRLIST%7Edefault-1.no_search_link&depth_1-utm_source=distribute.pc_relevant.none-task-blog-2%7Edefault%7ECTRLIST%7Edefault-1.no_search_link

android 按键 驱动程序,android按键驱动研究.pdf
https://blog.csdn.net/weixin_42551260/article/details/117577179?spm=1001.2101.3001.6650.1&utm_medium=distribute.pc_relevant.none-task-blog-2%7Edefault%7ECTRLIST%7Edefault-1.no_search_link&depth_1-utm_source=distribute.pc_relevant.none-task-blog-2%7Edefault%7ECTRLIST%7Edefault-1.no_search_link

Android System 自定义KEY事件及驱动
https://blog.csdn.net/qq_31829527/article/details/105954489

Android按键消息处理
https://blog.csdn.net/peng_cao/article/details/8627369?spm=1001.2101.3001.6650.1&utm_medium=distribute.pc_relevant.none-task-blog-2%7Edefault%7EBlogCommendFromBaidu%7Edefault-1.no_search_link&depth_1-utm_source=distribute.pc_relevant.none-task-blog-2%7Edefault%7EBlogCommendFromBaidu%7Edefault-1.no_search_link

android 按键处理流程,Android系统input按键处理流程(从驱动到framework)
https://blog.csdn.net/weixin_30727701/article/details/117601107?spm=1001.2101.3001.6650.1&utm_medium=distribute.pc_relevant.none-task-blog-2%7Edefault%7ECTRLIST%7Edefault-1.no_search_link&depth_1-utm_source=distribute.pc_relevant.none-task-blog-2%7Edefault%7ECTRLIST%7Edefault-1.no_search_link

2021-1-4 Android 添加新的键值并上报从驱动到上层
https://blog.csdn.net/qq_37858386/article/details/112170827

aw9523芯片按键失效问问题分析
https://ciellee.blog.csdn.net/article/details/101553530

Android中对标准内核的按键映射以及按键驱动
https://blog.csdn.net/xiaobaiing/article/details/45565123?utm_medium=distribute.pc_relevant.none-task-blog-2~default~baidujs_title~default-0.no_search_link&spm=1001.2101.3001.4242.1

kernel按键上报键值的映射
https://blog.csdn.net/u013986340/article/details/101022488

Android系统按键上报流程及其转化
https://blog.csdn.net/weixin_44008788/article/details/118755916

AndroidR Input子系统(5)解析“.kl“文件
https://blog.csdn.net/qq_34211365/article/details/109687690

Android记录输入事件研究
https://blog.csdn.net/infsafe/article/details/6120280?spm=1001.2101.3001.6650.1&utm_medium=distribute.pc_relevant.none-task-blog-2%7Edefault%7ECTRLIST%7Edefault-1.no_search_link&depth_1-utm_source=distribute.pc_relevant.none-task-blog-2%7Edefault%7ECTRLIST%7Edefault-1.no_search_link

Android 按键流程分析笔记
https://blog.csdn.net/luozirong/article/details/52799745?spm=1001.2101.3001.6650.17&utm_medium=distribute.pc_relevant.none-task-blog-2%7Edefault%7EBlogCommendFromBaidu%7Edefault-17.no_search_link&depth_1-utm_source=distribute.pc_relevant.none-task-blog-2%7Edefault%7EBlogCommendFromBaidu%7Edefault-17.no_search_link

Android按键事件处理流程 KeyEvent
https://blog.csdn.net/pengjin1985/article/details/39233011?spm=1001.2101.3001.6650.16&utm_medium=distribute.pc_relevant.none-task-blog-2%7Edefault%7EBlogCommendFromBaidu%7Edefault-16.no_search_link&depth_1-utm_source=distribute.pc_relevant.none-task-blog-2%7Edefault%7EBlogCommendFromBaidu%7Edefault-16.no_search_link

Android返回键处理、任务和home键处理
https://blog.csdn.net/HUandroid/article/details/72733494?spm=1001.2101.3001.6650.15&utm_medium=distribute.pc_relevant.none-task-blog-2%7Edefault%7EBlogCommendFromBaidu%7Edefault-15.no_search_link&depth_1-utm_source=distribute.pc_relevant.none-task-blog-2%7Edefault%7EBlogCommendFromBaidu%7Edefault-15.no_search_link

Android平台Home键处理机制
https://blog.csdn.net/galensphang/article/details/9821355?spm=1001.2101.3001.6650.13&utm_medium=distribute.pc_relevant.none-task-blog-2%7Edefault%7EBlogCommendFromBaidu%7Edefault-13.no_search_link&depth_1-utm_source=distribute.pc_relevant.none-task-blog-2%7Edefault%7EBlogCommendFromBaidu%7Edefault-13.no_search_link

Android8.0 按键事件处理流程
https://blog.csdn.net/w1070216393/article/details/84261996?spm=1001.2101.3001.6650.14&utm_medium=distribute.pc_relevant.none-task-blog-2%7Edefault%7EBlogCommendFromBaidu%7Edefault-14.no_search_link&depth_1-utm_source=distribute.pc_relevant.none-task-blog-2%7Edefault%7EBlogCommendFromBaidu%7Edefault-14.no_search_link

android长按home键流程
https://blog.csdn.net/harhy/article/details/8724779?spm=1001.2101.3001.6650.10&utm_medium=distribute.pc_relevant.none-task-blog-2%7Edefault%7EBlogCommendFromBaidu%7Edefault-10.no_search_link&depth_1-utm_source=distribute.pc_relevant.none-task-blog-2%7Edefault%7EBlogCommendFromBaidu%7Edefault-10.no_search_link

Android源码解析(二十七)-->HOME事件流程
https://blog.csdn.net/qq_23547831/article/details/51475929?spm=1001.2101.3001.6650.2&utm_medium=distribute.pc_relevant.none-task-blog-2%7Edefault%7ECTRLIST%7Edefault-2.no_search_link&depth_1-utm_source=distribute.pc_relevant.none-task-blog-2%7Edefault%7ECTRLIST%7Edefault-2.no_search_link

Android源码解析(二十八)-->电源开关机按键事件流程
https://blog.csdn.net/qq_23547831/article/details/51487978?utm_medium=distribute.pc_relevant.none-task-blog-2~default~baidujs_title~default-0.no_search_link&spm=1001.2101.3001.4242.1

Android源码基础解析之电源开关机按键事件流程
https://blog.csdn.net/qq_35559358/article/details/78647031?utm_medium=distribute.pc_relevant.none-task-blog-2~default~baidujs_title~default-5.no_search_link&spm=1001.2101.3001.4242.4

android 捕获home键
https://blog.csdn.net/zhzhyang0313/article/details/6995553?spm=1001.2101.3001.6650.1&utm_medium=distribute.pc_relevant.none-task-blog-2%7Edefault%7ECTRLIST%7Edefault-1.no_search_link&depth_1-utm_source=distribute.pc_relevant.none-task-blog-2%7Edefault%7ECTRLIST%7Edefault-1.no_search_link

Android捕获home按键 以及实体键捕获
https://blog.csdn.net/qwertyuiop159158/article/details/52900065?utm_medium=distribute.pc_relevant.none-task-blog-2~default~baidujs_title~default-1.no_search_link&spm=1001.2101.3001.4242.2

Android 底层按键获取
https://blog.csdn.net/linan_nwu/article/details/8222011?spm=1001.2101.3001.6650.1&utm_medium=distribute.pc_relevant.none-task-blog-2%7Edefault%7EBlogCommendFromBaidu%7Edefault-1.no_search_link&depth_1-utm_source=distribute.pc_relevant.none-task-blog-2%7Edefault%7EBlogCommendFromBaidu%7Edefault-1.no_search_link

Android 读取按键及Touch Panel
https://blog.csdn.net/hgl868/article/details/6860116

高通驱动实现 GPIO 中断上报键值
https://ciellee.blog.csdn.net/article/details/101312350?spm=1001.2101.3001.6650.3&utm_medium=distribute.pc_relevant.none-task-blog-2%7Edefault%7ECTRLIST%7Edefault-3.no_search_link&depth_1-utm_source=distribute.pc_relevant.none-task-blog-2%7Edefault%7ECTRLIST%7Edefault-3.no_search_link

AndroidQ 打通应用层到HAL层---(HAL模块实现)
https://blog.csdn.net/qq_34211365/article/details/105492973

Android源码解析(三十)-->触摸事件分发流程
https://blog.csdn.net/qq_23547831/article/details/51530671?utm_medium=distribute.pc_relevant.none-task-blog-2~default~baidujs_title~default-12.no_search_link&spm=1001.2101.3001.4242.7

android实现home键功能
https://blog.csdn.net/twtje0304_01/article/details/77914161#:~:text=Android%20%E7%9A%84%20Home%20%E6%8C%89%20%E9%94%AE%E5%8A%9F%E8%83%BD%20%E6%98%AF%E5%B0%86%E6%A1%8C%E9%9D%A2Activity%E6%8B%89%E5%88%B0Activity%E6%A0%88%E9%A1%B6%EF%BC%8C%20%E6%98%BE%E7%A4%BA%20%E7%B3%BB%E7%BB%9F%E6%A1%8C%E9%9D%A2%EF%BC%8C%E4%BB%A5%E6%AD%A4%E6%9D%A5,%28%29%3B%20intent.addCategory%20%28Intent.CATEGORY_%20HOME%29%3B%20intent.setAction%20%28Intent.ACTION_MAIN%29%3B%20startActivity%20%28in

Android HOME键那些事
https://blog.csdn.net/imyfriend/article/details/8293399
Android 按下Home键
https://blog.csdn.net/greatdaocaoren/article/details/75009580
Android 监听Home键
https://www.jianshu.com/p/d215bc8e1b3d
【Android】Android处理Home键方法小结
https://www.cnblogs.com/rayray/p/3408179.html

直接使用 sql 语句

        SQLiteDatabase db = analysisDBOpenHelper.getReadableDatabase();
        String find = "select count(*) from " + "info";
        Cursor cursor = db.rawQuery(find, null);
        cursor.moveToFirst();
        return cursor.getLong(0);

使用接口

return sqLiteDatabase.query(TABLENAME, null, null, null, null, null, null).getCount();

参考:

sqlite的rawQuery和query的一个问题总结
https://blog.csdn.net/HarryWeasley/article/details/40212127
sqlite数据库的问题
https://bbs.csdn.net/topics/390907936?page=1#post-398362317

问题现象

  • 未插耳机右上角有耳机图标
  • 设置内调节 mediacall volume 没有声音输出,但是拉动其他 ringalarm 有声音输出;确定音源文件也是有的。

原因

可以了解设置内的每个音量条的策略都是不一样的,ringalarm 都是默认强制从喇叭输出,但是 media 的插入耳机后则是由耳机输出,因此就出现以上问题了。

解决方法

所以该问题的实际原因就是不插耳机出现耳机图标的问题,只要让正常情况下使用扬声器输出,而不是耳机输出即可。

kernel/msm-4.9/arch/arm64/boot/dts/qcom/sq808-evk/qm215-audio.dtsi

qcom,msm-mbhc-hphl-swh = <1>;
qcom,msm-mbhc-gnd-swh = <0>;

packages/apps/Settings/res/values-zh-rCN/arrays.xml

@@ -37,6 +37,7 @@
     <item msgid="2693197579676214668">"5 分钟"</item>
     <item msgid="1955784331962974678">"10 分钟"</item>
     <item msgid="5578717731965793584">"30 分钟"</item>
+    <item msgid="1781492122915870416">"永不休眠"</item>
   </string-array>
   <string-array name="dream_timeout_entries">
     <item msgid="1999412608953538363">"永不"</item>

packages/apps/Settings/res/values/arrays.xml

@@ -48,6 +48,7 @@
         <item>5 minutes</item>
         <item>10 minutes</item>
         <item>30 minutes</item>
+        <item>Never</item>
     </string-array>

     <!-- Do not translate. -->
@@ -66,6 +67,8 @@
         <item>600000</item>
         <!-- Do not translate. -->
         <item>1800000</item>
+        <!-- Do not translate. -->
+        <item>2147483647</item>
     </string-array>

     <!-- Display settings.  The delay in inactivity before the dream is shown. These are shown in a list dialog. -->

packages/apps/Settings/src/com/android/settings/display/TimeoutPreferenceController.java

@@ -85,8 +85,10 @@ public class TimeoutPreferenceController extends AbstractPreferenceController im
     @Override
     public boolean onPreferenceChange(Preference preference, Object newValue) {
         try {
-            int value = Integer.parseInt((String) newValue);
-            Settings.System.putInt(mContext.getContentResolver(), SCREEN_OFF_TIMEOUT, value);
+            //+Begin mantis-66494 Modified for never goto sleep by james.zheng 2020-12-24
+            long value = Integer.parseInt((String) newValue);
+            Settings.System.putLong(mContext.getContentResolver(), SCREEN_OFF_TIMEOUT, value);
+            //-End mantis-66494 Modified for never goto sleep by james.zheng 2020-12-24
             updateTimeoutPreferenceDescription((TimeoutListPreference) preference, value);
         } catch (NumberFormatException e) {
             Log.e(TAG, "could not persist screen timeout setting", e);
@@ -120,9 +122,15 @@ public class TimeoutPreferenceController extends AbstractPreferenceController im
         } else {
             final CharSequence timeoutDescription = getTimeoutDescription(
                     currentTimeout, entries, values);
+            //+Begin mantis-66494 Modified for never goto sleep by james.zheng 2020-12-24
+            if(currentTimeout == 2147483647){
+                summary = timeoutDescription.toString();
+            } else {
+            //-End mantis-66494 Modified for never goto sleep by james.zheng 2020-12-24
             summary = timeoutDescription == null
                     ? ""
                     : mContext.getString(R.string.screen_timeout_summary, timeoutDescription);
+            }
         }
         preference.setSummary(summary);
     }

准备好开机 logo 的 png 图片。

最好是同分辨率的图片,否则可能背景色会变为白色。

制作 splash.img

  1. 把 png 放到 device/qcom/common/display/logo 里面。
  2. python ./logo_gen.py logo_xyz.png 生成 splash.img

烧录 开机 logo

  1. adb root
  2. adb reboot bootloader
  3. fastboot flash splash .\splash.img
  4. fastboot reboot

参考:

https://blog.csdn.net/u014296677/article/details/78423137
https://blog.csdn.net/csdnxialei/article/details/87461635
https://blog.csdn.net/qq_27061049/article/details/117752715
https://blog.csdn.net/yandongqiangZHRJ/article/details/8585273
https://www.cnblogs.com/zzb-Dream-90Time/p/7403098.html

引脚定义

接口 公头 母座 作用
1 DCD DCD 载波检测
2 RXD TXD 终端 -> 计算机
3 TXD RXD 计算机 -> 终端
4 DTR DTR 数据终端准备好
5 GND GND 信号地线
6 DSR DSR 数据准备好
7 RTS RTS 请求发送
8 CTS CTS 清楚发送
9 RI RI 振铃指示

数据传输方向

公头:

  • RXD: 终端 -> 计算机
  • TXD: 计算机 -> 终端

参考:

https://blog.csdn.net/zhenguo26/article/details/84064573

RS232 RS485 串口 电平标准
https://blog.csdn.net/lijiuyangzilsc/article/details/48599745

什么是RS232电平?什么是TTL电平?
https://www.jianshu.com/p/a942e8090e01

DB9串口线定义的解析
https://zhuanlan.zhihu.com/p/361011144