android 耳机插拔检测(kernel)

来源:互联网 发布:mac电脑单机游戏 编辑:程序博客网 时间:2024/06/09 13:48

Android的耳机检测其实代码改动很少的,也是因为少吧,所以一直没写文档。就这么拖了将近两个月。

 

 驱动程序有三个实现版本:

 

其一是

:drivers/char/micco_hsdetect.c

它通过

kobject_uevent

上报状态给用户空间。

 

其二是:

drivers/input/keyboard/micco_keys.c

它通过

input_report_switch

上报事件给用户空间。

 

其三是:

drivers/switch/switch_micco.c

注册了一个

switch_dev

,这个好像是

android

平台专用的。

 

参考自:

http://blog.csdn.net/absurd/archive/2009/11/01/4754912.aspx 

 

 

我是用第三种方法做的。

 

一、在littleton.c中注册platform_device

如下: 

#ifdef CONFIG_SWITCH_GPIO  

static structgpio_switch_platform_data headset_switch_data = 

.name = "h2w", 

.gpio = 127, 

 }; 

 

 

 

static structplatform_device headset_switch_device = 

 { 

.name = "switch-gpio", 

.dev = 

 { 

 

 .platform_data = &headset_switch_data, 

}; 

#endif 

 

littleton_init()中注册platform_device ,包括增加的headset_switch_device。

其中gpio_switch_platform_data 的name可以随意,但必须与上层的路径相符,gpio

号为耳机检测的中断GPIO,这里的127是指PXA310的GPIO127。platform_device 

的name为\drivers\switch\switch_gpio.c 中的 platform_driver的name

static struct platform_driver gpio_switch_driver =  

.probe= gpio_switch_probe, 

.remove = __devexit_p(gpio_switch_remove), 

.driver =

         { 

                   . name = "switch-gpio", 

                   .owner = THIS_MODULE,

         }, 

}; 

 

注册成功后可以使用shell查看开发板中/sys/class/switch目录下多了一个文件夹h2w

 

 

H2w 的监控和消息发送有android中的headsetobserver.java实现

0 0
原创粉丝点击