diff options
author | Dana Conrad <dconrad@fastmail.com> | 2024-07-25 19:10:42 -0500 |
---|---|---|
committer | Solomon Peachy <pizza@shaftnet.org> | 2024-07-30 11:39:47 -0400 |
commit | ef9490f68329821fc36b2ef9d3c19dc6d7698c55 (patch) | |
tree | f77e80a5f5886fad8cc038fef57d82d0e21029a5 | |
parent | 4d26f559eedebe92439c296111c303a47feb36a8 (diff) | |
download | rockbox-ef9490f68329821fc36b2ef9d3c19dc6d7698c55.tar.gz rockbox-ef9490f68329821fc36b2ef9d3c19dc6d7698c55.zip |
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
-rw-r--r-- | firmware/target/mips/ingenic_x1000/erosqnative/audiohw-erosqnative.c | 16 | ||||
-rw-r--r-- | firmware/target/mips/ingenic_x1000/erosqnative/button-erosqnative.c | 26 |
2 files changed, 33 insertions, 9 deletions
diff --git a/firmware/target/mips/ingenic_x1000/erosqnative/audiohw-erosqnative.c b/firmware/target/mips/ingenic_x1000/erosqnative/audiohw-erosqnative.c index df97aba0c8..4bd3316889 100644 --- a/firmware/target/mips/ingenic_x1000/erosqnative/audiohw-erosqnative.c +++ b/firmware/target/mips/ingenic_x1000/erosqnative/audiohw-erosqnative.c | |||
@@ -139,17 +139,19 @@ void audiohw_set_volume(int vol_l, int vol_r) | |||
139 | r = vol_r; | 139 | r = vol_r; |
140 | 140 | ||
141 | #if (defined(HAVE_HEADPHONE_DETECTION) && defined(HAVE_LINEOUT_DETECTION)) | 141 | #if (defined(HAVE_HEADPHONE_DETECTION) && defined(HAVE_LINEOUT_DETECTION)) |
142 | /* make sure headphones aren't present - don't want to | 142 | /* Due to the hardware's detection method, make the Line-Out |
143 | * blow out our eardrums cranking it to full */ | 143 | * the default. The LO can only be detected if it is active |
144 | if (lineout_inserted() && !headphones_inserted()) | 144 | * (assuming a high-impedance device is attached). HP takes priority |
145 | * if both are present. */ | ||
146 | if (headphones_inserted()) | ||
145 | { | 147 | { |
146 | eros_qn_switch_output(1); | 148 | eros_qn_switch_output(0); |
147 | |||
148 | l = r = eros_qn_get_volume_limit(); | ||
149 | } | 149 | } |
150 | else | 150 | else |
151 | { | 151 | { |
152 | eros_qn_switch_output(0); | 152 | eros_qn_switch_output(1); |
153 | |||
154 | l = r = eros_qn_get_volume_limit(); | ||
153 | } | 155 | } |
154 | #endif | 156 | #endif |
155 | 157 | ||
diff --git a/firmware/target/mips/ingenic_x1000/erosqnative/button-erosqnative.c b/firmware/target/mips/ingenic_x1000/erosqnative/button-erosqnative.c index 0d2207af2a..707dc372a8 100644 --- a/firmware/target/mips/ingenic_x1000/erosqnative/button-erosqnative.c +++ b/firmware/target/mips/ingenic_x1000/erosqnative/button-erosqnative.c | |||
@@ -75,12 +75,26 @@ volatile signed int enc_position = 0; | |||
75 | /* Value of headphone detect register */ | 75 | /* Value of headphone detect register */ |
76 | static uint8_t hp_detect_reg = 0x00; | 76 | static uint8_t hp_detect_reg = 0x00; |
77 | static uint8_t hp_detect_reg_old = 0x00; | 77 | static uint8_t hp_detect_reg_old = 0x00; |
78 | static uint8_t hp_detect_debounce1 = 0x00; | ||
79 | static uint8_t hp_detect_debounce2 = 0x00; | ||
80 | static uint8_t debounce_count = 0; | ||
78 | 81 | ||
79 | /* Interval to poll the register */ | 82 | /* Interval to poll the register */ |
80 | #define HPD_POLL_TIME (HZ/2) | 83 | #define HPD_POLL_TIME (HZ/4) |
81 | 84 | ||
82 | static int hp_detect_tmo_cb(struct timeout* tmo) | 85 | static int hp_detect_tmo_cb(struct timeout* tmo) |
83 | { | 86 | { |
87 | if (hp_detect_debounce1 == hp_detect_debounce2){ | ||
88 | if (debounce_count >= 2){ | ||
89 | debounce_count = 2; | ||
90 | } else { | ||
91 | debounce_count = debounce_count + 1; | ||
92 | } | ||
93 | } else { | ||
94 | debounce_count = 0; | ||
95 | hp_detect_debounce2 = hp_detect_debounce1; | ||
96 | } | ||
97 | |||
84 | i2c_descriptor* d = (i2c_descriptor*)tmo->data; | 98 | i2c_descriptor* d = (i2c_descriptor*)tmo->data; |
85 | i2c_async_queue(AXP_PMU_BUS, TIMEOUT_NOBLOCK, I2C_Q_ADD, 0, d); | 99 | i2c_async_queue(AXP_PMU_BUS, TIMEOUT_NOBLOCK, I2C_Q_ADD, 0, d); |
86 | return HPD_POLL_TIME; | 100 | return HPD_POLL_TIME; |
@@ -96,7 +110,7 @@ static void hp_detect_init(void) | |||
96 | .tran_mode = I2C_READ, | 110 | .tran_mode = I2C_READ, |
97 | .buffer[0] = (void*)&gpio_reg, | 111 | .buffer[0] = (void*)&gpio_reg, |
98 | .count[0] = 1, | 112 | .count[0] = 1, |
99 | .buffer[1] = &hp_detect_reg, | 113 | .buffer[1] = &hp_detect_debounce1, |
100 | .count[1] = 1, | 114 | .count[1] = 1, |
101 | .callback = NULL, | 115 | .callback = NULL, |
102 | .arg = 0, | 116 | .arg = 0, |
@@ -113,6 +127,8 @@ static void hp_detect_init(void) | |||
113 | if(r >= 0) | 127 | if(r >= 0) |
114 | { | 128 | { |
115 | hp_detect_reg = r; | 129 | hp_detect_reg = r; |
130 | hp_detect_debounce1 = r; | ||
131 | hp_detect_debounce2 = r; | ||
116 | hp_detect_reg_old = hp_detect_reg; | 132 | hp_detect_reg_old = hp_detect_reg; |
117 | } | 133 | } |
118 | 134 | ||
@@ -122,6 +138,9 @@ static void hp_detect_init(void) | |||
122 | 138 | ||
123 | bool headphones_inserted(void) | 139 | bool headphones_inserted(void) |
124 | { | 140 | { |
141 | if (debounce_count > 1){ | ||
142 | hp_detect_reg = hp_detect_debounce2; | ||
143 | } | ||
125 | /* if the status has changed, set the output volume accordingly */ | 144 | /* if the status has changed, set the output volume accordingly */ |
126 | if ((hp_detect_reg & 0x30) != (hp_detect_reg_old & 0x30)) | 145 | if ((hp_detect_reg & 0x30) != (hp_detect_reg_old & 0x30)) |
127 | { | 146 | { |
@@ -135,6 +154,9 @@ bool headphones_inserted(void) | |||
135 | 154 | ||
136 | bool lineout_inserted(void) | 155 | bool lineout_inserted(void) |
137 | { | 156 | { |
157 | if (debounce_count > 1){ | ||
158 | hp_detect_reg = hp_detect_debounce2; | ||
159 | } | ||
138 | /* if the status has changed, set the output volume accordingly */ | 160 | /* if the status has changed, set the output volume accordingly */ |
139 | if ((hp_detect_reg & 0x30) != (hp_detect_reg_old & 0x30)) | 161 | if ((hp_detect_reg & 0x30) != (hp_detect_reg_old & 0x30)) |
140 | { | 162 | { |