1. 程式人生 > >[Linux驅動煉成記] 08-GPIO按鍵

[Linux驅動煉成記] 08-GPIO按鍵

這裡以Amlogic A113為例

按鍵DTS配置

arch/arm64/boot/dts/amlogic/xxx.dts gpio key dts 配置 :

	gpio_keypad{
		compatible = "amlogic, gpio_keypad";
		status = "disable";
		scan_period = <20>;
		key_num = <2>;
		key_name = "mute","Alexa_wakeup";
		key_code = <115 116>;
		key_pin = <&gpio GPIOZ_10 GPIO_ACTIVE_LOW>,
				<&gpio_ao GPIOAO_4 GPIO_ACTIVE_LOW>;
		interrupts = <0 70 1
				0 71 2>;
		interrupt-names = "irq_keyup", "irq_keydown";
	};
    // key_name:按鍵名稱
    // key_num:按鍵數量
    // key_code:按鍵上報值
    // key_pin:gpio配置
驅動原始檔路徑
//配置
arch/arm64/configs/meson64_smarthome_defconfig->CONFIG_AMLOGIC_GPIO_KEY=y

//gpio key驅動檔案路徑
drivers/amlogic/input/keyboard/adc_keypad.c

//按鍵定義

include/dt-bindings/input/linux-event-codes.h
開發板測試

驅動正常載入之後,進入檔案系統,檢視資訊

# cat /proc/bus/input/devices
I: Bus=0010 Vendor=0001 Product=0001 Version=0100
N: Name="gpio_keypad"
P: Phys=gpio_keypad/input0
S: Sysfs=/devices/platform/gpio_keypad/input/input0
U: Uniq=
H: Handlers=kbd event0 
B: PROP=0
B: EV=100003
B: KEY=1f80000 0 0 0

測試按鍵是否按下擡起1

//按下按鍵,會上報鍵值
 cat /dev/input/event0