-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLCD_Touch.cpp
More file actions
971 lines (948 loc) · 40.6 KB
/
Copy pathLCD_Touch.cpp
File metadata and controls
971 lines (948 loc) · 40.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
/*****************************************************************************
* | File : LCD_Touch.c
* | Author : Waveshare team
* | Function : LCD Touch Pad Driver and Draw
* | Info :
* Image scanning
* Please use progressive scanning to generate images or fonts
*----------------
* | This version: V1.0
* | Date : 2017-08-16
* | Info : Basic version
*
******************************************************************************/
#include "LCD_Touch.h"
extern LCD_DIS sLCD_DIS;
extern uint8_t id;
static TP_DEV sTP_DEV;
static TP_DRAW sTP_Draw;
/*******************************************************************************
function:
Read the ADC of the channel
parameter:
Channel_Cmd : 0x90: Read channel Y +, select the ADC resolution is 12 bits, set to differential mode
0xd0: Read channel x +, select the ADC resolution is 12 bits, set to differential mode
*******************************************************************************/
static uint16_t TP_Read_ADC(uint8_t CMD)
{
uint16_t Data = 0;
//A cycle of at least 400ns.
gpio_init(TP_CS_PIN);
gpio_set_dir(TP_CS_PIN, GPIO_OUT);
gpio_put(TP_CS_PIN , 1);
gpio_put(TP_CS_PIN , 0);
// DEV_Digital_Write(TP_CS_PIN, 0);
SPI4W_Write_Byte(CMD);
// Driver_Delay_us(200);
sleep_us(200);
// dont write 0xff, it will block xpt2046
//Data = SPI4W_Read_Byte(0Xff);
Data = SPI4W_Read_Byte(0X00);
Data <<= 8;//7bit
Data |= SPI4W_Read_Byte(0X00);
//Data = SPI4W_Read_Byte(0Xff);
Data >>= 3;//5bit
sleep_us(10);
gpio_put(TP_CS_PIN , 1);
sleep_us(90);
// DEV_Digital_Write(TP_CS_PIN,1);
return Data;
}
/*******************************************************************************
function:
Read the 5th channel value and exclude the maximum and minimum returns the average
parameter:
Channel_Cmd : 0x90 :Read channel Y +
0xd0 :Read channel x +
*******************************************************************************/
#define READ_TIMES 5 //Number of readings
#define LOST_NUM 1 //Discard value
static uint16_t TP_Read_ADC_Average(uint8_t Channel_Cmd)
{
uint8_t i, j;
uint16_t Read_Buff[READ_TIMES];
uint16_t Read_Sum = 0, Read_Temp = 0;
//Read and save multiple samples
for(i = 0; i < READ_TIMES; i++){
Read_Buff[i] = TP_Read_ADC(Channel_Cmd);
// Driver_Delay_us(100);
}
//Sort from small to large
for (i = 0; i < READ_TIMES - 1; i ++) {
for (j = i + 1; j < READ_TIMES; j ++) {
if (Read_Buff[i] > Read_Buff[j]) {
Read_Temp = Read_Buff[i];
Read_Buff[i] = Read_Buff[j];
Read_Buff[j] = Read_Temp;
}
}
}
//Exclude the largest and the smallest
for (i = LOST_NUM; i < READ_TIMES - LOST_NUM; i ++)
Read_Sum += Read_Buff[i];
//Averaging
Read_Temp = Read_Sum / (READ_TIMES - 2 * LOST_NUM);
return Read_Temp;
}
/*******************************************************************************
function:
Read X channel and Y channel AD value
parameter:
Channel_Cmd : 0x90 :Read channel Y +
0xd0 :Read channel x +
*******************************************************************************/
void TP_Read_ADC_XY(uint16_t *pXCh_Adc, uint16_t *pYCh_Adc )
{
//LCD SPI speed = 3 MHz
spi_set_baudrate(SPI_PORT, 3000000);
*pXCh_Adc = (TP_Read_ADC_Average(0xD0) & 0x0fff);
*pYCh_Adc = (TP_Read_ADC_Average(0x90) & 0x0fff);
gpio_put(TP_CS_PIN , 1);
gpio_put(TP_CS_PIN , 0);
SPI4W_Write_Byte(0x81);
SPI4W_Write_Byte(0x80);
gpio_put(TP_CS_PIN , 1);
//LCD SPI speed in SPI_SPD
spi_set_baudrate(SPI_PORT, SPI_SPD);
}
/*******************************************************************************
function:
2 times to read the touch screen IC, and the two can not exceed the deviation,
ERR_RANGE, meet the conditions, then that the correct reading, otherwise the reading error.
parameter:
Channel_Cmd : pYCh_Adc = 0x90 :Read channel Y +
pXCh_Adc = 0xd0 :Read channel x +
*******************************************************************************/
#define ERR_RANGE 50 //tolerance scope
bool TP_Read_TwiceADC(uint16_t *pXCh_Adc, uint16_t *pYCh_Adc )
{
uint16_t XCh_Adc1, YCh_Adc1, XCh_Adc2, YCh_Adc2;
//Read the ADC values Read the ADC values twice
TP_Read_ADC_XY(&XCh_Adc1, &YCh_Adc1);
Driver_Delay_us(10);
TP_Read_ADC_XY(&XCh_Adc2, &YCh_Adc2);
Driver_Delay_us(10);
//The ADC error used twice is greater than ERR_RANGE to take the average
if( ((XCh_Adc2 <= XCh_Adc1 && XCh_Adc1 < XCh_Adc2 + ERR_RANGE) ||
(XCh_Adc1 <= XCh_Adc2 && XCh_Adc2 < XCh_Adc1 + ERR_RANGE))
&& ((YCh_Adc2 <= YCh_Adc1 && YCh_Adc1 < YCh_Adc2 + ERR_RANGE) ||
(YCh_Adc1 <= YCh_Adc2 && YCh_Adc2 < YCh_Adc1 + ERR_RANGE))) {
*pXCh_Adc = (XCh_Adc1 + XCh_Adc2) / 2;
*pYCh_Adc = (YCh_Adc1 + YCh_Adc2) / 2;
return true;
}
//The ADC error used twice is less than ERR_RANGE returns failed
return false;
}
/*******************************************************************************
function:
Calculation
parameter:
chCoordType:
1 : calibration
0 : relative position
*******************************************************************************/
static uint8_t TP_Scan(uint8_t chCoordType)
{
//In X, Y coordinate measurement, IRQ is disabled and output is low
if (!DEV_Digital_Read(TP_IRQ_PIN)) {//Press the button to press
//Read the physical coordinates
if (chCoordType) {
TP_Read_TwiceADC(&sTP_DEV.Xpoint, &sTP_DEV.Ypoint);
//Read the screen coordinates
} else
if (TP_Read_TwiceADC(&sTP_DEV.Xpoint, &sTP_DEV.Ypoint)) {
#ifdef LCD_2_8
if(LCD_2_8==id){
if (sTP_DEV.TP_Scan_Dir == R2L_D2U) { //Converts the result to screen coordinates
sTP_Draw.Xpoint = sTP_DEV.fXfac * sTP_DEV.Xpoint +
sTP_DEV.iXoff;
sTP_Draw.Ypoint = sTP_DEV.fYfac * sTP_DEV.Ypoint +
sTP_DEV.iYoff;
} else
if (sTP_DEV.TP_Scan_Dir == L2R_U2D) {
sTP_Draw.Xpoint = sLCD_DIS.LCD_Dis_Column -
sTP_DEV.fXfac * sTP_DEV.Xpoint -
sTP_DEV.iXoff;
sTP_Draw.Ypoint = sLCD_DIS.LCD_Dis_Page -
sTP_DEV.fYfac * sTP_DEV.Ypoint -
sTP_DEV.iYoff;
} else
if (sTP_DEV.TP_Scan_Dir == U2D_R2L) {
sTP_Draw.Xpoint = sTP_DEV.fXfac * sTP_DEV.Ypoint +
sTP_DEV.iXoff;
sTP_Draw.Ypoint = sTP_DEV.fYfac * sTP_DEV.Xpoint +
sTP_DEV.iYoff;
} else {
sTP_Draw.Xpoint = sLCD_DIS.LCD_Dis_Column -
sTP_DEV.fXfac * sTP_DEV.Ypoint -
sTP_DEV.iXoff;
sTP_Draw.Ypoint = sLCD_DIS.LCD_Dis_Page -
sTP_DEV.fYfac * sTP_DEV.Xpoint -
sTP_DEV.iYoff;
}
} else
#endif
{
//DEBUG("(Xad,Yad) = %d,%d\r\n",sTP_DEV.Xpoint,sTP_DEV.Ypoint);
if (sTP_DEV.TP_Scan_Dir == R2L_D2U) { //Converts the result to screen coordinates
sTP_Draw.Xpoint = sTP_DEV.fXfac * sTP_DEV.Xpoint +
sTP_DEV.iXoff;
sTP_Draw.Ypoint = sTP_DEV.fYfac * sTP_DEV.Ypoint +
sTP_DEV.iYoff;
} else
if (sTP_DEV.TP_Scan_Dir == L2R_U2D) {
sTP_Draw.Xpoint = sLCD_DIS.LCD_Dis_Column -
sTP_DEV.fXfac * sTP_DEV.Xpoint -
sTP_DEV.iXoff;
sTP_Draw.Ypoint = sLCD_DIS.LCD_Dis_Page -
sTP_DEV.fYfac * sTP_DEV.Ypoint -
sTP_DEV.iYoff;
} else
if (sTP_DEV.TP_Scan_Dir == U2D_R2L) {
sTP_Draw.Xpoint = sTP_DEV.fXfac * sTP_DEV.Ypoint +
sTP_DEV.iXoff;
sTP_Draw.Ypoint = sTP_DEV.fYfac * sTP_DEV.Xpoint +
sTP_DEV.iYoff;
} else {
sTP_Draw.Xpoint = sLCD_DIS.LCD_Dis_Column -
sTP_DEV.fXfac * sTP_DEV.Ypoint -
sTP_DEV.iXoff;
sTP_Draw.Ypoint = sLCD_DIS.LCD_Dis_Page -
sTP_DEV.fYfac * sTP_DEV.Xpoint -
sTP_DEV.iYoff;
}
// DEBUG("( x , y ) = %d,%d\r\n",sTP_Draw.Xpoint,sTP_Draw.Ypoint);
}
}
if (0 == (sTP_DEV.chStatus & TP_PRESS_DOWN)) { //Not being pressed
sTP_DEV.chStatus = TP_PRESS_DOWN | TP_PRESSED;
sTP_DEV.Xpoint0 = sTP_DEV.Xpoint;
sTP_DEV.Ypoint0 = sTP_DEV.Ypoint;
}
} else {
if (sTP_DEV.chStatus & TP_PRESS_DOWN) { //0x80
sTP_DEV.chStatus &= ~(1 << 7); //0x00
} else {
sTP_DEV.Xpoint0 = 0;
sTP_DEV.Ypoint0 = 0;
sTP_DEV.Xpoint = 0xffff;
sTP_DEV.Ypoint = 0xffff;
}
}
return (sTP_DEV.chStatus & TP_PRESS_DOWN);
}
/*******************************************************************************
function:
Draw Cross
parameter:
Xpoint : The x coordinate of the point
Ypoint : The y coordinate of the point
Color : Set color
*******************************************************************************/
static void TP_DrawCross(POINT Xpoint, POINT Ypoint, COLOR Color)
{
GUI_DrawLine(Xpoint - 12, Ypoint, Xpoint + 12, Ypoint,
Color, LINE_SOLID, DOT_PIXEL_1X1);
GUI_DrawLine(Xpoint, Ypoint - 12, Xpoint, Ypoint + 12,
Color, LINE_SOLID, DOT_PIXEL_1X1);
GUI_DrawPoint(Xpoint, Ypoint, Color, DOT_PIXEL_2X2 , DOT_FILL_AROUND);
GUI_DrawCircle(Xpoint, Ypoint, 6, Color, DRAW_EMPTY, DOT_PIXEL_1X1);
}
/*******************************************************************************
function:
The corresponding ADC value is displayed on the LC
parameter:
(Xpoint0 ,Xpoint0): The coordinates of the first point
(Xpoint1 ,Xpoint1): The coordinates of the second point
(Xpoint2 ,Xpoint2): The coordinates of the third point
(Xpoint3 ,Xpoint3): The coordinates of the fourth point
hwFac : Percentage of error
*******************************************************************************/
static void TP_ShowInfo(POINT Xpoint0, POINT Ypoint0,
POINT Xpoint1, POINT Ypoint1,
POINT Xpoint2, POINT Ypoint2,
POINT Xpoint3, POINT Ypoint3,
POINT hwFac)
{
#ifdef LCD_2_8
if(LCD_2_8==id) {
sFONT* TP_Font = &Font16;
LENGTH TP_Dx = TP_Font->Width;
GUI_DrawRectangle(40, 160, 240, 270, WHITE, DRAW_FULL, DOT_PIXEL_1X1);
GUI_DisString(40, 160, "x1", TP_Font, FONT_BACKGROUND, RED);
GUI_DisString(40 + 80, 160, "y1", TP_Font, FONT_BACKGROUND, RED);
GUI_DisString(40, 180, "x2", TP_Font, FONT_BACKGROUND, RED);
GUI_DisString(40 + 80, 180, "y2", TP_Font, FONT_BACKGROUND, RED);
GUI_DisString(40, 200, "x3", TP_Font, FONT_BACKGROUND, RED);
GUI_DisString(40 + 80, 200, "y3", TP_Font, FONT_BACKGROUND, RED);
GUI_DisString(40, 220, "x4", TP_Font, FONT_BACKGROUND, RED);
GUI_DisString(40 + 80, 220, "y4", TP_Font, FONT_BACKGROUND, RED);
GUI_DisString(40, 240, "fac is : ", TP_Font, FONT_BACKGROUND, RED);
GUI_DisNum(40 + 27, 160, Xpoint0, TP_Font, FONT_BACKGROUND, RED);
GUI_DisNum(40 + 27 + 80, 160, Ypoint0, TP_Font, FONT_BACKGROUND, RED);
GUI_DisNum(40 + 27, 180, Xpoint1, TP_Font, FONT_BACKGROUND, RED);
GUI_DisNum(40 + 27 + 80, 180, Ypoint1, TP_Font, FONT_BACKGROUND, RED);
GUI_DisNum(40 + 27, 200, Xpoint2, TP_Font, FONT_BACKGROUND, RED);
GUI_DisNum(40 + 27 + 80, 200, Ypoint2, TP_Font, FONT_BACKGROUND, RED);
GUI_DisNum(40 + 27, 220, Xpoint3, TP_Font, FONT_BACKGROUND, RED);
GUI_DisNum(40 + 27 + 80, 220, Ypoint3, TP_Font, FONT_BACKGROUND, RED);
GUI_DisNum(40 + 56 , 240, hwFac, TP_Font, FONT_BACKGROUND, RED);
} else
#endif
{
sFONT* TP_Font = &Font16;
LENGTH TP_Dx = TP_Font->Width;
GUI_DrawRectangle(40, 160, 250, 270, WHITE, DRAW_FULL, DOT_PIXEL_1X1);
GUI_DisString(40, 160, "x1", TP_Font, FONT_BACKGROUND, RED);
GUI_DisString(40 + 100, 160, "y1", TP_Font, FONT_BACKGROUND, RED);
GUI_DisString(40, 180, "x2", TP_Font, FONT_BACKGROUND, RED);
GUI_DisString(40 + 100, 180, "y2", TP_Font, FONT_BACKGROUND, RED);
GUI_DisString(40, 200, "x3", TP_Font, FONT_BACKGROUND, RED);
GUI_DisString(40 + 100, 200, "y3", TP_Font, FONT_BACKGROUND, RED);
GUI_DisString(40, 220, "x4", TP_Font, FONT_BACKGROUND, RED);
GUI_DisString(40 + 100, 220, "y4", TP_Font, FONT_BACKGROUND, RED);
GUI_DisString(40, 240, "fac is : ", TP_Font, FONT_BACKGROUND, RED);
GUI_DisNum(40 + 3 * TP_Dx, 160, Xpoint0, TP_Font, FONT_BACKGROUND, RED);
GUI_DisNum(40 + 3 * TP_Dx + 100, 160, Ypoint0, TP_Font, FONT_BACKGROUND, RED);
GUI_DisNum(40 + 3 * TP_Dx, 180, Xpoint1, TP_Font, FONT_BACKGROUND, RED);
GUI_DisNum(40 + 3 * TP_Dx + 100, 180, Ypoint1, TP_Font, FONT_BACKGROUND, RED);
GUI_DisNum(40 + 3 * TP_Dx, 200, Xpoint2, TP_Font, FONT_BACKGROUND, RED);
GUI_DisNum(40 + 3 * TP_Dx + 100, 200, Ypoint2, TP_Font, FONT_BACKGROUND, RED);
GUI_DisNum(40 + 3 * TP_Dx, 220, Xpoint3, TP_Font, FONT_BACKGROUND, RED);
GUI_DisNum(40 + 3 * TP_Dx + 100, 220, Ypoint3, TP_Font, FONT_BACKGROUND, RED);
GUI_DisNum(40 + 10 * TP_Dx , 240, hwFac, TP_Font, FONT_BACKGROUND, RED);
}
}
/*******************************************************************************
function:
Touch screen adjust
*******************************************************************************/
void TP_Adjust(void)
{
uint8_t cnt = 0;
uint16_t XYpoint_Arr[4][2];
uint32_t Dx, Dy;
uint16_t Sqrt1, Sqrt2;
float Dsqrt;
LCD_Clear(LCD_BACKGROUND);
GUI_DisString(0, 40, "Please use the stylus click the cross"\
"on the screen. The cross will always move until"\
"the screen adjustment is completed.",
&Font16, FONT_BACKGROUND, RED);
uint8_t Mar_Val = 12;
TP_DrawCross(Mar_Val, Mar_Val, RED);
sTP_DEV.chStatus = 0;
sTP_DEV.fXfac = 0;
while (1) {
TP_Scan(1);
if ((sTP_DEV.chStatus & 0xC0) == TP_PRESSED) {
sTP_DEV.chStatus &= ~(1 << 6);
XYpoint_Arr[cnt][0] = sTP_DEV.Xpoint;
XYpoint_Arr[cnt][1] = sTP_DEV.Ypoint;
// printf("X%d,Y%d = %d,%d\r\n",cnt,cnt,XYpoint_Arr[cnt][0],XYpoint_Arr[cnt][1]);
cnt ++;
Driver_Delay_ms(200);
switch(cnt) {
case 1:
//DEBUG("not touch TP_IRQ 2 = %d\r\n", GET_TP_IRQ);
TP_DrawCross(Mar_Val, Mar_Val, WHITE);
TP_DrawCross(sLCD_DIS.LCD_Dis_Column - Mar_Val, Mar_Val, RED);
Driver_Delay_ms(200);
break;
case 2:
//DEBUG("not touch TP_IRQ 3 = %d\r\n", GET_TP_IRQ);
TP_DrawCross(sLCD_DIS.LCD_Dis_Column - Mar_Val, Mar_Val, WHITE);
TP_DrawCross(Mar_Val, sLCD_DIS.LCD_Dis_Page - Mar_Val, RED);
Driver_Delay_ms(200);
break;
case 3:
//DEBUG("not touch TP_IRQ 4 = %d\r\n", GET_TP_IRQ);
TP_DrawCross(Mar_Val, sLCD_DIS.LCD_Dis_Page - Mar_Val, WHITE);
TP_DrawCross(sLCD_DIS.LCD_Dis_Column - Mar_Val,
sLCD_DIS.LCD_Dis_Page - Mar_Val, RED);
Driver_Delay_ms(200);
break;
case 4:
// 1.Compare the X direction
Dx = abs((int16_t)(XYpoint_Arr[0][0] - XYpoint_Arr[1][0]));//x1 - x2
Dy = abs((int16_t)(XYpoint_Arr[0][1] - XYpoint_Arr[1][1]));//y1 - y2
Dx *= Dx;
Dy *= Dy;
Sqrt1 = sqrt(Dx + Dy);
Dx = abs((int16_t)(XYpoint_Arr[2][0] - XYpoint_Arr[3][0]));//x3 - x4
Dy = abs((int16_t)(XYpoint_Arr[2][1] - XYpoint_Arr[3][1]));//y3 - y4
Dx *= Dx;
Dy *= Dy;
Sqrt2 = sqrt(Dx + Dy);
Dsqrt = (float)Sqrt1 / Sqrt2;
if(Dsqrt < 0.95 || Dsqrt > 1.05 || Sqrt1 == 0 || Sqrt2 == 0) {
//DEBUG("Adjust X direction \r\n");
cnt = 0;
TP_ShowInfo(XYpoint_Arr[0][0], XYpoint_Arr[0][1],
XYpoint_Arr[1][0], XYpoint_Arr[1][1],
XYpoint_Arr[2][0], XYpoint_Arr[2][1],
XYpoint_Arr[3][0], XYpoint_Arr[3][1],
Dsqrt * 100);
// Driver_Delay_ms(1000);
TP_DrawCross(sLCD_DIS.LCD_Dis_Column - Mar_Val,
sLCD_DIS.LCD_Dis_Page - Mar_Val, WHITE);
TP_DrawCross(Mar_Val, Mar_Val, RED);
continue;
}
// 2.Compare the Y direction
Dx = abs((int16_t)(XYpoint_Arr[0][0] - XYpoint_Arr[2][0]));//x1 - x3
Dy = abs((int16_t)(XYpoint_Arr[0][1] - XYpoint_Arr[2][1]));//y1 - y3
Dx *= Dx;
Dy *= Dy;
Sqrt1 = sqrt(Dx + Dy);
Dx = abs((int16_t)(XYpoint_Arr[1][0] - XYpoint_Arr[3][0]));//x2 - x4
Dy = abs((int16_t)(XYpoint_Arr[1][1] - XYpoint_Arr[3][1]));//y2 - y4
Dx *= Dx;
Dy *= Dy;
Sqrt2 = sqrt(Dx + Dy);//
Dsqrt = (float)Sqrt1 / Sqrt2;
if (Dsqrt < 0.95 || Dsqrt > 1.05) {
//DEBUG("Adjust Y direction \r\n");
cnt = 0;
TP_ShowInfo(XYpoint_Arr[0][0], XYpoint_Arr[0][1],
XYpoint_Arr[1][0], XYpoint_Arr[1][1],
XYpoint_Arr[2][0], XYpoint_Arr[2][1],
XYpoint_Arr[3][0], XYpoint_Arr[3][1],
Dsqrt * 100);
// Driver_Delay_ms(1000);
TP_DrawCross(sLCD_DIS.LCD_Dis_Column - Mar_Val,
sLCD_DIS.LCD_Dis_Page - Mar_Val, WHITE);
TP_DrawCross(Mar_Val, Mar_Val, RED);
continue;
}
//3.Compare diagonal
Dx = abs((int16_t)(XYpoint_Arr[1][0] - XYpoint_Arr[2][0]));//x1 - x3
Dy = abs((int16_t)(XYpoint_Arr[1][1] - XYpoint_Arr[2][1]));//y1 - y3
Dx *= Dx;
Dy *= Dy;
Sqrt1 = sqrt(Dx + Dy);//;
Dx = abs((int16_t)(XYpoint_Arr[0][0] - XYpoint_Arr[3][0]));//x2 - x4
Dy = abs((int16_t)(XYpoint_Arr[0][1] - XYpoint_Arr[3][1]));//y2 - y4
Dx *= Dx;
Dy *= Dy;
Sqrt2 = sqrt(Dx + Dy);//
Dsqrt = (float)Sqrt1 / Sqrt2;
if (Dsqrt < 0.95 || Dsqrt > 1.05) {
printf("Adjust diagonal direction\r\n");
cnt = 0;
TP_ShowInfo(XYpoint_Arr[0][0], XYpoint_Arr[0][1],
XYpoint_Arr[1][0], XYpoint_Arr[1][1],
XYpoint_Arr[2][0], XYpoint_Arr[2][1],
XYpoint_Arr[3][0], XYpoint_Arr[3][1],
Dsqrt * 100);
Driver_Delay_ms(1000);
TP_DrawCross(sLCD_DIS.LCD_Dis_Column - Mar_Val,
sLCD_DIS.LCD_Dis_Page - Mar_Val, WHITE);
TP_DrawCross(Mar_Val, Mar_Val, RED);
continue;
}
//4.Get the scale factor and offset
//Get the scanning direction of the touch screen
sTP_DEV.TP_Scan_Dir = sLCD_DIS.LCD_Scan_Dir;
sTP_DEV.fXfac = 0;
//According to the display direction to get
//the corresponding scale factor and offset
#ifdef LCD_2_8
if (LCD_2_8==id) {
if(sTP_DEV.TP_Scan_Dir == R2L_D2U) {
printf("R2L_D2U\r\n");
sTP_DEV.fXfac = (float)(sLCD_DIS.LCD_Dis_Column - 2 * Mar_Val) /
(int16_t)(XYpoint_Arr[1][0] -
XYpoint_Arr[0][0]);
sTP_DEV.fYfac = (float)(sLCD_DIS.LCD_Dis_Page - 2 * Mar_Val) /
(int16_t)(XYpoint_Arr[2][1] -
XYpoint_Arr[0][1]);
sTP_DEV.iXoff = (sLCD_DIS.LCD_Dis_Column -
sTP_DEV.fXfac * (XYpoint_Arr[1][0] +
XYpoint_Arr[0][0])) / 2;
sTP_DEV.iYoff = (sLCD_DIS.LCD_Dis_Page -
sTP_DEV.fYfac * (XYpoint_Arr[2][1] +
XYpoint_Arr[0][1])) / 2;
} else
if(sTP_DEV.TP_Scan_Dir == L2R_U2D) {
printf("L2R_U2D\r\n");
sTP_DEV.fXfac = (float)(sLCD_DIS.LCD_Dis_Column - 2 * Mar_Val) /
(int16_t)(XYpoint_Arr[0][0] -
XYpoint_Arr[1][0]);
sTP_DEV.fYfac = (float)(sLCD_DIS.LCD_Dis_Page - 2 * Mar_Val) /
(int16_t)(XYpoint_Arr[0][1] -
XYpoint_Arr[2][1]);
sTP_DEV.iXoff = (sLCD_DIS.LCD_Dis_Column -
sTP_DEV.fXfac * (XYpoint_Arr[0][0] +
XYpoint_Arr[1][0])) / 2;
sTP_DEV.iYoff = (sLCD_DIS.LCD_Dis_Page - sTP_DEV.fYfac *
(XYpoint_Arr[0][1] + XYpoint_Arr[2][1])) / 2;
} else
if (sTP_DEV.TP_Scan_Dir == U2D_R2L) {
printf("U2D_R2L\r\n");
sTP_DEV.fXfac = (float)(sLCD_DIS.LCD_Dis_Column - 2 * Mar_Val) /
(int16_t)(XYpoint_Arr[1][1] - XYpoint_Arr[0][1]);
sTP_DEV.fYfac = (float)(sLCD_DIS.LCD_Dis_Page - 2 * Mar_Val) /
(int16_t)(XYpoint_Arr[2][0] - XYpoint_Arr[0][0]);
sTP_DEV.iXoff = (sLCD_DIS.LCD_Dis_Column -
sTP_DEV.fXfac * (XYpoint_Arr[1][1] +
XYpoint_Arr[0][1])) / 2;
sTP_DEV.iYoff = (sLCD_DIS.LCD_Dis_Page -
sTP_DEV.fYfac * (XYpoint_Arr[2][0] +
XYpoint_Arr[0][0])) / 2;
} else {
printf("D2U_L2R\r\n");
sTP_DEV.fXfac = (float)(sLCD_DIS.LCD_Dis_Column - 2 * Mar_Val) /
(int16_t)(XYpoint_Arr[0][1] -
XYpoint_Arr[1][1]);
sTP_DEV.fYfac = (float)(sLCD_DIS.LCD_Dis_Page - 2 * Mar_Val) /
(int16_t)(XYpoint_Arr[0][0] -
XYpoint_Arr[2][0]);
sTP_DEV.iXoff = (sLCD_DIS.LCD_Dis_Column -
sTP_DEV.fXfac * (XYpoint_Arr[0][1] +
XYpoint_Arr[1][1])) / 2;
sTP_DEV.iYoff = (sLCD_DIS.LCD_Dis_Page -
sTP_DEV.fYfac * (XYpoint_Arr[0][0] +
XYpoint_Arr[2][0])) / 2;
}
} else
#endif
{
if(sTP_DEV.TP_Scan_Dir == R2L_D2U) {
printf("R2L_D2U\r\n");
sTP_DEV.fXfac = (float)(sLCD_DIS.LCD_Dis_Column - 2 * Mar_Val) /
(int16_t)(XYpoint_Arr[1][0] -XYpoint_Arr[0][0]);
sTP_DEV.fYfac = (float)(sLCD_DIS.LCD_Dis_Page - 2 * Mar_Val) /
(int16_t)(XYpoint_Arr[2][1]-XYpoint_Arr[0][1]);
sTP_DEV.iXoff = (sLCD_DIS.LCD_Dis_Column -
sTP_DEV.fXfac * (XYpoint_Arr[1][0] +
XYpoint_Arr[0][0])) / 2;
sTP_DEV.iYoff = (sLCD_DIS.LCD_Dis_Page -
sTP_DEV.fYfac * (XYpoint_Arr[2][1] +
XYpoint_Arr[0][1])) / 2;
} else
if(sTP_DEV.TP_Scan_Dir == L2R_U2D) {
printf("L2R_U2D\r\n");
sTP_DEV.fXfac = (float)(sLCD_DIS.LCD_Dis_Column - 2 * Mar_Val) /
(int16_t)(XYpoint_Arr[0][0] -
XYpoint_Arr[1][0]);
sTP_DEV.fYfac = (float)(sLCD_DIS.LCD_Dis_Page - 2 * Mar_Val) /
(int16_t)(XYpoint_Arr[0][1] -
XYpoint_Arr[2][1]);
sTP_DEV.iXoff = (sLCD_DIS.LCD_Dis_Column -
sTP_DEV.fXfac * (XYpoint_Arr[0][0] +
XYpoint_Arr[1][0])
) / 2;
sTP_DEV.iYoff = (sLCD_DIS.LCD_Dis_Page - sTP_DEV.fYfac *
(XYpoint_Arr[0][1] + XYpoint_Arr[2][1])) / 2;
} else
if (sTP_DEV.TP_Scan_Dir == U2D_R2L) {
printf("U2D_R2L\r\n");
sTP_DEV.fXfac = (float)(sLCD_DIS.LCD_Dis_Column - 2 * Mar_Val) /
(int16_t)(XYpoint_Arr[1][1] - XYpoint_Arr[0][1]);
sTP_DEV.fYfac = (float)(sLCD_DIS.LCD_Dis_Page - 2 * Mar_Val) /
(int16_t)(XYpoint_Arr[2][0] - XYpoint_Arr[0][0]);
sTP_DEV.iXoff = (sLCD_DIS.LCD_Dis_Column -
sTP_DEV.fXfac * (XYpoint_Arr[1][1] +
XYpoint_Arr[0][1])) / 2;
sTP_DEV.iYoff = (sLCD_DIS.LCD_Dis_Page -
sTP_DEV.fYfac * (XYpoint_Arr[2][0] +
XYpoint_Arr[0][0])) / 2;
} else {
printf("D2U_L2R\r\n");
sTP_DEV.fXfac = (float)(sLCD_DIS.LCD_Dis_Column - 2 * Mar_Val) /
(int16_t)(XYpoint_Arr[0][1] -
XYpoint_Arr[1][1]);
sTP_DEV.fYfac = (float)(sLCD_DIS.LCD_Dis_Page - 2 * Mar_Val) /
(int16_t)(XYpoint_Arr[0][0] -
XYpoint_Arr[2][0]);
sTP_DEV.iXoff = (sLCD_DIS.LCD_Dis_Column -
sTP_DEV.fXfac * (XYpoint_Arr[0][1] +
XYpoint_Arr[1][1])) / 2;
sTP_DEV.iYoff = (sLCD_DIS.LCD_Dis_Page -
sTP_DEV.fYfac * (XYpoint_Arr[0][0] +
XYpoint_Arr[2][0])) / 2;
}
}
printf("sTP_DEV.fXfac = %f \r\n", sTP_DEV.fXfac);
printf("sTP_DEV.fYfac = %f \r\n", sTP_DEV.fYfac);
printf("sTP_DEV.iXoff = %d \r\n", sTP_DEV.iXoff);
printf("sTP_DEV.iYoff = %d \r\n", sTP_DEV.iYoff);
//6.Calibration is successful
printf("Adjust OK\r\n");
LCD_Clear(LCD_BACKGROUND);
GUI_DisString(20, 110, "Touch Screen Adjust OK!",
&Font16 , FONT_BACKGROUND , RED);
Driver_Delay_ms(1000);
LCD_Clear(LCD_BACKGROUND);
return;
//Exception handling,Reset Initial value
default :
cnt = 0;
TP_DrawCross(sLCD_DIS.LCD_Dis_Column - Mar_Val,
sLCD_DIS.LCD_Dis_Page - Mar_Val, WHITE);
TP_DrawCross(Mar_Val, Mar_Val, RED);
GUI_DisString(40, 26, "TP Need readjust!",
&Font16 , FONT_BACKGROUND , RED);
break;
}
}
}
}
/*******************************************************************************
function:
Use the default calibration factor
*******************************************************************************/
void TP_GetAdFac(void)
{
#ifdef LCD_2_8
if(LCD_2_8==id) {
if( sTP_DEV.TP_Scan_Dir == L2R_U2D) {
sTP_DEV.fXfac = 0.066626;
sTP_DEV.fYfac = 0.089779 ;
sTP_DEV.iXoff = -20 ;
sTP_DEV.iYoff = -34 ;
}else if(sTP_DEV.TP_Scan_Dir == D2U_L2R)
{
sTP_DEV.fXfac = -0.089997 ;
sTP_DEV.fYfac = 0.067416 ;
sTP_DEV.iXoff = 350 ;
sTP_DEV.iYoff = -20 ;
} else
if( sTP_DEV.TP_Scan_Dir == R2L_D2U ) {
sTP_DEV.fXfac = 0.066339 ;
sTP_DEV.fYfac = 0.087059 ;
sTP_DEV.iXoff = -13 ;
sTP_DEV.iYoff = -26 ;
} else
if( sTP_DEV.TP_Scan_Dir == U2D_R2L ) {
sTP_DEV.fXfac = -0.089616 ;
sTP_DEV.fYfac = 0.063399 ;
sTP_DEV.iXoff = 350 ;
sTP_DEV.iYoff = -5 ;
} else {
LCD_Clear(LCD_BACKGROUND);
GUI_DisString(0, 60, "Does not support touch-screen \
calibration in this direction",
&Font16, FONT_BACKGROUND, RED);
}
} else
#endif
{
if( sTP_DEV.TP_Scan_Dir == D2U_L2R ) { //SCAN_DIR_DFT = D2U_L2R
sTP_DEV.fXfac = -0.132443 ;
sTP_DEV.fYfac = 0.089997 ;
sTP_DEV.iXoff = 516 ;
sTP_DEV.iYoff = -22 ;
} else
if( sTP_DEV.TP_Scan_Dir == L2R_U2D ) {
sTP_DEV.fXfac = 0.089697 ;
sTP_DEV.fYfac = 0.134792 ;
sTP_DEV.iXoff = -21 ;
sTP_DEV.iYoff = -39 ;
} else
if( sTP_DEV.TP_Scan_Dir == R2L_D2U ) {
sTP_DEV.fXfac = 0.089915 ;
sTP_DEV.fYfac = 0.133178 ;
sTP_DEV.iXoff = -22 ;
sTP_DEV.iYoff = -38 ;
} else
if( sTP_DEV.TP_Scan_Dir == U2D_R2L ) {
sTP_DEV.fXfac = -0.132906 ;
sTP_DEV.fYfac = 0.087964 ;
sTP_DEV.iXoff = 517 ;
sTP_DEV.iYoff = -20 ;
} else {
LCD_Clear(LCD_BACKGROUND);
GUI_DisString(0, 60, "Does not support touch-screen \
calibration in this direction",
&Font16, FONT_BACKGROUND, RED);
}
}
}
/*******************************************************************************
function:
Paint the Delete key and paint color choose area
*******************************************************************************/
void TP_Dialog(LCD_SCAN_DIR LCD_ScanDir)
{
LCD_Clear(LCD_BACKGROUND);
LCD_SetGramScanWay(LCD_ScanDir);
#ifdef LCD_2_8
if(LCD_2_8==id){
if(sLCD_DIS.LCD_Dis_Column > sLCD_DIS.LCD_Dis_Page) {
//Clear screen
GUI_DisString(sLCD_DIS.LCD_Dis_Column - 60, 0,
"CLEAR", &Font16, RED, BLUE);
//adjustment
GUI_DisString(sLCD_DIS.LCD_Dis_Column - 120, 0,
"AD", &Font16, RED, BLUE);
//choose the color
GUI_DrawRectangle(sLCD_DIS.LCD_Dis_Column - 30, 20,
sLCD_DIS.LCD_Dis_Column, 50,
BLUE, DRAW_FULL, DOT_PIXEL_1X1);
GUI_DrawRectangle(sLCD_DIS.LCD_Dis_Column - 30, 60,
sLCD_DIS.LCD_Dis_Column, 90,
GREEN, DRAW_FULL, DOT_PIXEL_1X1);
GUI_DrawRectangle(sLCD_DIS.LCD_Dis_Column - 30, 100,
sLCD_DIS.LCD_Dis_Column, 130,
RED, DRAW_FULL, DOT_PIXEL_1X1);
GUI_DrawRectangle(sLCD_DIS.LCD_Dis_Column - 30, 140,
sLCD_DIS.LCD_Dis_Column, 170,
YELLOW, DRAW_FULL, DOT_PIXEL_1X1);
GUI_DrawRectangle(sLCD_DIS.LCD_Dis_Column - 30, 180,
sLCD_DIS.LCD_Dis_Column, 210,
BLACK, DRAW_FULL, DOT_PIXEL_1X1);
} else {
GUI_DisString(sLCD_DIS.LCD_Dis_Column - 60, 0,
"CLEAR", &Font16, RED, BLUE);
GUI_DisString(sLCD_DIS.LCD_Dis_Column - 120, 0,
"AD", &Font16, RED, BLUE);
GUI_DrawRectangle(0, 0, 15, 15, BLUE, DRAW_FULL, DOT_PIXEL_1X1);
GUI_DrawRectangle(20, 0, 35, 15, GREEN, DRAW_FULL, DOT_PIXEL_1X1);
GUI_DrawRectangle(40, 0, 55, 15, RED, DRAW_FULL, DOT_PIXEL_1X1);
GUI_DrawRectangle(60, 0, 75, 15, YELLOW, DRAW_FULL, DOT_PIXEL_1X1);
GUI_DrawRectangle(80, 0, 95, 15, BLACK, DRAW_FULL, DOT_PIXEL_1X1);
}
} else
#endif
{
//Horizontal screen display
if(sLCD_DIS.LCD_Dis_Column > sLCD_DIS.LCD_Dis_Page) {
//Clear screen
GUI_DisString(sLCD_DIS.LCD_Dis_Column - 60, 0,
"CLEAR", &Font16, RED, BLUE);
//adjustment
GUI_DisString(sLCD_DIS.LCD_Dis_Column - 120, 0,
"AD", &Font16, RED, BLUE);
//choose the color
GUI_DrawRectangle(sLCD_DIS.LCD_Dis_Column - 50, 20,
sLCD_DIS.LCD_Dis_Column, 70,
BLUE, DRAW_FULL, DOT_PIXEL_1X1);
GUI_DrawRectangle(sLCD_DIS.LCD_Dis_Column - 50, 80,
sLCD_DIS.LCD_Dis_Column, 130,
GREEN, DRAW_FULL, DOT_PIXEL_1X1);
GUI_DrawRectangle(sLCD_DIS.LCD_Dis_Column - 50, 140,
sLCD_DIS.LCD_Dis_Column, 190,
RED, DRAW_FULL, DOT_PIXEL_1X1);
GUI_DrawRectangle(sLCD_DIS.LCD_Dis_Column - 50, 200,
sLCD_DIS.LCD_Dis_Column, 250,
YELLOW, DRAW_FULL, DOT_PIXEL_1X1);
GUI_DrawRectangle(sLCD_DIS.LCD_Dis_Column - 50, 260,
sLCD_DIS.LCD_Dis_Column, 310,
BLACK, DRAW_FULL, DOT_PIXEL_1X1);
} else { //Vertical screen display
GUI_DisString(sLCD_DIS.LCD_Dis_Column - 60, 0,
"CLEAR", &Font16, RED, BLUE);
GUI_DisString(sLCD_DIS.LCD_Dis_Column - 120, 0,
"AD", &Font24, RED, BLUE);
GUI_DrawRectangle(20, 20, 70, 70, BLUE, DRAW_FULL, DOT_PIXEL_1X1);
GUI_DrawRectangle(80, 20, 130, 70, GREEN, DRAW_FULL, DOT_PIXEL_1X1);
GUI_DrawRectangle(140, 20, 190, 70, RED, DRAW_FULL, DOT_PIXEL_1X1);
GUI_DrawRectangle(200, 20, 250, 70, YELLOW, DRAW_FULL, DOT_PIXEL_1X1);
GUI_DrawRectangle(260, 20, 310, 70, BLACK, DRAW_FULL, DOT_PIXEL_1X1);
}
}
}
/*******************************************************************************
function:
Draw Board
*******************************************************************************/
void TP_DrawBoard(LCD_SCAN_DIR LCD_ScanDir)
{
// sTP_DEV.chStatus &= ~(1 << 6);
TP_Scan(0);
if (sTP_DEV.chStatus & TP_PRESS_DOWN) { //Press the button
//Horizontal screen
if (sTP_Draw.Xpoint < sLCD_DIS.LCD_Dis_Column &&
//Determine whether the law is legal
sTP_Draw.Ypoint < sLCD_DIS.LCD_Dis_Page) {
// printf("x:%d y:%d\r\n",sTP_Draw.Xpoint,sTP_Draw.Ypoint);
#ifdef LCD_2_8
if(LCD_2_8 == id) {
if(sLCD_DIS.LCD_Dis_Column > sLCD_DIS.LCD_Dis_Page) {
if (sTP_Draw.Xpoint > (sLCD_DIS.LCD_Dis_Column - 60) &&
sTP_Draw.Ypoint < 16) {//Clear Board
TP_Dialog(LCD_ScanDir);
} else
if (sTP_Draw.Xpoint > (sLCD_DIS.LCD_Dis_Column - 120) &&
sTP_Draw.Xpoint < (sLCD_DIS.LCD_Dis_Column - 80) &&
sTP_Draw.Ypoint < 16) { //afresh adjustment
TP_Adjust();
sTP_Draw.Xpoint = 0;
sTP_Draw.Ypoint = 0;
TP_Dialog(LCD_ScanDir);
} else
if (sTP_Draw.Xpoint > 290 && sTP_Draw.Xpoint < 320 &&
sTP_Draw.Ypoint > 17 && sTP_Draw.Ypoint < 47) {
sTP_Draw.Color = BLUE;
} else
if (sTP_Draw.Xpoint > 290 && sTP_Draw.Xpoint < 320 &&
sTP_Draw.Ypoint > 57 && sTP_Draw.Ypoint < 87) {
sTP_Draw.Color = GREEN;
} else
if (sTP_Draw.Xpoint > 290 && sTP_Draw.Xpoint < 320 &&
sTP_Draw.Ypoint > 97 && sTP_Draw.Ypoint < 127) {
sTP_Draw.Color = RED;
} else
if (sTP_Draw.Xpoint > 290 && sTP_Draw.Xpoint < 320 &&
sTP_Draw.Ypoint > 137 && sTP_Draw.Ypoint < 167) {
sTP_Draw.Color = YELLOW;
} else
if (sTP_Draw.Xpoint > 290 && sTP_Draw.Xpoint < 320 &&
sTP_Draw.Ypoint > 177 && sTP_Draw.Ypoint < 207) {
sTP_Draw.Color = BLACK;
} else {
GUI_DrawPoint(sTP_Draw.Xpoint, sTP_Draw.Ypoint,
sTP_Draw.Color , DOT_PIXEL_2X2, DOT_FILL_RIGHTUP);
}
} else {
if (sTP_Draw.Xpoint > (sLCD_DIS.LCD_Dis_Column - 60) &&
sTP_Draw.Ypoint < 16) {//Clear Board
TP_Dialog(LCD_ScanDir);
} else
if (sTP_Draw.Xpoint > (sLCD_DIS.LCD_Dis_Column - 120) &&
sTP_Draw.Xpoint < (sLCD_DIS.LCD_Dis_Column - 80) &&
sTP_Draw.Ypoint < 16) { //afresh adjustment
TP_Adjust();
sTP_Draw.Xpoint = 81;
sTP_Draw.Ypoint = 10;
TP_Dialog(LCD_ScanDir);
} else
if (sTP_Draw.Xpoint > 0 && sTP_Draw.Xpoint < 15 &&
sTP_Draw.Ypoint > 0 && sTP_Draw.Ypoint < 15) {
sTP_Draw.Color = BLUE;
} else
if (sTP_Draw.Xpoint > 20 && sTP_Draw.Xpoint < 35 &&
sTP_Draw.Ypoint > 0 && sTP_Draw.Ypoint < 15) {
sTP_Draw.Color = GREEN;
} else
if (sTP_Draw.Xpoint > 40 && sTP_Draw.Xpoint < 55 &&
sTP_Draw.Ypoint > 0 && sTP_Draw.Ypoint < 15) {
sTP_Draw.Color = RED;
} else
if (sTP_Draw.Xpoint > 60 && sTP_Draw.Xpoint < 75 &&
sTP_Draw.Ypoint > 0 && sTP_Draw.Ypoint < 15) {
sTP_Draw.Color = YELLOW;
} else
if (sTP_Draw.Xpoint > 80 && sTP_Draw.Xpoint < 95 &&
sTP_Draw.Ypoint > 0 && sTP_Draw.Ypoint < 15) {
sTP_Draw.Color = BLACK;
} else {
GUI_DrawPoint(sTP_Draw.Xpoint, sTP_Draw.Ypoint,
sTP_Draw.Color , DOT_PIXEL_2X2, DOT_FILL_RIGHTUP);
}
}
} else
#endif
{
//Judgment is horizontal screen
if(sLCD_DIS.LCD_Dis_Column > sLCD_DIS.LCD_Dis_Page) {
// printf("horizontal x:%d,y:%d\n",sTP_Draw.Xpoint,sTP_Draw.Ypoint);
if (sTP_Draw.Xpoint > (sLCD_DIS.LCD_Dis_Column - 60) &&
sTP_Draw.Ypoint < 16) { //Clear Board
TP_Dialog(LCD_ScanDir);
} else
if (sTP_Draw.Xpoint > (sLCD_DIS.LCD_Dis_Column - 120) &&
sTP_Draw.Xpoint < (sLCD_DIS.LCD_Dis_Column - 80) &&
sTP_Draw.Ypoint < 24) { //afresh adjustment
TP_Adjust();
sTP_Draw.Xpoint = sLCD_DIS.LCD_Dis_Column - 49;
sTP_Draw.Ypoint = 261;
TP_Dialog(LCD_ScanDir);
} else
if (sTP_Draw.Xpoint > (sLCD_DIS.LCD_Dis_Column - 50) &&
sTP_Draw.Xpoint < sLCD_DIS.LCD_Dis_Column &&
sTP_Draw.Ypoint > 20 &&
sTP_Draw.Ypoint < 70) {
sTP_Draw.Color = BLUE;
} else
if (sTP_Draw.Xpoint > (sLCD_DIS.LCD_Dis_Column - 50) &&
sTP_Draw.Xpoint < sLCD_DIS.LCD_Dis_Column &&
sTP_Draw.Ypoint > 80 &&
sTP_Draw.Ypoint < 130) {
sTP_Draw.Color = GREEN;
} else
if (sTP_Draw.Xpoint > (sLCD_DIS.LCD_Dis_Column - 50) &&
sTP_Draw.Xpoint < sLCD_DIS.LCD_Dis_Column &&
sTP_Draw.Ypoint > 140 &&
sTP_Draw.Ypoint < 190) {
sTP_Draw.Color = RED;
} else
if (sTP_Draw.Xpoint > (sLCD_DIS.LCD_Dis_Column - 50) &&
sTP_Draw.Xpoint < sLCD_DIS.LCD_Dis_Column &&
sTP_Draw.Ypoint > 200 && sTP_Draw.Ypoint < 250) {
sTP_Draw.Color = YELLOW;
} else
if (sTP_Draw.Xpoint > (sLCD_DIS.LCD_Dis_Column - 50) &&
sTP_Draw.Xpoint < sLCD_DIS.LCD_Dis_Column &&
sTP_Draw.Ypoint > 260 &&
sTP_Draw.Ypoint < 310) {
sTP_Draw.Color = BLACK;
} else {
GUI_DrawPoint(sTP_Draw.Xpoint, sTP_Draw.Ypoint,
sTP_Draw.Color , DOT_PIXEL_1X1, DOT_FILL_RIGHTUP);
GUI_DrawPoint(sTP_Draw.Xpoint + 1, sTP_Draw.Ypoint,
sTP_Draw.Color , DOT_PIXEL_1X1, DOT_FILL_RIGHTUP);
GUI_DrawPoint(sTP_Draw.Xpoint, sTP_Draw.Ypoint + 1,
sTP_Draw.Color , DOT_PIXEL_1X1, DOT_FILL_RIGHTUP);
GUI_DrawPoint(sTP_Draw.Xpoint + 1, sTP_Draw.Ypoint + 1,
sTP_Draw.Color , DOT_PIXEL_1X1, DOT_FILL_RIGHTUP);
GUI_DrawPoint(sTP_Draw.Xpoint, sTP_Draw.Ypoint,
sTP_Draw.Color , DOT_PIXEL_2X2, DOT_FILL_RIGHTUP);
}
//Vertical screen
} else {
// printf("Vertical x:%d,y:%d\n",sTP_Draw.Xpoint,sTP_Draw.Ypoint);
if (sTP_Draw.Xpoint > (sLCD_DIS.LCD_Dis_Column - 60) &&
sTP_Draw.Ypoint < 16) {//Clear Board
TP_Dialog(LCD_ScanDir);
} else
if(sTP_Draw.Xpoint > (sLCD_DIS.LCD_Dis_Column - 120) &&
sTP_Draw.Xpoint < (sLCD_DIS.LCD_Dis_Column - 80) &&
sTP_Draw.Ypoint < 24) { //afresh adjustment
TP_Adjust();
sTP_Draw.Xpoint = sLCD_DIS.LCD_Dis_Column - 49;
sTP_Draw.Ypoint = 261;
TP_Dialog(LCD_ScanDir);
} else
if(sTP_Draw.Xpoint > 20 && sTP_Draw.Xpoint < 70 &&
sTP_Draw.Ypoint > 20 && sTP_Draw.Ypoint < 70) {
sTP_Draw.Color = BLUE;
} else
if(sTP_Draw.Xpoint > 80 && sTP_Draw.Xpoint < 130 &&
sTP_Draw.Ypoint > 20 && sTP_Draw.Ypoint < 70) {
sTP_Draw.Color = GREEN;
} else
if(sTP_Draw.Xpoint > 140 && sTP_Draw.Xpoint < 190 &&
sTP_Draw.Ypoint > 20 && sTP_Draw.Ypoint < 70) {
sTP_Draw.Color = RED;
} else
if(sTP_Draw.Xpoint > 200 && sTP_Draw.Xpoint < 250 &&
sTP_Draw.Ypoint > 20 && sTP_Draw.Ypoint < 70) {
sTP_Draw.Color = YELLOW;
} else
if(sTP_Draw.Xpoint > 260 && sTP_Draw.Xpoint < 310 &&
sTP_Draw.Ypoint > 20 && sTP_Draw.Ypoint < 70) {
sTP_Draw.Color = BLACK;
} else {
GUI_DrawPoint(sTP_Draw.Xpoint, sTP_Draw.Ypoint,
sTP_Draw.Color , DOT_PIXEL_2X2,
DOT_FILL_RIGHTUP );
}
}
}
}
}
}
/*******************************************************************************
function:
Touch pad initialization
*******************************************************************************/
void TP_Init( LCD_SCAN_DIR Lcd_ScanDir )
{
DEV_Digital_Write(TP_CS_PIN, 1);
sTP_DEV.TP_Scan_Dir = Lcd_ScanDir;
TP_Read_ADC_XY(&sTP_DEV.Xpoint, &sTP_DEV.Ypoint);
}