您尚未登录。

楼主 #1 2019-04-26 23:50:07

晕哥
管理员
注册时间: 2017-09-06
已发帖子: 9,342
积分: 9202

V3s/S3 Linux 测试 轮询/中断 GPIO 按钮驱动程序 / 旋转编码器 等

GPIO KEY 按键驱动(轮询)测试:

参考: https://github.com/ARM-software/u-boot/blob/master/arch/arm/dts/sun4i-a10-inet9f-rev03.dts


1. Linux驱动配置 gpio keys poll 驱动:

CONFIG_KEYBOARD_GPIO_POLLED=y


2. arch/arm/boot/dts/sun8i-v3s.dtsi 添加引脚定义:

key_pins: key_pins@0 {
               pins = "PB0", "PB1";
               function = "gpio_in";
               bias-pull-up;
               };

3. arch/arm/boot/dts/sun8i-v3s-licheepi-zero.dts 添加:

#include <dt-bindings/input/input.h>

       gpio_keys {
               compatible = "gpio-keys-polled";
               pinctrl-names = "default";
               pinctrl-0 = <&key_pins>;
               #address-cells = <1>;
               #size-cells = <0>;
               poll-interval = <20>;

               button@0 {
                       label = "Left Joystick Left";
                       linux,code = <ABS_X>;
                       linux,input-type = <EV_ABS>;
                       linux,input-value = <0xffffffff>; /* -1 */
                       gpios = <&pio 1 0 GPIO_ACTIVE_LOW>; /* PB0 */
               };

               button@1 {
                       label = "Left Joystick Right";
                       linux,code = <ABS_Z>;
                       linux,input-type = <EV_ABS>;
                       linux,input-value = <1>;
                       gpios = <&pio 1 1 GPIO_ACTIVE_LOW>; /* PB1 */
               };
       };

4. 编译烧录运行测试:

# evtest /dev/input/event0
Input driver version is 1.0.1
Input device ID: bus 0x19 vendor 0x1 product 0x1 version 0x100
Input device name: "gpio_keys"
Supported events:
  Event type 0 (EV_SYN)
  Event type 1 (EV_KEY)
  Event type 3 (EV_ABS)
    Event code 0 (ABS_X)
      Value      0
      Min       -1
      Max        0
    Event code 2 (ABS_Z)
      Value      0
      Min        0
      Max        1
Properties:
Testing ... (interrupt to exit)
Event: time 80.855039, type 3 (EV_ABS), code 2 (ABS_Z), value 1
Event: time 80.855039, -------------- SYN_REPORT ------------
Event: time 80.915049, type 3 (EV_ABS), code 2 (ABS_Z), value 0
Event: time 80.915049, -------------- SYN_REPORT ------------
Event: time 84.545066, type 3 (EV_ABS), code 2 (ABS_Z), value 1
Event: time 84.545066, -------------- SYN_REPORT ------------
Event: time 84.605043, type 3 (EV_ABS), code 2 (ABS_Z), value 0
Event: time 84.605043, -------------- SYN_REPORT ------------
Event: time 90.845038, type 3 (EV_ABS), code 2 (ABS_Z), value 1
Event: time 90.845038, -------------- SYN_REPORT ------------
Event: time 90.995036, type 3 (EV_ABS), code 2 (ABS_Z), value 0
Event: time 90.995036, -------------- SYN_REPORT ------------
Event: time 91.145036, type 3 (EV_ABS), code 2 (ABS_Z), value 1
Event: time 91.145036, -------------- SYN_REPORT ------------
Event: time 91.355035, type 3 (EV_ABS), code 2 (ABS_Z), value 0
Event: time 91.355035, -------------- SYN_REPORT ------------
Event: time 91.445037, type 3 (EV_ABS), code 2 (ABS_Z), value 1
Event: time 91.445037, -------------- SYN_REPORT ------------
Event: time 91.625037, type 3 (EV_ABS), code 2 (ABS_Z), value 0
Event: time 91.625037, -------------- SYN_REPORT ------------
Event: time 101.375037, type 3 (EV_ABS), code 0 (ABS_X), value -1
Event: time 101.375037, -------------- SYN_REPORT ------------




离线

楼主 #2 2019-04-27 09:23:07

晕哥
管理员
注册时间: 2017-09-06
已发帖子: 9,342
积分: 9202

Re: V3s/S3 Linux 测试 轮询/中断 GPIO 按钮驱动程序 / 旋转编码器 等

--------------------------------------------------------------------------------





离线

楼主 #3 2019-04-27 09:28:27

晕哥
管理员
注册时间: 2017-09-06
已发帖子: 9,342
积分: 9202

Re: V3s/S3 Linux 测试 轮询/中断 GPIO 按钮驱动程序 / 旋转编码器 等

GPIO KEY 按键驱动(中断)测试:

参考: https://gitlab.labs.nic.cz/turris/u-boot-turris/commit/643ad899f545fd101aa7a67771e74d582a1829b2


1. Linux驱动配置 gpio keys 驱动:

CONFIG_KEYBOARD_GPIO=y


2. arch/arm/boot/dts/sun8i-v3s.dtsi 添加引脚定义:

key_pins: key_pins@0 {
pins = "PB0", "PB1";
function = "gpio_in";
allwinner,drive = <0>;
allwinner,pull = <1>;
};

3. arch/arm/boot/dts/sun8i-v3s-licheepi-zero.dts 添加:

#include <dt-bindings/input/input.h>

gpio_keys {
        compatible = "gpio-keys";
        pinctrl-names = "default";
        pinctrl-0 = <&key_pins>;
        #address-cells = <1>;
        #size-cells = <0>;
        autorepeat;
        button@0 {
                label = "Key back";
                linux,code = <KEY_BACK>;
                gpios = <&pio 1 0 GPIO_ACTIVE_LOW>; /* PB0 */
        };


         button@1 {
                 label = "Key home";
                 linux,code = <KEY_HOME>;
                 gpios = <&pio 1 1 GPIO_ACTIVE_LOW>; /* PB1 */
         };

};

4. 编译烧录运行测试, 支持长按:

# evtest /dev/input/event2
Input driver version is 1.0.1
Input device ID: bus 0x19 vendor 0x1 product 0x1 version 0x100
Input device name: "gpio_keys"
Supported events:
  Event type 0 (EV_SYN)
  Event type 1 (EV_KEY)
    Event code 102 (KEY_HOME)
    Event code 158 (KEY_BACK)
Key repeat handling:
  Repeat type 20 (EV_REP)
    Repeat code 0 (REP_DELAY)
      Value    250
    Repeat code 1 (REP_PERIOD)
      Value     33
Properties:
Testing ... (interrupt to exit)
Event: time 3606.960158, type 1 (EV_KEY), code 102 (KEY_HOME), value 1
Event: time 3606.960158, -------------- SYN_REPORT ------------
Event: time 3607.220140, type 1 (EV_KEY), code 102 (KEY_HOME), value 2
Event: time 3607.220140, -------------- SYN_REPORT ------------
Event: time 3607.270142, type 1 (EV_KEY), code 102 (KEY_HOME), value 2
Event: time 3607.270142, -------------- SYN_REPORT ------------
Event: time 3607.320136, type 1 (EV_KEY), code 102 (KEY_HOME), value 2
Event: time 3607.320136, -------------- SYN_REPORT ------------
Event: time 3607.370136, type 1 (EV_KEY), code 102 (KEY_HOME), value 2
Event: time 3607.370136, -------------- SYN_REPORT ------------
Event: time 3607.370277, type 1 (EV_KEY), code 102 (KEY_HOME), value 0
Event: time 3607.370277, -------------- SYN_REPORT ------------
Event: time 3616.220150, type 1 (EV_KEY), code 158 (KEY_BACK), value 1
Event: time 3616.220150, -------------- SYN_REPORT ------------
Event: time 3616.480130, type 1 (EV_KEY), code 158 (KEY_BACK), value 2
Event: time 3616.480130, -------------- SYN_REPORT ------------
Event: time 3616.530130, type 1 (EV_KEY), code 158 (KEY_BACK), value 2
Event: time 3616.530130, -------------- SYN_REPORT ------------
Event: time 3616.580139, type 1 (EV_KEY), code 158 (KEY_BACK), value 2
Event: time 3616.580139, -------------- SYN_REPORT ------------
Event: time 3616.630136, type 1 (EV_KEY), code 158 (KEY_BACK), value 2
Event: time 3616.630136, -------------- SYN_REPORT ------------
Event: time 3616.680132, type 1 (EV_KEY), code 158 (KEY_BACK), value 2
Event: time 3616.680132, -------------- SYN_REPORT ------------
Event: time 3616.730131, type 1 (EV_KEY), code 158 (KEY_BACK), value 2
Event: time 3616.730131, -------------- SYN_REPORT ------------
Event: time 3616.780134, type 1 (EV_KEY), code 158 (KEY_BACK), value 2
Event: time 3616.780134, -------------- SYN_REPORT ------------
Event: time 3616.830131, type 1 (EV_KEY), code 158 (KEY_BACK), value 2
Event: time 3616.830131, -------------- SYN_REPORT ------------
Event: time 3616.850155, type 1 (EV_KEY), code 158 (KEY_BACK), value 0
Event: time 3616.850155, -------------- SYN_REPORT ------------




离线

楼主 #4 2019-04-27 09:55:11

晕哥
管理员
注册时间: 2017-09-06
已发帖子: 9,342
积分: 9202

Re: V3s/S3 Linux 测试 轮询/中断 GPIO 按钮驱动程序 / 旋转编码器 等

参考: https://www.kernel.org/doc/Documentation/devicetree/bindings/input/gpio-keys.txt

接上帖, GPIO 也可以换作 interrupts, Linux 官方文档提示 二选一

gpio_keys {
                compatible = "gpio-keys";
                pinctrl-names = "default";
                pinctrl-0 = <&key_pins>;
                #address-cells = <1>;
                #size-cells = <0>;
                autorepeat;
                button@0 {
                        label = "Key back";
                        linux,code = <KEY_BACK>;

                        interrupt-parent = <&pio>;
                        interrupts = <1 0 IRQ_TYPE_EDGE_FALLING>;//PB0

                };


                button@1 {
                        label = "Key home";
                        linux,code = <KEY_HOME>;

                        interrupt-parent = <&pio>;
                        interrupts = <1 1 IRQ_TYPE_EDGE_FALLING>; //PB1
                };

        };


查看中断:

# cat /proc/interrupts
           CPU0
17:          0     GIC-0  29 Level     arch_timer
18:       3375     GIC-0  30 Level     arch_timer
21:          0     GIC-0  50 Level     /soc/timer@01c20c00
22:          0     GIC-0  82 Level     1c02000.dma-controller
23:       9025     GIC-0  92 Level     sunxi-mmc
24:        479     GIC-0  93 Level     sunxi-mmc
25:         21     GIC-0 103 Level     musb-hdrc.1.auto
26:          0     GIC-0 104 Level     ehci_hcd:usb1
27:          0     GIC-0 105 Level     ohci_hcd:usb2
28:          0     GIC-0  72 Level     1c20400.rtc
34:          0     GIC-0  62 Level     sun4i-a10-lradc-keys
36:        226     GIC-0  32 Level     ttyS0
37:          0     GIC-0  38 Level     mv64xxx_i2c
39:          1  sunxi_pio_edge   0 Edge      Key back
40:         68  sunxi_pio_edge   1 Edge      Key home

IPI0:          0  CPU wakeup interrupts
IPI1:          0  Timer broadcast interrupts
IPI2:          0  Rescheduling interrupts
IPI3:          0  Function call interrupts
IPI4:          0  CPU stop interrupts
IPI5:          0  IRQ work interrupts
IPI6:          0  completion interrupts





离线

楼主 #5 2019-04-27 14:07:17

晕哥
管理员
注册时间: 2017-09-06
已发帖子: 9,342
积分: 9202

Re: V3s/S3 Linux 测试 轮询/中断 GPIO 按钮驱动程序 / 旋转编码器 等

IMG_20190427_142043.jpg


旋转编码器(中断)测试:

参考: https://github.com/teknoid/dac/blob/master/misc/gpio-rotary.dts

接线方法:

PB0 - CLK
PB1 - DT
3V3
GND

1. Linux驱动配置 gpio keys 驱动:

CONFIG_INPUT_GPIO_ROTARY_ENCODER=y


2. arch/arm/boot/dts/sun8i-v3s.dtsi 添加引脚定义:

key_pins: key_pins@0 {
pins = "PB0", "PB1";
function = "gpio_in";
allwinner,drive = <0>;
allwinner,pull = <1>;
};

3. arch/arm/boot/dts/sun8i-v3s-licheepi-zero.dts 添加:

#include <dt-bindings/input/input.h>

rotary@0 {
        compatible = "rotary-encoder";

        pinctrl-names = "default";
        pinctrl-0 = <&key_pins>;

        gpios = <&pio 1 0 GPIO_ACTIVE_LOW>, <&pio 1 1 GPIO_ACTIVE_LOW>; /* PB0, PB1 */
        linux,axis = <0>; /* REL_X */
        rotary-encoder,encoding = "gray";
        rotary-encoder,relative-axis;
};

4. 编译烧录运行测试, 支持长按:

# evtest /dev/input/event1
Input driver version is 1.0.1
Input device ID: bus 0x19 vendor 0x0 product 0x0 version 0x0
Input device name: "rotary@0"
Supported events:
  Event type 0 (EV_SYN)
  Event type 2 (EV_REL)
    Event code 0 (REL_X)
Properties:
Testing ... (interrupt to exit)
Event: time 2474.959560, type 2 (EV_REL), code 0 (REL_X), value 1
Event: time 2474.959560, -------------- SYN_REPORT ------------
Event: time 2476.204760, type 2 (EV_REL), code 0 (REL_X), value 1
Event: time 2476.204760, -------------- SYN_REPORT ------------
Event: time 2476.907228, type 2 (EV_REL), code 0 (REL_X), value 1
Event: time 2476.907228, -------------- SYN_REPORT ------------
Event: time 2477.565278, type 2 (EV_REL), code 0 (REL_X), value 1
Event: time 2477.565278, -------------- SYN_REPORT ------------
Event: time 2478.140605, type 2 (EV_REL), code 0 (REL_X), value 1
Event: time 2478.140605, -------------- SYN_REPORT ------------
Event: time 2478.548095, type 2 (EV_REL), code 0 (REL_X), value -1
Event: time 2478.548095, -------------- SYN_REPORT ------------
Event: time 2479.051748, type 2 (EV_REL), code 0 (REL_X), value -1
Event: time 2479.051748, -------------- SYN_REPORT ------------
Event: time 2479.541767, type 2 (EV_REL), code 0 (REL_X), value -1
Event: time 2479.541767, -------------- SYN_REPORT ------------
Event: time 2479.924168, type 2 (EV_REL), code 0 (REL_X), value -1
Event: time 2479.924168, -------------- SYN_REPORT ------------
Event: time 2480.279108, type 2 (EV_REL), code 0 (REL_X), value -1
Event: time 2480.279108, -------------- SYN_REPORT ------------





离线

楼主 #6 2019-04-27 19:57:18

晕哥
管理员
注册时间: 2017-09-06
已发帖子: 9,342
积分: 9202

Re: V3s/S3 Linux 测试 轮询/中断 GPIO 按钮驱动程序 / 旋转编码器 等

荔枝派zero 旋转编码器演示视频





离线

页脚

工信部备案:粤ICP备20025096号 Powered by FluxBB

感谢为中文互联网持续输出优质内容的各位老铁们。 QQ: 516333132, 微信(wechat): whycan_cn (哇酷网/挖坑网/填坑网) service@whycan.cn