触屏消抖实验-33

Posted 杨斌并

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了触屏消抖实验-33相关的知识,希望对你有一定的参考价值。

代码

  • test.c
#include <linux/init.h>
#include <linux/module.h>
#include <linux/platform_device.h>
#include <linux/errno.h>
#include <linux/ioport.h>
#include <linux/miscdevice.h>
#include <linux/fs.h>
#include <linux/uaccess.h>
#include <linux/io.h>
#include <linux/gpio.h>
#include <linux/of_gpio.h>
#include <linux/interrupt.h>
#include <linux/of_irq.h>
#include <linux/time.h>

int gpio_num;
int irq = 0;
struct device_node *test_device_node;
struct property *test_node_property;


static void  timer_function(unsigned long data);

DEFINE_TIMER(test_timer, timer_function, 0, 0);

static void timer_function(unsigned long data){

    printk("timer_function \\n");
    // mod_timer(&test_timer, jiffies + 1*HZ);
}
struct of_device_id of_match_table[] = {

    {.compatible = "test_keys"},
    {}

};

irq_handler_t test_key(int irq, void *args){
    printk("test_key \\n");

    test_timer.expires = jiffies + msecs_to_jiffies(20);
    add_timer(&test_timer);

    return IRQ_HANDLED;

}

int beep_probe(struct platform_device *pdev){

    int ret = 0;


    printk("beep_probe 匹配成功了 \\n");
    test_device_node = of_find_node_by_path("/test_key");
    if (test_device_node == NULL)
    {
        printk("of_find_node_by_path is error \\n");
        return -1;
    }
    
    gpio_num = of_get_named_gpio(test_device_node, "touch-gpio", 0);
    if (gpio_num < 0)
    {
        printk("of_get_named_gpio is error \\n");
        return -1;
    }
    
    gpio_direction_input(gpio_num);

    
    //irq = gpio_to_irq(gpio_num);

    irq = irq_of_parse_and_map(test_device_node, 0);

    printk("irq is %d \\n", irq);

    ret = request_irq(irq, test_key, IRQF_TRIGGER_RISING, "test_key", NULL);
    if (ret < 0)
    {
        printk("request_irq is error \\n");
        return ret;
    }
    

    return 0;
}

int beep_remove(struct platform_device *pdev){
    printk("beep_remove \\n");
    return 0;
}

const struct platform_device_id  beep_idtable = {
    .name = "test_keys"
};

struct platform_driver beep_device =
{
    .probe = beep_probe,
    .remove = beep_remove,
    .driver = {
        .name = "123",
        .owner = THIS_MODULE,
        .of_match_table = of_match_table
    },
    .id_table = &beep_idtable
};

static int beep_driver_init(void){
    printk(KERN_EMERG "hello world enter \\n");
    int ret = 0;
    ret = platform_driver_register(&beep_device);
    if (ret < 0)
    {
        printk("platform_driver_register 失败\\n");
    }

    printk("platform_driver_register ok\\n");
    
    return 0;
}

static void beep_driver_exit(void){
    printk(KERN_EMERG "hello world exit! \\n");
    del_timer(&test_timer);
    free_irq(irq, NULL);
    platform_driver_unregister(&beep_device);
}

module_init(beep_driver_init);
module_exit(beep_driver_exit);
MODULE_LICENSE("GPL");
MODULE_AUTHOR("LIYU");

以上是关于触屏消抖实验-33的主要内容,如果未能解决你的问题,请参考以下文章

09B-独立按键消抖实验02——小梅哥FPGA设计思想与验证方法视频教程配套文档

09A-独立按键消抖实验01——小梅哥FPGA设计思想与验证方法视频教程配套文档

FPGA实验蜂鸣器

触屏设备触摸事件实验和记录

Arduino 按键输入检测,消抖示例程序

Verilog实现按键消抖