Android headset insertion Detection

Source: Internet
Author: User

Android
In fact, the code of the headset detection is rarely changed.

This is because there are few documents.

It took nearly two months.

The driver has three implementation versions:

First, drivers/Char/micco_hsdetect.c
It reports the status to the user space through kobject_uevent.

Second: Drivers/input/keyboard/micco_keys.c
It reports events to the user space through input_report_switch.

Third: Drivers/switch/switch_micco.c
Registered a switch_dev, which seems to be dedicated to the Android platform.

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

I am using the third method.

1. Register platform_device in Littleton. C as follows:

# Ifdef config_switch_gpio
Static struct gpio_switch_platform_data headset_switch_data = {
. Name = "h2w ",
. Gpio = 127,
};

Static struct platform_device headset_switch_device = {
. Name = "Switch-gpio ",
. Dev = {
. Platform_data = & headset_switch_data,
}
};

# Endif

Register platform_device in littleton_init (), including the added headset_switch_device.

The name of gpio_switch_platform_data can be customized, but must be consistent with the upper-layer path. The gpio number is the interrupt gpio detected by the headset. Here, 127 is the gpio127 of pxa310.

The name of platform_device is the name of platform_driver registered in/Drivers/switch/switch_gpio.c.

Static struct platform_driver gpio_switch_driver = {
. Probe = gpio_switch_probe,
. Remove = _ devexit_p (gpio_switch_remove ),
. Driver = {
. Name = "Switch-gpio ",
. Owner = this_module,
},
};

After successful registration, you can use shell to check that the/sys/class/switch directory on the Development Board has an additional folder h2w.

2. switch_gpio.c reports the message.

Gpio_switch_probe application is interrupted, while the Interrupt Processing gpio_irq_handler
() The function uses schedule_work to call gpio_switch_work. Get the interrupt in gpio_switch_work ()
Determine the state of gpio (gpio_127) through the switch_set_state () function of switch_class.c.
. (It is best to draw a flowchart)

Download and run the Development Board, view/sys/class/switch/h2w in the development board, and view the content including name and State (view supplement). The cat state is 0 if no earphones are inserted, after the headset is inserted, the cat state is 1.

3. Modify headsetobserver. Java on the upper layer (/frameworks/base/services/Java/COM/Android/Server)

The upper-layer headsetobserver. Java determines how to implement channel switching through the State reported at the bottom layer.

You need to modify it as follows:

// Private Static final string headset_uevent_match = "devpath =/devices/virtual/switch/h2w ";

Private Static final string headset_uevent_match = "devpath =/class/switch/h2w ";

References: http://groups.google
. Com/group/A... AD/41a261bc4498a7c4

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.