kernel:4.4
systerm:buildroot
soc:rk3288
ic:CY8C9540A
矩阵键盘的编程原理,行列扫描:
行列扫描的话,就是一开始按照原理图让GPIO口高4位输出高电平,低4位输出低电平,若这4行按键里,有按键按下了,那么那一行按键对应的io的电平就会被拉低,我们就可以知道按键的行坐标.获取按键列坐标的方法也是类似的,就是一开始让p1口高4位输出低电平,低4位输出高电平,若这4列按键里,有按键按下了,那么那一列按键对应的io的电平就会被拉低,我们就可以知道按键的行列坐标。
menuconconfig location:
Symbol: KEYBOARD_MATRIX [=y]
Type : tristate
Prompt: GPIO driven matrix keypad support
Location:
-> Device Drivers
-> Input device support
-> Generic input layer (needed for keyboard, mouse, ...) (INPUT [=y])
-> Keyboards (INPUT_KEYBOARD [=y])
Defined at drivers/input/keyboard/Kconfig:269
Depends on: !UML && INPUT [=y] && INPUT_KEYBOARD [=y] && (GPIOLIB [=y] || COMPILE_TEST [=n])
Selects: INPUT_MATRIXKMAP [=y]
source files:
kernel\drivers\input\keyboard\matrix_keypad.c
下面我们来看看设备树的配置:
matrix_keypad: matrix_keypad {
compatible = "gpio-matrix-keypad";
pinctrl-names = "default";
//pinctrl-0 = <&matrix_keypad_pins>;
debounce-delay-ms = <5>;
col-scan-delay-us = <5>;
row-gpios = <
&gpio2 15 GPIO_ACTIVE_HIGH
&gpio2 14 GPIO_ACTIVE_HIGH
&gpio2 13 GPIO_ACTIVE_HIGH
&gpio2 12 GPIO_ACTIVE_HIGH
&gpio2 11 GPIO_ACTIVE_HIGH
&gpio2 10 GPIO_ACTIVE_HIGH
&gpio2 9 GPIO_ACTIVE_HIGH
>;
col-gpios = <
&gpio8 8 GPIO_ACTIVE_HIGH
&gpio8 7 GPIO_ACTIVE_HIGH
&gpio8 6 GPIO_ACTIVE_HIGH
&gpio8 3 GPIO_ACTIVE_HIGH
&gpio8 2 GPIO_ACTIVE_HIGH
&gpio8 1 GPIO_ACTIVE_HIGH
&gpio8 0 GPIO_ACTIVE_HIGH
>;
linux,keymap = <
MATRIX_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(0x5, 0x6, KEY_F5)
MATRIX_KEY(0x6, 0x1, KEY_F6)
MATRIX_KEY(0x6, 0x2, KEY_F7)
MATRIX_KEY(0x6, 0x3, KEY_F8)
MATRIX_KEY(0x6, 0x4, KEY_F9)
MATRIX_KEY(0x6, 0x5, KEY_F10)
MATRIX_KEY(0x6, 0x6, KEY_F11)
>;
};
row-gpios:行坐标对应的GPIO,
col-gpios:列坐标对应的GPIO,
keymap:坐标值
键码值对应:kernel\include\dt-bindings\input\linux-event-codes.h
下面是驱动代码: