Widora_NEO: 添加poll模式按键



  • poll模式的按键检测由内核模块gpio_button_hotplug来执行, 模块会记录下按下的时间,并通过uevent 把pressed和released事件信息发送到用户空间, openwrt的hotplug机制会根据事件信息中BUTTON的名称来调用/etc/rc.button下相应名称的脚本.
    添加poll模式按键步骤:

    1. 修改 Widora32M.dts,在gpio-keys-polled节点中增加BTN_0按键。
        ... ...
        gpio-keys-polled {
                    compatible = "gpio-keys-polled";
                    #address-cells = <1>;
                    #size-cells = <0>;
                    poll-interval = <20>;
                    wps@0{
                            label = "reset";
                            gpios = <&gpio1 6 1>;
                            linux,code = <0x211>;
                    };
    		BTN_0@1{
    			label = "button_io39";
    			gpios = <&gpio1 7 1>;
    			linux,code = <0x100>;
    		};
             };
       ... ... 
    

    按键名参照../build_dir/target-mipsel_24kec+dsp_uClibc-0.9.33.2/linux-ramips_mt7688/gpio-button-hotplug/gpio-button-hotplug.c, 应该也可以自己添加:
    0_1526871226484_button_map.JPG
    其中的 linux code 可在../build_dir/target-mipsel-24kec+dsp_uClibc-0.9.33.2/linux-ramips_mt7688/linux-3.18.29/include/uapi/linux/input.h中查到。

    1. 编译固件,完成后刷入widora.

    2. 在/etc/rc.button目录中参照其他脚本编辑一个名称为BTN_0的脚本 :

    #!/bin/sh
    [ "${ACTION}" = "released" -o "${ACTION}" = "timeout" ] || exit 21
    . /lib/functions.sh
    echo "$BUTTON pressed for $SEEN seconds" > /dev/console
    espeak --stdout "pressed for $SEEN seconds" | aplay
    return 0
    
    

    固件中没有espeak的话可以用opkg update; opkg install espeak安装。

    1. 硬件设置,需要将相应的gpio39脚上拉,不然系统启动的时候会进入failsafe模式. 键按下时接地。

    2. 试验检测
      按下键,松开后espeak会用语音播放按下的秒数。

    3. 执行命令 cat /sys/kernel/debug/gpio 查看当前gpio使用情况

    root@Widora:~# cat /sys/kernel/debug/gpio
    GPIOs 0-31, platform/10000600.gpio, 10000600.gpio:
    
    GPIOs 32-63, platform/10000600.gpio, 10000600.gpio:
     gpio-38  (reset               ) in  hi
     gpio-39  (button_io39         ) in  hi
    
    GPIOs 64-95, platform/10000600.gpio, 10000600.gpio:
    
    1. 问题
      狂按按钮会出现Bug:
    [  557.050000] BUG: Bad page map in process aplay  pte:b933bd95 pmd:86160000
    [  557.060000] addr:00401000 vm_flags:00000875 anon_vma:  (null) mapping:87570d4c index:1
    [  557.070000] vma->vm_ops->fault: filemap_fault+0x0/0x438
    [  557.070000] vma->vm_file->f_op->mmap: generic_file_readonly_mmap+0x0/0x24
    [  557.080000] CPU: 0 PID: 1550 Comm: aplay Tainted: G    B          3.18.29 #18
    [  557.090000] Stack : 00000000 00000000 00000000 00000000 803541f2 00000041 00000000 00000001
              00000001 b933bd95 802afbc8 803089e3 0000060e 80353420 878fe908 b933bd95
              86287004 0040e000 00800000 80047628 00000006 80024378 00000000 00000000
              802b30cc 86281bec 00000000 00000000 00000000 00000000 00000000 00000000
              00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
              ...
    


  • 此回复已被删除!