diff options
Diffstat (limited to 'firmware/target/mips/ingenic_jz47xx/onda_vx747/sadc-onda_vx747.c')
-rw-r--r-- | firmware/target/mips/ingenic_jz47xx/onda_vx747/sadc-onda_vx747.c | 55 |
1 files changed, 30 insertions, 25 deletions
diff --git a/firmware/target/mips/ingenic_jz47xx/onda_vx747/sadc-onda_vx747.c b/firmware/target/mips/ingenic_jz47xx/onda_vx747/sadc-onda_vx747.c index 64ea86135f..2624eb3d82 100644 --- a/firmware/target/mips/ingenic_jz47xx/onda_vx747/sadc-onda_vx747.c +++ b/firmware/target/mips/ingenic_jz47xx/onda_vx747/sadc-onda_vx747.c | |||
@@ -25,6 +25,7 @@ | |||
25 | #include "button.h" | 25 | #include "button.h" |
26 | #include "button-target.h" | 26 | #include "button-target.h" |
27 | #include "powermgmt.h" | 27 | #include "powermgmt.h" |
28 | #include "kernel.h" | ||
28 | 29 | ||
29 | #define BTN_OFF (1 << 29) | 30 | #define BTN_OFF (1 << 29) |
30 | #define BTN_VOL_DOWN (1 << 27) | 31 | #define BTN_VOL_DOWN (1 << 27) |
@@ -36,21 +37,22 @@ | |||
36 | 37 | ||
37 | 38 | ||
38 | #define TS_AD_COUNT 5 | 39 | #define TS_AD_COUNT 5 |
39 | #define M_SADC_CFG_SNUM ((TS_AD_COUNT - 1) << SADC_CFG_SNUM_BIT) | 40 | #define SADC_CFG_SNUM ((TS_AD_COUNT - 1) << SADC_CFG_SNUM_BIT) |
40 | 41 | ||
41 | #define SADC_CFG_INIT ( \ | 42 | #define SADC_CFG_INIT ( \ |
42 | (2 << SADC_CFG_CLKOUT_NUM_BIT) | \ | 43 | (2 << SADC_CFG_CLKOUT_NUM_BIT) | \ |
43 | SADC_CFG_XYZ1Z2 | \ | 44 | SADC_CFG_XYZ1Z2 | \ |
44 | M_SADC_CFG_SNUM | \ | 45 | SADC_CFG_SNUM | \ |
45 | (2 << SADC_CFG_CLKDIV_BIT) | \ | 46 | (2 << SADC_CFG_CLKDIV_BIT) | \ |
46 | SADC_CFG_PBAT_HIGH | \ | 47 | SADC_CFG_PBAT_HIGH | \ |
47 | SADC_CFG_CMD_INT_PEN \ | 48 | SADC_CFG_CMD_INT_PEN \ |
48 | ) | 49 | ) |
49 | 50 | ||
50 | static short x_pos = -1, y_pos = -1, datacount = 0; | 51 | static signed int x_pos, y_pos; |
52 | static int datacount = 0, cur_touch = 0; | ||
51 | static bool pen_down = false; | 53 | static bool pen_down = false; |
52 | static int cur_touch = 0; | 54 | static volatile unsigned short bat_val = 0; |
53 | static unsigned short bat_val = 0; | 55 | static struct mutex battery_mtx; |
54 | 56 | ||
55 | static enum touchscreen_mode current_mode = TOUCHSCREEN_POINT; | 57 | static enum touchscreen_mode current_mode = TOUCHSCREEN_POINT; |
56 | static const int touchscreen_buttons[3][3] = | 58 | static const int touchscreen_buttons[3][3] = |
@@ -93,15 +95,21 @@ const unsigned short percent_to_volt_charge[11] = | |||
93 | unsigned int battery_adc_voltage(void) | 95 | unsigned int battery_adc_voltage(void) |
94 | { | 96 | { |
95 | register unsigned short dummy; | 97 | register unsigned short dummy; |
98 | |||
99 | mutex_lock(&battery_mtx); | ||
100 | |||
96 | dummy = REG_SADC_BATDAT; | 101 | dummy = REG_SADC_BATDAT; |
97 | dummy = REG_SADC_BATDAT; | 102 | dummy = REG_SADC_BATDAT; |
98 | 103 | ||
99 | bat_val = 0; | 104 | bat_val = 0; |
100 | REG_SADC_ENA |= SADC_ENA_PBATEN; | 105 | REG_SADC_ENA |= SADC_ENA_PBATEN; |
101 | 106 | ||
107 | /* Primitive wakeup event */ | ||
102 | while(bat_val == 0) | 108 | while(bat_val == 0) |
103 | yield(); | 109 | yield(); |
104 | 110 | ||
111 | mutex_unlock(&battery_mtx); | ||
112 | |||
105 | return (bat_val*BATTERY_SCALE_FACTOR)>>12; | 113 | return (bat_val*BATTERY_SCALE_FACTOR)>>12; |
106 | } | 114 | } |
107 | 115 | ||
@@ -127,6 +135,8 @@ void button_init_device(void) | |||
127 | __gpio_as_input(32*3 + 16); | 135 | __gpio_as_input(32*3 + 16); |
128 | __gpio_as_input(32*3 + 1); | 136 | __gpio_as_input(32*3 + 1); |
129 | __gpio_as_input(32*3 + 0); | 137 | __gpio_as_input(32*3 + 0); |
138 | |||
139 | mutex_init(&battery_mtx); | ||
130 | } | 140 | } |
131 | 141 | ||
132 | static int touch_to_pixels(short x, short y) | 142 | static int touch_to_pixels(short x, short y) |
@@ -162,6 +172,7 @@ int button_read_device(int *data) | |||
162 | { | 172 | { |
163 | int ret = 0, tmp; | 173 | int ret = 0, tmp; |
164 | 174 | ||
175 | /* Filter button events out if HOLD button is pressed at firmware/ level */ | ||
165 | if((~REG_GPIO_PXPIN(3)) & BTN_HOLD) | 176 | if((~REG_GPIO_PXPIN(3)) & BTN_HOLD) |
166 | return 0; | 177 | return 0; |
167 | 178 | ||
@@ -186,7 +197,7 @@ int button_read_device(int *data) | |||
186 | else if(pen_down) | 197 | else if(pen_down) |
187 | { | 198 | { |
188 | ret |= BUTTON_TOUCH; | 199 | ret |= BUTTON_TOUCH; |
189 | if(data != NULL) | 200 | if(data != NULL && cur_touch != 0) |
190 | *data = cur_touch; | 201 | *data = cur_touch; |
191 | } | 202 | } |
192 | 203 | ||
@@ -226,18 +237,16 @@ void SADC(void) | |||
226 | REG_SADC_CTRL &= (~SADC_CTRL_PENDM ); | 237 | REG_SADC_CTRL &= (~SADC_CTRL_PENDM ); |
227 | REG_SADC_CTRL |= SADC_CTRL_PENUM; | 238 | REG_SADC_CTRL |= SADC_CTRL_PENUM; |
228 | pen_down = false; | 239 | pen_down = false; |
229 | x_pos = -1; | 240 | datacount = 0; |
230 | y_pos = -1; | ||
231 | cur_touch = 0; | 241 | cur_touch = 0; |
232 | } | 242 | } |
233 | if(state & SADC_CTRL_TSRDYM) | 243 | if(state & SADC_CTRL_TSRDYM) |
234 | { | 244 | { |
235 | unsigned int dat; | 245 | unsigned int dat; |
236 | unsigned short xData, yData; | 246 | unsigned short xData, yData; |
237 | short tsz1Data, tsz2Data; | 247 | signed short tsz1Data, tsz2Data; |
238 | 248 | ||
239 | dat = REG_SADC_TSDAT; | 249 | dat = REG_SADC_TSDAT; |
240 | |||
241 | xData = (dat >> 0) & 0xFFF; | 250 | xData = (dat >> 0) & 0xFFF; |
242 | yData = (dat >> 16) & 0xFFF; | 251 | yData = (dat >> 16) & 0xFFF; |
243 | 252 | ||
@@ -245,34 +254,30 @@ void SADC(void) | |||
245 | tsz1Data = (dat >> 0) & 0xFFF; | 254 | tsz1Data = (dat >> 0) & 0xFFF; |
246 | tsz2Data = (dat >> 16) & 0xFFF; | 255 | tsz2Data = (dat >> 16) & 0xFFF; |
247 | 256 | ||
248 | if( !pen_down ) | 257 | if(!pen_down) |
249 | return; | 258 | return; |
250 | 259 | ||
251 | tsz1Data = tsz2Data - tsz1Data; | 260 | tsz1Data = tsz2Data - tsz1Data; |
252 | 261 | ||
253 | if((tsz1Data > 15) || (tsz1Data < -15)) | 262 | if((tsz1Data > 100) || (tsz1Data < -100)) |
254 | { | 263 | { |
255 | if(x_pos == -1) | 264 | if(datacount == 0) |
265 | { | ||
256 | x_pos = xData; | 266 | x_pos = xData; |
257 | else | ||
258 | x_pos = (x_pos + xData) / 2; | ||
259 | |||
260 | if(y_pos == -1) | ||
261 | y_pos = yData; | 267 | y_pos = yData; |
268 | } | ||
262 | else | 269 | else |
263 | y_pos = (y_pos + yData) / 2; | 270 | { |
271 | x_pos += xData; | ||
272 | y_pos += yData; | ||
273 | } | ||
264 | } | 274 | } |
265 | 275 | ||
266 | datacount++; | 276 | datacount++; |
267 | 277 | ||
268 | if(datacount > TS_AD_COUNT - 1) | 278 | if(datacount >= TS_AD_COUNT) |
269 | { | 279 | { |
270 | if(x_pos != -1) | 280 | cur_touch = touch_to_pixels(x_pos/datacount, y_pos/datacount); |
271 | { | ||
272 | cur_touch = touch_to_pixels(x_pos, y_pos); | ||
273 | x_pos = -1; | ||
274 | y_pos = -1; | ||
275 | } | ||
276 | datacount = 0; | 281 | datacount = 0; |
277 | } | 282 | } |
278 | } | 283 | } |