fbdev/fb_notify: fix blank_mode pointer crash
[firefly-linux-kernel-4.4.55.git] / drivers / input / touchscreen / gsl_point_id.c
1 /*
2  * drivers/input/touchscreen/gsl_point_id.c
3  *
4  * Copyright (c) 2012 Shanghai Basewin
5  *      Guan Yuwei<guanyuwei@basewin.com>
6  *
7  *  This program is free software; you can redistribute it and/or modify
8  *  it under the terms of the GNU General Public License version 2 as
9  *  published by the Free Software Foundation.
10  */
11
12 //#include "linux/module.h"
13 //#include <wdm.h>
14 /*
15 NTSTATUS
16 DriverEntry(
17   IN PDRIVER_OBJECT DriverObject,
18   IN PUNICODE_STRING RegistryPath
19 );
20
21 #ifdef ALLOC_PRAGMA
22 #pragma alloc_text(INIT, DriverEntry)
23 #endif
24
25 NTSTATUS
26 DllInitialize( IN PUNICODE_STRING pus )
27 {
28     DbgPrint("GSL_POINT_ID: DllInitialize(%S)\n", pus->Buffer );
29     return STATUS_SUCCESS;
30 }
31
32 NTSTATUS
33 DllUnload( )
34 {
35     DbgPrint("GSL_POINT_ID: DllUnload\n");
36     return STATUS_SUCCESS;
37 }
38 */
39 //#define       GESTURE_ABLE    1
40 #define GESTURE_LICH    1
41
42 #define GSL_VERSION             0x20140421
43 #ifndef NULL
44 #define NULL  ((void*)0)
45 #endif
46 #ifndef UINT
47 #define UINT  unsigned int
48 #endif
49
50 #define POINT_MAX               10
51 #define PP_DEEP                 10
52 #define PS_DEEP                 10
53 #define PR_DEEP                 10
54 #define POINT_DEEP              (PP_DEEP + PS_DEEP + PR_DEEP)
55 #define PRESSURE_DEEP           8
56 #define CONFIG_LENGTH           512
57 #define TRUE                    1
58 #define FALSE                   0
59 #define FLAG_ABLE               (0x4<<12)
60 #define FLAG_FILL               (0x2<<12)
61 #define FLAG_KEY                (0x1<<12)
62 #define FLAG_COOR               (0x0fff0fff)
63 #define FLAG_COOR_EX            (0xffff0fff)
64 #define FLAG_ID                 (0xf0000000)
65
66 struct gsl_touch_info
67 {
68         int x[10];
69         int y[10];
70         int id[10];
71         int finger_num; 
72 };
73
74 typedef struct
75 {
76         unsigned int i;
77         unsigned int j;
78         unsigned int min;//distance min
79         unsigned int d[POINT_MAX][POINT_MAX];//distance;
80 }gsl_DISTANCE_TYPE;
81
82 typedef union
83 {
84         struct
85         {
86                 unsigned y:12;
87                 unsigned key:1;
88                 unsigned fill:1;
89                 unsigned able:1;
90                 unsigned predict:1;
91                 unsigned x:16;
92         }other;
93         struct
94         {
95                 unsigned y:13;
96                 unsigned rev_2:3;
97                 unsigned x:16;
98         }dis;
99         unsigned int all;
100 }gsl_POINT_TYPE;
101
102 typedef union
103 {
104         struct
105         {
106                 unsigned delay:8;
107                 unsigned report:8;
108                 unsigned rev_1:14;
109                 unsigned able:1;
110                 unsigned init:1;
111         }other;
112         unsigned int all;
113 }gsl_DELAY_TYPE;
114
115 typedef union
116 {
117         struct
118         {
119                 unsigned rev_0:8;
120                 unsigned rev_1:8;
121
122                 unsigned rev_2:7;
123                 unsigned ex:1;
124
125                 unsigned interpolation:4;
126                 unsigned rev_3:1;
127                 unsigned only:1;
128                 unsigned mask:1;
129                 unsigned reset:1;
130         }other;
131         unsigned int all;
132 }gsl_STATE_TYPE;
133
134 typedef struct
135 {
136         unsigned int rate;
137         unsigned int dis;
138         gsl_POINT_TYPE coor;
139 }gsl_EDGE_TYPE;
140
141 typedef union
142 {
143         struct  
144         {
145                 short y;
146                 short x;
147         }other;
148         unsigned int all;
149 }gsl_DECIMAL_TYPE;
150
151 typedef union
152 {
153         struct
154         {
155                 unsigned over_report_mask:1;
156                 unsigned opposite_x:1;
157                 unsigned opposite_y:1;
158                 unsigned opposite_xy:1;
159                 unsigned line:1;
160                 unsigned line_neg:1;
161                 unsigned line_half:1;
162                 unsigned middle_drv:1;
163
164                 unsigned key_only_one:1;
165                 unsigned key_line:1;
166                 unsigned refe_rt:1;
167                 unsigned refe_var:1;
168                 unsigned base_median:1;
169                 unsigned key_rt:1;
170                 unsigned refe_reset:1;
171                 unsigned sub_cross:1;
172
173                 unsigned row_neg:1;
174                 unsigned sub_line_coe:1;
175                 unsigned sub_row_coe:1;
176                 unsigned c2f_able:1;
177                 unsigned thumb:1;
178                 unsigned graph_h:1;
179                 unsigned init_repeat:1;
180                 unsigned near_reset_able:1;
181
182                 unsigned emb_dead:1; 
183                 unsigned emb_point_mask:1; 
184                 unsigned interpolation:1;
185                 unsigned sum2_able:1;
186                 unsigned reduce_pin:1;
187                 unsigned drv_order_ex:1;
188                 unsigned id_over:1;
189                 unsigned rev_1:1;
190         }other;
191         unsigned int all;
192 }gsl_FLAG_TYPE;
193
194 static gsl_POINT_TYPE point_array[POINT_DEEP][POINT_MAX];
195 static gsl_POINT_TYPE *point_pointer[PP_DEEP];
196 static gsl_POINT_TYPE *point_stretch[PS_DEEP];
197 static gsl_POINT_TYPE *point_report[PR_DEEP];
198 static gsl_POINT_TYPE point_now[POINT_MAX];
199 static gsl_DELAY_TYPE point_delay[POINT_MAX];
200 static int filter_deep[POINT_MAX];
201 static gsl_EDGE_TYPE point_edge;
202 static gsl_DECIMAL_TYPE point_decimal[POINT_MAX];
203
204 static unsigned int pressure_now[POINT_MAX];
205 static unsigned int pressure_array[PRESSURE_DEEP][POINT_MAX];
206 static unsigned int pressure_report[POINT_MAX];
207 static unsigned int *pressure_pointer[PRESSURE_DEEP];
208
209 #define pp              point_pointer
210 #define ps              point_stretch
211 #define pr              point_report
212 #define point_predict   pp[0]
213 #define pa              pressure_pointer
214
215 static  gsl_STATE_TYPE global_state;
216 static  int inte_count;
217 static  unsigned int csensor_count;
218 static  unsigned int click_count[4];
219 static  gsl_POINT_TYPE point_click[4];
220 static  unsigned int double_click;
221 static  int point_n;
222 static  int point_num;
223 static  int prev_num;
224 static  int point_near;
225 static  unsigned int point_shake;
226 static  unsigned int reset_mask_send;
227 static  unsigned int reset_mask_max;
228 static  unsigned int reset_mask_count;
229 static  gsl_FLAG_TYPE global_flag;
230 static  unsigned int id_first_coe;
231 static  unsigned int id_speed_coe;
232 static  unsigned int id_static_coe;
233 static  unsigned int average;
234 static  unsigned int soft_average;
235 static  unsigned int report_delay;
236 static  unsigned int report_ahead;
237 static  unsigned char median_dis[4];
238 static  unsigned int shake_min;
239 static  int match_y[2];
240 static  int match_x[2];
241 static  int ignore_y[2];
242 static  int ignore_x[2];
243 static  int screen_y_max;
244 static  int screen_x_max;
245 static  int point_num_max;
246 static  unsigned int drv_num;
247 static  unsigned int sen_num;
248 static  unsigned int drv_num_nokey;
249 static  unsigned int sen_num_nokey;
250 static  unsigned int coordinate_correct_able;
251 static  unsigned int coordinate_correct_coe_x[64];
252 static  unsigned int coordinate_correct_coe_y[64];
253 static  unsigned int edge_cut[4];
254 static  unsigned int stretch_array[4*4*2];
255 static  unsigned int shake_all_array[2*8];
256 static  unsigned int reset_mask_dis;
257 static  unsigned int reset_mask_type;
258 static  unsigned int key_map_able;
259 static  unsigned int key_range_array[8*3];
260 static  int  filter_able;
261 static  unsigned int filter_coe[4];
262 static  unsigned int multi_x_array[4],multi_y_array[4];
263 static  unsigned int multi_group[4][64];
264 static  int ps_coe[4][8],pr_coe[4][8];
265 static  int point_repeat[2];
266 static  int near_set[2];
267 static  int diagonal;
268 //      unsigned int key_dead_time                      ;
269 //      unsigned int point_dead_time            ;
270 //      unsigned int point_dead_time2           ;
271 //      unsigned int point_dead_distance        ;
272 //      unsigned int point_dead_distance2       ;
273 //      unsigned int pressure_able;
274 //      unsigned int pressure_save[POINT_MAX];
275 static  unsigned int edge_first;
276 static  unsigned int edge_first_coe;
277
278 static  unsigned int point_corner;
279 //-------------------------------------------------
280 static  unsigned int config_static[CONFIG_LENGTH];
281 //-------------------------------------------------
282 #ifdef GESTURE_ABLE
283
284 #define MAXSTACK        200
285 #define GesturePtNum    15
286 typedef union
287 {
288         
289         struct
290         {
291                 unsigned y:16;
292                 unsigned x:12;
293                 unsigned id:4;
294         } point_data;
295         unsigned int data_int;
296 }POINT_TYPE_DEFINE;
297
298 typedef struct 
299 {
300         int top;
301         POINT_TYPE_DEFINE  point_buff[MAXSTACK];
302 }TouchFinger;
303
304 static struct  
305 {
306         int num[10];
307         int flag;
308         int position;
309 }vector_x_y[2];
310 static TouchFinger point_stack;
311 static int qushi_x[10];
312 static int qushi_y[10];
313 static int vector_change_x[MAXSTACK];
314 static int vector_change_y[MAXSTACK];
315 static int rate_weight[MAXSTACK];       
316 static POINT_TYPE_DEFINE top,bottom,left,right;
317 static int Letter_width;
318 static int Letter_height;
319 static unsigned int max_x,min_x,max_y,min_y;
320 static char gesture_letter;
321 #endif
322 //+++++++++++++++++++++++++++++++++++++++++++++++++++++++
323 #ifdef GESTURE_LICH
324 #define GESTURE_BUF_SIZE                256
325 #define GESTURE_SIZE_REFE               255
326 #define GESTURE_SIZE_NUM                32
327 #define GESTURE_XY                      0x1
328 #define GESTURE_DEAL                    0x2
329 #define GESTURE_LRUD                    0x4
330 #define GESTURE_ALL                     0x7fffffff
331 typedef union
332 {
333         struct
334         {
335                 unsigned y:12;
336                 unsigned rev:4;
337                 unsigned x:16;
338         }other;
339         unsigned int all;
340 }GESTURE_POINT_TYPE;
341 typedef struct  
342 {
343         int coe;
344         int out;
345         unsigned int coor[GESTURE_SIZE_NUM/2];
346 }GESTURE_MODEL_TYPE;
347 //GESTURE_POINT_TYPE gesture_buf[GESTURE_BUF_SIZE];//gesture_buf
348 #define gesture_buf      ((GESTURE_POINT_TYPE*)config_static)
349 #define gesture_standard ((GESTURE_POINT_TYPE*)(&config_static[GESTURE_BUF_SIZE]))
350 static int  gesture_num,gesture_num_last;//gesture_num
351 static int  gesture_dis_min;
352 static int  gesture_deal;
353 static int  gesture_last;
354 static int  gesture_threshold[2];
355 static  int x_scale;
356 static  int y_scale;
357 static int double_down,double_up;
358 static const GESTURE_MODEL_TYPE * model_extern = NULL;
359 static int  model_extern_len = 0;
360 static int  GestureSqrt(int d);
361 static int  GestureDistance(GESTURE_POINT_TYPE* d1,GESTURE_POINT_TYPE* d2,int sqrt_able);
362 static int  GesturePush(GESTURE_POINT_TYPE* data);
363 static int  GestureStretch(void);
364 static int  GestureLength(void);
365 static int  GestureDeal(void);
366 static int  GestureModel(const GESTURE_MODEL_TYPE * model,int len,int threshold,int *out);
367 static int  GestureMain(unsigned int data[],unsigned int pn);
368 static void GestureStandard(void);
369 static void GestureInit(void);
370 static void ChangeXY(void);
371 static int  GestureLRUD(void);
372 static void GestureSet(unsigned int conf[]);
373 static const GESTURE_MODEL_TYPE model_default[]
374 ={
375         {0x10,'3',{
376         0x37170105,0x78580000,0xba990a03,0xedd92e14,0xb9d85347,0x7798655b,0x3657716b,0x1f156d74,
377         0x60406969,0xa2816f69,0xe3c28075,0xf9fbb899,0xc3e3e0d2,0x83a4f6ee,0x4262fffc,0x0021f7fd,}},
378         {0x10,'6',{
379         0xa2be0400,0x70881f10,0x4258402e,0x1d2e6c54,0x040ea084,0x0a01d6bc,0x381df9ec,0x7054fffd,
380         0xa88cfafe,0xdac2ddef,0xfff0b2cb,0xe2f78497,0xaac7747a,0x728e7472,0x3b56817b,0x0420968b,}},
381         {0x10,'7',{
382         0x12000001,0x37240000,0x5b490000,0x806e0000,0xa5930000,0xcab70000,0xefdc0300,0xf9fd1f0e,
383         0xe2ee3d30,0xc5d4564a,0xa7b76c61,0x8c9a8579,0x717e9f93,0x5863bbad,0x434cdbc9,0x3c3dffec,}},
384         {0x10,'8',{
385         0xdaff030c,0x8eb40000,0x41670c06,0x001c3116,0x431e5448,0x8f69635d,0xd1b58a6f,0xcedfd0af,
386         0x88acf5e6,0x3c62fffd,0x0718cdf1,0x341493aa,0x7a556d7d,0xc19e4f60,0xf9e51c3c,0xb5dc0005,}},     
387         {0x10,'8',{
388         0x627d231e,0x2f49382c,0x03175a48,0x21098172,0x563c958c,0x856eb0a2,0x8f99dac4,0x5b76eee5,
389         0x243ffdf5,0x090ddbf4,0x2918acc2,0x4d3a8497,0x78636172,0xa38e4050,0xd0ba1f2e,0xffe7000f,}},
390         {0x10,'9',{
391         0xe8ff0715,0xb4ce0001,0x819a0500,0x4f68150c,0x1e362a1e,0x000c543c,0x270d7169,0x5b417273,
392         0x9076666d,0xbda74a5a,0xddcf1e36,0xc8d7321b,0xb4be634b,0xa4ac967d,0x959ccab0,0x898fffe4,}},
393         {0x10,'A',{
394         0xaeca000b,0x74900e02,0x41582d1b,0x182a5942,0x02099375,0x0600cfb1,0x2c15fcea,0x664af1fe,
395         0x957ec8dd,0xb5a894b0,0xc9bf5876,0xd7d31c3a,0xd4d75134,0xd3d38d6f,0xdbd4c9ab,0xffe9fce6,}},
396         {0x10,'A',{
397         0x8eab0102,0x56711307,0x2c3f3a25,0x0e1b6b51,0x0004a689,0x0e02ddc2,0x3e22fbf2,0x725be8fa,
398         0x9284b6d0,0xa69d7f9b,0xb3ae4562,0xb7b80b28,0xa7a6290c,0xb1aa6346,0xd0be947d,0xffe7bba7,}},
399         {0x10,'B',{
400         0x56591a00,0x474e4e35,0x343f8168,0x242cb59c,0x0f1be7ce,0x170ddbf4,0x3c25b4c4,0x6e549ca6,
401         0xa3889799,0xd8bd9d96,0xfcf1bea8,0xd3e9e4d4,0xa0baf6f0,0x6b85fcfa,0x3650fffd,0x001bfbff,}},
402         {0x10,'C',{
403         0xfaff2337,0xdaec0913,0xb0c50003,0x879c0500,0x5f720f09,0x3b4c271a,0x1d2b4534,0x08116a56,
404         0x0003937f,0x0a03bca8,0x2515ddce,0x4b38f2e8,0x7560fff9,0x9e89f7fd,0xc6b2e8f0,0xeed9d7df,}},
405         {0x10,'C',{
406         0xacbf0100,0x86990a04,0x64751b12,0x45533225,0x2b375141,0x17217160,0x080f9582,0x0103bba8,
407         0x0200e2cf,0x200ff9f1,0x4633fefc,0x6c59ffff,0x9380fcfd,0xb9a6f4f9,0xdccbe4ed,0xffeeceda,}},
408         {0x10,'C',{
409         0x57670a00,0x3a492116,0x222d3d2e,0x0f175e4d,0x0408816f,0x0001a693,0x0300cab8,0x0e07eddc,
410         0x2f1dfefb,0x5241f5fc,0x7362e2ec,0x8e80c9d6,0xa89bafbc,0xc3b594a1,0xe1d27e89,0xfff06673,}},
411         {0x10,'D',{
412         0x99b5858f,0x5f7c8883,0x28429c8f,0x010fc6ab,0x240cf4e1,0x5d41fefb,0x957af1fc,0xc1adcbe0,
413         0xd2cc92af,0xd3d25875,0xd7d71f3b,0xd7d71b02,0xd4d75538,0xd4d48f72,0xe1d9c9ac,0xffe6f4e6,}},
414         {0x10,'E',{
415         0x391c948f,0x73569595,0xad908a92,0xddc8677e,0xf1ee304d,0xc3dd0d1b,0x89a70002,0x536d1304,
416         0x233b3a25,0x08137053,0x0301aa8d,0x220edcc6,0x573af7ee,0x9174fffc,0xcaaef6ff,0xffe5dbeb,}},
417         {0x10,'G',{
418         0xaaca0000,0x698a0000,0x2a491106,0x000f4226,0x23067061,0x64437674,0xa3836874,0xdac04759,
419         0xfaec0b2a,0xfefb401f,0xffff8160,0xf5fdc0a1,0xc9e9eedf,0x89a9fff9,0x4869faff,0x0928e3f3,}},     
420         {0x10,'G',{
421         0xeaff1421,0xb9d20308,0x88a00000,0x57700f05,0x2b3f2618,0x09174d37,0x00037f66,0x0d05af97,
422         0x2a1adac7,0x5940ede5,0x8b72f2f3,0xbca4e9ee,0xe4d2cbde,0xfbf09cb3,0xf5f8ceb5,0xe9f1ffe6,}},
423         {0x10,'H',{
424         0x03021300,0x06053a26,0x0b0a604d,0x0b0b8774,0x0a0bae9a,0x0506d4c1,0x0002fbe8,0x1104e0f0,
425         0x2e1ec3d1,0x503dadb5,0x7764a5a7,0x9e8aa1a2,0xc4b1a3a0,0xead8ada8,0xfff8d1bd,0xfffff8e4,}},
426         {0x10,'K',{
427         0x1d1a2000,0x171a6040,0x1114a080,0x060edfc0,0x1100e2ff,0x3420a8c5,0x6f4f8b95,0xaf8f8285,
428         0xefcf8683,0xe1fcb3a0,0xa0c1c2bb,0x6080c6c5,0x2c40c9c7,0x6c4cd8d1,0xac8ceadf,0xedccfef3,}},
429         {0x10,'K',{
430         0x22341900,0x15185436,0x0e119072,0x0c0cccae,0x0709f6ea,0x0a07b9d8,0x2918859e,0x5b406170,
431         0x90796658,0x627c8b7c,0x2a47a79a,0x110db8b1,0x4d2fbfbc,0x896bcac4,0xc3a6d9d1,0xffe1ede2,}},
432         {0x10,'L',{
433         0x3f4a0c00,0x35372c1c,0x2c314d3d,0x26296e5d,0x1b218e7e,0x1316af9f,0x0910cfc0,0x0004f1e0,
434         0x1605ffff,0x3727ffff,0x5848ffff,0x7a69fdff,0x9b8afcfd,0xbcabfcfc,0xddcdfafb,0xffeef9f9,}},
435         {0x10,'M',{
436         0x0900e0ff,0x2017a0c0,0x3a296381,0x4e442443,0x5a583010,0x6b5f6f4f,0x7471ae8f,0x7977eece,
437         0x8c80c5e5,0xa19886a5,0xbaad4766,0xd3c70a29,0xddda3516,0xe7e17555,0xf4f0b494,0xfffaf4d4,}},
438         {0x10,'N',{
439         0x0400e7ff,0x130bb8cf,0x281e89a1,0x38305a71,0x51452c43,0x675d1d13,0x68684e36,0x6b697f66,
440         0x726fb097,0x7875e0c8,0x907ee8f8,0xa79ebbd2,0xbfb38fa4,0xd1c95f77,0xe6da3148,0xfff20019,}},
441         {0x10,'O',{
442         0x2e3f311f,0x101e5c46,0x03088f76,0x0001c2a8,0x1e08e7da,0x4f35fdf4,0x8168fcff,0xb39beef5,
443         0xdac7cedf,0xf3e9a0b8,0xfef96d87,0xf9ff3c54,0xdaec1326,0xaac30108,0x77900100,0x465e1407,}},
444         {0x10,'O',{
445         0xd0e30213,0x9cb60000,0x68820c05,0x384f2416,0x17254c36,0x040c8066,0x0001b49a,0x1305e4ce,
446         0x442bfaf0,0x785efffe,0xab92f1f9,0xd3c1cfe3,0xf1e3a1b9,0xfffa6e88,0xf8ff3b54,0xd5e81024,}},
447         {0x10,'O',{
448         0x000f768a,0x0900455d,0x2b171e30,0x5a420611,0x8d740100,0xbca5170b,0xe3d23824,0xfcf2644c,
449         0xfaff977e,0xe3f0c4af,0xbdd2e6d7,0x8ea7faf2,0x5b74fefe,0x2e44e9f6,0x0a1bc2d6,0x02028fa9,}},
450         {0x10,'O',{
451         0x829c0900,0x4e682315,0x24384a34,0x08157c61,0x0002b598,0x0d03edd1,0x4326fffd,0x7a5feef8,
452         0xab93cfe0,0xd5c1a7bd,0xf4e67690,0xfbff3d5a,0xcfec1b26,0x96b31818,0x5e7a251d,0x28433b2f,}},
453         {0x10,'O',{
454         0x381e5e68,0x6e535156,0xa388504f,0xd8be5e56,0xf9ed876d,0xf9fcbaa1,0xd8ece5d2,0xa5c0f9f2,
455         0x708bfffd,0x3b55fbfe,0x1423d7ed,0x0006a4bf,0x09027089,0x26154157,0x50391e2e,0x7e670010,}},     
456         {0x10,'O',{
457         0x8670020b,0xb8a01307,0xe3ce3423,0xf8f0664c,0xfffc9b81,0xf1faceb5,0xcee4f4e5,0x9ab4fffb,
458         0x657fffff,0x364ceaf8,0x1623c0d7,0x00098ea7,0x06015973,0x24122e41,0x4d380c1c,0x82670104,}},
459         {0x10,'S',{
460         0xb7cf0001,0x869e0301,0x556d0905,0x273e1f12,0x0311442c,0x2009665a,0x5138726b,0x826a7876,
461         0xb39b807b,0xdfcb998b,0xfff5bea7,0xdcf2ded0,0xadc6f1e8,0x7c94fbf7,0x4b63fffd,0x1932ffff,}},
462         {0x10,'S',{
463         0xcbde0200,0xa8ba1209,0x8597241a,0x6a753f2f,0x806c5751,0xa6935e5b,0xccb96662,0xf2e0746b,
464         0xfcff9482,0xe0f0b2a6,0xbdcfc2bb,0x97abd1c9,0x7385ddd7,0x4c60e8e3,0x273af4ee,0x0014fff9,}},
465         {0x10,'U',{
466         0x050d2209,0x0001573c,0x03008c71,0x1106bfa6,0x2f1bebda,0x604ae1f0,0x8873bccd,0xa59990a8,
467         0xbcb05f78,0xcdc72c46,0xd0d00911,0xc9cb3e24,0xc6c87359,0xc9c6a88d,0xd8d2ddc2,0xffe4fff6,}},
468         {0x10,'V',{
469         0x09000f00,0x1911301f,0x27205240,0x342d7563,0x413a9785,0x4f47b9a8,0x6057d9c9,0x7569f9ea,
470         0x9486f4ff,0xa99fd5e5,0xb8b0b4c5,0xc9c093a3,0xdbd17484,0xe9e35263,0xf5ef2f41,0xfff90b1d,}},
471         {0x10,'V',{
472         0x08001908,0x160f3b2b,0x251d5d4c,0x312b806f,0x3e37a392,0x4843c6b5,0x524de9d8,0x5b58f2fb,
473         0x6560cfe0,0x776dafbf,0x8a8090a0,0x9d947080,0xb4a85361,0xccc03745,0xe6d91d2a,0xfff2000e,}},
474         {0x10,'W',{
475         0x06001f00,0x110c5f3f,0x1c189f7f,0x2822debe,0x4131e3fd,0x554ba4c3,0x655c6484,0x786f2444,
476         0x847f2f0f,0x8a866f4f,0x928eae8f,0x9e99eece,0xbaacd0ee,0xd5c893b3,0xebe05373,0xfff61333,}},
477         {0x10,'W',{
478         0xf7ff2000,0xe4ed6040,0xd5dba181,0xbdcbe0c0,0xa0aad3f3,0x909892b3,0x848a5272,0x80811131,
479         0x777d3d1d,0x636d7e5e,0x535bbf9e,0x3c48fdde,0x272fc1e2,0x121a82a2,0x030a4161,0x00020021,}},
480         {0x10,'Y',{
481         0x16000b13,0x442d0303,0x4b48341b,0x61505e4b,0x91795c62,0xbca74551,0xe1d02637,0xfcf40c14,
482         0xe8f13922,0xdbe16951,0xd6d99a82,0xced3cbb2,0xb0c4f0e1,0x7f98fbf7,0x4e67fefd,0x1d36fdff,}},
483         {0x10,'Z',{
484         0x30160200,0x644a0403,0x997f0303,0xcdb30202,0xe7e80d00,0xc4d63622,0x9bb05c4a,0x73857f6c,
485         0x5061a893,0x293eccbb,0x0013f2dd,0x2d13fcfd,0x6248f6f8,0x967cf1f3,0xcbb1edef,0xffe5f1ec,}},
486         //--------------------------------------------------------------------------------------------
487         {0x10,0x1001,{
488         0x0003ecff,0x0502c6d9,0x0b099fb2,0x1410788c,0x221b5265,0x362b2f40,0x5341121d,0x7966020a,
489         0xa08d0100,0xc3b3170b,0xd9ce3a28,0xede25f4d,0xf4f28672,0xfaf6ac99,0xfffdd3c0,0xfffffae6,}},
490         {0x10,0x1002,{
491         0x1900847d,0x4c328785,0x7f658b88,0xb198898b,0xe3cb7f88,0xf8f24f68,0xecf81d35,0xbfd9010b,
492         0x90a61504,0x8186462d,0x7c7d7960,0x7f7bac93,0x8883dfc6,0xaf97fff4,0xdcc7eafa,0xffeec1d7,}},
493         {0x10,0x1003,{
494         0x7543141a,0xd7a82e17,0xf8f78f5c,0xc6e6e9bf,0x6497f8fa,0x1338b3db,0x03024f82,0x4a1c0620,
495         0xaf7c1001,0xf8da582b,0xeafebc8b,0x9acbfbe6,0x3868eeff,0x0a1892c4,0x2712305f,0x85520e11,}},
496         {0x10,0x1004,{
497         0x04003204,0x120b8e60,0x1714ebbd,0x2f27b8e6,0x43385b89,0x5b4c032d,0x6a666032,0x7770bc8e,
498         0x8c82b8e6,0x9b945c8a,0xaea2012d,0xbbb75d2f,0xc9c1ba8c,0xe3d5bce7,0xf1ea5f8d,0xfff50231,}},
499         {0x10,0x1005,{
500         0x1900020a,0x4d330400,0x7c65180a,0xa18f3f2b,0xb3ac7258,0xbcb8a58b,0xb0b9d7bf,0x8aa0fcec,
501         0x5971f2fd,0x414bc2db,0x433f8ea8,0x534a5d76,0x71613246,0x9d85101e,0xd0b60609,0xffea1409,}},
502         {0x10,0x1006,{
503         0xdeff0714,0x9abc0002,0x57790a02,0x1d373018,0x01076d4b,0x2f0f988a,0x72519c9c,0xb2948b9c,
504         0xa3bc576b,0x60815653,0x26417963,0x020eb191,0x2005e7d3,0x6442fbf4,0xa785fbff,0xebc9e7f3,}},
505         {0x10,0x1007,{
506         0xf6ff0600,0xe4ed140c,0xd5dd261d,0xc5cd362e,0xb3bc463e,0xa2aa574e,0x939a6860,0x83897970,
507         0x747c8a82,0x646c9c93,0x525baca4,0x434abdb4,0x333bcfc6,0x222addd5,0x121beee6,0x0009fff6,}},
508         {0x10,0x1008,{
509         0x09000900,0x19111b13,0x28202d24,0x39303d35,0x49424e45,0x5a515d56,0x6b626d65,0x7d747b74,
510         0x8e868b82,0x9d969c93,0xaca4aea5,0xbcb4bfb6,0xcac4d1c7,0xdbd2e1d9,0xece3f1e9,0xfff5fff8,}},
511         {0x10,0x1009,{
512         0x0a00faff,0x1d14edf4,0x2e25dce5,0x3e36cbd4,0x4e44bac2,0x5f57aab2,0x6f679aa2,0x7f778890,
513         0x8c85757e,0x9c94636b,0xaba3515a,0xbbb2414a,0xcbc33039,0xddd31f28,0xeee51119,0xfff7000a,}},
514         {0x10,0x100a,{
515         0xf4fffaff,0xe1eaeff6,0xd1d9dde6,0xc1cacdd5,0xb4bbbac3,0xa2aca8b0,0x929a99a1,0x83888791,
516         0x767d747d,0x666e636b,0x535c545e,0x444d424b,0x333d323a,0x242b212a,0x141c0f18,0x000a0008,}},
517         {0x10,0x100b,{
518         0x30000208,0x90600200,0xf1c11e0c,0xb5e64d3f,0x55855653,0x32245556,0x93625756,0xf1c3745e,
519         0xbaeaa997,0x598ab2b0,0x0f29aab1,0x7040a8a7,0xd1a0b8ae,0xd0f8ecd0,0x6f9ffcf5,0x0e3ffcff,}},
520         {0x10,0x100c,{
521         0x2600140c,0x66494226,0x827c8d66,0x6d80d8b4,0x284ffaf4,0x0a0ab9e0,0x411f8097,0x8e689182,
522         0xd6b47f94,0xf9f23960,0xd5f80012,0x91af270a,0x7e83734c,0x7e7dc19a,0xb490fae5,0xffdbe9fe,}},
523         {0x10,0x100d,{
524         0x768e0c00,0x465e2619,0x192f4635,0x0107745a,0x32178a85,0x674d858a,0x9b81747d,0xccb45c69,
525         0xf7e33b4d,0xebfd0d21,0xb6d00004,0x939e270d,0x888d5d42,0x83859378,0x7c80c9ae,0x6c75ffe4,}},     
526         {0x10,0x100e,{
527         0xb3bd1000,0x9ea82d1e,0x87924a3b,0x6f7b6658,0x56628375,0x3e4a9e91,0x2934bcad,0x1720ddcd,
528         0x010bfced,0x2513ffff,0x4937fdff,0x6d5bf9fa,0x9280f4f7,0xb6a4f0f1,0xdac8eeef,0xffececed,}},
529 };
530 #endif
531 //+++++++++++++++++++++++++++++++++++++++++++++++++++++++
532 static void SortBubble(int t[],int size)
533 {
534         int temp = 0;
535         int m,n;
536         for(m=0;m<size;m++)
537         {
538                 for(n=m+1;n<size;n++)
539                 {
540                         temp = t[m];
541                         if (temp>t[n])
542                         {
543                                 t[m] = t[n];
544                                 t[n] = temp;
545                         }
546                 }
547         }
548 }
549 int abs(int i){
550         if(i<0)
551                 return ~(--i);
552         return i;
553 }
554 static int Sqrt(int d)
555 {
556         int ret = 0;
557         int i;
558         for(i=14;i>=0;i--)
559         {
560                 if((ret + (0x1<<i))*(ret + (0x1<<i)) <= d)
561                         ret |= (0x1<<i);
562         }
563         return ret;
564 }
565
566 static void PointCoor(void)
567 {
568         int i;
569         point_num &= 0xff;
570         for(i=0;i<point_num;i++)
571         {
572                 if(global_state.other.ex)
573                         point_now[i].all &= (FLAG_COOR_EX | FLAG_KEY | FLAG_ABLE);
574                 else
575                         point_now[i].all &= (FLAG_COOR | FLAG_KEY | FLAG_ABLE);
576         }
577 }
578 static void PointRepeat(void)
579 {
580         int i,j;
581         int x,y;
582         int x_min,x_max,y_min,y_max;
583         int pn;
584         if(point_near)
585                 point_near --;
586         if(prev_num > point_num)
587                 point_near = 8;
588         if(point_repeat[0]==0 || point_repeat[1]==0)
589         {
590                 if(point_near)
591                         pn = 96;
592                 else
593                         pn = 32;
594         }
595         else
596         {
597                 if(point_near)
598                         pn = point_repeat[1];
599                 else
600                         pn = point_repeat[0];
601         }
602         for(i=0;i<POINT_MAX;i++)
603         {
604                 if(point_now[i].all == 0)
605                         continue;
606                 if (point_now[i].other.key)
607                         continue;
608                 x_min = point_now[i].other.x - pn;
609                 x_max = point_now[i].other.x + pn;
610                 y_min = point_now[i].other.y - pn;
611                 y_max = point_now[i].other.y + pn;
612                 for(j=i+1;j<POINT_MAX;j++)
613                 {
614                         if(point_now[j].all == 0)
615                                 continue;
616                         if (point_now[j].other.key)
617                                 continue;
618                         x = point_now[j].other.x;
619                         y = point_now[j].other.y;
620                         if(x>x_min && x<x_max && y>y_min && y<y_max)
621                         {
622                                 point_now[i].other.x = 
623                                         (point_now[i].other.x + 
624                                          point_now[j].other.x + 1) / 2;
625                                 point_now[i].other.y = 
626                                         (point_now[i].other.y + 
627                                          point_now[j].other.y + 1) / 2;
628                                 point_now[j].all = 0;
629                                 i--;
630                                 point_near = 8;
631                                 break;
632                         }
633                 }
634         }
635 }
636
637 static void PointPointer(void)
638 {
639         int i,pn;
640         point_n ++ ;
641         if(point_n >= PP_DEEP * PS_DEEP * PR_DEEP * PRESSURE_DEEP)
642                 point_n = 0;
643         pn = point_n % PP_DEEP;
644         for(i=0;i<PP_DEEP;i++)
645         {
646                 pp[i] = point_array[pn];
647                 if(pn == 0)
648                         pn = PP_DEEP - 1;
649                 else
650                         pn--;
651         }
652         pn = point_n % PS_DEEP;
653         for(i=0;i<PS_DEEP;i++)
654         {
655                 ps[i] = point_array[pn+PP_DEEP];
656                 if(pn == 0)
657                         pn = PS_DEEP - 1;
658                 else
659                         pn--;
660         }
661         pn = point_n % PR_DEEP;
662         for(i=0;i<PR_DEEP;i++)
663         {
664                 pr[i] = point_array[pn+PP_DEEP+PS_DEEP];
665                 if(pn == 0)
666                         pn = PR_DEEP - 1;
667                 else
668                         pn--;
669         }
670         pn = point_n % PRESSURE_DEEP;
671         for(i=0;i<PRESSURE_DEEP;i++)
672         {
673                 pa[i] = pressure_array[pn];
674                 if(pn == 0)
675                         pn = PRESSURE_DEEP - 1;
676                 else
677                         pn--;
678         }
679         //------------------------------------------------------
680         pn = 0;
681         for(i=0;i<POINT_MAX;i++)
682         {
683                 if(point_now[i].all)
684                         point_now[pn++].all = point_now[i].all;
685                 pp[0][i].all = 0;
686                 ps[0][i].all = 0;
687                 pr[0][i].all = 0;
688         }
689         point_num = pn;
690         for(i=pn;i<POINT_MAX;i++)
691                 point_now[i].all = 0;
692 }
693
694 static unsigned int CCO(unsigned int x,unsigned int coe[],int k)
695 {
696         if(k == 0)
697         {
698                 if(x & 32)
699                         return (x & ~31)+(31 - (coe[31-(x&31)] & 31));
700                 else
701                         return (x & ~31)+(coe[x&31] & 31);
702         }
703         if(k == 1)
704         {
705                 if(x & 64)
706                         return (x & ~63)+(63 - (coe[63-(x&63)] & 63));
707                 else
708                         return (x & ~63)+(coe[x&63] & 63);
709         }
710         if(k == 2)
711         {
712                 return (x & ~63)+(coe[x&63] & 63);
713         }
714         return 0;
715 }
716
717 static void CoordinateCorrect(void)
718 {
719         typedef struct
720         {
721                 unsigned int range;
722                 unsigned int group; 
723         }MULTI_TYPE;
724 #ifdef LINE_MULTI_SIZE
725         #define LINE_SIZE       LINE_MULTI_SIZE
726 #else
727         #define LINE_SIZE               4
728 #endif
729         int i,j;
730         unsigned int *px[LINE_SIZE+1],*py[LINE_SIZE+1];
731         MULTI_TYPE multi_x[LINE_SIZE],multi_y[LINE_SIZE];
732         unsigned int edge_size = 64;
733         int kx,ky;
734         if((coordinate_correct_able&0xf) == 0)
735                 return;
736         kx = (coordinate_correct_able>>4)&0xf;
737         ky = (coordinate_correct_able>>8)&0xf;
738         px[0] = coordinate_correct_coe_x;
739         py[0] = coordinate_correct_coe_y;
740         for(i=0;i<LINE_SIZE;i++)
741         {
742                 px[i+1] = NULL;
743                 py[i+1] = NULL;
744         }
745         if(kx == 3 || ky == 3)
746         {
747                 i=0;
748                 if(((coordinate_correct_able>>4)&0xf) == 3)
749                         px[1] = multi_group[i++];
750                 if(((coordinate_correct_able>>8)&0xf) == 3)
751                         py[1] = multi_group[i++];
752         }
753         else
754         {
755                 for(i=0;i<LINE_SIZE;i++)
756                 {
757                         multi_x[i].range = multi_x_array[i] & 0xffff;
758                         multi_x[i].group = multi_x_array[i] >> 16;
759                         multi_y[i].range = multi_y_array[i] & 0xffff;
760                         multi_y[i].group = multi_y_array[i] >> 16;
761                 }
762                 j=1;
763                 for(i=0;i<LINE_SIZE;i++)
764                         if(multi_x[i].range && multi_x[i].group<LINE_SIZE)
765                                 px[j++] = multi_group[multi_x[i].group];
766                 j=1;
767                 for(i=0;i<LINE_SIZE;i++)
768                         if(multi_y[i].range && multi_y[i].group<LINE_SIZE)
769                                 py[j++] = multi_group[multi_y[i].group];
770         }
771         for(i=0;i<(int)point_num && i<POINT_MAX;i++)
772         {
773                 if(point_now[i].all==0)
774                         break;
775                 if (point_now[i].other.key != 0)
776                         continue;
777                 if (point_now[i].other.x >= edge_size && 
778                         point_now[i].other.x <= drv_num_nokey * 64 - edge_size)
779                 {
780                         if(kx == 3)
781                         {
782                                 if (point_now[i].other.x & 64)
783                                         point_now[i].other.x = CCO(point_now[i].other.x, px[0], 2);
784                                 else
785                                         point_now[i].other.x = CCO(point_now[i].other.x, px[1], 2);
786                         }
787                         else
788                         {
789                                 for(j=0;j<LINE_SIZE+1;j++)
790                                 {
791                                         if (!(j >= LINE_SIZE || 
792                                                 px[j + 1] == NULL || 
793                                                 multi_x[j].range == 0 || 
794                                                 point_now[i].other.x < multi_x[j].range))
795                                                 continue;
796                                         point_now[i].other.x = CCO(point_now[i].other.x, px[j], kx);
797                                         break;
798                                 }
799                         }
800                 }
801                 if (point_now[i].other.y >= edge_size && 
802                         point_now[i].other.y <= sen_num_nokey * 64 - edge_size)
803                 {
804                         if(ky == 3)
805                         {
806                                 if (point_now[i].other.y & 64)
807                                         point_now[i].other.y = CCO(point_now[i].other.y, py[0], 2);
808                                 else
809                                         point_now[i].other.y = CCO(point_now[i].other.y, py[1], 2);
810                         }
811                         else
812                         {
813                                 for(j=0;j<LINE_SIZE+1;j++)
814                                 {
815                                         if (!(j >= LINE_SIZE || 
816                                                 py[j + 1] == NULL || 
817                                                 multi_y[j].range == 0 || 
818                                                 point_now[i].other.y < multi_y[j].range))
819                                                 continue;
820                                         point_now[i].other.y = CCO(point_now[i].other.y, py[j], ky);
821                                         break;
822                                 }
823                         }
824                 }
825         }
826 #undef LINE_SIZE
827 }
828
829 static void PointPredictOne(unsigned int n)
830 {
831         pp[0][n].all = pp[1][n].all & FLAG_COOR;
832         pp[0][n].other.predict = 0;
833 }
834
835 static void PointPredictTwo(unsigned int n)
836 {
837         unsigned int t;
838         pp[0][n].all = 0;
839         t = pp[1][n].other.x * 2;
840         if (t > pp[2][n].other.x)
841                 t -= pp[2][n].other.x;
842         else
843                 t = 0;
844         if(t > 0xffff)
845                 pp[0][n].other.x = 0xffff;
846         else
847                 pp[0][n].other.x = t;
848         t = pp[1][n].other.y * 2;
849         if (t > pp[2][n].other.y)
850                 t -= pp[2][n].other.y;
851         else
852                 t = 0;
853         if(t > 0xfff)
854                 pp[0][n].other.y = 0xfff;
855         else
856                 pp[0][n].other.y = t;
857         pp[0][n].other.predict = 1;
858 }
859
860 static void PointPredictThree(unsigned int n)
861 {
862         unsigned int t,t2;
863         pp[0][n].all = 0;
864         t = pp[1][n].other.x * 5 + pp[3][n].other.x;
865         t2 = pp[2][n].other.x * 4;
866         if(t > t2)
867                 t -= t2;
868         else
869                 t = 0;
870         t /= 2;
871         if(t > 0xffff)
872                 pp[0][n].other.x = 0xffff;
873         else
874                 pp[0][n].other.x = t;
875         t = pp[1][n].other.y * 5 + pp[3][n].other.y;
876         t2 = pp[2][n].other.y * 4;
877         if(t > t2)
878                 t -= t2;
879         else
880                 t = 0;
881         t /= 2;
882         if(t > 0xfff)
883                 pp[0][n].other.y = 0xfff;
884         else
885                 pp[0][n].other.y = t;
886         pp[0][n].other.predict = 1;
887 }
888
889 static void PointPredict(void)
890 {
891         int i;
892         for(i=0;i<POINT_MAX;i++)
893         {
894                 if(pp[1][i].all != 0)
895                 {
896                         if (global_state.other.interpolation
897                                 || pp[2][i].all == 0
898                                 || pp[2][i].other.fill != 0
899                                 || pp[3][i].other.fill != 0
900                                 || pp[1][i].other.key != 0
901                                 || global_state.other.only)
902                         {
903                                 PointPredictOne(i);
904                         }
905                         else if(pp[2][i].all != 0)
906                         {
907                                 if(pp[3][i].all != 0)
908                                         PointPredictThree(i);
909                                 else
910                                         PointPredictTwo(i);
911                         }
912                         pp[0][i].all |= FLAG_FILL;
913                         pa[0][i] = pa[1][i];
914                 }
915                 else
916                         pp[0][i].all = 0x0fff0fff;
917                 if (pp[1][i].other.key)
918                         pp[0][i].all |= FLAG_KEY;
919         }
920 }
921
922 static unsigned int PointDistance(gsl_POINT_TYPE *p1,gsl_POINT_TYPE *p2)
923 {
924         int a,b,ret;
925         a = p1->dis.x;
926         b = p2->dis.x;
927         ret = (a-b)*(a-b);
928         a = p1->dis.y;
929         b = p2->dis.y;
930         ret += (a-b)*(a-b);
931         return ret;
932 }
933
934 static void DistanceInit(gsl_DISTANCE_TYPE *p)
935 {
936         int i;
937         unsigned int *p_int = &(p->d[0][0]);
938         for(i=0;i<POINT_MAX*POINT_MAX;i++)
939                 *p_int++ = 0x7fffffff;
940 }
941
942 static int DistanceMin(gsl_DISTANCE_TYPE *p)
943 {
944         int i,j;
945         p->min = 0x7fffffff;
946         for(j=0;j<POINT_MAX;j++)
947         {
948                 for(i=0;i<POINT_MAX;i++)
949                 {
950                         if(p->d[j][i] < p->min)
951                         {
952                                 p->i = i;
953                                 p->j = j;
954                                 p->min = p->d[j][i];
955                         }
956                 }
957         }
958         if(p->min == 0x7fffffff)
959                 return 0;
960         return 1;
961 }
962
963 static void DistanceIgnore(gsl_DISTANCE_TYPE *p)
964 {
965         int i,j;
966         for(i=0;i<POINT_MAX;i++)
967                 p->d[p->j][i] = 0x7fffffff;
968         for(j=0;j<POINT_MAX;j++)
969                 p->d[j][p->i] = 0x7fffffff;
970 }
971
972 static int SpeedGet(int d)
973 {
974         int i;
975         for(i=8;i>0;i--)
976         {
977                 if(d > 0x100<<i)
978                         break;
979         }
980         return i;
981 }
982
983 static void PointId(void)
984 {
985         int i,j;
986         gsl_DISTANCE_TYPE distance;
987         unsigned int id_speed[POINT_MAX];
988         DistanceInit(&distance);
989         for(i=0;i<POINT_MAX;i++)
990         {
991                 if (pp[0][i].other.predict == 0 || pp[1][i].other.fill != 0)
992                         id_speed[i] = id_first_coe;
993                 else
994                         id_speed[i] = SpeedGet( PointDistance(&pp[1][i],&pp[0][i]) );
995         }
996         for(i=0;i<POINT_MAX;i++)
997         {
998                 if(pp[0][i].all == FLAG_COOR)
999                         continue;
1000                 for(j=0;j<point_num && j<POINT_MAX;j++)
1001                 {
1002                         distance.d[j][i] = PointDistance(&point_now[j],&pp[0][i]);
1003                 }
1004         }
1005         if(point_num == 0)
1006                 return;
1007         if (global_state.other.only)
1008         {
1009                 //do
1010                 {
1011                         if(DistanceMin(&distance))
1012                         {
1013                                 if (pp[1][0].all != 0 && 
1014                                         pp[1][0].other.key != 
1015                                         point_now[distance.j].other.key)
1016                                 {
1017                                         DistanceIgnore(&distance);
1018                                         return;
1019                                         //continue;
1020                                 }
1021                                 pp[0][0].all = point_now[distance.j].all;
1022                         }
1023                         else
1024                                 pp[0][0].all = point_now[0].all;
1025                         for(i=0;i<POINT_MAX;i++)
1026                                 point_now[i].all = 0;
1027                 }
1028                 //while(0);
1029                 point_num = 1;
1030         }
1031         else
1032         {
1033                 for(j=0;j<point_num && j<POINT_MAX;j++)
1034                 {
1035                         if(DistanceMin(&distance) == 0)
1036                                 break;
1037                         if(distance.min >= (id_static_coe + 
1038                                 id_speed[distance.i] * id_speed_coe) /**average/(soft_average+1)*/)
1039                         {
1040                                 //point_now[distance.j].id = 0xf;//new id
1041                                 continue;
1042                         }
1043                         pp[0][distance.i].all = point_now[distance.j].all;
1044                         pa[0][distance.i] = pressure_now[distance.j];
1045                         point_now[distance.j].all = 0;
1046                         DistanceIgnore(&distance);
1047                 }
1048         }
1049 }
1050
1051 static int ClearLenPP(int i)
1052 {
1053         int n;
1054         for(n=0;n<PP_DEEP;n++)
1055         {
1056                 if(pp[n][i].all)
1057                         break;
1058         }
1059         return n;
1060 }
1061 static void PointNewId(void)
1062 {
1063         int id,j;
1064         for(j=0;j<POINT_MAX;j++)
1065                 if((pp[0][j].all & FLAG_COOR) == FLAG_COOR)
1066                         pp[0][j].all = 0;
1067         for(j=0;j<POINT_MAX;j++)
1068         {
1069                 if(point_now[j].all != 0)
1070                 {
1071                         if (point_now[j].other.able)
1072                                 continue;
1073                         for(id=1;id<=POINT_MAX;id++)
1074                         {
1075                                 if(ClearLenPP(id-1) > (int)(1+1))
1076                                 {
1077                                         pp[0][id-1].all = point_now[j].all;
1078                                         pa[0][id-1] = pressure_now[j];
1079                                         point_now[j].all = 0;
1080                                         break;
1081                                 }
1082                         }
1083                 }
1084         }
1085 }
1086
1087 static void PointOrder(void)
1088 {
1089         int i;
1090         for(i=0;i<POINT_MAX;i++)
1091         {
1092                 if (pp[0][i].other.fill == 0)
1093                         continue;
1094                 if (pp[1][i].all == 0 || pp[1][i].other.fill != 0 || filter_able == 0 || filter_able == 1)
1095                 {
1096                         pp[0][i].all = 0;
1097                         pressure_now[i] = 0;
1098                 }
1099         }
1100 }
1101
1102 static void PointCross(void)
1103 {
1104         unsigned int i,j;
1105         unsigned int t;
1106         for(j=0;j<POINT_MAX;j++)
1107         {
1108                 for(i=j+1;i<POINT_MAX;i++)
1109                 {
1110                         if(pp[0][i].all == 0 || pp[0][j].all == 0
1111                         || pp[1][i].all == 0 || pp[1][j].all == 0)
1112                                 continue;
1113                         if (((pp[0][j].other.x < pp[0][i].other.x && pp[1][j].other.x > pp[1][i].other.x)
1114                                 || (pp[0][j].other.x > pp[0][i].other.x && pp[1][j].other.x < pp[1][i].other.x))
1115                                 && ((pp[0][j].other.y < pp[0][i].other.y && pp[1][j].other.y > pp[1][i].other.y)
1116                                 || (pp[0][j].other.y > pp[0][i].other.y && pp[1][j].other.y < pp[1][i].other.y)))
1117                         {
1118                                 t = pp[0][i].other.x;
1119                                 pp[0][i].other.x = pp[0][j].other.x;
1120                                 pp[0][j].other.x = t;
1121                                 t = pp[0][i].other.y;
1122                                 pp[0][i].other.y = pp[0][j].other.y;
1123                                 pp[0][j].other.y = t;
1124                         }
1125                 }
1126         }
1127 }
1128
1129 static void GetPointNum(gsl_POINT_TYPE *pt)
1130 {
1131         int i;
1132         point_num = 0;
1133         for(i=0;i<POINT_MAX;i++)
1134                 if(pt[i].all != 0)
1135                         point_num++;
1136 }
1137
1138 static void PointDelay(void)
1139 {
1140         int i,j;
1141         for(i=0;i<POINT_MAX;i++)
1142         {
1143                 if(report_delay == 0)
1144                 {//
1145                         point_delay[i].all = 0;
1146                         if(pp[0][i].all)
1147                                 point_delay[i].other.able = 1;
1148                         continue;
1149                 }
1150                 if (pp[0][i].all != 0 && 
1151                         point_delay[i].other.init == 0 && 
1152                         point_delay[i].other.able == 0)
1153                 {
1154                         if(point_num == 0)
1155                                 continue;
1156                         point_delay[i].other.delay = (report_delay >> 3 * 
1157                                 ((point_num>10 ? 10 : point_num) - 1)) & 0x7;
1158                         point_delay[i].other.report = (report_ahead >> 3 * 
1159                                 ((point_num>10 ? 10 : point_num) - 1)) & 0x7;
1160                         if (point_delay[i].other.report > point_delay[i].other.delay)
1161                                 point_delay[i].other.report = point_delay[i].other.delay;
1162                         point_delay[i].other.init = 1;
1163                 }
1164                 if(pp[0][i].all == 0)
1165                 {
1166                         point_delay[i].other.init = 0;
1167                 }
1168                 if (point_delay[i].other.able == 0 && point_delay[i].other.init != 0)
1169                 {
1170                         for (j = 0; j <= (int)point_delay[i].other.delay; j++)
1171                         if (pp[j][i].all == 0 || 
1172                                 pp[j][i].other.fill != 0 || 
1173                                 pp[j][i].other.able != 0)
1174                                         break;
1175                         if (j <= (int)point_delay[i].other.delay)
1176                                 continue;
1177                         point_delay[i].other.able = 1;
1178                 }
1179                 if (pp[point_delay[i].other.report][i].all == 0)
1180                 {
1181                         point_delay[i].other.able = 0;
1182                         continue;
1183                 }
1184                 if (point_delay[i].other.able == 0)
1185                         continue;
1186                 if (point_delay[i].other.report)
1187                 {
1188                         if (PointDistance(&pp[point_delay[i].other.report][i], 
1189                                 &pp[point_delay[i].other.report - 1][i]) < 3 * 3)
1190                                 point_delay[i].other.report--;
1191                 }
1192         }
1193 }
1194
1195 static void FilterOne(int i,int *ps_c,int *pr_c,int denominator)
1196 {
1197         int j;
1198         int x=0,y=0;
1199         pr[0][i].all = ps[0][i].all;
1200         if(pr[0][i].all == 0)
1201                 return;
1202         if(denominator <= 0)
1203                 return;
1204         for(j=0;j<8;j++)
1205         {
1206                 x += (int)pr[j][i].other.x * (int)pr_c[j] + 
1207                         (int)ps[j][i].other.x * (int)ps_c[j];
1208                 y += (int)pr[j][i].other.y * (int)pr_c[j] + 
1209                         (int)ps[j][i].other.y * (int)ps_c[j];
1210         }
1211         x = (x + denominator/2) / denominator;
1212         y = (y + denominator/2) / denominator;
1213         if(x < 0)
1214                 x = 0;
1215         if(x > 0xffff)
1216                 x = 0xffff;
1217         if(y < 0)
1218                 y = 0;
1219         if(y > 0xfff)
1220                 y = 0xfff;
1221         pr[0][i].other.x = x;
1222         pr[0][i].other.y = y;
1223 }
1224
1225 static unsigned int FilterSpeed(int i)
1226 {
1227         return (Sqrt(PointDistance(&ps[0][i],&ps[1][i])) + 
1228                 Sqrt(PointDistance(&ps[1][i],&ps[2][i])))/2;
1229 }
1230
1231 static int MedianSpeedOver(int id,int deep)
1232 {
1233         int i;
1234         unsigned int dis;
1235         int speed_over = 0;
1236         deep = deep/2 - 1;
1237         if(deep < 0 || deep > 3)
1238                 return TRUE;
1239         dis = median_dis[deep] * median_dis[deep];
1240         for(i=0;i<=deep && i<POINT_DEEP;i++)
1241         {
1242                 if(PointDistance(&ps[i][id],&ps[i+1][id]) > dis)
1243                         speed_over ++;
1244         }
1245         if(speed_over >= 2)
1246                 return TRUE;
1247         return FALSE;
1248 }
1249
1250 static void PointMedian(void)
1251 {
1252         int i,j;
1253         int deep;
1254         int buf_x[PS_DEEP],buf_y[PS_DEEP];
1255         for(i=0;i<POINT_MAX;i++)
1256         {
1257                 if(filter_deep[i] < 3)
1258                         deep = 3;
1259                 else
1260                         deep = filter_deep[i] + 2;
1261                 if(deep >= PS_DEEP)
1262                         deep = PS_DEEP-1;
1263                 deep |= 1;
1264                 for(;deep>=3;deep-=2)
1265                 {
1266                         if(MedianSpeedOver(i,deep))
1267                                 continue;
1268                         for(j=0;j<deep;j++)
1269                         {
1270                                 buf_x[j] = ps[j][i].other.x;
1271                                 buf_y[j] = ps[j][i].other.y;
1272                         }
1273                         SortBubble(buf_x,deep);
1274                         SortBubble(buf_y,deep);
1275                         pr[0][i].other.x = buf_x[deep / 2];
1276                         pr[0][i].other.y = buf_y[deep / 2];
1277                 }
1278                 filter_deep[i] = deep;
1279         }
1280 }
1281 static void PointFilter(void)
1282 {
1283         int i,j;
1284         int speed_now;
1285         int filter_speed[6];
1286         int ps_c[8];
1287         int pr_c[8];
1288         for(i=0;i<POINT_MAX;i++)
1289         {
1290                 pr[0][i].all = ps[0][i].all;
1291         }
1292         for(i=0;i<POINT_MAX;i++)
1293         {
1294                 if(pr[0][i].all!=0 && pr[1][i].all == 0)
1295                 {
1296                         for(j=1;j<PR_DEEP;j++)
1297                                 pr[j][i].all = ps[0][i].all;
1298                         for(j=1;j<PS_DEEP;j++)
1299                                 ps[j][i].all = ps[0][i].all;
1300                 }
1301         }
1302         if(filter_able >=0 && filter_able <= 1)
1303                 return;
1304         if(filter_able > 1)
1305         {
1306                 for(i=0;i<8;i++)
1307                 {
1308                         ps_c[i] = (filter_coe[i/4] >> ((i%4)*8)) & 0xff;
1309                         pr_c[i] = (filter_coe[i/4+2] >> ((i%4)*8)) & 0xff;
1310                         if(ps_c[i] >= 0x80)
1311                                 ps_c[i] |= 0xffffff00;
1312                         if(pr_c[i] >= 0x80)
1313                                 pr_c[i] |= 0xffffff00;
1314                 }
1315                 for(i=0;i<POINT_MAX;i++)
1316                 {
1317                         FilterOne(i,ps_c,pr_c,filter_able);
1318                 }
1319         }
1320         else if(filter_able == -1)
1321         {
1322                 PointMedian();
1323         }
1324         else if(filter_able < 0)
1325         {
1326                 for(i=0;i<4;i++)
1327                         filter_speed[i+1] = median_dis[i];
1328                 filter_speed[0] = median_dis[0] * 2 - median_dis[1];
1329                 filter_speed[5] = median_dis[3] /2;
1330                 for(i=0;i<POINT_MAX;i++)
1331                 {
1332                         if(pr[0][i].all == 0)
1333                         {
1334                                 filter_deep[i] = 0;
1335                                 continue;
1336                         }
1337                         speed_now = FilterSpeed(i);
1338                         if(filter_deep[i] > 0 && 
1339                                 speed_now > filter_speed[filter_deep[i]+1 - 2])
1340                                 filter_deep[i] --;
1341                         else if(filter_deep[i] < 3 && 
1342                                 speed_now < filter_speed[filter_deep[i]+1 + 2])
1343                                 filter_deep[i] ++;
1344                                 
1345                         FilterOne(i,ps_coe[filter_deep[i]],
1346                                 pr_coe[filter_deep[i]],0-filter_able);
1347                 }
1348         }
1349 }
1350 static unsigned int KeyMap(int *drv,int *sen)
1351 {
1352         typedef struct
1353         {
1354                 unsigned int up_down,left_right;
1355                 unsigned int coor;
1356         }KEY_TYPE_RANGE;
1357         KEY_TYPE_RANGE *key_range = (KEY_TYPE_RANGE * )key_range_array;
1358         int i;
1359         for(i=0;i<8;i++)
1360         {
1361                 if((unsigned int)*drv >= (key_range[i].up_down >> 16) 
1362                 && (unsigned int)*drv <= (key_range[i].up_down & 0xffff)
1363                 && (unsigned int)*sen >= (key_range[i].left_right >> 16)
1364                 && (unsigned int)*sen <= (key_range[i].left_right & 0xffff))
1365                 {
1366                         *sen = key_range[i].coor >> 16;
1367                         *drv = key_range[i].coor & 0xffff;
1368                         return key_range[i].coor;
1369                 }
1370         }
1371         return 0;
1372 }
1373
1374 static unsigned int ScreenResolution(gsl_POINT_TYPE *p)
1375 {
1376         int x,y;
1377         x = p->other.x;
1378         y = p->other.y;
1379         if (p->other.key == FALSE)
1380         {
1381                 y = ((y - match_y[1]) * match_y[0] + 2048)/4096;
1382                 x = ((x - match_x[1]) * match_x[0] + 2048)/4096 ;
1383         }
1384         y = y * (int)screen_y_max / ((int)sen_num_nokey * 64);
1385         x = x * (int)screen_x_max / ((int)drv_num_nokey * 64);
1386         if (p->other.key == FALSE)
1387         {
1388                 if((ignore_y[0]!=0 || ignore_y[1]!=0))
1389                 {
1390                         if(y < ignore_y[0])
1391                                 return 0;
1392                         if(ignore_y[1] <= screen_y_max/2 && y > screen_y_max - ignore_y[1])
1393                                 return 0;
1394                         if(ignore_y[1] >= screen_y_max/2 && y > ignore_y[1])
1395                                 return 0;
1396                 }
1397                 if(ignore_x[0]!=0 || ignore_x[1]!=0)
1398                 {
1399                         if(x < ignore_x[0])
1400                                 return 0;
1401                         if(ignore_x[1] <= screen_y_max/2 && x > screen_x_max - ignore_x[1])
1402                                 return 0;
1403                         if(ignore_x[1] >= screen_y_max/2 && x > ignore_x[1])
1404                                 return 0;
1405                 }
1406                 if(y <= (int)edge_cut[2])
1407                         y = (int)edge_cut[2] + 1;
1408                 if(y >= screen_y_max - (int)edge_cut[3])
1409                         y = screen_y_max - (int)edge_cut[3] - 1;
1410                 if(x <= (int)edge_cut[0])
1411                         x = (int)edge_cut[0] + 1;
1412                 if(x >= screen_x_max - (int)edge_cut[1])
1413                         x = screen_x_max - (int)edge_cut[1] - 1;
1414                 if (global_flag.other.opposite_x)
1415                         y = screen_y_max - y;
1416                 if (global_flag.other.opposite_y)
1417                         x = screen_x_max - x;
1418                 if (global_flag.other.opposite_xy)
1419                 {
1420                         y ^= x;
1421                         x ^= y;
1422                         y ^= x;
1423                 }
1424         }
1425         else
1426         {
1427                 if(y < 0)
1428                         y = 0;
1429                 if(x < 0)
1430                         x = 0;
1431                 if((key_map_able & 0x1) != FALSE && KeyMap(&x,&y) == 0)
1432                         return 0;
1433         }
1434         return ((y<<16) & 0x0fff0000) + (x & 0x0000ffff);
1435 }
1436
1437 static void PointReport(struct gsl_touch_info *cinfo)
1438 {
1439         int i;
1440         unsigned int data[POINT_MAX];
1441         int num = 0;
1442         if (point_num > point_num_max && global_flag.other.over_report_mask != 0)
1443         {
1444                 point_num = 0;
1445                 cinfo->finger_num = 0;  
1446                 return;
1447         }
1448         for(i=0;i<POINT_MAX;i++)
1449                 data[i] = 0;
1450         num = 0;
1451         if (global_flag.other.id_over)
1452         {
1453                 for(i=0;i<POINT_MAX && num<point_num_max;i++)
1454                 {
1455                         if (point_delay[i].other.able == 0)
1456                                 continue;
1457                         if (point_delay[i].other.report >= PR_DEEP - 1)
1458                                 continue;
1459                         if (pr[point_delay[i].other.report + 1][i].other.able == 0)
1460                                 continue;
1461                         if (pr[point_delay[i].other.report][i].all)
1462                         {
1463                                 pr[point_delay[i].other.report][i].other.able = 1;
1464                                 data[i] = ScreenResolution(&pr[point_delay[i].other.report][i]);
1465                                 if(data[i])
1466                                 {
1467                                         data[i] |= (i+1)<<28;
1468                                         num++;
1469                                 }
1470                         }
1471                 }
1472                 for(i=0;i<POINT_MAX && num<point_num_max;i++)
1473                 {
1474                         if (point_delay[i].other.able == 0)
1475                                 continue;
1476                         if (point_delay[i].other.report >= PR_DEEP)
1477                                 continue;
1478                         if (pr[point_delay[i].other.report][i].all == 0)
1479                                 continue;
1480                         if (pr[point_delay[i].other.report][i].other.able == 0)
1481                         {
1482                                 pr[point_delay[i].other.report][i].other.able = 1;
1483                                 data[i] = ScreenResolution(&pr[point_delay[i].other.report][i]);
1484                                 if(data[i])
1485                                 {
1486                                         data[i] |= (i+1)<<28;
1487                                         num++;
1488                                 }
1489                         }
1490                 }
1491         }
1492         else
1493         {
1494                 num=0;
1495                 for(i=0;i<point_num_max;i++)
1496                 {
1497                         if (point_delay[i].other.able == 0)
1498                                 continue;
1499                         if (point_delay[i].other.report >= PR_DEEP)
1500                                 continue;
1501                         data[num] = ScreenResolution(&pr[point_delay[i].other.report][i]);
1502                         if(data[num])
1503                                 data[num++] |= (i+1)<<28;
1504                 }
1505         }
1506         num = 0;
1507         for(i=0;i<POINT_MAX;i++)
1508         {
1509                 if(data[i] == 0)
1510                         continue;
1511                 point_now[num].all = data[i];
1512                 cinfo->x[num] = (data[i] >> 16) & 0xfff;
1513                 cinfo->y[num] = data[i] & 0xfff;
1514                 cinfo->id[num] = data[i] >> 28; 
1515                 pressure_now[num] = pressure_report[i];
1516                 num ++; 
1517         }
1518         point_num = num;
1519         cinfo->finger_num = num;
1520 }
1521
1522
1523
1524 static void PointEdge(void)
1525 {
1526         typedef struct
1527         {
1528                 int range;
1529                 int coe;
1530         }STRETCH_TYPE;
1531         typedef struct
1532         {
1533                 STRETCH_TYPE up[4];
1534                 STRETCH_TYPE down[4];
1535                 STRETCH_TYPE left[4];
1536                 STRETCH_TYPE right[4];
1537         }STRETCH_TYPE_ALL;
1538         STRETCH_TYPE_ALL *stretch;
1539         int i,id;
1540         int data[2];
1541         int x,y;
1542         int sac[4*4*2];
1543         if(screen_x_max == 0 || screen_y_max == 0)
1544                 return;
1545         id = 0;
1546         for(i=0;i<4*4*2;i++)
1547         {
1548                 sac[i] = stretch_array[i];
1549                 if(sac[i])
1550                         id++;
1551         }
1552         if(id == 0)
1553                 return;
1554         stretch = (STRETCH_TYPE_ALL *)sac;
1555         for(i=0;i<4;i++)
1556         {
1557                 if(stretch->right[i].range > screen_y_max * 64 / 128
1558                 || stretch->down [i].range > screen_x_max * 64 / 128)
1559                 {
1560                         for(i=0;i<4;i++)
1561                         {
1562                                 if(stretch->up[i].range)
1563                                         stretch->up[i].range = 
1564                                                 stretch->up[i].range * 
1565                                                 drv_num_nokey * 64 / screen_x_max;
1566                                 if(stretch->down[i].range)
1567                                         stretch->down[i].range = 
1568                                                 (screen_x_max - 
1569                                                 stretch->down[i].range) * 
1570                                                 drv_num_nokey * 64 / screen_x_max;
1571                                 if(stretch->left[i].range)
1572                                         stretch->left[i].range = 
1573                                                 stretch->left[i].range * 
1574                                                 sen_num_nokey * 64 / screen_y_max;
1575                                 if(stretch->right[i].range)
1576                                         stretch->right[i].range = 
1577                                                 (screen_y_max - 
1578                                                 stretch->right[i].range) * 
1579                                                 sen_num_nokey * 64 / screen_y_max;
1580                         }
1581                         break;
1582                 }
1583         }
1584         for(id=0;id<POINT_MAX;id++)
1585         {
1586                 if (point_now[id].all == 0 || point_now[id].other.key != 0)
1587                         continue;
1588                 x = point_now[id].other.x;
1589                 y = point_now[id].other.y;
1590
1591                 data[0] = 0;
1592                 data[1] = y;
1593                 for(i=0;i<4;i++)
1594                 {
1595                         if(stretch->left[i].range == 0)
1596                                 break;
1597                         if(data[1] < stretch->left[i].range)
1598                         {
1599                                 data[0] += (stretch->left[i].range - data[1]) * 
1600                                         stretch->left[i].coe/128;
1601                                 data[1] = stretch->left[i].range;
1602                         }
1603                 }
1604                 y = data[1] - data[0];
1605                 if(y <= 0)
1606                         y = 1;
1607                 if(y >= (int)sen_num_nokey*64)
1608                         y = sen_num_nokey*64 - 1;
1609
1610                 data[0] = 0;
1611                 data[1] = sen_num_nokey * 64 - y;
1612                 for(i=0;i<4;i++)
1613                 {
1614                         if(stretch->right[i].range == 0)
1615                                 break;
1616                         if(data[1] < stretch->right[i].range)
1617                         {
1618                                 data[0] += (stretch->right[i].range - data[1]) * 
1619                                         stretch->right[i].coe/128;
1620                                 data[1] = stretch->right[i].range;
1621                         }
1622                 }
1623                 y = sen_num_nokey * 64 - (data[1] - data[0]);
1624                 if(y <= 0)
1625                         y = 1;
1626                 if(y >= (int)sen_num_nokey*64)
1627                         y = sen_num_nokey*64 - 1;
1628
1629                 data[0] = 0;
1630                 data[1] = x;
1631                 for(i=0;i<4;i++)
1632                 {
1633                         if(stretch->up[i].range == 0)
1634                                 break;
1635                         if(data[1] < stretch->up[i].range)
1636                         {
1637                                 data[0] += (stretch->up[i].range - data[1]) * 
1638                                         stretch->up[i].coe/128;
1639                                 data[1] = stretch->up[i].range;
1640                         }
1641                 }
1642                 x = data[1] - data[0];
1643                 if(x <= 0)
1644                         x = 1;
1645                 if(x >= (int)drv_num_nokey*64)
1646                         x = drv_num_nokey*64 - 1;
1647
1648                 data[0] = 0;
1649                 data[1] = drv_num_nokey * 64 - x;
1650                 for(i=0;i<4;i++)
1651                 {
1652                         if(stretch->down[i].range == 0)
1653                                 break;
1654                         if(data[1] < stretch->down[i].range)
1655                         {
1656                                 data[0] += (stretch->down[i].range - data[1]) * 
1657                                         stretch->down[i].coe/128;
1658                                 data[1] = stretch->down[i].range;
1659                         }
1660                 }
1661                 x = drv_num_nokey * 64 - (data[1] - data[0]);
1662                 if(x <= 0)
1663                         x = 1;
1664                 if(x >= (int)drv_num_nokey*64)
1665                         x = drv_num_nokey*64 - 1;
1666
1667                 point_now[id].other.x = x;
1668                 point_now[id].other.y = y;
1669         }
1670 }
1671
1672 static void PointStretch(void)
1673 {
1674         static int save_dr[POINT_MAX],save_dn[POINT_MAX];
1675         typedef struct  
1676         {
1677                 int dis;
1678                 int coe;
1679         }SHAKE_TYPE;
1680         SHAKE_TYPE * shake_all = (SHAKE_TYPE *) shake_all_array;
1681         int i,j;
1682         int dn;
1683         int dr;
1684         int dc[9],ds[9];
1685         int len = 8;
1686         unsigned int temp;
1687         for(i=0;i<POINT_MAX;i++)
1688         {
1689                 ps[0][i].all = pp[0][i].all;
1690         }
1691         for(i=0;i<POINT_MAX;i++)
1692         {
1693                 if (pp[0][i].all == 0 || pp[0][i].other.key)
1694                 {
1695                         point_shake &= ~(0x1<<i);
1696                         if(i == 0)
1697                                 point_edge.rate = 0;
1698                         continue;
1699                 }
1700                 if(i == 0)
1701                 {
1702                         if(edge_first!=0 && ps[1][i].all == 0)
1703                         {
1704                                 point_edge.coor.all = ps[0][i].all;
1705                                 if (point_edge.coor.other.x < (unsigned int)((edge_first >> 24) & 0xff))
1706                                         point_edge.coor.other.x = ((edge_first >> 24) & 0xff);
1707                                 if (point_edge.coor.other.x > drv_num_nokey * 64 - ((edge_first >> 16) & 0xff))
1708                                         point_edge.coor.other.x = drv_num_nokey * 64 - ((edge_first >> 16) & 0xff);
1709                                 if (point_edge.coor.other.y < (unsigned int)((edge_first >> 8) & 0xff))
1710                                         point_edge.coor.other.y = ((edge_first >> 8) & 0xff);
1711                                 if (point_edge.coor.other.y > sen_num_nokey * 64 - ((edge_first >> 0) & 0xff))
1712                                         point_edge.coor.other.y = sen_num_nokey * 64 - ((edge_first >> 0) & 0xff);
1713                                 if(point_edge.coor.all != ps[0][i].all)
1714                                 {
1715                                         point_edge.dis = PointDistance(&ps[0][i],&point_edge.coor);
1716                                         if(point_edge.dis)
1717                                                 point_edge.rate = 0x1000;
1718                                 }
1719                         }
1720                         if(point_edge.rate!=0 && point_edge.dis!=0)
1721                         {
1722                                 temp = PointDistance(&ps[0][i],&point_edge.coor);
1723                                 if(temp >= point_edge.dis * edge_first_coe / 0x80)
1724                                 {
1725                                         point_edge.rate = 0;
1726                                 }
1727                                 else if(temp > point_edge.dis)
1728                                 {
1729                                         temp = (point_edge.dis * edge_first_coe / 0x80 - temp) * 
1730                                                 0x1000 / point_edge.dis;
1731                                         if(temp < point_edge.rate)
1732                                                 point_edge.rate = temp;
1733                                 }
1734                                 ps[0][i].other.x = point_edge.coor.other.x + 
1735                                         (ps[0][i].other.x - point_edge.coor.other.x) * 
1736                                         (0x1000 - point_edge.rate) / 0x1000;
1737                                 ps[0][i].other.y = point_edge.coor.other.y + 
1738                                         (ps[0][i].other.y - point_edge.coor.other.y) * 
1739                                         (0x1000 - point_edge.rate) / 0x1000;
1740                         }
1741                 }
1742                 if(ps[1][i].all == 0)
1743                 {
1744                         continue;
1745                 }
1746                 else if((point_shake & (0x1<<i)) == 0)
1747                 {
1748                         if(PointDistance(&ps[0][i],&ps[1][i]) < (unsigned int)shake_min)
1749                         {
1750                                 ps[0][i].all = ps[1][i].all;
1751                                 continue;
1752                         }
1753                         else
1754                                 point_shake |= (0x1<<i);
1755                 }
1756         }
1757         for(i=0;i<len;i++)
1758         {
1759                 if(shake_all[i].dis == 0)
1760                 {
1761                         len=i;
1762                         break;
1763                 }
1764         }
1765         if(len == 1)
1766         {
1767                 ds[0] = shake_all[0].dis;
1768                 dc[0] = (shake_all[0].coe*100+64)/128;
1769                 for(i=0;i<POINT_MAX;i++)
1770                 {
1771                         if(ps[1][i].all == 0)
1772                         {
1773                                 for(j=1;j<PS_DEEP;j++)
1774                                         ps[j][i].all = ps[0][i].all;
1775                                 continue;
1776                         }
1777                         if((point_shake & (0x1<<i)) == 0)
1778                                 continue;
1779                         dn = PointDistance(&pp[0][i],&ps[1][i]);
1780                         dn = Sqrt(dn);
1781                         dr = dn>ds[0] ? dn-ds[0] : 0;
1782                         temp = ps[0][i].all;
1783                         if(dn == 0 || dr == 0)
1784                         {
1785                                 ps[0][i].other.x = ps[1][i].other.x;
1786                                 ps[0][i].other.y = ps[1][i].other.y;
1787                         }
1788                         else
1789                         {
1790                                 ps[0][i].other.x = (int)ps[1][i].other.x + 
1791                                         ((int)pp[0][i].other.x - 
1792                                         (int)ps[1][i].other.x) * dr / dn;
1793                                 ps[0][i].other.y = (int)ps[1][i].other.y + 
1794                                         ((int)pp[0][i].other.y - 
1795                                         (int)ps[1][i].other.y) * dr / dn;
1796                         }
1797                         if(dc[0] > 0)
1798                         {
1799                                 if(ps[0][i].all == ps[1][i].all && temp != ps[0][i].all)
1800                                 {
1801                                         ps[0][i].all = temp;
1802                                         point_decimal[i].other.x += 
1803                                                 (short)ps[0][i].other.x - 
1804                                                 (short)ps[1][i].other.x;
1805                                         point_decimal[i].other.y += 
1806                                                 (short)ps[0][i].other.y - 
1807                                                 (short)ps[1][i].other.y;
1808                                         ps[0][i].other.x = ps[1][i].other.x;
1809                                         ps[0][i].other.y = ps[1][i].other.y;
1810                                         if (point_decimal[i].other.x >  dc[0] && ps[1][i].other.x < 0xffff)
1811                                         {
1812                                                 ps[0][i].other.x += 1;
1813                                                 point_decimal[i].other.x = 0;
1814                                         }
1815                                         if (point_decimal[i].other.x  < -dc[0] && ps[1][i].other.x > 0)
1816                                         {
1817                                                 ps[0][i].other.x -= 1;
1818                                                 point_decimal[i].other.x = 0;
1819                                         }
1820                                         if (point_decimal[i].other.y >  dc[0] && ps[1][i].other.y < 0xffff)
1821                                         {
1822                                                 ps[0][i].other.y += 1;
1823                                                 point_decimal[i].other.y = 0;
1824                                         }
1825                                         if (point_decimal[i].other.y  < -dc[0] && ps[1][i].other.y > 0)
1826                                         {
1827                                                 ps[0][i].other.y -= 1;
1828                                                 point_decimal[i].other.y = 0;
1829                                         }
1830                                 }
1831                                 else
1832                                 {
1833                                         point_decimal[i].other.x = 0;
1834                                         point_decimal[i].other.y = 0;
1835                                 }
1836                         }
1837                 }
1838                 
1839         }
1840         else if(len >= 2)
1841         {
1842                 for(i=0;i<8 && i<len;i++)
1843                 {
1844                         ds[i+1] = shake_all[i].dis;
1845                         dc[i+1] = shake_all[i].coe;//;ds[i+1] * shake_all[i].coe;
1846                 }
1847                 if(shake_all[0].coe >= 128 || shake_all[0].coe <= shake_all[1].coe)
1848                 {
1849                         ds[0] = ds[1];
1850                         dc[0] = dc[1];
1851                 }
1852                 else
1853                 {
1854                         ds[0] = ds[1] + (128 - shake_all[0].coe) * 
1855                                 (ds[1]-ds[2])/(shake_all[0].coe - shake_all[1].coe);
1856                         dc[0] = 128;
1857                 }
1858                 for(i=0;i<POINT_MAX;i++)
1859                 {
1860                         if(ps[1][i].all == 0)
1861                         {
1862                                 for(j=1;j<PS_DEEP;j++)
1863                                         ps[j][i].all = ps[0][i].all;
1864                                 save_dr[i] = 128;
1865                                 save_dn[i] = 0;
1866                                 continue;
1867                         }
1868                         if((point_shake & (0x1<<i)) == 0)
1869                                 continue;
1870                         dn = PointDistance(&pp[0][i],&ps[1][i]);
1871                         dn = Sqrt(dn);
1872                         if(dn >= ds[0])
1873                         {
1874                                 continue;
1875                         }
1876                         if(dn < save_dn[i])
1877                         {
1878                                 dr = save_dr[i];
1879                                 save_dn[i] = dn;
1880                                 ps[0][i].other.x = (int)ps[1][i].other.x + 
1881                                         (((int)pp[0][i].other.x - 
1882                                         (int)ps[1][i].other.x) * dr) / 128;
1883                                 ps[0][i].other.y = (int)ps[1][i].other.y + 
1884                                         (((int)pp[0][i].other.y - 
1885                                         (int)ps[1][i].other.y) * dr) / 128;
1886                                 continue;
1887                         }
1888                         for(j=0;j<=len;j++)
1889                         {
1890                                 if(j == len || dn == 0)
1891                                 {
1892                                         ps[0][i].other.x = ps[1][i].other.x;
1893                                         ps[0][i].other.y = ps[1][i].other.y;
1894                                         break;
1895                                 }
1896                                 else if(ds[j] > dn && dn >=ds[j+1])
1897                                 {
1898                                         dr = dc[j+1] + ((dn - ds[j+1]) * (dc[j] - dc[j+1])) / (ds[j] - ds[j+1]);
1899                                         save_dr[i] = dr;
1900                                         save_dn[i] = dn;
1901 //                                      ps[0][i].x = (int)ps[1][i].x + ((int)pp[0][i].x - (int)ps[1][i].x) * dr / dn / 128;
1902 //                                      ps[0][i].y = (int)ps[1][i].y + ((int)pp[0][i].y - (int)ps[1][i].y) * dr / dn / 128;
1903                                         ps[0][i].other.x = (int)ps[1][i].other.x + 
1904                                                 (((int)pp[0][i].other.x - 
1905                                                 (int)ps[1][i].other.x) * dr + 64) / 128;
1906                                         ps[0][i].other.y = (int)ps[1][i].other.y + 
1907                                                 (((int)pp[0][i].other.y - 
1908                                                 (int)ps[1][i].other.y) * dr + 64) / 128;
1909                                         break;
1910                                 }
1911                         }
1912                 }
1913         }
1914         else
1915         {
1916                 return;
1917         }
1918 }
1919
1920 static void ResetMask(void)
1921 {
1922         if(reset_mask_send)
1923         {
1924                 reset_mask_send = 0;
1925         }
1926         if (global_state.other.mask)
1927                 return;
1928         if(reset_mask_dis ==0 || reset_mask_type == 0)
1929                 return;
1930         if(reset_mask_max == 0xfffffff1)
1931         {
1932                 if(point_num == 0) 
1933                         reset_mask_max = 0xf0000000 + 1;
1934                 return;
1935         }
1936         if(reset_mask_max >  0xf0000000)
1937         {
1938                 reset_mask_max --;
1939                 if(reset_mask_max == 0xf0000000)
1940                 {
1941                         reset_mask_send = reset_mask_type;
1942                         global_state.other.mask = 1;
1943                 }
1944                 return;
1945         }
1946         if(point_num > 1 || pp[0][0].all == 0)
1947         {
1948                 reset_mask_count = 0;
1949                 reset_mask_max = 0;
1950                 reset_mask_count = 0;
1951                 return;
1952         }
1953         reset_mask_count ++;
1954         if(reset_mask_max == 0)
1955                 reset_mask_max = pp[0][0].all;
1956         else 
1957                 if(PointDistance((gsl_POINT_TYPE*)(&reset_mask_max),pp[0]) > 
1958                         (((unsigned int)reset_mask_dis) & 0xffffff) && 
1959                         reset_mask_count > (((unsigned int)reset_mask_dis) >> 24))
1960                         reset_mask_max = 0xfffffff1;
1961 }
1962
1963 static int ConfigCoorMulti(int data[])
1964 {
1965         int i,j;
1966         int n = 0;
1967         for(i=0;i<4;i++)
1968         {
1969                 if(data[247+i]!=0)
1970                 {
1971                         if((data[247+i]&63)==0 && (data[247+i]>>16)<4)
1972                                 n++;
1973                         else
1974                                 return FALSE;
1975                 }
1976                 if(data[251+i]!=0)
1977                 {
1978                         if((data[251+i]&63)==0 && (data[251+i]>>16)<4)
1979                                 n++;
1980                         else
1981                                 return FALSE;
1982                 }
1983         }
1984         if(n == 0 || n > 4)
1985                 return FALSE;
1986         for(j=0;j<n;j++)
1987         {
1988                 for(i=0;i<64;i++)
1989                 {
1990                         if(data[256+j*64+i] >= 64)
1991                                 return FALSE;
1992                         if(i)
1993                         {
1994                                 if(data[256+j*64+i] < data[256+j*64+i-1])
1995                                         return FALSE;
1996                         }
1997                 }
1998         }
1999         return TRUE;
2000 }
2001
2002 static int ConfigFilter(unsigned int data[])
2003 {
2004         int i;
2005         unsigned int ps_c[8];
2006         unsigned int pr_c[8];
2007         unsigned int sum = 0;
2008         //if(data[242]>1 && (data[255]>=0 && data[255]<=256))
2009         if (data[242]>1 && (data[255] <= 256))
2010         {
2011                 for(i=0;i<8;i++)
2012                 {
2013                         ps_c[i] = (data[243+i/4] >> ((i%4)*8)) & 0xff;
2014                         pr_c[i] = (data[243+i/4+2] >> ((i%4)*8)) & 0xff;
2015                         if(ps_c[i] >= 0x80)
2016                                 ps_c[i] |= 0xffffff00;
2017                         if(pr_c[i] >= 0x80)
2018                                 pr_c[i] |= 0xffffff00;
2019                         sum += ps_c[i];
2020                         sum += pr_c[i];
2021                 }
2022                 if(sum == data[242] || sum + data[242] == 0)
2023                         return TRUE;
2024         }
2025         return FALSE;
2026 }
2027
2028 static int ConfigKeyMap(int data[])
2029 {
2030         int i;
2031         if(data[217] != 1)
2032                 return FALSE;
2033         for(i=0;i<8;i++)
2034         {
2035                 if(data[218+2] == 0)
2036                         return FALSE;
2037                 if((data[218+i*3+0]>>16) > (data[218+i*3+0]&0xffff))
2038                         return FALSE;
2039                 if((data[218+i*3+1]>>16) > (data[218+i*3+1]&0xffff))
2040                         return FALSE;
2041         }
2042         return TRUE;
2043 }
2044
2045 static int DiagonalDistance(gsl_POINT_TYPE *p,int type)
2046 {
2047         int divisor,square;
2048         divisor = ((int)sen_num_nokey * (int)sen_num_nokey + 
2049                 (int)drv_num_nokey * (int)drv_num_nokey)/16;
2050         if(divisor == 0)
2051                 divisor = 1;
2052         if(type == 0)
2053                 square = ((int)sen_num_nokey*(int)(p->other.x) - 
2054                         (int)drv_num_nokey*(int)(p->other.y)) / 4;
2055         else
2056                 square = ((int)sen_num_nokey*(int)(p->other.x) + 
2057                         (int)drv_num_nokey*(int)(p->other.y) - 
2058                         (int)sen_num_nokey*(int)drv_num_nokey * 64) / 4;
2059         return square * square / divisor;
2060 }
2061
2062 static void DiagonalCompress(gsl_POINT_TYPE *p,int type,int dis,int dis_max)
2063 {
2064         int x,y;
2065         int tx,ty;
2066         int cp_ceof;
2067         if(dis_max == 0)
2068                 return;
2069         if(dis > dis_max)
2070                 cp_ceof = (dis - dis_max)*128/(3*dis_max) + 128;
2071         else
2072                 cp_ceof = 128;
2073         if(cp_ceof > 256)
2074                 cp_ceof = 256;
2075         x = p->other.x;
2076         y = p->other.y;
2077         if(type)
2078                 y = (int)sen_num_nokey*64 - y;
2079         x *= (int)sen_num_nokey;
2080         y *= (int)drv_num_nokey;
2081         tx = x;
2082         ty = y;
2083         x = ((tx+ty)+(tx-ty)*cp_ceof/256)/2;
2084         y = ((tx+ty)+(ty-tx)*cp_ceof/256)/2;
2085         x /= (int)sen_num_nokey;
2086         y /= (int)drv_num_nokey;
2087         if(type)
2088                 y = sen_num_nokey*64 - y;
2089         if(x < 1)
2090                 x = 1;
2091         if(y < 1)
2092                 y = 1;
2093         if(x >= (int)drv_num_nokey*64)
2094                 x = drv_num_nokey*64 - 1;
2095         if(y >= (int)sen_num_nokey*64)
2096                 y = (int)sen_num_nokey*64 - 1;
2097         p->other.x = x;
2098         p->other.y = y;
2099 }
2100
2101 static void PointDiagonal(void)
2102 {
2103         int i;
2104         int diagonal_size;
2105         int dis;
2106         unsigned int diagonal_start;
2107         if(diagonal == 0)
2108                 return;
2109         diagonal_size = diagonal * diagonal;
2110         diagonal_start = diagonal * 3/2;
2111         for(i=0;i<POINT_MAX;i++)
2112         {
2113                 if (ps[0][i].all == 0 || ps[0][i].other.key != 0)
2114                 {
2115                         point_corner &= ~(0x3<<i*2);
2116                         continue;
2117                 }
2118                 else if((point_corner & (0x3<<i*2)) == 0)
2119                 {
2120                         if ((ps[0][i].other.x <= diagonal_start && 
2121                                 ps[0][i].other.y <= diagonal_start) ||
2122                                 (ps[0][i].other.x >= drv_num_nokey * 64 - diagonal_start && 
2123                                  ps[0][i].other.y >= sen_num_nokey * 64 - diagonal_start))
2124                                 point_corner |= 0x2<<i*2;
2125                         else if ((ps[0][i].other.x <= diagonal_start && 
2126                                 ps[0][i].other.y >= sen_num_nokey * 64 - diagonal_start) || 
2127                                 (ps[0][i].other.x >= drv_num_nokey * 64 - diagonal_start && 
2128                                 ps[0][i].other.y <= diagonal_start))
2129                                 point_corner |= 0x3<<i*2;
2130                         else
2131                                 point_corner |= 0x1<<i*2;
2132                 }
2133                 if(point_corner & (0x2<<i*2))
2134                 {
2135                         dis = DiagonalDistance(&(ps[0][i]),point_corner & (0x1<<i*2));
2136                         if(dis <= diagonal_size*4)
2137                         {
2138                                 DiagonalCompress(&(ps[0][i]),point_corner & (0x1<<i*2),dis,diagonal_size);
2139                         }
2140                         else if(dis > diagonal_size*4)
2141                         {
2142                                 point_corner &= ~(0x3<<i*2);
2143                                 point_corner |= 0x1<<i*2;
2144                         }
2145                 }
2146         }
2147 }
2148
2149 static void PressureSave(void)
2150 {
2151         int i;
2152         if((point_num & 0x1000)==0)
2153         {
2154                 return;
2155         }
2156         for(i=0;i<POINT_MAX;i++)
2157         {
2158                 pressure_now[i] = point_now[i].all >> 28;
2159                 point_now[i].all &= ~(0xf<<28);
2160         }
2161 }
2162
2163 static void PointPressure(void)
2164 {
2165         int i,j;
2166         for(i=0;i<POINT_MAX;i++)
2167         {
2168                 if(pa[0][i]!=0 && pa[1][i]==0)
2169                 {
2170                         pressure_report[i] = pa[0][i]*5;
2171                         for(j=1;j<PRESSURE_DEEP;j++)
2172                                 pa[j][i] = pa[0][i];
2173                         continue;
2174                 }
2175                 j = (pressure_report[i]+1)/2 + pa[0][i] + 
2176                         pa[1][i] + (pa[2][i]+1)/2 - pressure_report[i];
2177                 if(j >= 2)
2178                         j -= 2;
2179                 else if(j <= -2)
2180                         j += 2;
2181                 else
2182                         j = 0;
2183                 pressure_report[i] = pressure_report[i]+j;
2184         }
2185 }
2186
2187 void gsl_ReportPressure(unsigned int *p)
2188 {
2189         int i;
2190         for(i=0;i<POINT_MAX;i++)
2191         {
2192                 if(i < point_num)
2193                 {
2194                         if(pressure_now[i] == 0)
2195                                 p[i] = 0;
2196                         else if(pressure_now[i] <= 7)
2197                                 p[i] = 1;
2198                         else if(pressure_now[i] > 63+7)
2199                                 p[i] = 63;
2200                         else
2201                                 p[i] = pressure_now[i] - 7;
2202                 }
2203                 else
2204                         p[i] = 0;
2205         }
2206 }
2207 //EXPORT_SYMBOL(gsl_ReportPressure);
2208
2209 int  gsl_TouchNear(void)
2210 {
2211                 return 0;
2212 }
2213 //EXPORT_SYMBOL(gsl_TouchNear);
2214
2215 static void DoubleClick(void)
2216 {
2217         int i;
2218         unsigned int width[3];
2219         double_click = 0;
2220 //      printk("sileadinc DoubleClick c = %08x , %08x\n",csensor_count,pp[0][0].all);
2221         if (point_num >= 2 || (point_num == 1 && pp[0][0].all == 0) || pp[0][0].other.key)
2222         {
2223 //              printk("sileadinc DoubleClick return\n");
2224                 for(i=0;i<sizeof(click_count)/sizeof(click_count[0]);i++)
2225                         click_count[i] = 0;
2226                 return;
2227         }
2228         if(point_num!=0 && prev_num==0)
2229         {
2230                 for(i=sizeof(click_count)/sizeof(click_count[0])-1;i>0;i--)
2231                         click_count[i] = click_count[i-1];
2232                 click_count[0] = csensor_count;
2233                 for(i=sizeof(point_click)/sizeof(point_click[0])-1;i>1;i--)
2234                         point_click[i].all = point_click[i-2].all;
2235                 point_click[0].all = pp[0][0].all;
2236                 point_click[1].all = pp[0][0].all;
2237         }
2238         if(point_num!=0 && prev_num!=0)
2239         {
2240                 if(PointDistance(&point_click[1],&pp[0][0]) > PointDistance(&point_click[1],&point_click[0]))
2241                         point_click[0].all = pp[0][0].all;
2242         }
2243         if(point_num==0 && prev_num!=0)
2244         {
2245 //              printk("sileadinc DoubleClick point_click %08x  %08x %08x %08x\n",point_click[0],point_click[1],point_click[2],point_click[3]);
2246                 for(i=sizeof(click_count)/sizeof(click_count[0])-1;i>0;i--)
2247                         click_count[i] = click_count[i-1];
2248                 click_count[0] = csensor_count;
2249                 for(i=0;i<sizeof(click_count)/sizeof(click_count[0])-1;i++)
2250                         width[i] = (click_count[i] - click_count[i+1]) & 0xffff;
2251                 if(!(width[0]>=double_down*average && width[2]>=double_down*average && width[1]<=double_up*average))
2252                 {
2253 //                      printk("sileadinc DoubleClick width %08x %08x %08x\n",width[0],width[1],width[2]);
2254                         return;
2255                 }
2256                 if(PointDistance(&point_click[0],&point_click[1]) > 64*64
2257                 || PointDistance(&point_click[2],&point_click[3]) > 64*64
2258                 || PointDistance(&point_click[1],&point_click[3]) > 128*128)
2259                 {
2260 //                      printk("sileadinc DoubleClick distance %08x %08x %08x\n",
2261 //                      PointDistance(&point_click[0],&point_click[1]),
2262 //                      PointDistance(&point_click[2],&point_click[3]),
2263 //                      PointDistance(&point_click[1],&point_click[3]));
2264                         return;
2265                 }
2266                 for(i=0;i<sizeof(click_count)/sizeof(click_count[0]);i++)
2267                         click_count[i] = 0;//?point_click
2268                 double_click = '*';
2269 //              printk("sileadinc DoubleClick succeed double_click=%c\n",double_click);
2270         }
2271
2272
2273 static void gsl_id_reg_init(int flag)
2274 {
2275         int i,j;
2276         for(j=0;j<POINT_DEEP;j++)
2277                 for(i=0;i<POINT_MAX;i++)
2278                         point_array[j][i].all = 0;      
2279         for(j=0;j<PRESSURE_DEEP;j++)
2280                 for(i=0;i<POINT_MAX;i++)
2281                         pressure_array[j][i] = 0;
2282         for(i=0;i<POINT_MAX;i++)
2283         {
2284                 point_delay[i].all = 0;
2285                 filter_deep[i] = 0;
2286                 point_decimal[i].all = 0;
2287         }
2288         point_edge.rate = 0;
2289         point_n = 0;
2290         if(flag)
2291                 point_num = 0;
2292         prev_num = 0;
2293         point_shake = 0;
2294         reset_mask_send = 0;
2295         reset_mask_max = 0;
2296         reset_mask_count = 0;
2297         point_near = 0;
2298         point_corner = 0;       
2299         global_state.all = 0;
2300         double_click = 0;
2301         inte_count = 0;
2302         csensor_count = 0;
2303 #ifdef GESTURE_LICH
2304         GestureInit();
2305 #endif
2306 }
2307
2308 static int DataCheck(void)
2309 {
2310         if(drv_num==0 || drv_num_nokey==0 || sen_num==0 || sen_num_nokey==0)
2311                 return 0;
2312         if(screen_x_max==0 || screen_y_max==0)
2313                 return 0;
2314         return 1;
2315 }
2316
2317 void gsl_DataInit(unsigned int * conf_in)
2318 {
2319         int i, j;
2320         unsigned int *conf;
2321         int len;
2322         gsl_id_reg_init(1);
2323         conf = config_static;
2324         coordinate_correct_able = 0;
2325         for(i=0;i<32;i++)
2326         {
2327                 coordinate_correct_coe_x[i] = i;
2328                 coordinate_correct_coe_y[i] = i;
2329         }
2330         id_first_coe = 8;
2331         id_speed_coe = 128*128;
2332         id_static_coe = 64*64;
2333         average = 3+1;
2334         soft_average = 3;
2335         report_delay=0;
2336         report_ahead = 0x9249249;
2337         for(i=0;i<4;i++)
2338                 median_dis[i]=0;
2339         shake_min = 0*0;
2340         for(i=0;i<2;i++)
2341         {
2342                 match_y[i]=0;
2343                 match_x[i]=0;
2344                 ignore_y[i]=0;
2345                 ignore_x[i]=0;
2346         }
2347         match_y[0]=4096;
2348         match_x[0]=4096;
2349         screen_y_max = 480;
2350         screen_x_max = 800;
2351         point_num_max=10;
2352         drv_num = 16;
2353         sen_num = 10;
2354         drv_num_nokey = 16;
2355         sen_num_nokey = 10;
2356         for(i=0;i<4;i++)
2357                 edge_cut[i] = 0;
2358         for(i=0;i<32;i++)
2359                 stretch_array[i] = 0;
2360         for(i=0;i<16;i++)
2361                 shake_all_array[i] = 0;
2362         reset_mask_dis = 0;
2363         reset_mask_type=0;
2364         diagonal = 0;
2365         key_map_able = 0;
2366         for(i=0;i<8*3;i++)
2367                 key_range_array[i] = 0;
2368         filter_able = 0;
2369         filter_coe[0] = ( 0<<6*4)+( 0<<6*3)+( 0<<6*2)+(40<<6*1)+(24<<6*0);
2370         filter_coe[1] = ( 0<<6*4)+( 0<<6*3)+(16<<6*2)+(24<<6*1)+(24<<6*0);
2371         filter_coe[2] = ( 0<<6*4)+(16<<6*3)+(24<<6*2)+(16<<6*1)+( 8<<6*0);
2372         filter_coe[3] = ( 6<<6*4)+(16<<6*3)+(24<<6*2)+(12<<6*1)+( 6<<6*0);
2373         for(i=0;i<4;i++)
2374         {
2375                 multi_x_array[i]=0;
2376                 multi_y_array[i]=0;
2377         }
2378         point_repeat[0] = 32;
2379         point_repeat[1] = 96;
2380         edge_first = 0;
2381         edge_first_coe = 0x80;
2382         //----------------------------------------------
2383         if(conf_in == NULL)
2384         {
2385                 return;
2386         }
2387         if(conf_in[0] <= 0xfff)
2388         {
2389                 if(ConfigCoorMulti((int*)conf_in))
2390                         len = 512;
2391                 else if(ConfigFilter(conf_in))
2392                         len = 256;
2393                 else if (ConfigKeyMap((int*)conf_in))
2394                         len = 241;
2395                 else
2396                         len = 215;
2397         }
2398         else if(conf_in[1] <= CONFIG_LENGTH)
2399                 len = conf_in[1];
2400         else
2401                 len = CONFIG_LENGTH;
2402         for(i=0;i<len;i++)
2403                 conf[i] = conf_in[i];
2404         for(;i<CONFIG_LENGTH;i++)
2405                 conf[i] = 0;
2406         if(conf_in[0] <= 0xfff)
2407         {
2408                 coordinate_correct_able = conf[0];
2409                 drv_num = conf[1];
2410                 sen_num = conf[2];
2411                 drv_num_nokey = conf[3];
2412                 sen_num_nokey = conf[4];
2413                 id_first_coe = conf[5];
2414                 id_speed_coe = conf[6];
2415                 id_static_coe = conf[7];
2416                 average = conf[8];
2417                 soft_average = conf[9];
2418
2419                 report_delay = conf[13];
2420                 shake_min = conf[14];
2421                 screen_y_max = conf[15];
2422                 screen_x_max = conf[16];
2423                 point_num_max = conf[17];
2424                 global_flag.all = conf[18];
2425                 for(i=0;i<4;i++)
2426                         median_dis[i] = (unsigned char)conf[19+i];
2427                 for(i=0;i<2;i++)
2428                 {
2429                         match_y[i] = conf[23+i];
2430                         match_x[i] = conf[25+i];
2431                         ignore_y[i] = conf[27+i];
2432                         ignore_x[i] = conf[29+i];
2433                 }
2434                 for(i=0;i<64;i++)
2435                 {
2436                         coordinate_correct_coe_x[i] = conf[31+i];
2437                         coordinate_correct_coe_y[i] = conf[95+i];
2438                 }
2439                 for(i=0;i<4;i++)
2440                         edge_cut[i] = conf[159+i];
2441                 for(i=0;i<32;i++)
2442                         stretch_array[i] = conf[163+i];
2443                 for(i=0;i<16;i++)
2444                         shake_all_array[i] = conf[195+i];
2445                 reset_mask_dis = conf[213];
2446                 reset_mask_type = conf[214];
2447                 key_map_able = conf[217];
2448                 for(i=0;i<8*3;i++)
2449                         key_range_array[i] = conf[218+i];
2450                 filter_able = conf[242];
2451                 for(i=0;i<4;i++)
2452                         filter_coe[i] = conf[243+i];
2453                 for(i=0;i<4;i++)
2454                         multi_x_array[i] = conf[247+i];
2455                 for(i=0;i<4;i++)
2456                         multi_y_array[i] = conf[251+i];
2457                 diagonal = conf[255];
2458                 for(i=0;i<4;i++)
2459                   for(j=0;j<64;j++)
2460                           multi_group[i][j] = conf[256+64*i+j];
2461                 for(i=0;i<4;i++)
2462                 {
2463                   for(j=0;j<8;j++)
2464                   {
2465                           ps_coe[i][j] = conf[256 + 64*3 + 8*i+j];
2466                           pr_coe[i][j] = conf[256 + 64*3 + 8*i+j + 32];
2467                         }
2468                 }
2469                 //-----------------------
2470                 near_set[0] = 0;
2471                 near_set[1] = 0;
2472         }
2473         else
2474         {
2475                 global_flag.all = conf[0x10];
2476                 point_num_max = conf[0x11];
2477                 drv_num = conf[0x12]&0xffff;
2478                 sen_num = conf[0x12]>>16;
2479                 drv_num_nokey = conf[0x13]&0xffff;
2480                 sen_num_nokey = conf[0x13]>>16;
2481                 screen_x_max = conf[0x14]&0xffff;
2482                 screen_y_max = conf[0x14]>>16;
2483                 average = conf[0x15];
2484                 reset_mask_dis = conf[0x16];
2485                 reset_mask_type = conf[0x17];
2486                 point_repeat[0] = conf[0x18]>>16;
2487                 point_repeat[1] = conf[0x18]&0xffff;
2488                 //conf[0x19~0x1f]
2489                 near_set[0] = conf[0x19]>>16;
2490                 near_set[1] = conf[0x19]&0xffff;
2491                 diagonal = conf[0x1a];
2492                 //-------------------------
2493                 
2494                 id_first_coe = conf[0x20];
2495                 id_speed_coe = conf[0x21];
2496                 id_static_coe = conf[0x22];
2497                 match_y[0] = conf[0x23]>>16;
2498                 match_y[1] = conf[0x23]&0xffff;
2499                 match_x[0] = conf[0x24]>>16;
2500                 match_x[1] = conf[0x24]&0xffff;
2501                 ignore_y[0] = conf[0x25]>>16;
2502                 ignore_y[1] = conf[0x25]&0xffff;
2503                 ignore_x[0] = conf[0x26]>>16;
2504                 ignore_x[1] = conf[0x26]&0xffff;
2505                 edge_cut[0] = (conf[0x27]>>24) & 0xff;
2506                 edge_cut[1] = (conf[0x27]>>16) & 0xff;
2507                 edge_cut[2] = (conf[0x27]>> 8) & 0xff;
2508                 edge_cut[3] = (conf[0x27]>> 0) & 0xff;
2509                 report_delay = conf[0x28];
2510                 shake_min = conf[0x29];
2511                 for(i=0;i<16;i++)
2512                 {
2513                         stretch_array[i*2+0] = conf[0x2a+i] & 0xffff;
2514                         stretch_array[i*2+1] = conf[0x2a+i] >> 16;
2515                 }
2516                 for(i=0;i<8;i++)
2517                 {
2518                         shake_all_array[i*2+0] = conf[0x3a+i] & 0xffff;
2519                         shake_all_array[i*2+1] = conf[0x3a+i] >> 16;
2520                 }
2521                 report_ahead                    = conf[0x42];
2522 //              key_dead_time                   = conf[0x43];
2523 //              point_dead_time                 = conf[0x44];
2524 //              point_dead_time2                = conf[0x45];
2525 //              point_dead_distance             = conf[0x46];
2526 //              point_dead_distance2    = conf[0x47];
2527                 edge_first                              = conf[0x48];
2528                 edge_first_coe                  = conf[0x49];
2529                 //goto_test
2530                 
2531                 key_map_able = conf[0x60];
2532                 for(i=0;i<8*3;i++)
2533                         key_range_array[i] = conf[0x61+i];
2534                 
2535                 coordinate_correct_able = conf[0x100];
2536                 for(i=0;i<4;i++)
2537                 {
2538                         multi_x_array[i] = conf[0x101+i];       
2539                         multi_y_array[i] = conf[0x105+i];
2540                 }
2541                 for(i=0;i<64;i++)
2542                 {
2543                         coordinate_correct_coe_x[i] = (conf[0x109+i/4]>>(i%4*8)) & 0xff;
2544                         coordinate_correct_coe_y[i] = (conf[0x109+64/4+i/4]>>(i%4*8)) & 0xff;
2545                 }       
2546                 for(i=0;i<4;i++)
2547                 {
2548                   for(j=0;j<64;j++)
2549                           multi_group[i][j] = (conf[0x109+64/4*2+(64*i+j)/4]>>((64*i+j)%4*8)) & 0xff;
2550                 }
2551
2552                 filter_able = conf[0x180];
2553                 for(i=0;i<4;i++)
2554                         filter_coe[i] = conf[0x181+i];
2555                 for(i=0;i<4;i++)
2556                         median_dis[i] = (unsigned char)conf[0x185+i];
2557                 for(i=0;i<4;i++)
2558                 {
2559                     for(j=0;j<8;j++)
2560                     {
2561                             ps_coe[i][j] = conf[0x189 + 8*i+j];
2562                             pr_coe[i][j] = conf[0x189 + 8*i+j + 32];
2563                     }
2564                 }
2565 #ifdef GESTURE_LICH
2566                 GestureSet(&conf[0x189 + 64]);
2567 #endif
2568         }
2569         //---------------------------------------------
2570         if(average == 0)
2571                 average = 4;
2572         for(i=0;i<8;i++)
2573         {
2574                 if(shake_all_array[i*2] & 0x8000)
2575                         shake_all_array[i*2] = shake_all_array[i*2] & ~0x8000;
2576                 else
2577                         shake_all_array[i*2] = Sqrt(shake_all_array[i*2]);
2578         }
2579         for(i=0;i<2;i++)
2580         {
2581                 if(match_x[i] & 0x8000)
2582                         match_x[i] |= 0xffff0000;
2583                 if(match_y[i] & 0x8000)
2584                         match_y[i] |= 0xffff0000;
2585                 if(ignore_x[i] & 0x8000)
2586                         ignore_x[i] |= 0xffff0000;
2587                 if(ignore_y[i] & 0x8000)
2588                         ignore_y[i] |= 0xffff0000;
2589         }
2590         for(i=0;i<CONFIG_LENGTH;i++)
2591                 config_static[i] = 0;
2592 }
2593 //EXPORT_SYMBOL(gsl_DataInit);
2594
2595 unsigned int gsl_version_id(void)
2596 {
2597         return GSL_VERSION;
2598 }
2599 //EXPORT_SYMBOL(gsl_version_id);
2600
2601 unsigned int gsl_mask_tiaoping(void)
2602 {
2603         return reset_mask_send;
2604 }
2605 //EXPORT_SYMBOL(gsl_mask_tiaoping);
2606
2607
2608 static void GetFlag(void)
2609 {
2610         int i = 0;
2611         int num_save;
2612         if(((point_num & 0x100)!=0) || 
2613                 ((point_num & 0x200) != 0 && 
2614                 global_state.other.reset == 1))
2615         {
2616                 gsl_id_reg_init(0);
2617         }
2618         if((point_num & 0x300) == 0)
2619         {
2620                 global_state.other.reset = 1;
2621         }
2622         if(point_num & 0x400)
2623                 global_state.other.only = 1;
2624         else
2625                 global_state.other.only = 0;
2626         if(point_num & 0x2000)
2627                 global_state.other.interpolation = 0xf;
2628         else if (global_state.other.interpolation)
2629                 global_state.other.interpolation--;
2630         if(point_num & 0x4000)
2631                 global_state.other.ex = 1;
2632         else
2633                 global_state.other.ex = 0;
2634         inte_count ++;  
2635         csensor_count = ((unsigned int)point_num)>>16;
2636         num_save = point_num & 0xff;
2637         if(num_save > POINT_MAX)
2638                 num_save = POINT_MAX;
2639         for(i=0;i<POINT_MAX;i++)
2640         {
2641                 if(i >= num_save)
2642                         point_now[i].all = 0;
2643         }
2644         point_num = (point_num & (~0xff)) + num_save;
2645 }
2646
2647 void gsl_alg_id_main(struct gsl_touch_info *cinfo)
2648 {
2649         int i;
2650         point_num = cinfo->finger_num;
2651         for(i=0;i<POINT_MAX;i++)
2652         {
2653                 point_now[i].all = (cinfo->id[i]<<28) | 
2654                         (cinfo->x[i]<<16) | cinfo->y[i];
2655         }
2656         
2657         GetFlag();
2658         if(DataCheck() == 0)
2659         {
2660                 point_num = 0;
2661                 cinfo->finger_num = 0;  
2662                 return;
2663         }
2664         PressureSave();
2665         PointCoor();
2666         CoordinateCorrect();
2667         PointEdge();
2668         PointRepeat();
2669         GetPointNum(point_now);
2670         PointPointer();
2671         PointPredict();
2672         PointId();
2673         PointNewId();
2674         PointOrder();
2675         PointCross();
2676         GetPointNum(pp[0]);
2677         DoubleClick();
2678         prev_num = point_num;
2679         ResetMask();
2680         PointStretch();
2681         PointDiagonal();
2682         PointFilter();
2683         GetPointNum(pr[0]);
2684 #ifdef GESTURE_LICH
2685         GestureMain(&(pr[0][0].all),point_num); 
2686 #endif
2687         PointDelay();
2688         PointPressure();
2689         PointReport(cinfo);
2690 }
2691 //EXPORT_SYMBOL(gsl_alg_id_main);
2692
2693
2694 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2695 #ifdef GESTURE_LICH
2696
2697 int gsl_obtain_gesture(void)
2698 {
2699         return GestureDeal();
2700 }
2701 //EXPORT_SYMBOL(gsl_obtain_gesture);
2702
2703 static int GestureMain(unsigned int data_coor[],unsigned int num)
2704 {
2705         gesture_deal = FALSE;
2706         if(gesture_dis_min == 0)
2707                 return FALSE;
2708         if(num == 0)
2709         {
2710                 if(gesture_num == 0)
2711                         return FALSE;
2712                 if(gesture_num <= 8)
2713                 {
2714                         GestureInit();
2715                         return FALSE;
2716                 }
2717                 gesture_deal = GESTURE_ALL;
2718                 return TRUE;
2719         }
2720         else if(gesture_num < 0)
2721         {
2722                 return FALSE;
2723         }
2724         else if(num == 1 && data_coor[0] != 0)
2725         {
2726                 GesturePush((GESTURE_POINT_TYPE*) data_coor);
2727                 return FALSE;
2728         }
2729         else// if(num > 1)
2730         {
2731                 gesture_num = -1;
2732                 return FALSE;
2733         }
2734 //      return TRUE;
2735 }
2736
2737 static int GestureSqrt(int d)
2738 {
2739         int ret = 0;
2740         int i;
2741         for(i=14;i>=0;i--)
2742         {
2743                 if((ret + (0x1<<i))*(ret + (0x1<<i)) <= d)
2744                         ret |= (0x1<<i);
2745         }
2746         return ret;
2747 }
2748
2749 static int GestureDistance(GESTURE_POINT_TYPE* d1,GESTURE_POINT_TYPE* d2,int sqrt_able)
2750 {
2751         if(sqrt_able)
2752                 return GestureSqrt((d1->other.x - d2->other.x) * 
2753                         (d1->other.x - d2->other.x) + 
2754                         (d1->other.y - d2->other.y) * 
2755                         (d1->other.y - d2->other.y));
2756         else
2757                 return (d1->other.x - d2->other.x) * 
2758                         (d1->other.x - d2->other.x) + 
2759                         (d1->other.y - d2->other.y) * 
2760                         (d1->other.y - d2->other.y);
2761 }
2762
2763 static int GesturePush(GESTURE_POINT_TYPE* data)
2764 {
2765         if(gesture_num >= GESTURE_BUF_SIZE)
2766                 return FALSE;
2767         if(gesture_num == 0)
2768         {
2769                 gesture_buf[gesture_num ++].all = data->all & 0xffff0fff;
2770                 return TRUE;
2771         }
2772         if(GestureDistance(data,&gesture_buf[gesture_num-1],TRUE) <= gesture_dis_min)
2773                 return FALSE;
2774         gesture_buf[gesture_num ++].all = data->all & 0xffff0fff;
2775                 return TRUE;
2776 }
2777
2778 static void GestureInit(void)
2779 {
2780         gesture_num_last = gesture_num;
2781         gesture_num = 0;
2782         gesture_deal = FALSE;
2783         if(gesture_dis_min < 0 || gesture_dis_min > 64)
2784                 gesture_dis_min = 2;
2785 }
2786
2787 static int GestureStretch(void)
2788 {
2789         unsigned int x_max=0,x_min=0xffff,y_max=0,y_min=0xffff;
2790         int i;
2791 //      if(gesture_num <= GESTURE_SIZE_NUM/2)
2792 //              return FALSE;
2793         if(gesture_num >= GESTURE_BUF_SIZE)
2794                 return FALSE;
2795         for(i=0;i<gesture_num;i++)
2796         {
2797                 if(gesture_buf[i].other.x > x_max)
2798                         x_max = gesture_buf[i].other.x;
2799                 if (gesture_buf[i].other.x < x_min)
2800                         x_min = gesture_buf[i].other.x;
2801                 if (gesture_buf[i].other.y > y_max)
2802                         y_max = gesture_buf[i].other.y;
2803                 if (gesture_buf[i].other.y < y_min)
2804                         y_min = gesture_buf[i].other.y;
2805         }
2806         if(x_max < x_min+64*2 || y_max < y_min+64*3)
2807                 return FALSE;
2808         for(i=0;i<gesture_num;i++)
2809         {
2810                 gesture_buf[i].other.x = (gesture_buf[i].other.x - x_min) * 
2811                         GESTURE_SIZE_REFE / (x_max - x_min);
2812                 gesture_buf[i].other.y = (gesture_buf[i].other.y - y_min) * 
2813                         GESTURE_SIZE_REFE / (y_max - y_min);
2814         }
2815         return TRUE;
2816 }
2817
2818 static int GestureLength(void)
2819 {
2820         int i;
2821         int len = 0;
2822         for(i=1;i<gesture_num;i++)
2823         {
2824                 len += GestureDistance(&gesture_buf[i],&gesture_buf[i-1],TRUE);
2825         }
2826         return len;
2827 }
2828
2829 static void GestureStandard(void)
2830 {
2831         int i,n,t;
2832         int len_now = 0;
2833         int len_his = 0;
2834         int len_total = GestureLength();
2835         gesture_standard[0].all = gesture_buf[0].all&0x0fffffff;
2836         gesture_standard[GESTURE_SIZE_NUM - 1].all = 
2837                 gesture_buf[gesture_num -1].all&0x0fffffff;
2838         for(i=1,n=0;i<GESTURE_SIZE_NUM-1;i++)
2839         {
2840                 while(++n<gesture_num)
2841                 {
2842                         len_now = GestureDistance(&gesture_buf[n],&gesture_buf[n-1],TRUE);
2843                         len_his += len_now;
2844                         if(len_his*(GESTURE_SIZE_NUM-1) >= len_total*i)
2845                                 break;
2846                 }
2847                 if(n >= gesture_num || len_now == 0)
2848                         break;
2849                 gesture_standard[i].all = 0;
2850                 t = (int)gesture_buf[n - 1].other.x
2851                         + ((int)gesture_buf[n].other.x - (int)gesture_buf[n - 1].other.x)
2852                         * ((int)len_total*i/(GESTURE_SIZE_NUM-1) - (int)len_his + (int)len_now)
2853                         / (int)len_now
2854                         ;
2855                 if(t < 0)
2856                         t = 0;
2857                 gesture_standard[i].other.x = t;
2858                 t = (int)gesture_buf[n - 1].other.y
2859                         + ((int)gesture_buf[n].other.y - (int)gesture_buf[n - 1].other.y)
2860                         * ((int)len_total*i/(GESTURE_SIZE_NUM-1) - (int)len_his + (int)len_now)
2861                         / (int)len_now
2862                         ;
2863                 if(t < 0)
2864                         t = 0;
2865                 gesture_standard[i].other.y = t;
2866                 n--;
2867                 len_his -= len_now;
2868         }
2869 }
2870
2871 static int GestureModel(const GESTURE_MODEL_TYPE * model,int len,int threshold,int *out)
2872 {
2873         int offset[] = {-2,-1,0,1,2};
2874         int ret_offset;
2875         int i,j,k,n;
2876         int min,min_n;
2877         GESTURE_POINT_TYPE model_coor;
2878         if(model == NULL || threshold <= 0)
2879         {
2880                 *out = 0x7fffffff;
2881                 return 0x7fffffff;
2882         }
2883         min=0x7fffffff;
2884         min_n = 0;
2885         for(j=0;j<len;j++)
2886         {
2887                 for(k=0;k<sizeof(offset)/sizeof(offset[0]);k++)
2888                 {
2889                         n = 0;
2890                         ret_offset = 0;
2891                         for(i=0;i<GESTURE_SIZE_NUM;i++)
2892                         {
2893                                 if(i+offset[k] < 0 || i+offset[k] >= GESTURE_SIZE_NUM)
2894                                         continue;
2895                                 if((i&1)==0)
2896                                         model_coor.all = model[j].coor[i/2] & 0x00ff00ff;
2897                                 else
2898                                         model_coor.all = (model[j].coor[i/2]>>8) & 0x00ff00ff;
2899                                 ret_offset += GestureDistance(&gesture_standard[i+offset[k]],&model_coor,FALSE);
2900                                 n ++;
2901                         }
2902                         if(n == 0)
2903                                 continue;
2904                         ret_offset = ret_offset / n * model[j].coe / 0x10;//coe <0x3fff
2905                         if(ret_offset < min)
2906                         {
2907                                 min_n = j;
2908                                 min = ret_offset;
2909                         }
2910                 }
2911         }
2912         if(min < threshold)
2913                 *out = model[min_n].out;
2914         else
2915                 *out = 0x7fffffff;
2916         return min;
2917 }
2918
2919 static void ChangeXY(void)
2920 {
2921         int i;
2922         for(i=0;i<gesture_num && i<GESTURE_BUF_SIZE;i++)
2923                 gesture_buf[i].all = ((gesture_buf[i].all & 0xfff) << 16) + 
2924                 ((gesture_buf[i].all>>16) & 0xffff);
2925 }
2926
2927 static void GestureSet(unsigned int conf[])
2928 {
2929         if(conf == NULL)
2930                 return;
2931         //if(conf[0] >= 0 && conf[0] <= 64)
2932         if (conf[0] <= 64)
2933                 gesture_dis_min = conf[0];
2934         else
2935                 gesture_dis_min = 0;
2936         if(conf[1] != 0)
2937                 gesture_threshold[0] = conf[1];
2938         else
2939                 gesture_threshold[0] = 0xfff;
2940         gesture_threshold[1] = conf[2];
2941         x_scale = (conf[3]==0) ? 4 : conf[3];
2942         y_scale = (conf[4]==0) ? 4 : conf[4];
2943         if(conf[5] == 0)
2944         {
2945                 double_down = 2;
2946                 double_up = 30;
2947         }
2948         else
2949         {
2950                 double_down = conf[5] & 0xffff;
2951                 double_up = conf[5] >> 16;
2952         }
2953 }
2954
2955 static int GestureDeal(void)
2956 {
2957         int i;
2958         int gesture_out[2];
2959         int gesture_val[2];
2960
2961         //while(1)
2962         for (;;)
2963         {
2964                 gesture_last = double_click;
2965                 if(gesture_last)
2966                         break;
2967                 if(gesture_deal & GESTURE_XY)
2968                 {
2969                         gesture_deal &= ~GESTURE_XY;
2970                         ChangeXY();
2971                 }
2972                 if((gesture_deal & GESTURE_DEAL) == 0)
2973                         return FALSE;
2974                 gesture_deal &= ~GESTURE_DEAL;
2975                 gesture_last = GestureLRUD();
2976                 if(gesture_last)
2977                         break;
2978                 if(GestureStretch() == FALSE)
2979                         break;
2980                 GestureStandard();
2981                 gesture_val[0] =  GestureModel(model_default,
2982                         sizeof(model_default)/sizeof(model_default[0]),
2983                         gesture_threshold[0],&gesture_out[0]);
2984                 gesture_val[1] =  GestureModel(model_extern,
2985                         model_extern_len,gesture_threshold[1],&gesture_out[1]);
2986                 gesture_last = 0x7fffffff;
2987                 for(i=0;i<2;i++)
2988                 {
2989                         if(gesture_val[i] <= gesture_last)
2990                         {
2991 //                              gesture_value = gesture_val[i];
2992                                 gesture_last  = gesture_out[i];
2993                         }
2994                 }
2995                 break;
2996         }
2997         GestureInit();
2998         return gesture_last;
2999 }
3000
3001 void gsl_GestureExtern(const GESTURE_MODEL_TYPE *model,int len)
3002 {
3003         model_extern = model;
3004         model_extern_len = len;
3005 }
3006 //EXPORT_SYMBOL(gsl_GestureExtern);
3007
3008 static int GestureLRUD(void)
3009 {
3010         int x1=0,y1=0,x2=0,y2=0,i=0;
3011         int flag3=0;
3012         int middle_x;
3013         int middle_y;
3014         int min_scale=5;
3015 //      printk("flag3,gesture_deal=%x\n",gesture_deal);
3016         if(gesture_deal & GESTURE_XY)
3017         {
3018                 gesture_deal &= ~GESTURE_XY;
3019                 ChangeXY();
3020 //              printk("flag3,ChangeXY_GestureLRUD,gesture_deal=%x\n",gesture_deal);
3021         }
3022         if((gesture_deal & GESTURE_LRUD) == 0)
3023                 return FALSE;
3024         gesture_deal &= ~GESTURE_LRUD;
3025 //      int screen_x_max=0,screen_y_max=0;
3026         x1 = gesture_buf[0].other.x;//480
3027         y1 = gesture_buf[0].other.y;//800
3028         x2 = gesture_buf[gesture_num - 1].other.x;
3029         y2 = gesture_buf[gesture_num - 1].other.y;
3030 //      if(!x1&&!y1&&!x2&&!y2)
3031 //              return '6';
3032         middle_x =( x1 + x2)/2;
3033         middle_y = (y1 + y2)/2;
3034         for(i=1;i<gesture_num;i++)
3035         {
3036                 if (abs(gesture_buf[i].other.x - middle_x)<(int)sen_num_nokey * 64 / x_scale)//screen_y_max/8)//30
3037                         flag3|=0x1;
3038                 else
3039                         flag3|=0x2;
3040                 if (abs(gesture_buf[i].other.y - middle_y)<(int)drv_num_nokey * 64 / y_scale)//screen_x_max/8)//25
3041                         flag3|=(0x1<<4);
3042                 else
3043                         flag3|=(0x2<<4);
3044                 if ((int)gesture_buf[i].other.x - (int)gesture_buf[i - 1].other.x>min_scale)
3045                         flag3|=(0x1<<8);
3046                 else if ((int)gesture_buf[i].other.x - (int)gesture_buf[i - 1].other.x<-min_scale)
3047                         flag3|=(0x2<<8);
3048                 if ((int)gesture_buf[i].other.y - (int)gesture_buf[i - 1].other.y>min_scale)
3049                         flag3|=(0x1<<12);
3050                 else if ((int)gesture_buf[i].other.y - (int)gesture_buf[i - 1].other.y<-min_scale)
3051                         flag3|=(0x2<<12);
3052         }
3053 //      printk("flag3_____flag3=%x,x_scale=%d,y_scale=%d\n",flag3,x_scale,y_scale);
3054 //      if(flag3&&!point_num)
3055 //      {
3056 //              printk("flag3,x1=%d,y1=%d,x2=%d,y2=%d,screen_x_max=%d,screen_y_max=%d\n",x1,y1,x2,y2,screen_x_max,screen_y_max);
3057 //              printk("flag3====== %x,x1-x2=%d,x2-x1=%d,y1-y2=%d,y2-y1=%d\n",flag3,x1-x2,x2-x1,y1-y2,y2-y1);
3058 //      }
3059 //      if(!point_num)
3060 //      if(1)
3061         {
3062                 if((flag3==0x2031||flag3==0x2131||flag3==0x2231||flag3==0x2331))//&&(y2-y1>screen_x_max/3))
3063                         return 0xa1fc;//up(a1,fc)
3064                 else if((flag3==0x1031||flag3==0x1131||flag3==0x1231||flag3==0x1331))//&&(y1-y2>screen_x_max/3))
3065                         return 0xa1fd;//down
3066                 else if((flag3==0x213||flag3==0x1213||flag3==0x2213||flag3==0x2213))//&&(x2-x1>screen_y_max/3))
3067                         return 0xa1fb;//left
3068                 else if((flag3==0x113||flag3==0x1113||flag3==0x2113||flag3==0x3113))//&&(x1-x2>screen_y_max/3))
3069                         return 0xa1fa;//right
3070 //              if(abs(x2-x1)<64*4&&abs(y2-y1)<64*6)
3071 //                      return (int)'5';
3072         }
3073         return FALSE;
3074 }
3075
3076 unsigned int gsl_GestureBuffer(unsigned int **buf)
3077 {
3078         int i;
3079         if(gesture_num_last >= GESTURE_BUF_SIZE)
3080                 gesture_num_last = GESTURE_BUF_SIZE - 1;
3081         for(i=0;i<gesture_num_last;i++)
3082         {
3083                 gesture_buf[i].all = ScreenResolution((gsl_POINT_TYPE*)(&gesture_buf[i].all));
3084         }
3085         *buf = &(gesture_buf[0].all);
3086         return gesture_num_last;
3087 }
3088 //EXPORT_SYMBOL(gsl_GestureBuffer);
3089 #endif
3090 /*
3091 // The DLL must have an entry point, but it is never called.
3092 //
3093 NTSTATUS
3094 DriverEntry(
3095   IN PDRIVER_OBJECT DriverObject,
3096   IN PUNICODE_STRING RegistryPath
3097 )
3098 {
3099     return STATUS_SUCCESS;
3100 }*/