linux touchpanel驱动demo

时间: 2023-07-25 19:35:05 浏览: 59
以下是一个简单的Linux Touch Panel驱动的demo: ```c #include <linux/module.h> #include <linux/kernel.h> #include <linux/init.h> #include <linux/input.h> #include <linux/i2c.h> #include <linux/delay.h> #define DEVICE_NAME "touchpanel" static struct i2c_device_id touchpanel_id_table[] = { {DEVICE_NAME, 0}, {} }; MODULE_DEVICE_TABLE(i2c, touchpanel_id_table); static int touchpanel_probe(struct i2c_client *client, const struct i2c_device_id *id) { struct input_dev *input; int error = 0; input = input_allocate_device(); if (!input) { dev_err(&client->dev, "input_allocate_device failed\n"); error = -ENOMEM; goto err_free_mem; } input->name = "Touch Panel"; input->id.bustype = BUS_I2C; input->dev.parent = &client->dev; input_set_capability(input, EV_KEY, BTN_TOUCH); error = input_register_device(input); if (error) { dev_err(&client->dev, "input_register_device failed\n"); goto err_free_mem; } return 0; err_free_mem: input_free_device(input); return error; } static int touchpanel_remove(struct i2c_client *client) { struct input_dev *input = i2c_get_clientdata(client); input_unregister_device(input); input_free_device(input); return 0; } static const struct of_device_id touchpanel_of_match[] = { { .compatible = "linux,touchpanel", }, {} }; MODULE_DEVICE_TABLE(of, touchpanel_of_match); static struct i2c_driver touchpanel_driver = { .probe = touchpanel_probe, .remove = touchpanel_remove, .id_table = touchpanel_id_table, .driver = { .name = DEVICE_NAME, .of_match_table = touchpanel_of_match, }, }; module_i2c_driver(touchpanel_driver); MODULE_AUTHOR("Your Name"); MODULE_DESCRIPTION("Touch Panel Driver"); MODULE_LICENSE("GPL"); ``` 这个驱动程序使用I2C总线与触摸屏进行通信,并向输入子系统注册输入设备。在`probe`函数中,它分配了一个新的输入设备并配置其名称、总线类型和父设备。它还设置了该设备支持BTN_TOUCH事件。在`remove`函数中,它注销了输入设备并释放了分配的内存。这个驱动程序还包含了一些必要的Linux模块元数据,如作者、描述和许可证信息。

相关推荐

最新推荐

recommend-type

常用的Linux命令大全

touch 创建文件 mv 移动文件 rm 删除文件 rmdir 删除目录 1.1 pwd 命令 该命令的英文解释为 print working directory(打印工作目录)。输入 pwd 命令, Linux 会输出当前目录。 1.2 cd 命令 cd 命令用来改变所在目录...
recommend-type

Linux操作系统大作业

利用touch命令在当前目录创建一个新的空文件 newfile。 利用cp命令复制系统文件/etc/profile到当前目录下。 复制文件 profile到一个新文件profile.bak作为备份。 用 grep命令在 profile 文件中对关键字...
recommend-type

pre_o_1csdn63m9a1bs0e1rr51niuu33e.a

pre_o_1csdn63m9a1bs0e1rr51niuu33e.a
recommend-type

matlab建立计算力学课程的笔记和文件.zip

matlab建立计算力学课程的笔记和文件.zip
recommend-type

FT-Prog-v3.12.38.643-FTD USB 工作模式设定及eprom读写

FT_Prog_v3.12.38.643--FTD USB 工作模式设定及eprom读写
recommend-type

zigbee-cluster-library-specification

最新的zigbee-cluster-library-specification说明文档。
recommend-type

管理建模和仿真的文件

管理Boualem Benatallah引用此版本:布阿利姆·贝纳塔拉。管理建模和仿真。约瑟夫-傅立叶大学-格勒诺布尔第一大学,1996年。法语。NNT:电话:00345357HAL ID:电话:00345357https://theses.hal.science/tel-003453572008年12月9日提交HAL是一个多学科的开放存取档案馆,用于存放和传播科学研究论文,无论它们是否被公开。论文可以来自法国或国外的教学和研究机构,也可以来自公共或私人研究中心。L’archive ouverte pluridisciplinaire
recommend-type

实现实时数据湖架构:Kafka与Hive集成

![实现实时数据湖架构:Kafka与Hive集成](https://img-blog.csdnimg.cn/img_convert/10eb2e6972b3b6086286fc64c0b3ee41.jpeg) # 1. 实时数据湖架构概述** 实时数据湖是一种现代数据管理架构,它允许企业以低延迟的方式收集、存储和处理大量数据。与传统数据仓库不同,实时数据湖不依赖于预先定义的模式,而是采用灵活的架构,可以处理各种数据类型和格式。这种架构为企业提供了以下优势: - **实时洞察:**实时数据湖允许企业访问最新的数据,从而做出更明智的决策。 - **数据民主化:**实时数据湖使各种利益相关者都可
recommend-type

2. 通过python绘制y=e-xsin(2πx)图像

可以使用matplotlib库来绘制这个函数的图像。以下是一段示例代码: ```python import numpy as np import matplotlib.pyplot as plt def func(x): return np.exp(-x) * np.sin(2 * np.pi * x) x = np.linspace(0, 5, 500) y = func(x) plt.plot(x, y) plt.xlabel('x') plt.ylabel('y') plt.title('y = e^{-x} sin(2πx)') plt.show() ``` 运行这段
recommend-type

JSBSim Reference Manual

JSBSim参考手册,其中包含JSBSim简介,JSBSim配置文件xml的编写语法,编程手册以及一些应用实例等。其中有部分内容还没有写完,估计有生之年很难看到完整版了,但是内容还是很有参考价值的。