forked from len0rd/rockbox
ErosQNative: Debounce jack detection and make Line-Out default
Making line-out default output should allow detection to work correctly. Headphone detection should work whether or not headphone is currently the active output due to the low impedance (relatively) of the headphones. Line-Out sinks will likely be high impedance, so we need the output as a pull-down for detection. Debounce detection to prevent false triggers due to voltage swings during playback. Change-Id: If5e497d900330f64d0f49a135e953ee6b0499668
This commit is contained in:
parent
4d26f559ee
commit
ef9490f683
2 changed files with 33 additions and 9 deletions
|
|
@ -139,18 +139,20 @@ void audiohw_set_volume(int vol_l, int vol_r)
|
||||||
r = vol_r;
|
r = vol_r;
|
||||||
|
|
||||||
#if (defined(HAVE_HEADPHONE_DETECTION) && defined(HAVE_LINEOUT_DETECTION))
|
#if (defined(HAVE_HEADPHONE_DETECTION) && defined(HAVE_LINEOUT_DETECTION))
|
||||||
/* make sure headphones aren't present - don't want to
|
/* Due to the hardware's detection method, make the Line-Out
|
||||||
* blow out our eardrums cranking it to full */
|
* the default. The LO can only be detected if it is active
|
||||||
if (lineout_inserted() && !headphones_inserted())
|
* (assuming a high-impedance device is attached). HP takes priority
|
||||||
|
* if both are present. */
|
||||||
|
if (headphones_inserted())
|
||||||
|
{
|
||||||
|
eros_qn_switch_output(0);
|
||||||
|
}
|
||||||
|
else
|
||||||
{
|
{
|
||||||
eros_qn_switch_output(1);
|
eros_qn_switch_output(1);
|
||||||
|
|
||||||
l = r = eros_qn_get_volume_limit();
|
l = r = eros_qn_get_volume_limit();
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
eros_qn_switch_output(0);
|
|
||||||
}
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (es9018k2m_present_flag) /* ES9018K2M */
|
if (es9018k2m_present_flag) /* ES9018K2M */
|
||||||
|
|
|
||||||
|
|
@ -75,12 +75,26 @@ volatile signed int enc_position = 0;
|
||||||
/* Value of headphone detect register */
|
/* Value of headphone detect register */
|
||||||
static uint8_t hp_detect_reg = 0x00;
|
static uint8_t hp_detect_reg = 0x00;
|
||||||
static uint8_t hp_detect_reg_old = 0x00;
|
static uint8_t hp_detect_reg_old = 0x00;
|
||||||
|
static uint8_t hp_detect_debounce1 = 0x00;
|
||||||
|
static uint8_t hp_detect_debounce2 = 0x00;
|
||||||
|
static uint8_t debounce_count = 0;
|
||||||
|
|
||||||
/* Interval to poll the register */
|
/* Interval to poll the register */
|
||||||
#define HPD_POLL_TIME (HZ/2)
|
#define HPD_POLL_TIME (HZ/4)
|
||||||
|
|
||||||
static int hp_detect_tmo_cb(struct timeout* tmo)
|
static int hp_detect_tmo_cb(struct timeout* tmo)
|
||||||
{
|
{
|
||||||
|
if (hp_detect_debounce1 == hp_detect_debounce2){
|
||||||
|
if (debounce_count >= 2){
|
||||||
|
debounce_count = 2;
|
||||||
|
} else {
|
||||||
|
debounce_count = debounce_count + 1;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
debounce_count = 0;
|
||||||
|
hp_detect_debounce2 = hp_detect_debounce1;
|
||||||
|
}
|
||||||
|
|
||||||
i2c_descriptor* d = (i2c_descriptor*)tmo->data;
|
i2c_descriptor* d = (i2c_descriptor*)tmo->data;
|
||||||
i2c_async_queue(AXP_PMU_BUS, TIMEOUT_NOBLOCK, I2C_Q_ADD, 0, d);
|
i2c_async_queue(AXP_PMU_BUS, TIMEOUT_NOBLOCK, I2C_Q_ADD, 0, d);
|
||||||
return HPD_POLL_TIME;
|
return HPD_POLL_TIME;
|
||||||
|
|
@ -96,7 +110,7 @@ static void hp_detect_init(void)
|
||||||
.tran_mode = I2C_READ,
|
.tran_mode = I2C_READ,
|
||||||
.buffer[0] = (void*)&gpio_reg,
|
.buffer[0] = (void*)&gpio_reg,
|
||||||
.count[0] = 1,
|
.count[0] = 1,
|
||||||
.buffer[1] = &hp_detect_reg,
|
.buffer[1] = &hp_detect_debounce1,
|
||||||
.count[1] = 1,
|
.count[1] = 1,
|
||||||
.callback = NULL,
|
.callback = NULL,
|
||||||
.arg = 0,
|
.arg = 0,
|
||||||
|
|
@ -113,6 +127,8 @@ static void hp_detect_init(void)
|
||||||
if(r >= 0)
|
if(r >= 0)
|
||||||
{
|
{
|
||||||
hp_detect_reg = r;
|
hp_detect_reg = r;
|
||||||
|
hp_detect_debounce1 = r;
|
||||||
|
hp_detect_debounce2 = r;
|
||||||
hp_detect_reg_old = hp_detect_reg;
|
hp_detect_reg_old = hp_detect_reg;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -122,6 +138,9 @@ static void hp_detect_init(void)
|
||||||
|
|
||||||
bool headphones_inserted(void)
|
bool headphones_inserted(void)
|
||||||
{
|
{
|
||||||
|
if (debounce_count > 1){
|
||||||
|
hp_detect_reg = hp_detect_debounce2;
|
||||||
|
}
|
||||||
/* if the status has changed, set the output volume accordingly */
|
/* if the status has changed, set the output volume accordingly */
|
||||||
if ((hp_detect_reg & 0x30) != (hp_detect_reg_old & 0x30))
|
if ((hp_detect_reg & 0x30) != (hp_detect_reg_old & 0x30))
|
||||||
{
|
{
|
||||||
|
|
@ -135,6 +154,9 @@ bool headphones_inserted(void)
|
||||||
|
|
||||||
bool lineout_inserted(void)
|
bool lineout_inserted(void)
|
||||||
{
|
{
|
||||||
|
if (debounce_count > 1){
|
||||||
|
hp_detect_reg = hp_detect_debounce2;
|
||||||
|
}
|
||||||
/* if the status has changed, set the output volume accordingly */
|
/* if the status has changed, set the output volume accordingly */
|
||||||
if ((hp_detect_reg & 0x30) != (hp_detect_reg_old & 0x30))
|
if ((hp_detect_reg & 0x30) != (hp_detect_reg_old & 0x30))
|
||||||
{
|
{
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue