Linux设备模型之input子系统详解
一:前言
最近在研究android的sensor driver,主要是E-compass,其中用到了Linux input子系统.在网上也看了很多这方面的资料,感觉还是这篇分析的比较细致透彻,因此转载一下以便自己学习,同时和大家分享!
(这篇博客主要是以键盘驱动为例的,不过讲解的是Linux Input Subsystem,可以仔细的研究一下!)
键盘驱动将检测到的所有按键都上报给了input子系统。Input子系统是所有I/O设备驱动的中间层,为上层提供了一个统一的界面。例如,在终端系统中,我们不需要去管有多少个键盘,多少个鼠标。它只要从input子系统中去取对应的事件(按键,鼠标移位等)就可以了。
二:使用input device的例子
下面的代码是基于linux kernel 2.6.25.分析的代码主要位于kernel2.6.25/drivers/input下面.
在内核自带的文档Documentation/input/input-programming.txt中。有一个使用input子系统的例子,并附带相应的说明。以此为例分析如下:
#include <linux/input.h>
#include <linux/module.h>
#include <linux/init.h>
#include <asm/irq.h>
#include <asm/io.h>
static void button_interrupt(int irq, void *dummy, struct pt_regs *fp)
{
input_report_key(&button_dev, BTN_1, inb(BUTTON_PORT) & 1);
input_sync(&button_dev);
}
static int __init button_init(void)
{
if (request_irq(BUTTON_IRQ, button_interrupt, 0, "button", NULL)) {
printk(KERN_ERR "button.c: Can't allocate irq %d\n", button_irq);
return -EBUSY;
}
button_dev.evbit[0] = BIT(EV_KEY);
button_dev.keybit[LONG(BTN_0)] = BIT(BTN_0);
input_register_device(&button_dev);
}
static void __exit button_exit(void)
{
&n
相关文档:
例一:发送Signaling Packet:
Signaling Command是2个Bluetooth实体之间的L2CAP层命令传输。所以得Signaling Command使用CID 0x0001.
多个Command可以在一个C-frame(control frame)中发送。
如果要直接发送Signaling Command.需要建立SOCK_RAW类型的L2CAP连接Socket。这样才有机会自己填充Command Code,Identi ......
在配置Apache James Mail Server 的时候,Linux 默认占用了25号端口,需要把它关掉才能运行James Mail Server。
nmap localhost : 查看占用的端口。
由于服务是由守护进程维护,所以 找到该服务的PID,然后kill掉就OK了。
netstat -anep | grep 25
tcp 0 & ......
作者:Sam(甄峰) sam_cdoe@hotmail.com
1.创建thread.
int pthread_create(pthread_t *restrict thread, const pthread_attr_t *restrict attr,
void *(*start_routine)(void*), void *restrict arg);
参数1:pthread_t *restrict t ......
1.
今天上班追了个问题,追了半天发现是fopen打开大于2G的文件有问题。
马上Google下,做个笔记:
// 定义宏,使得可以处理大文件(>4GB)
#undef _FILE_OFFSET_BITS
#define _FILE_OFFSET_BITS 64 &nb ......