Portapack application development tutorial (9) add speaker function

Recently, I am mainly improving the portapack hardware. I now have the built-in battery hardware. The switch is not difficult. Just change the shell. The next job is to add speakers and microphones.

Speaking to a friend, it turns out that the portapack hardware supports speakers, but the software is not open.

I looked for information and found an issue in the original repo

https://github.com/furrtek/portapack-havoc/issues/284

There is a foreigner's comment, it is recommended to check these two codes.

firmware\application\audio.cpp
firmware\common\ak4951.cpp
After I watched it, I found it was basically a play.

Then I imitated the disable and enable of the headset in the mute and unmute functions in audio.cpp and added the disable and enable of the speaker.

When joining, pay attention to the realization of several virtual functions in the header file, so that audio.cpp can call the speaker related functions in ak4951.cpp.

Otherwise, you will be prompted that functions such as speaker_enable cannot be found. As for how to join, please refer to the related functions of the headset.

Then I found a small speaker, two wires, the two ends were connected to the outer two feet of the 3pin speaker, and there was sound. If the sound is light, the speaker can be attached to the shell to form resonance (I feel this principle is the same People’s hands hold the antenna to enhance the reception effect). You can also adjust the volume in the upper right corner.

If the power bank is powered, the volume cannot exceed 80, and the volume cannot be lower than 70, otherwise there will be no sound. If battery-powered, the volume can reach 99, but it will be distorted above 90.

Later I found out that if the speaker is kept on, the power consumption is quite severe.

So I thought of a way to add an icon to the top column, and use this icon to control whether the speaker is turned on.

This icon is added in ui_navigation and can be modeled after stealth icon. But it is impossible for this ui_navigation to directly manipulate audio.

I imitated antenna_bias and asked him to access the variables and functions in portapack.cpp, and then portapack.cpp can access audio.cpp, so that a complete chain is realized. Please see my github repo for details.

Demo video:

https://www.bilibili.com/video/BV1tt4y117wM

Guess you like

Origin blog.csdn.net/shukebeta008/article/details/105897595