diff options
Diffstat (limited to 'firmware')
-rw-r--r-- | firmware/target/mips/ingenic_jz47xx/xduoo_x3/sadc-xduoo_x3.c | 83 |
1 files changed, 69 insertions, 14 deletions
diff --git a/firmware/target/mips/ingenic_jz47xx/xduoo_x3/sadc-xduoo_x3.c b/firmware/target/mips/ingenic_jz47xx/xduoo_x3/sadc-xduoo_x3.c index b478beceeb..9e0ca1f077 100644 --- a/firmware/target/mips/ingenic_jz47xx/xduoo_x3/sadc-xduoo_x3.c +++ b/firmware/target/mips/ingenic_jz47xx/xduoo_x3/sadc-xduoo_x3.c | |||
@@ -30,12 +30,16 @@ | |||
30 | #include "logf.h" | 30 | #include "logf.h" |
31 | #include "adc.h" | 31 | #include "adc.h" |
32 | 32 | ||
33 | #define BATT_WAIT_TIME HZ * 30 | ||
34 | |||
33 | #define PIN_BTN_POWER (32*0+30) | 35 | #define PIN_BTN_POWER (32*0+30) |
34 | #define PIN_BTN_HOLD (32*1+15) | 36 | #define PIN_BTN_HOLD (32*1+15) |
35 | 37 | ||
36 | #define PIN_KEY_INT (32*4+13) | 38 | #define PIN_KEY_INT (32*4+13) |
37 | #define KEY_INT_IRQ GPIO141 | 39 | #define KEY_INT_IRQ GPIO141 |
38 | 40 | ||
41 | #define PIN_KEY_BOP (32*3+17) /* Back Option Play */ | ||
42 | |||
39 | #define PIN_CHARGE_CON (32*1+7) | 43 | #define PIN_CHARGE_CON (32*1+7) |
40 | 44 | ||
41 | #define PIN_PH_DECT (32*1+11) | 45 | #define PIN_PH_DECT (32*1+11) |
@@ -46,6 +50,8 @@ | |||
46 | #define IRQ_LO_DECT GPIO_IRQ(PIN_LO_DECT) | 50 | #define IRQ_LO_DECT GPIO_IRQ(PIN_LO_DECT) |
47 | #define GPIO_LO_DECT GPIO44 | 51 | #define GPIO_LO_DECT GPIO44 |
48 | 52 | ||
53 | /*#define ENABLE_BUTTON_COMBOS*/ | ||
54 | |||
49 | static volatile unsigned short bat_val,key_val; | 55 | static volatile unsigned short bat_val,key_val; |
50 | 56 | ||
51 | bool headphones_inserted(void) | 57 | bool headphones_inserted(void) |
@@ -70,11 +76,15 @@ void button_init_device(void) | |||
70 | __gpio_disable_pull(PIN_BTN_POWER); | 76 | __gpio_disable_pull(PIN_BTN_POWER); |
71 | __gpio_disable_pull(PIN_BTN_HOLD); | 77 | __gpio_disable_pull(PIN_BTN_HOLD); |
72 | 78 | ||
73 | #if 0 | 79 | #ifdef ENABLE_BUTTON_COMBOS |
74 | /* We poll this, no need to set it up for an interrupt */ | 80 | __gpio_as_output(PIN_KEY_BOP); |
81 | __gpio_disable_pull(PIN_KEY_BOP); | ||
82 | __gpio_clear_pin(PIN_KEY_BOP); | ||
83 | #endif | ||
84 | |||
75 | __gpio_as_irq_fall_edge(PIN_KEY_INT); | 85 | __gpio_as_irq_fall_edge(PIN_KEY_INT); |
86 | __gpio_enable_pull(PIN_KEY_INT); | ||
76 | system_enable_irq(GPIO_IRQ(PIN_KEY_INT)); | 87 | system_enable_irq(GPIO_IRQ(PIN_KEY_INT)); |
77 | #endif | ||
78 | 88 | ||
79 | __gpio_set_pin(PIN_CHARGE_CON); /* 0.7 A */ | 89 | __gpio_set_pin(PIN_CHARGE_CON); /* 0.7 A */ |
80 | __gpio_as_output(PIN_CHARGE_CON); | 90 | __gpio_as_output(PIN_CHARGE_CON); |
@@ -88,31 +98,23 @@ void button_init_device(void) | |||
88 | 98 | ||
89 | bool button_hold(void) | 99 | bool button_hold(void) |
90 | { | 100 | { |
91 | return (__gpio_get_pin(PIN_BTN_HOLD) ? true : false); | 101 | return (__gpio_get_pin(PIN_BTN_HOLD) ? true : false); |
92 | } | 102 | } |
93 | 103 | ||
94 | /* NOTE: Due to how this is wired, button combinations are not allowed | 104 | /* NOTE: Due to how this is wired, button combinations are not allowed |
95 | unless one of the two buttons is the POWER | 105 | unless one of the two buttons is the POWER |
106 | ENABLE_BUTTON_COMBOS when defined also allows 'Back, Option, Play' | ||
96 | */ | 107 | */ |
97 | int button_read_device(void) | 108 | int button_read_device(void) |
98 | { | 109 | { |
110 | int btn = BUTTON_NONE; | ||
99 | #ifndef BOOTLOADER | 111 | #ifndef BOOTLOADER |
100 | static bool hold_button = false; | 112 | static bool hold_button = false; |
101 | bool hold_button_old; | 113 | bool hold_button_old; |
102 | 114 | ||
103 | hold_button_old = hold_button; | 115 | hold_button_old = hold_button; |
104 | hold_button = (__gpio_get_pin(PIN_BTN_HOLD) ? true : false); | 116 | hold_button = (__gpio_get_pin(PIN_BTN_HOLD) ? true : false); |
105 | #endif | ||
106 | 117 | ||
107 | int btn = BUTTON_NONE; | ||
108 | bool gpio_btn = (__gpio_get_pin(PIN_BTN_POWER) ? false : true); | ||
109 | |||
110 | /* Don't initiate a new request if we have one pending */ | ||
111 | if (!(REG_SADC_ADENA & (ADENA_VBATEN | ADENA_AUXEN))) { | ||
112 | REG_SADC_ADENA = ADENA_VBATEN | ADENA_AUXEN; | ||
113 | } | ||
114 | |||
115 | #ifndef BOOTLOADER | ||
116 | if (hold_button != hold_button_old) { | 118 | if (hold_button != hold_button_old) { |
117 | backlight_hold_changed(hold_button); | 119 | backlight_hold_changed(hold_button); |
118 | } | 120 | } |
@@ -121,9 +123,19 @@ int button_read_device(void) | |||
121 | } | 123 | } |
122 | #endif | 124 | #endif |
123 | 125 | ||
126 | bool gpio_btn = (__gpio_get_pin(PIN_BTN_POWER) ? false : true); | ||
124 | if (gpio_btn) | 127 | if (gpio_btn) |
125 | btn |= BUTTON_POWER; | 128 | btn |= BUTTON_POWER; |
126 | 129 | ||
130 | #ifdef ENABLE_BUTTON_COMBOS | ||
131 | if (__gpio_get_pin(PIN_KEY_INT) && (!__gpio_get_pin(PIN_KEY_BOP))) | ||
132 | #else | ||
133 | if (__gpio_get_pin(PIN_KEY_INT)) | ||
134 | #endif | ||
135 | { | ||
136 | return btn; | ||
137 | } | ||
138 | |||
127 | if (key_val < 261) | 139 | if (key_val < 261) |
128 | btn |= BUTTON_VOL_UP; | 140 | btn |= BUTTON_VOL_UP; |
129 | else | 141 | else |
@@ -151,6 +163,15 @@ int button_read_device(void) | |||
151 | /* called on button press interrupt */ | 163 | /* called on button press interrupt */ |
152 | void KEY_INT_IRQ(void) | 164 | void KEY_INT_IRQ(void) |
153 | { | 165 | { |
166 | |||
167 | /* Don't initiate a new request if we have one pending */ | ||
168 | if(!(REG_SADC_ADENA & (ADENA_AUXEN)) | ||
169 | #ifdef ENABLE_BUTTON_COMBOS | ||
170 | && (!__gpio_get_pin(PIN_KEY_BOP)) | ||
171 | #endif | ||
172 | ){ | ||
173 | REG_SADC_ADENA |= ADENA_AUXEN; | ||
174 | } | ||
154 | } | 175 | } |
155 | 176 | ||
156 | /* Notes on batteries | 177 | /* Notes on batteries |
@@ -194,6 +215,21 @@ const unsigned short percent_to_volt_charge[11] = | |||
194 | /* Returns battery voltage from ADC [millivolts] */ | 215 | /* Returns battery voltage from ADC [millivolts] */ |
195 | int _battery_voltage(void) | 216 | int _battery_voltage(void) |
196 | { | 217 | { |
218 | static long last_tick = 0; | ||
219 | |||
220 | if (TIME_AFTER(current_tick, last_tick + BATT_WAIT_TIME)) | ||
221 | { | ||
222 | last_tick = current_tick; | ||
223 | REG_SADC_ADENA |= ADENA_VBATEN; | ||
224 | __intc_mask_irq(IRQ_SADC); | ||
225 | while ((REG_SADC_ADENA & ADENA_VBATEN) && | ||
226 | TIME_BEFORE(current_tick, last_tick + HZ / 20)) | ||
227 | ;; | ||
228 | __intc_unmask_irq(IRQ_SADC); | ||
229 | if (!(REG_SADC_ADENA & ADENA_VBATEN)) | ||
230 | bat_val = REG_SADC_ADVDAT; | ||
231 | } | ||
232 | |||
197 | return (bat_val*BATTERY_SCALE_FACTOR)>>10; | 233 | return (bat_val*BATTERY_SCALE_FACTOR)>>10; |
198 | } | 234 | } |
199 | 235 | ||
@@ -238,6 +274,25 @@ void SADC(void) | |||
238 | if(state & ADCTRL_ARDYM) | 274 | if(state & ADCTRL_ARDYM) |
239 | { | 275 | { |
240 | key_val = REG_SADC_ADADAT; | 276 | key_val = REG_SADC_ADADAT; |
277 | #ifdef ENABLE_BUTTON_COMBOS | ||
278 | __gpio_mask_irq(PIN_KEY_INT); | ||
279 | __gpio_clear_pin(PIN_KEY_BOP); | ||
280 | __gpio_unmask_irq(PIN_KEY_INT); | ||
281 | #endif | ||
282 | |||
283 | if (!__gpio_get_pin(PIN_KEY_INT)) /* key(s) are down kick off another read */ | ||
284 | { | ||
285 | __gpio_set_pin(PIN_KEY_BOP); | ||
286 | REG_SADC_ADENA = ADENA_AUXEN; | ||
287 | } | ||
288 | #ifdef ENABLE_BUTTON_COMBOS | ||
289 | else | ||
290 | { | ||
291 | __gpio_mask_irq(PIN_KEY_INT); | ||
292 | __gpio_clear_pin(PIN_KEY_BOP); | ||
293 | __gpio_unmask_irq(PIN_KEY_INT); | ||
294 | } | ||
295 | #endif | ||
241 | } | 296 | } |
242 | if(state & ADCTRL_VRDYM) | 297 | if(state & ADCTRL_VRDYM) |
243 | { | 298 | { |