==============================================
1. 应用程序调用open()
以androidM Gsensor为例
hal层中acceleration.cpp中
FindDataFd()
fd = open("/sys/class/misc/m_acc_misc/accdevnum", O_RDONLY);
len = read(fd, buf, sizeof(buf)-1);
buf[len] = '\0';
sscanf(buf, "%d\n", &num);
sprintf(buf_s, "/dev/input/event%d", num);
fd = open(buf_s, O_RDONLY);
readEvents()
mInputReader.fill(mdata_fd)
mInputReader.readEvent(&event)
即open("/dev/input/event%d", O_RDONLY);
-----------------------------------------
vfs
sys_open(); // 系统调用
struct file file->f_ops = cdev->ops;
file->f_ops->open();
-----------------------------------------
input handler层: evdev.c
cdev
xxx_ops = {
.open = xxx_open,
.read = xxx_read,
}
evdev_connect()
cdev_init(&evdev->cdev, &evdev_fops);
static const struct file_operations evdev_fops = {
.owner = THIS_MODULE,
.read = evdev_read,
.write = evdev_write,
.poll = evdev_poll,
.open = evdev_open,
};
实际上最终调用了evdev_open()
evdev_open(struct inode *inode, struct file *file)
|
struct evdev *evdev = container_of(inode->i_cdev, struct evdev, cdev); // 以小博大,inode->i_cdev就是connect()中住的的cdev
unsigned int bufsize = evdev_compute_buffer_size(evdev->handle.dev); // 通过handle找到 input device,根据input device 获取缓冲区的大小(几个input event),但是我们驱动中未给定缓冲区大小,系统会自动给定一个
unsigned int
input子系统分析:3. 应用层获取数据,及驱动数据上报流程
最新推荐文章于 2024-01-23 21:08:52 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)