summaryrefslogtreecommitdiff
path: root/firmware/target/mips/ingenic_x1000/erosqnative/button-erosqnative.c
diff options
context:
space:
mode:
Diffstat (limited to 'firmware/target/mips/ingenic_x1000/erosqnative/button-erosqnative.c')
-rw-r--r--firmware/target/mips/ingenic_x1000/erosqnative/button-erosqnative.c26
1 files changed, 24 insertions, 2 deletions
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 */
76static uint8_t hp_detect_reg = 0x00; 76static uint8_t hp_detect_reg = 0x00;
77static uint8_t hp_detect_reg_old = 0x00; 77static uint8_t hp_detect_reg_old = 0x00;
78static uint8_t hp_detect_debounce1 = 0x00;
79static uint8_t hp_detect_debounce2 = 0x00;
80static 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
82static int hp_detect_tmo_cb(struct timeout* tmo) 85static 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
123bool headphones_inserted(void) 139bool 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
136bool lineout_inserted(void) 155bool 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 {