Android bottom Audio channel headphone Plug and switch housing development

Source: Internet
Author: User

Android Potential Development headphone plug connection to audio channel switch example


Because you are using headphones with a separate headset, you have to escalate the event separately. The detection of headphone jacks on the Android system layer is inferred based on The value of the/sys/class/switch/h2w/state (in 4.4.4_r2 for the sample is located in Wiredaccessorymanager.java).

Just implement a switch class -based h2w switches in the kernel that is "either true or false ." the Android system will be able to monitor the plug and unplug information.

Insert headphones when playing music, use Tinymix (refer to:Android audio underlying debug - based on Tinyalsa ) command to find the value of playback Path from SPK to hp_no_mic, it is possible to indicate that the headset Plug and Unplug software detects normal.

# Tinymix

Mixer name: ' Rk_rk616_tiny '

Number of Controls:7

CTL Type num Name value

0 ENUM 1 Playback Path hp_no_mic

1 ENUM 1 Capture mic Path mic OFF

2 ENUM 1 Voice call Path OFF

3 ENUM 1 Voip Path OFF

4 INT 2 Speaker Playback Volume 24 24

5 INT 2 Headphone Playback Volume 24 24

6 ENUM 1 Modem Input Enable on

#


But the horn was still ringing, stating that it had not been closed. Check the schematic "control pin on the power amplifier" on which GPIO is followed.

According to the manual, only to Gpio2_d7 can output low level can achieve the speaker's closure , using a multimeter measured after inserting the headset, the pin is still high level. View Code churn records in the previous version number a colleague is directly in the rk_headset.c Headphone plug-in program changes to pull it down, this can be achieved but considered inappropriate. the Android Upper layer should also have audio channel switching. It is better to control it according to the upper layer.

This will also force the speaker to be turned on when plugged into the headset. Give the user the "decision on which audio communication to use".

This should be implemented in the kernel, because the Alsa has switched normally, it means that the upper layer has already called the corresponding interface. From the drive to analyze.

Equipment resources: Can see Speak and handphone of the Enable GPIO all give is Rk30_pin2_pd7 .

static struct Rk616_platform_data Rk616_pdata = {

. Power_init = Rk616_power_on_init,

. Power_deinit = Rk616_power_deinit,

. scl_rate = Rk616_scl_rate,

. Lcd0_func = input,//port lcd0 as input

. Lcd1_func = input,//port lcd1 as input

. LVDS_CH_NR = 1,//the number of used LVDS channel

. HDMI_IRQ = Rk30_pin2_pd6,

. Spk_ctl_gpio = Rk30_pin2_pd7 ,

. Hp_ctl_gpio = Rk30_pin2_pd7 ,

};

Functions for controlling audio output channels in device drivers:

static int rk616_playback_path_put (struct Snd_kcontrol *kcontrol,

struct Snd_ctl_elem_value *ucontrol)

{

......

Case Hp_path:

Case Hp_no_mic:

Case RING_HP:

Case Ring_hp_no_mic:

Rk616_set_gpio (rk616_codec_set_spk, gpio_low);

if (Pre_path = = OFF)

RK616_CODEC_POWER_UP (Rk616_codec_playback);

Snd_soc_update_bits (codec, Rk616_spkl_ctl,

Rk616_vol_mask, Hpout_volume); , volume (bit 0-4)

Snd_soc_update_bits (codec, Rk616_spkr_ctl,

Rk616_vol_mask, Hpout_volume);

Rk616_set_gpio (rk616_codec_set_hp, gpio_high);

Break

......

}

Visible in the output to the headphone channel, disable SPEAKER and enable HP are set gpio_high, and finally rk30_pin2_ The PD7 is still high , and SPEAKERis not disabled. The schematic does not have a separate headphone to enable the pin. set hp_ctl_gpio to invalid_gpioin the resource. Problem solved.

Bonus: Principle headphones There has always been audio output, no matter the insertion is not plugged into the headset, while inserting the headset SPEAKER is forbidden.

Strayed Astray:

1. Mistakenly think to see the Android upper layer code in each kind of search for a very long time. It is a waste of time, assuming that using tinymix to view the audio channel switch is normal, the kernel is no problem, the problem is also in the kernel and hardware.

Summary: The vast Android system does not allow you to understand each piece very carefully, but the assumption will be very good division of hierarchy. The problem will be solved very well. The focus of the record is not on the detailed model version number and so on the more virtual aspects, but, in such a problem is good at analyzing the mind face.

Copyright notice: This article blog original article. Blogs, without consent, may not be reproduced.

Android bottom Audio channel headphone Plug and switch housing development

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.