【Linux高级驱动】input子系统框架
【1.input子系统框架(drivers\input)】
如何得出某个驱动所遵循的框架?
1) 通过网络搜索
2) 自己想办法跟内核代码!
2.1 定位此驱动是属于哪种类型的(触摸屏驱动为字符设备)
2.2 搜索register_chrdev得到,input.c
2.3 分析input.c文件
static const struct file_operations input_fops = {
.owner = THIS_MODULE,
.open = input_open_file,
};
2.4 分析如何来用input子系统
/*2.取出input_handler里面的操作方法*/
if (handler)
new_fops = fops_get(handler->fops); //evdev_fops
old_fops = file->f_op;
file->f_op = new_fops; //file中的f_op覆盖了
/*3.执行底层的open函数*/
new_fops->open(inode, file); //事件处理层的操作方法里面的open函数evdev_open
evdev_open
2.5 根据handler = input_table[iminor(inode) >> 5];
猜测,有某段代码将input_handler放入了input_table[iminor(inode) >> 5]
搜索input_table,看在哪里放了
evdev_init ] = handler;
static struct input_handler evdev_handler = {
.event = evdev_event,
.connect = evdev_connect,
.disconnect = evdev_disconnect,
.fops = &evdev_fops,
.minor = EVDEV_MINOR_BASE,
.name = "evdev",
.id_table = evdev_ids,
};
【input子系统框架讲解】
1.input子系统的核心层(input.c)
功能:1)给用户提供接口(register_chrdev,cdev,file_operations结构体)
2)给用input子系统内部组件提供接口,建立三者之间的联系
static const struct file_operations input_fops = {
.owner = THIS_MODULE,
.open = input_open_file,
};
2.input子系统的事件处理层(evdev.c)
功能:专门用来为设备驱动层上报事件的
static struct input_handler evdev_handler = { //表示事件处理句柄
.event = evdev_event, //上报事件的时候,会调用此函数
.connect = evdev_connect, //建立连接的时候,会调用此函数
.disconnect = evdev_disconnect,
.fops = &evdev_fops, //事件处理方法(xxx_read)
.minor = EVDEV_MINOR_BASE, //64
.name = "evdev",
.id_table = evdev_ids,
};
static const struct file_operations evdev_fops = {
.owner = THIS_MODULE,
.read = evdev_read, //当应用程序来读数据的时候,便会调用此函数
.write = evdev_write,
.poll = evdev_poll,
.open = evdev_open,
.release = evdev_release,
.unlocked_ioctl = evdev_ioctl,
.fasync = evdev_fasync,
.flush = evdev_flush
};
3.input子系统的设备驱动层(s3c2410_ts.c为例子)(是驱动工作人员的主要任务)
功能:1)跟硬件交互,操作硬件,获取硬件的外部事件
2)提交事件给事件处理层
);
/*1.5 映射*/
ts.io = ioremap(res->start, resource_size(res));
/*1.6 注册中断*/
ret = request_irq(ts.irq_tc, stylus_irq, IRQF_DISABLED,
"s3c2410_ts_pen", ts.input);
/*2. 申请ADC服务*/
/*3. 初始化硬件(初始化触摸屏控制器)*/
/*4. 构建一个struct input_dev结构体*/
struct input_dev *input_dev; //表示一个输入设备
/*4.1 设置input_dev*/
/*4.2 注册input_dev,注册到子系统(input子系统中)*/
input_register_device(ts.input);
【input子系统里面涉及的几个重要结构体】
{
unsigned long evbit[BITS_TO_LONGS(EV_CNT)]; //事件类型
unsigned long keybit[BITS_TO_LONGS(KEY_CNT)]; //按键类当中什么按键
unsigned long relbit[BITS_TO_LONGS(REL_CNT)]; //相对位移的什么事件
unsigned long absbit[BITS_TO_LONGS(ABS_CNT)]; //绝对位移的什么事件
...
};
struct input_handler //用来表示一个事件处理句柄
{
/*上报事件*/
void (*event)(struct input_handle *handle, unsigned int type, unsigned int code, int value);
/*建立连接的*/
int (*connect)(struct input_handler *handler, struct input_dev *dev, const struct input_device_id *id);
const struct file_operations *fops;
...
}
struct input_handle //用来建立input_dev与input_handler的连接的
{
...
struct input_dev *dev;
struct input_handler *handler;
struct list_head d_node;
struct list_head h_node;
}
struct input_event //用来表示一个输入事件
{
struct timeval time; //事件产生的时间
__u16 type; //事件类型 EV_KEY
__u16 code; //事件码 KEY_A KEY_B
__s32 value; //事件值 1-按下 0-松开
}
【input子系统中涉及的重要函数:(input.c)】
ts.input->keybit[BIT_WORD(BTN_TOUCH)] = BIT_MASK(BTN_TOUCH);
方法二:set_bit
例如:
set_bit(EV_KEY,ts.input->evbit);
set_bit(EV_ABS,ts.input->evbit);
set_bit(BIN_TOUCH,ts.input->keybit);
【input子系统框架】

【input子系统框架完整版】

@成鹏致远
(email:wwwlllll@126.com)
(qq:552158509)
【Linux高级驱动】input子系统框架的更多相关文章
- 【Linux高级驱动】input子系统框架【转】
转自:http://www.cnblogs.com/lcw/p/3802617.html [1.input子系统框架(drivers\input)] 如何得出某个驱动所遵循的框架? 1) 通过网 ...
- Linux 驱动框架---input子系统框架
前面从具体(Linux 驱动框架---input子系统)的工作过程学习了Linux的input子系统相关的架构知识,但是前面的学习比较实际缺少总结,所以今天就来总结一下输入子系统的架构分层,站到远处来 ...
- input子系统框架
废话不多说,直接进入主题.在驱动insmod后,我们应用层对input设备如何操作?以下以全志a64为实例. 在/dev/input/eventX下(X的形成为后续会分析),是内核把接口暴露给应用层, ...
- 网络驱动移植之解析Linux网络驱动的基本框架
内核源码:linux-2.6.38.8.tar.bz2 概括而言,编写Linux网络驱动其实只要完成两件事即可,一是分配并初始化网络设备,二是注册网络设备. 1.分配并初始化网络设备 动态分配网络设备 ...
- 【Linux高级驱动】rtc驱动开发
[1.分层思想] 1.1 rtc-dev.c //设备接口层,功能:给用户提供接口 subsys_initcall(rtc_init); , RTC_DEV_MAX, "rtc&qu ...
- 【Linux高级驱动】linux设备驱动模型之平台设备驱动机制
[1:引言: linux字符设备驱动的基本编程流程] 1.实现模块加载函数 a.申请主设备号 register_chrdev(major,name,file_operations); b.创 ...
- ARM Linux 驱动Input子系统之按键驱动测试
上一篇已经谈过,在现内核的中引入设备树之后对于内核驱动的编写,主要集中在硬件接口的配置上了即xxxx.dts文件的编写. 在自己的开发板上移植按键驱动: 1.根据开发板的原理图 确定按键的硬件接口为: ...
- 【Linux高级驱动】I2C驱动框架分析
1.i2c-dev.c(i2c设备驱动组件层) 功能:1)给用户提供接口 i2c_dev_init //入口函数 /*申请主设备号*/ register_chrdev(I2C_MAJOR(), &q ...
- 【Linux高级驱动】LCD驱动框架分析
1.framebuffer接口层(fbmem.c) 功能:给用户提供接口 fbmem_init ),"fb",&fb_fops) /*2.创建一个设备类*/ fb_cl ...
随机推荐
- Java中九大内置对象
1.Request对象 该对象封装了用户提交的信息,通过调用该对象相应的方法可以获取封装的信息,即使用该对象可以获取用户提交的信息. 当Request对象获取客户提交的汉字字符时,会出现乱码问题 ...
- hdu 2167 方格取数 【状压dp】(经典)
<题目链接> 题目大意: 给出一些数字组成的n*n阶矩阵,这些数字都在[10,99]内,并且这个矩阵的 3<=n<=15,从这个矩阵中随机取出一些数字,在取完某个数字后,该数 ...
- hdu1873 看病要排队【优先队列】
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1873 看病要排队 Time Limit: 3000/1000 MS (Java/Others) ...
- HttpClient之初步认识与使用1
今天在项目中看到HttpClient的内容,然后去看了一下资料,有了初步的见解,在此记录一下~ 一. 搭建环境 (1)创建一个java项目叫HttpClientTest (2)为了使用HttpClie ...
- 洛谷.2292.[HNOI2004]L语言(Trie DP)
题目链接 /* 简单的DP,查找是否有字典中的单词时在Trie树上做 要注意在最初Match(0)一遍后,i还是要从0开始匹配,因为如果有长度为1的单词,Match(i+1)不会从1更新 1M=102 ...
- angular.js--demo2-----声明局部控制器controller
<!doctype html><html ng-app="HelloAngular"> <head> <meta charset=&quo ...
- Java内存区域与内存溢出异常--HotSpot虚拟机对象探秘
以常用的HotSpot和常用的Java堆为例,深入探讨HotSpot虚拟机在Java堆中对象分配.布局和访问的全过程 1.对象的创建 ①虚拟机遇到一条new指令后,首先将去检查这个指令的参数是否能够在 ...
- 在global.asax中启动定时任务
public class MvcApplication : System.Web.HttpApplication { protected void Application_Start() { Area ...
- 自定义Directive使用ngModel
我们知道ngModel是AngularJS中默认的一个Directive,用于数据的双向绑定.通常是这样使用的: <input type="text" ng-model=&q ...
- web架构延变
在现代的软件系统中,几乎所有的系统都使用到了数据库,不论是关系型数据,例如MySql.SQLite.Oracle.SQLServer等,还是非关系性数据,例如mongoDB.redis等.本文已web ...