fix(tx15): headphone detection (#6686)
This commit is contained in:
@@ -139,9 +139,14 @@ static void audio_update_dma_buffer(uint8_t tc)
|
||||
}
|
||||
}
|
||||
|
||||
bool audioHeadphoneDetect()
|
||||
{
|
||||
return gpio_read(AUDIO_HP_DETECT_PIN);
|
||||
}
|
||||
|
||||
void audioSetVolume(uint8_t volume)
|
||||
{
|
||||
tas2505_set_volume(&_tas2505, volume * 9 / 10); // TX15 HP cannot handle the full power of TAS2505
|
||||
tas2505_set_volume(&_tas2505, volume * 9 / 10, audioHeadphoneDetect()); // TX15 HP cannot handle the full power of TAS2505
|
||||
}
|
||||
|
||||
extern "C" void DMA1_Stream4_IRQHandler(void)
|
||||
|
||||
@@ -133,7 +133,7 @@ int tas2505_init(tas2505_t* dev)
|
||||
// max value is 126
|
||||
#define VOLUME_MIN_DB 60
|
||||
|
||||
void tas2505_set_volume(tas2505_t* dev, uint8_t volume)
|
||||
void tas2505_set_volume(tas2505_t* dev, uint8_t volume, bool headphone_mode = false)
|
||||
{
|
||||
if (volume > VOLUME_LEVEL_MAX) {
|
||||
volume = VOLUME_LEVEL_MAX;
|
||||
@@ -145,7 +145,12 @@ void tas2505_set_volume(tas2505_t* dev, uint8_t volume)
|
||||
} else {
|
||||
uint32_t vol = (VOLUME_MIN_DB * 2) -
|
||||
((uint32_t)volume * (VOLUME_MIN_DB * 2)) / VOLUME_LEVEL_MAX;
|
||||
tas2505_write_reg(dev, TAS2505_SPKVOL1, vol);
|
||||
tas2505_write_reg(dev, TAS2505_HP_VOL, vol);
|
||||
if (headphone_mode) {
|
||||
tas2505_write_reg(dev, TAS2505_SPKVOL1, 0xFE);
|
||||
tas2505_write_reg(dev, TAS2505_HP_VOL, vol);
|
||||
} else {
|
||||
tas2505_write_reg(dev, TAS2505_SPKVOL1, vol);
|
||||
tas2505_write_reg(dev, TAS2505_HP_VOL, 0xFE);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -94,4 +94,4 @@ typedef struct {
|
||||
|
||||
int tas2505_probe(tas2505_t* dev, etx_i2c_bus_t bus, uint16_t addr);
|
||||
int tas2505_init(tas2505_t* dev);
|
||||
void tas2505_set_volume(tas2505_t* dev, uint8_t volume);
|
||||
void tas2505_set_volume(tas2505_t* dev, uint8_t volume, bool headphone_mode);
|
||||
|
||||
@@ -32,7 +32,7 @@
|
||||
#define AUDIO_SAMPLE_FMT_S16 0
|
||||
#define AUDIO_SAMPLE_FMT_U16 1
|
||||
|
||||
|
||||
bool audioHeadphoneDetect();
|
||||
void audioSetVolume(uint8_t volume);
|
||||
void audioConsumeCurrentBuffer();
|
||||
|
||||
|
||||
@@ -47,6 +47,9 @@
|
||||
#if defined(AUDIO)
|
||||
uint8_t currentSpeakerVolume = 255;
|
||||
uint8_t requiredSpeakerVolume = 255;
|
||||
#if defined(AUDIO_HP_DETECT_PIN)
|
||||
bool hpDetected = false;
|
||||
#endif
|
||||
#endif
|
||||
|
||||
uint8_t currentBacklightBright = 0;
|
||||
@@ -207,6 +210,13 @@ void handleUsbConnection()
|
||||
|
||||
void checkSpeakerVolume()
|
||||
{
|
||||
#if defined(AUDIO_HP_DETECT_PIN)
|
||||
// volume needs to be set on plug/unplug to set the the right volume on each device
|
||||
if (hpDetected != audioHeadphoneDetect()) {
|
||||
hpDetected = !hpDetected;
|
||||
audioSetVolume(currentSpeakerVolume);
|
||||
}
|
||||
#endif
|
||||
#if defined(AUDIO)
|
||||
if (currentSpeakerVolume != requiredSpeakerVolume) {
|
||||
currentSpeakerVolume = requiredSpeakerVolume;
|
||||
|
||||
@@ -22,6 +22,13 @@
|
||||
#include "audio.h"
|
||||
#include "simuaudio.h"
|
||||
|
||||
#if defined(AUDIO_HP_DETECT_PIN)
|
||||
bool audioHeadphoneDetect()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
#endif
|
||||
|
||||
#if !defined(SOFTWARE_VOLUME)
|
||||
static int _simu_volume = 0;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user