fix(tx15): headphone detection (#6686)

This commit is contained in:
3djc
2025-10-18 20:39:13 +10:00
committed by GitHub
parent e904da89e7
commit f4ecf03a9e
6 changed files with 33 additions and 6 deletions
+6 -1
View File
@@ -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)
+8 -3
View File
@@ -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);
}
}
}
+1 -1
View File
@@ -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);
+1 -1
View File
@@ -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();
+10
View File
@@ -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;
+7
View File
@@ -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;