700字范文,内容丰富有趣,生活中的好帮手!
700字范文 > -06-22 hi3516ev200 按键输入 gpio_key input 驱动 device tree 设备树方式

-06-22 hi3516ev200 按键输入 gpio_key input 驱动 device tree 设备树方式

时间:2018-09-09 02:44:27

相关推荐

-06-22 hi3516ev200 按键输入 gpio_key input 驱动 device tree 设备树方式

Linux device tree 基础知识不补充,自行查找。。。。。。

root@yex-Ubuntu:/home/work/hiSDK/hi3516ev200/hi3516/linux-4.9.y# ls Documentation/devicetree/bindings/input/gpio-keys.txt Documentation/devicetree/bindings/input/gpio-keys.txt

1.在内核文件目录下搜索关于HI3516EV200 的dts 文件:

arch/arm/boot/dts/

hi3516ev200-demb.dtb hi3516ev200-demb.dts hi3516ev200.dtsi

有一个*.dtb文件明显设备用到了device tree

2.添加gpio6.4 在hi3516ev200-demb.dts 文件中

20 /dts-v1/;21 #include "hi3516ev200.dtsi"22 23 / {24 model = "Hisilicon HI3516EV200 DEMO Board";25 compatible = "hisilicon,hi3516ev200";26 27 memory {28 device_type = "memory";29 reg = <0x40000000 0x20000000>;30 };31 ***32 gpio-keys {33 compatible = "gpio-keys";34 35 call {36label = "gpio-call";37linux,code = <0x101>;38gpios = <&gpio_chip6 4 0>;39debounce-interval = <200>;40 };41 42 };***43 44 };45 46 &uart0 {47 status = "okay";48 };

直接编译内核镜像 uImage 后下载到target板上运行,会看到

/sdcard/bin # cat /sys/firmware/devicetree/base/gpio-keys/call/label

gpio-call

/sdcard/bin #

证明添加成功。

3.在内核驱动drivers目录下找到一个用 input 驱动模式编写的gpio 驱动模板

drivers/input/keyboard/gpio_keys.c

将其copy在某个自建目录下/home/work,并在该目录下建立Makefile 文件,编辑内容:

ifneq ($(KERNELRELEASE),)obj-m:=gpio_keys.oelse#generate the pathCURRENT_PATH:=$(shell pwd)#the absolute path#LINUX_KERNEL_PATH:=/lib/modules/$(shell uname -r)/buildLINUX_KERNEL_PATH:=/home/work/hiSDK/hi3516ev200/hi3516/linux-4.9.yTOOLCHAIN="/opt/hisi-linux/x86-arm/arm-himix100-linux/bin/arm-himix100-linux-"#complie objectdefault:make -C $(LINUX_KERNEL_PATH) ARCH=arm CROSS_COMPILE=$(TOOLCHAIN) M=$(CURRENT_PATH) modulesclean:make -C $(LINUX_KERNEL_PATH) M=$(CURRENT_PATH) cleanendif

4.在gpio_keys.c中几乎无需修改,只要加入DBUG 的log测试下

make 建立驱动模块

gpio_keys.ko

root@yex-Ubuntu:/home/work/hiSDK/linux/IPC_APP/drv-module/gpio# make make -C /home/work/hiSDK/hi3516ev200/hi3516/linux-4.9.y ARCH=arm CROSS_COMPILE="/opt/hisi-linux/x86-arm/arm-himix100-linux/bin/arm-himix100-linux-" M=/home/work/hiSDK/linux/IPC_APP/drv-module/gpio modulesmake[1]: Entering directory '/home/work/hiSDK/hi3516ev200/hi3516/linux-4.9.y'CC [M] /home/work/hiSDK/linux/IPC_APP/drv-module/gpio/gpio_keys.oBuilding modules, stage 2.MODPOST 1 modulesLD [M] /home/work/hiSDK/linux/IPC_APP/drv-module/gpio/gpio_keys.komake[1]: Leaving directory '/home/work/hiSDK/hi3516ev200/hi3516/linux-4.9.y'

将驱动模块下载到target板上

~ # cd /sdcard//sdcard # cd bin//sdcard/bin # tftp -l gpio_keys.ko -r gpio_keys.ko -g 192.168.9.10 69gpio_keys.ko 100% |*******************************| 16516 0:00:00 ETA/sdcard/bin # insmod gpio_keys.ko Debug button->desc: gpio-call, gpio: 52, code: 101, irq: 95, debounce_interval: 200input: gpio-keys as /devices/platform/gpio-keys/input/input0

应用hexdump 命令打开/dev/input/event0后,并将gpio脚与gnd短接,将出现采集采集信号的动作信息

/sdcard/bin # hexdump /dev/input/event0 Debug gpio_keys_open0000000 0024 0000 4d2d 0000 0001 0101 0001 00000000010 0024 0000 4d2d 0000 0000 0000 0000 0000Debug gpio_keys_gpio_isrDebug gpio_keys_gpio_work_func0000020 0036 0000 4a09 0002 0001 0101 0000 00000000030 0036 0000 4a09 0002 0000 0000 0000 0000Debug gpio_keys_gpio_isrDebug gpio_keys_gpio_isrDebug gpio_keys_gpio_work_funcDebug gpio_keys_gpio_isrDebug gpio_keys_gpio_work_func0000040 003e 0000 8285 0003 0001 0101 0001 00000000050 003e 0000 8285 0003 0000 0000 0000 0000

5.系统默认添加驱动

打开/drivers/input/keyboard/Makefile可找到obj-$(CONFIG_KEYBOARD_GPIO) += gpio_keys.o

vi drivers/input/keyboard/Makefile

查找CONFIG_KEYBOARD_GPIO(或者自添加)

vi drivers/input/keyboard/Kconfig

可以看到:KEYBOARD_GPIO 设置

203 config KEYBOARD_GPIO204 tristate "GPIO Buttons"205 depends on GPIOLIB || COMPILE_TEST206 help207 This driver implements support for buttons connected208 to GPIO pins of various CPUs (and some other chips).209 210 Say Y here if your device has buttons connected211 directly to such GPIO pins. Your board-specific212 setup logic must also provide a platform device,213 with configuration data saying which GPIOs are used.214 215 To compile this driver as a module, choose M here: the216 module will be called gpio_keys.

所以打开设置

make menuconfigDevice Drivers ---> Input device support ---> [*] Keyboards ---><*> GPIO Buttons

make uImage

更新target板目标镜像

检测

~ # hexdump /dev/input/event0 0000000 0014 0000 84e8 0006 0001 0101 0001 00000000010 0014 0000 84e8 0006 0000 0000 0000 0000random: fast init done0000020 002e 0000 394a 000a 0001 0101 0000 00000000030 002e 0000 394a 000a 0000 0000 0000 00000000040 0031 0000 f431 000e 0001 0101 0001 0000

~ # cat /proc/bus/input/devices I: Bus=0019 Vendor=0001 Product=0001 Version=0100N: Name="gpio-keys"P: Phys=gpio-keys/input0S: Sysfs=/devices/platform/gpio-keys/input/input0U: Uniq=H: Handlers=event0 B: PROP=0B: EV=3B: KEY=2 0 0 0 0 0 0 0 0

Break your leg。。。。。。

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。