一、配置Linux内核KEY驱动
1、开启 KEY 驱动
Device Drivers
--》Input device support
--》Generic input layer (needed for keyboard, mouse, ...)
--》Keyboards
--》GPIO Buttons
2、KEY 配置说明
开启 Linux 内核中 GPIO Buttons 项后,Linux 内核配置文件中 CONFIG_KEYBOARD_GPIO 将被开启。
二、确定Linux内核中源码
三、Linux 内核中 KEY 源码分析
待完成……
四、按键硬件原理
i.MX 6ULL 驱动开发 九:中断(非阻塞处理)_lqonlylove的博客-CSDN博客
五、添加设备树
1、设备树添加说明
Linux 驱动开发 六十:《input.txt》翻译_lqonlylove的博客-CSDN博客
Linux 驱动开发 六十一:《gpio-keys.txt》翻译_lqonlylove的博客-CSDN博客
2、添加设备树
gpio-keys {
compatible = "gpio-keys";
#address-cells = <1>;
#size-cells = <0>;
autorepeat;
pinctrl-names = "default";
pinctrl-0 = <&pinctrl_key>;
key0 {
label = "GPIO Key Enter";
linux,code = <KEY_ENTER>;
gpios = <&gpio1 18 GPIO_ACTIVE_LOW>;
interrupt-parent = <&gpio1>;
interrupts = <18 IRQ_TYPE_EDGE_FALLING>;
};
};
3、测试
# pwd
/root
# cd /proc/
# ls
1 4 62 execdomains net
10 40 65 fb pagetypeinfo
105 41 66 filesystems partitions
11 46 7 fs self
12 47 8 interrupts softirqs
13 48 89 iomem stat
132 49 9 ioports swaps
14 5 93 irq sys
142 50 asound kallsyms sysrq-trigger
15 51 buddyinfo key-users sysvipc
16 52 bus keys thread-self
17 53 cgroups kmsg timer_list
18 54 cmdline kpagecount tty
19 55 consoles kpageflags uptime
2 56 cpu loadavg version
20 57 cpuinfo locks vmallocinfo
21 58 crypto meminfo vmstat
22 59 device-tree misc zoneinfo
23 6 devices modules
24 60 diskstats mounts
3 61 driver mtd
# cd device-tree/
# ls
#address-cells key
#size-cells leds
aliases memory
alphaled model
backlight name
beep pxp_v4l2
chosen regulators
clocks reserved-memory
compatible sii902x-reset
cpus soc
gpio-keys sound
gpioled spi4
interrupt-controller@00a01000
# cd gpio-keys/
# ls
#address-cells autorepeat key0 pinctrl-0
#size-cells compatible name pinctrl-names
# cat name
gpio-keys#
# cat compatible
gpio-keys#
#
# cd key0/
# ls
gpios interrupts linux,code
interrupt-parent label name
# cat label
GPIO Key Enter#
# cat name
key0#
#
六、测试
# cat /proc/bus/input/devices
I: Bus=0019 Vendor=0000 Product=0000 Version=0000
N: Name="20cc000.snvs:snvs-powerkey"
P: Phys=snvs-pwrkey/input0
S: Sysfs=/devices/platform/soc/2000000.aips-bus/20cc000.snvs/20cc000.snvs:snvs-powerkey/input/input0
U: Uniq=
H: Handlers=kbd event0
B: PROP=0
B: EV=3
B: KEY=100000 0 0 0
I: Bus=0018 Vendor=0000 Product=0000 Version=0000
N: Name="EP0820M09"
P: Phys=
S: Sysfs=/devices/platform/soc/2100000.aips-bus/21a4000.i2c/i2c-1/1-0038/input/input1
U: Uniq=
H: Handlers=js0 event1
B: PROP=0
B: EV=9
B: ABS=2608000 3
I: Bus=0019 Vendor=0001 Product=0001 Version=0100
N: Name="gpio-keys"
P: Phys=gpio-keys/input0
S: Sysfs=/devices/platform/gpio-keys/input/input2
U: Uniq=
H: Handlers=kbd event2
B: PROP=0
B: EV=100003
B: KEY=10000000
#
# hexdump /dev/input/event2
0000000 02cd 0000 18a6 0007 0001 001c 0001 0000
0000010 02cd 0000 18a6 0007 0000 0000 0000 0000
0000020 02cd 0000 d7ba 0009 0001 001c 0000 0000
0000030 02cd 0000 d7ba 0009 0000 0000 0000 0000
0000040 02ce 0000 9ad6 000a 0001 001c 0001 0000
0000050 02ce 0000 9ad6 000a 0000 0000 0000 0000
0000060 02ce 0000 e4b4 000c 0001 001c 0000 0000
0000070 02ce 0000 e4b4 000c 0000 0000 0000 0000
0000080 02cf 0000 ed34 0008 0001 001c 0001 0000
0000090 02cf 0000 ed34 0008 0000 0000 0000 0000
00000a0 02cf 0000 852d 000b 0001 001c 0000 0000
00000b0 02cf 0000 852d 000b 0000 0000 0000 0000
^C
#