7. 按键¶
LubanCat-RV06 板卡上有三个按键,分别是 reset
, recovery
, ADC
按键。
reset
: 仅有复位板卡的功能recovery
: 在板卡上电的时候按住recovery
按键,可以进入恢复模式,可以烧录固件。进入linux系统后可以作为其他按键使用,默认配置为volume+
按键。ADC
: 作为ADC按键使用,进入linux系统后默认配置为volume-
按键。
在本小节内容中,介绍怎么使用 recovery
和 ADC
按键。
7.1. evtest工具¶
linux系统中有一个工具 evtest
可以用来测试输入设备,可以用来测试按键。
1 | evtest
|
运行结果如下:
1 2 3 4 5 6 | # evtest
No device specified, trying to scan all of /dev/input/event*
Available devices:
/dev/input/event0: recovery-key
/dev/input/event1: adc-key
Select the device event number [0-1]:
|
可以看到有 recovery-key
和 adc-key
两个设备,分别对应 recovery
和 ADC
按键。
我们在命令行中输入0,读取 recovery-key
按键信息。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | # evtest
No device specified, trying to scan all of /dev/input/event*
Available devices:
/dev/input/event0: recovery-key
/dev/input/event1: adc-key
Select the device event number [0-1]: 0
Input driver version is 1.0.1
Input device ID: bus 0x19 vendor 0x1 product 0x1 version 0x100
Input device name: "recovery-key"
Supported events:
Event type 0 (EV_SYN)
Event type 1 (EV_KEY)
Event code 115 (KEY_VOLUMEUP)
Properties:
Testing ... (interrupt to exit)
|
可以看到
recovery-key
对应的是KEY_VOLUMEUP
,即volume+
按键。
按下并松开 recovery
按键,可以看到输出信息
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | # evtest
No device specified, trying to scan all of /dev/input/event*
Available devices:
/dev/input/event0: recovery-key
/dev/input/event1: adc-key
Select the device event number [0-1]: 0
Input driver version is 1.0.1
Input device ID: bus 0x19 vendor 0x1 product 0x1 version 0x100
Input device name: "recovery-key"
Supported events:
Event type 0 (EV_SYN)
Event type 1 (EV_KEY)
Event code 115 (KEY_VOLUMEUP)
Properties:
Testing ... (interrupt to exit)
Event: time 1739258561.998534, type 1 (EV_KEY), code 115 (KEY_VOLUMEUP), value 1
Event: time 1739258561.998534, -------------- SYN_REPORT ------------
Event: time 1739258562.205217, type 1 (EV_KEY), code 115 (KEY_VOLUMEUP), value 0
Event: time 1739258562.205217, -------------- SYN_REPORT ------------
|
可以看到
value 1
表示按下按键,value 0
表示松开按键。
7.2. dev接口¶
7.2.1. 查看按键设备¶
按键在设备树配置成按键后,会在 /dev/input/
目录下生成对应的设备节点。
1 | ls /dev/input/
|
结果如下:
1 2 3 | # ls /dev/input/
by-path event0 event1
#
|
可以看到有 event0
和 event1
两个设备节点。单凭设备节点无法区分是哪个按键。
使用下面命令可以查看 event0
和 event1
对应的按键。
1 | ls -l /dev/input/by-path/
|
运行结果:
1 2 3 4 | # ls -l /dev/input/by-path/
total 0
lrwxrwxrwx 1 root root 9 Feb 10 06:09 platform-recovery-key-event -> ../event0
lrwxrwxrwx 1 root root 9 Feb 10 06:09 platform-adc-key-event -> ../event1
|
可以看到 platform-recovery-key-event
对应 event0
, platform-adc-key-event
对应 event1
。
而 platform-recovery-key-event
对应的是 recovery
按键,
platform-adc-key-event
对应的是 ADC
按键。
7.2.2. 读取按键信息¶
这里以读取 recovery
按键为例,读取按键按下的信息。
需要使用下面命令获取按键信息
1 2 3 4 | # 读取按键信息
hexdump /dev/input/event0
# 然后按下recovery按键,然后松开
|
结果如下:
1 2 3 4 5 | # hexdump /dev/input/event0
0000000 f755 67aa 9842 0009 0001 0073 0001 0000
0000010 f755 67aa 9842 0009 0000 0000 0000 0000
0000020 f755 67aa bf53 000c 0001 0073 0000 0000
0000030 f755 67aa bf53 000c 0000 0000 0000 0000
|
可以看到按下按键后,会有一些信息输出。
分析
第一行: 0000000 f755 67aa 9842 0009 0001 0073 0001 0000
第一列是event事件序列号,
0000000
第2-5列是时间戳,
f755 67aa 9842 0009
第6-7列是事件类型,
0001 0073
,其中0001
表示按键事件,0073
表示按键值第8列是按键值,
0001
表示按下按键
第二行是 0000010 f755 67aa 9842 0009 0000 0000 0000 0000
是同步信息,可以忽略
第三行是 0000020 f755 67aa bf53 000c 0001 0073 0000 0000
第一列是event事件序列号,
0000020
第2-5列是时间戳,
f755 67aa bf53 000c
第6-7列是事件类型,
0001 0073
,其中0001
表示按键事件,0073
表示按键值第8列是按键值,
0000
表示松开按键
第四行是 0000030 f755 67aa bf53 000c 0000 0000 0000 0000
是同步信息,可以忽略
7.3. 更换按键值¶
可以修改设备树的ADC节点从而修改该按键的按键值。
这是默认的设备树配置:
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 | recovery-key {
compatible = "adc-keys";
io-channels = <&saradc 0>;
io-channel-names = "buttons";
poll-interval = <100>;
keyup-threshold-microvolt = <1800000>;
key {
label = "key_volumeup";
linux,code = <KEY_VOLUMEUP>;
press-threshold-microvolt = <0>;
};
};
adc-key {
compatible = "adc-keys";
io-channels = <&saradc 1>;
io-channel-names = "buttons";
poll-interval = <100>;
keyup-threshold-microvolt = <1800000>;
key {
label = "key_volumedown";
linux,code = <KEY_VOLUMEDOWN>;
press-threshold-microvolt = <0>;
};
};
|
主要修改两个地方:
label = "key_volumeup";
:将key_volumeup修改成其他的按键名称linux,code = <KEY_VOLUMEUP>;
:将KEY_VOLUMEUP修改成其他的按键值
按键值可以在SDK的该文件 sysdrv/source/kernel/include/uapi/linux/input-event-codes.h
翻阅。