Example of headset plugging and audio channel switching for Android underlying development

Source: Internet
Author: User

Example of headset plugging and audio channel switching for Android underlying development

Example of headset plugging and audio channel switching for Android underlying development


Because the headset is separated by the headset microphone, the incident should be reported separately. In the Android system layer, the earphone Jack is determined based on the value of/sys/class/switch/h2w/state (in the example of 4.4.4 _ r2, WiredAccessoryManager. java ).

You only need to implement a "True or false" switch-based h2w switch in the kernel. The Android system can monitor the plugging information.

When playing music, insert the headset and use the tinymix command (refer to: Android audio underlying debugging-tinyalsa-based) to find that the Playback Path value is changed from SPK to HP_NO_MIC, the plug-in and plug-in Software Check is normal.
<喎?http: www.bkjia.com kf ware vc " target="_blank" class="keylink"> VcD4KPHA + PHN0cm9uZz4jIHRpbnltaXggPC9zdHJvbmc + merge + TWl4ZXIgbmFtZTog "RK_RK616_TINY'

Number of controls: 7

Ctl type num name value

0 ENUM 1 Playback PathHP_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

5 INT 2 Headphone Playback Volume 24

6 ENUM 1 Modem Input Enable ON

#


However, the horn is still ringing, indicating that it is not disabled. Find out which GPIO the schematic "control pin on the power amplifier" goes on.

The Android upper layer should also have audio channel switching, which is better controlled based on the upper layer. In this way, you can enable the speaker forcibly when inserting the headset and hand over the "determine which audio communication is used" to the user.

This should be implemented in the kernel. Because Alsa has switched normally, it indicates that the upper layer has called the corresponding interface. From the driver.

Device Resource: You can see that the Enable GPIO of Speak and handphone gives 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,

};

Function for controlling the audio output channel in the device driver:

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;

......

}

It can be seen that when the output is to the headset channel, the SPEAKER and enable HP are both set GPIO_HIGH. Finally, the RK30_PIN2_PD7 is still high and the SPEAKER is not disabled. The schematic diagram does not have a single enable pin for the headset. Set hp_ctl_gpio to INVALID_GPIO in the resource to solve the problem.

What's more: the principle headset has always had audio output, no matter whether the headset is inserted or not; when the headset is inserted, only the SPEAKER is disabled.

Astray:

1. it is a waste of time to look at the Android upper-Layer Code for a long time in various types. If you use tinymix to view the normal switching of the audio channel, it means that there is no problem with all the above kernel, the problem also lies in the kernel and hardware.

Conclusion: a huge Android system is not suitable for every piece of information. However, if layers are well divided, the problem will be well solved. The record focuses not on the specific model and version, but on the analysis of such problems.

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.