/
Sample_app.ino
3603 lines (3161 loc) · 123 KB
/
Sample_app.ino
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
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
//this file contains the test application for FT801 plus board
#include "SPI.h"
#include "Wire.h"
#include "FT_NHD_43CTP_SHIELD.h"
#include "SampleApp.h"
#include "SampleAppRawdata.h"
#define VERTEX2F(x,y) ((1UL<<30)|(((x)&32767UL)<<15)|(((y)&32767UL)<<0))
#define VERTEX2II(x,y,handle,cell) ((2UL<<30)|(((x)&511UL)<<21)|(((y)&511UL)<<12)|(((handle)&31UL)<<7)|(((cell)&127UL)<<0))
#define BITMAP_SOURCE(addr) ((1UL<<24)|(((addr)&1048575UL)<<0))
#define CLEAR_COLOR_RGB(red,green,blue) ((2UL<<24)|(((red)&255UL)<<16)|(((green)&255UL)<<8)|(((blue)&255UL)<<0))
#define TAG(s) ((3UL<<24)|(((s)&255UL)<<0))
#define COLOR_RGB(red,green,blue) ((4UL<<24)|(((red)&255UL)<<16)|(((green)&255UL)<<8)|(((blue)&255UL)<<0))
#define BITMAP_HANDLE(handle) ((5UL<<24)|(((handle)&31UL)<<0))
#define CELL(cell) ((6UL<<24)|(((cell)&127UL)<<0))
#define BITMAP_LAYOUT(format,linestride,height) ((7UL<<24)|(((format)&31UL)<<19)|(((linestride)&1023UL)<<9)|(((height)&511UL)<<0))
#define BITMAP_SIZE(filter,wrapx,wrapy,width,height) ((8UL<<24)|(((filter)&1UL)<<20)|(((wrapx)&1UL)<<19)|(((wrapy)&1UL)<<18)|(((width)&511UL)<<9)|(((height)&511UL)<<0))
#define ALPHA_FUNC(func,ref) ((9UL<<24)|(((func)&7UL)<<8)|(((ref)&255UL)<<0))
#define STENCIL_FUNC(func,ref,mask) ((10UL<<24)|(((func)&7UL)<<16)|(((ref)&255UL)<<8)|(((mask)&255UL)<<0))
#define BLEND_FUNC(src,dst) ((11UL<<24)|(((src)&7UL)<<3)|(((dst)&7UL)<<0))
#define STENCIL_OP(sfail,spass) ((12UL<<24)|(((sfail)&7UL)<<3)|(((spass)&7UL)<<0))
#define POINT_SIZE(size) ((13UL<<24)|(((size)&8191UL)<<0))
#define LINE_WIDTH(width) ((14UL<<24)|(((width)&4095UL)<<0))
#define CLEAR_COLOR_A(alpha) ((15UL<<24)|(((alpha)&255UL)<<0))
#define COLOR_A(alpha) ((16UL<<24)|(((alpha)&255UL)<<0))
#define CLEAR_STENCIL(s) ((17UL<<24)|(((s)&255UL)<<0))
#define CLEAR_TAG(s) ((18UL<<24)|(((s)&255UL)<<0))
#define STENCIL_MASK(mask) ((19UL<<24)|(((mask)&255UL)<<0))
#define TAG_MASK(mask) ((20UL<<24)|(((mask)&1UL)<<0))
#define BITMAP_TRANSFORM_A(a) ((21UL<<24)|(((a)&131071UL)<<0))
#define BITMAP_TRANSFORM_B(b) ((22UL<<24)|(((b)&131071UL)<<0))
#define BITMAP_TRANSFORM_C(c) ((23UL<<24)|(((c)&16777215UL)<<0))
#define BITMAP_TRANSFORM_D(d) ((24UL<<24)|(((d)&131071UL)<<0))
#define BITMAP_TRANSFORM_E(e) ((25UL<<24)|(((e)&131071UL)<<0))
#define BITMAP_TRANSFORM_F(f) ((26UL<<24)|(((f)&16777215UL)<<0))
#define SCISSOR_XY(x,y) ((27UL<<24)|(((x)&511UL)<<9)|(((y)&511UL)<<0))
#define SCISSOR_SIZE(width,height) ((28UL<<24)|(((width)&1023UL)<<10)|(((height)&1023UL)<<0))
#define CALL(dest) ((29UL<<24)|(((dest)&65535UL)<<0))
#define JUMP(dest) ((30UL<<24)|(((dest)&65535UL)<<0))
#define BEGIN(prim) ((31UL<<24)|(((prim)&15UL)<<0))
#define COLOR_MASK(r,g,b,a) ((32UL<<24)|(((r)&1UL)<<3)|(((g)&1UL)<<2)|(((b)&1UL)<<1)|(((a)&1UL)<<0))
#define CLEAR(c,s,t) ((38UL<<24)|(((c)&1UL)<<2)|(((s)&1UL)<<1)|(((t)&1UL)<<0))
#define END() ((33UL<<24))
#define SAVE_CONTEXT() ((34UL<<24))
#define RESTORE_CONTEXT() ((35UL<<24))
#define RETURN() ((36UL<<24))
#define MACRO(m) ((37UL<<24)|(((m)&1UL)<<0))
#define DISPLAY() ((0UL<<24))
uint32_t coprostatus;
uint16_t FT_DispWidth=480,DisplayWidth = 480, FT_DispHeight=272,DisplayHeight = 272,FT_DispPCLK = 8;
/* Optimized implementation of sin and cos table - precision is 16 bit */
#ifdef SAMAPP_ENABLE_APIS_SET0
PROGMEM prog_uint16_t sintab[] = {
0, 402, 804, 1206, 1607, 2009, 2410, 2811, 3211, 3611, 4011, 4409, 4807, 5205, 5601, 5997, 6392,
6786, 7179, 7571, 7961, 8351, 8739, 9126, 9511, 9895, 10278, 10659, 11038, 11416, 11792, 12166, 12539,
12909, 13278, 13645, 14009, 14372, 14732, 15090, 15446, 15799, 16150, 16499, 16845, 17189, 17530, 17868,
18204, 18537, 18867, 19194, 19519, 19840, 20159, 20474, 20787, 21096, 21402, 21705, 22004, 22301, 22594,
22883, 23169, 23452, 23731, 24006, 24278, 24546, 24811, 25072, 25329, 25582, 25831, 26077, 26318, 26556, 26789,
27019, 27244, 27466, 27683, 27896, 28105, 28309, 28510, 28706, 28897, 29085, 29268, 29446, 29621, 29790, 29955,
30116, 30272, 30424, 30571, 30713, 30851, 30984, 31113, 31236, 31356, 31470, 31580, 31684, 31785, 31880, 31970,
32056, 32137, 32213, 32284, 32350, 32412, 32468, 32520, 32567, 32609, 32646, 32678, 32705, 32727, 32744, 32757,
32764, 32767, 32764};
int16_t SAMAPP_qsin(uint16_t a)
{
uint8_t f;
int16_t s0,s1;
if (a & 32768)
return -SAMAPP_qsin(a & 32767);
if (a & 16384)
a = 32768 - a;
f = a & 127;
s0 = pgm_read_word(sintab + (a >> 7));
s1 = pgm_read_word(sintab + (a >> 7) + 1);
return (s0 + ((int32_t)f * (s1 - s0) >> 7));
}
/* cos funtion */
int16_t SAMAPP_qcos(uint16_t a)
{
return (SAMAPP_qsin(a + 16384));
}
#endif
/* Global object for transport */
FT801IMPL_SPI FTImpl(FT_CS_PIN,FT_PDN_PIN,FT_INT_PIN);
/* api to test the init of transport layer */
int16_t TestApp_Bootup()
{
uint32_t chipid = 0;
FTImpl.Init(FT_DISPLAY_WQVGA_480x272);
delay(20);//safer side
chipid = FTImpl.Read32(FT_ROM_CHIPID);
/* identify the chip */
if(FT801_CHIPID != chipid)
{
Serial.print("Error in chip id read ");
Serial.println(chipid, HEX);
return 1;
}
return 0;
}
int32_t FTUtility_Dec2Ascii(char *pSrc,int32_t value)
{
int16_t Length;
char *pdst,charval;
int32_t CurrVal = value,tmpval,i;
char tmparray[16],idx = 0;
Length = strlen(pSrc);
pdst = pSrc + Length;
if(0 == value)
{
*pdst++ = '0';
*pdst++ = '\0';
return 0;
}
if(CurrVal < 0)
{
*pdst++ = '-';
CurrVal = - CurrVal;
}
/* insert the value */
while(CurrVal > 0){
tmpval = CurrVal;
CurrVal /= 10;
tmpval = tmpval - CurrVal*10;
charval = '0' + tmpval;
tmparray[idx++] = charval;
}
for(i=0;i<idx;i++)
{
*pdst++ = tmparray[idx - i - 1];
}
*pdst++ = '\0';
return 0;
}
int16_t SAMAPP_API_Screen(char *str)
{
FTImpl.StartTransferCmd();
FTImpl.WriteCmd(CMD_DLSTART);
FTImpl.WriteCmd(CLEAR(1,1,1));
FTImpl.WriteCmd(COLOR_RGB(0x80,0x80,0x00));
FTImpl.Cmd_Text((DisplayWidth/2), DisplayHeight/2, 31, FT_OPT_CENTER, str);
FTImpl.WriteCmd(DISPLAY());
FTImpl.WriteCmd(CMD_SWAP);
coprostatus = FTImpl.Finish();
FTImpl.EndTransferCmd();
delay(3000);
return coprostatus;
}
#ifdef SAMAPP_ENABLE_APIS_SET0
/*****************************************************************************/
/* Example code to display few points at various offsets with various colors */
/*****************************************************************************/
void SAMAPP_GPU_Points()
{
/* Construct DL of points */
FTImpl.DLStart();
FTImpl.Clear(1,1,1);
FTImpl.ColorRGB(128, 0, 0);
FTImpl.PointSize(5 * 16);
FTImpl.Begin(FT_POINTS);
FTImpl.Vertex2f((DisplayWidth/5) * 16, (DisplayHeight/2) * 16);
FTImpl.ColorRGB(0, 128, 0);
FTImpl.PointSize(15 * 16);
FTImpl.Vertex2f((DisplayWidth*2/5) * 16, (DisplayHeight/2) * 16);
FTImpl.ColorRGB(0, 0, 128);
FTImpl.PointSize(25 * 16);
FTImpl.Vertex2f((DisplayWidth*3/5) * 16, (DisplayHeight/2) * 16);
FTImpl.ColorRGB(128, 0, 128);
FTImpl.PointSize(35 * 16);
FTImpl.Vertex2f((DisplayWidth*4/5) * 16, (DisplayHeight/2) * 16);
FTImpl.DLEnd();
FTImpl.Finish();
delay(3000);
}
void SAMAPP_GPU_Lines()
{
int16_t LineHeight = 25;
FTImpl.DLStart();
FTImpl.Clear(1,1,1);
FTImpl.ColorRGB(128, 0, 0);
FTImpl.LineWidth(5 * 16);
FTImpl.Begin(FT_LINES);
FTImpl.Vertex2f((DisplayWidth/4) * 16, ((DisplayHeight-LineHeight)/2) * 16);
FTImpl.Vertex2f((DisplayWidth/4) * 16, ((DisplayHeight+LineHeight)/2) * 16);
FTImpl.ColorRGB(0, 128, 0);
FTImpl.LineWidth(10 * 16);
LineHeight = 40;
FTImpl.Vertex2f((DisplayWidth*2/4) * 16, ((DisplayHeight-LineHeight)/2) * 16);
FTImpl.Vertex2f((DisplayWidth*2/4) * 16, ((DisplayHeight+LineHeight)/2) * 16);
FTImpl.ColorRGB(128, 128, 0);
FTImpl.LineWidth(20 * 16);
LineHeight = 55;
FTImpl.Vertex2f((DisplayWidth*3/4) * 16, ((DisplayHeight-LineHeight)/2) * 16);
FTImpl.Vertex2f((DisplayWidth*3/4) * 16, ((DisplayHeight+LineHeight)/2) * 16);
FTImpl.DLEnd();
FTImpl.Finish();
delay(3000);
}
void SAMAPP_GPU_Rectangles()
{
int16_t RectWidth,RectHeight;
FTImpl.DLStart();
FTImpl.Clear(1,1,1);
FTImpl.ColorRGB(0, 0, 128);
FTImpl.LineWidth(1 * 16);
FTImpl.Begin(FT_RECTS);
RectWidth = 5;RectHeight = 25;
FTImpl.Vertex2f(((DisplayWidth/4)-(RectWidth/2)) * 16, ((DisplayHeight-RectHeight)/2) * 16);
FTImpl.Vertex2f(((DisplayWidth/4)+(RectWidth/2)) * 16, ((DisplayHeight+RectHeight)/2) * 16);
FTImpl.ColorRGB(0, 0, 128);
FTImpl.LineWidth(5* 16);
RectWidth = 10;RectHeight = 40;
FTImpl.Vertex2f(((DisplayWidth*2/4)-(RectWidth/2)) * 16, ((DisplayHeight-RectHeight)/2) * 16);
FTImpl.Vertex2f(((DisplayWidth*2/4)+(RectWidth/2)) * 16, ((DisplayHeight+RectHeight)/2) * 16);
FTImpl.ColorRGB(128, 128, 0);
FTImpl.LineWidth(10* 16);
RectWidth = 20;RectHeight = 55;
FTImpl.Vertex2f(((DisplayWidth*3/4)-(RectWidth/2)) * 16, ((DisplayHeight-RectHeight)/2) * 16);
FTImpl.Vertex2f(((DisplayWidth*3/4)+(RectWidth/2)) * 16, ((DisplayHeight+RectHeight)/2) * 16);
FTImpl.DLEnd();
FTImpl.Finish();
delay(3000);
}
/* Display lena face at different locations with various colors, -ve offsets, alpha blend etc */
void SAMAPP_GPU_Bitmap()
{
SAMAPP_Bitmap_header_t *p_bmhdr;
int16_t BMoffsetx,BMoffsety;
p_bmhdr = (SAMAPP_Bitmap_header_t *)&SAMAPP_Bitmap_RawData_Header[0];
/* Copy raw data into address 0 followed by generation of bitmap */
FTImpl.Writefromflash(FT_RAM_G,&SAMAPP_Bitmap_RawData[p_bmhdr->Arrayoffset], p_bmhdr->Stride*p_bmhdr->Height);
FTImpl.DLStart();
FTImpl.Clear(1,1,1);
FTImpl.ColorRGB(255,255,255);
FTImpl.BitmapSource(FT_RAM_G);
FTImpl.BitmapLayout(p_bmhdr->Format, p_bmhdr->Stride, p_bmhdr->Height);
FTImpl.BitmapSize(FT_NEAREST,FT_BORDER,FT_BORDER, p_bmhdr->Width, p_bmhdr->Height);
FTImpl.Begin(FT_BITMAPS); // start drawing bitmaps
BMoffsetx = ((FT_DispWidth/4) - (p_bmhdr->Width/2));
BMoffsety = ((FT_DispHeight/2) - (p_bmhdr->Height/2));
FTImpl.Vertex2ii(BMoffsetx, BMoffsety, 0, 0);
FTImpl.ColorRGB(255, 64, 64); // red at (200, 120)
BMoffsetx = ((FT_DispWidth*2/4) - (p_bmhdr->Width/2));
BMoffsety = ((FT_DispHeight/2) - (p_bmhdr->Height/2));
FTImpl.Vertex2ii(BMoffsetx, BMoffsety, 0, 0);
FTImpl.ColorRGB(64, 180, 64); // green at (216, 136)
BMoffsetx += (p_bmhdr->Width/2);
BMoffsety += (p_bmhdr->Height/2);
FTImpl.Vertex2ii(BMoffsetx, BMoffsety, 0, 0);
FTImpl.ColorRGB(255, 255, 64); // transparent yellow at (232, 152)
FTImpl.ColorA(150);
BMoffsetx += (p_bmhdr->Width/2);
BMoffsety += (p_bmhdr->Height/2);
FTImpl.Vertex2ii(BMoffsetx, BMoffsety, 0, 0);
FTImpl.ColorA(255);
FTImpl.ColorRGB(255,255,255);
FTImpl.Vertex2f(-10*16, -10*16);//for -ve coordinates use vertex2f instruction
FTImpl.End();
FTImpl.DLEnd();
FTImpl.Finish();
delay(3000);
}
#define FT_GPU_NUMCHAR_PERFONT (128)
#define FT_GPU_FONT_TABLE_SIZE (148)
typedef struct FT_Gpu_Fonts
{
/* All the values are in bytes */
/* Width of each character font from 0 to 127 */
uint8_t FontWidth[FT_GPU_NUMCHAR_PERFONT];
/* Bitmap format of font wrt bitmap formats supported by FT801 - L1, FT_L4, L8 */
uint32_t FontBitmapFormat;
/* Font line stride in FT801 ROM */
uint32_t FontLineStride;
/* Font width in pixels */
uint32_t FontWidthInPixels;
/* Font height in pixels */
uint32_t FontHeightInPixels;
/* Pointer to font graphics raw data */
uint32_t PointerToFontGraphicsData;
}FT_Gpu_Fonts_t;
void SAMAPP_GPU_Fonts()
{
int32_t i,j,hoffset,voffset,stringlen;
uint32_t FontTableAddress;
const char Display_string[] = "Hello World";
FT_Fonts_t Display_fontstruct;
hoffset = ((FT_DispWidth - 100)/2);voffset = FT_DispHeight/2;
/* Read the font address from 0xFFFFC location */
FontTableAddress = FTImpl.Read32(0xFFFFC);
stringlen = sizeof(Display_string) - 1;
for(i=0;i<16;i++)
{
/* Read the font table from hardware */
FTImpl.Read((FontTableAddress + i*FT_GPU_FONT_TABLE_SIZE),(uint8_t *)&Display_fontstruct,FT_GPU_FONT_TABLE_SIZE);
FTImpl.DLStart();
FTImpl.Clear(1,1,1);
/* Display string at the center of display */
FTImpl.Begin(FT_BITMAPS);
hoffset = ((FT_DispWidth - 120)/2);
voffset = ((FT_DispHeight - Display_fontstruct.FontHeightInPixels)/2);
/* Display hello world by offsetting wrt char size */
for(j=0;j<stringlen;j++)
{
FTImpl.Vertex2ii(hoffset,voffset,(i+16),Display_string[j]);
hoffset += Display_fontstruct.FontWidth[Display_string[j]];
}
FTImpl.DLEnd();
FTImpl.Finish();
delay(1000);
}
}
void SAMAPP_GPU_Text8x8()
{
/* Write the data into FT_RAM_G */
const char Text_Array[] = "abcdefgh";
int32_t String_size,hoffset = 16,voffset = 16;
String_size = sizeof(Text_Array) - 1;
FTImpl.Write(FT_RAM_G,(uint8_t *)Text_Array, String_size);
FTImpl.DLStart();
FTImpl.Clear(1,1,1);
FTImpl.BitmapSource(FT_RAM_G);
FTImpl.BitmapLayout(FT_TEXT8X8, 1*8,1);//L1 format, each input data element is in 1 byte size
FTImpl.BitmapSize(FT_NEAREST, FT_BORDER, FT_REPEAT, 8*8, 8*2);//output is 8x8 format - draw 8 characters in horizontal repeated in 2 line
FTImpl.Begin(FT_BITMAPS);
/* Display text 8x8 at hoffset, voffset location */
FTImpl.Vertex2f(hoffset*16,voffset*16);
/*
abcdabcdabcdabcd
efghefghefghefgh
*/
FTImpl.BitmapLayout(FT_TEXT8X8, 1*4,2);//L1 format and each datatype is 1 byte size
FTImpl.BitmapSize(FT_NEAREST, FT_REPEAT, FT_BORDER, 8*16, 8*2);//each character is 8x8 in size - so draw 32 characters in horizontal and 32 characters in vertical
hoffset = FT_DispWidth/2;
voffset = FT_DispHeight/2;
FTImpl.Vertex2f(hoffset*16,voffset*16);
FTImpl.DLEnd();
FTImpl.Finish();
delay(3000);
}
void SAMAPP_GPU_TextVGA()
{
/* Write the data into FT_RAM_G */
uint16_t Text_Array[160];
int32_t String_size,hoffset = 32,voffset = 32,i;
for(i=0;i<160;i++)
{
Text_Array[i] = random(65536);//within range
}
String_size = 160*2;
FTImpl.Write(FT_RAM_G,(uint8_t *)Text_Array, String_size);
FTImpl.DLStart();
FTImpl.Clear(1,1,1);
FTImpl.BitmapSource(FT_RAM_G);
/* mandatory for textvga as background color is also one of the parameter in textvga format */
FTImpl.BlendFunc(FT_ONE,FT_ZERO);
//draw 8x8
FTImpl.BitmapLayout(FT_TEXTVGA, 2*4,8);//L1 format, but each input data element is of 2 bytes in size
FTImpl.BitmapSize(FT_NEAREST,FT_BORDER,FT_BORDER, 8*8, 8*8);//output is 8x8 format - draw 8 characters in horizontal and 8 vertical
FTImpl.Begin(FT_BITMAPS);
FTImpl.Vertex2f(hoffset*16,voffset*16);
FTImpl.End();
//draw textvga
FTImpl.BitmapLayout(FT_TEXTVGA, 2*16,8);//L1 format but each datatype is 16bit size
FTImpl.BitmapSize(FT_NEAREST, FT_BORDER, FT_REPEAT, 8*32, 8*32);//8 pixels per character and 32 rows/colomns
FTImpl.Begin(FT_BITMAPS);
hoffset = FT_DispWidth/2;
voffset = FT_DispHeight/2;
/* Display textvga at hoffset, voffset location */
FTImpl.Vertex2f(hoffset*16,voffset*16);
FTImpl.DLEnd();
FTImpl.Finish();
delay(3000);
}
void SAMAPP_GPU_Bargraph()
{
/* Write the data into FT_RAM_G */
uint8_t Y_Array[512],NumSineWaves = 4;
int32_t String_size,hoffset = 0,voffset = 0,i;
hoffset = 0;
voffset = 0;
for(i=0;i<512;i++)
{
Y_Array[i] = random(128) + 64;//within range
}
String_size = 512;
FTImpl.Write(FT_RAM_G,(uint8_t *)&Y_Array[0], String_size);
FTImpl.DLStart();
FTImpl.ClearColorRGB(0xff,0xff,0xff);
FTImpl.Clear(1,1,1);
FTImpl.BitmapSource(FT_RAM_G);
FTImpl.BitmapLayout(FT_BARGRAPH, 256,1);
FTImpl.ColorRGB(128, 0,0);
FTImpl.BitmapSize(FT_NEAREST, FT_BORDER, FT_BORDER, 256, 256);
FTImpl.Begin(FT_BITMAPS);
/* Display text 8x8 at hoffset, voffset location */
FTImpl.Vertex2ii(hoffset,voffset,0,0);
hoffset = 256;
FTImpl.Vertex2ii(hoffset,voffset,0,1);
FTImpl.DLEnd();
FTImpl.Finish();
delay(1000);
for(i=0;i<512;i++)
{
int32_t tmpval,tmpidx;
//tmpidx = (i + 256)&(512 - 1);
tmpidx = i;
tmpval = 128 + ((int32_t)(i/3)*SAMAPP_qsin(-65536*i/48)/65536);//within range
Y_Array[i] = tmpval&0xff;
}
String_size = 512;
FTImpl.Write(FT_RAM_G,(uint8_t *)Y_Array, String_size);
delay(1000);
FTImpl.DLStart();
FTImpl.Clear(1,1,1);
FTImpl.BitmapSource(FT_RAM_G);
FTImpl.BitmapLayout(FT_BARGRAPH, 256,1);
FTImpl.BitmapSize(FT_NEAREST, FT_BORDER, FT_BORDER, 256, 256);
FTImpl.Begin(FT_BITMAPS);
FTImpl.ColorRGB(255, 0,0);
/* Display bargraph at hoffset, voffset location */
hoffset = 0;
voffset = 0;
FTImpl.Vertex2ii(hoffset,voffset,0,0);
hoffset = 256;
voffset = 0;
FTImpl.Vertex2ii(hoffset,voffset,0,1);
hoffset = 0;
voffset += 4;
FTImpl.ColorRGB(0, 0,0);
FTImpl.Vertex2ii(hoffset,voffset,0,0);
hoffset = 256;
FTImpl.Vertex2ii(hoffset,voffset,0,1);
FTImpl.DLEnd();
FTImpl.Finish();
delay(1000);
}
void SAMAPP_GPU_LineStrips()
{
FTImpl.DLStart();
FTImpl.ClearColorRGB(5, 45, 10);
FTImpl.Clear(1,1,1);
FTImpl.ColorRGB(255, 168, 64);
FTImpl.Begin(FT_LINE_STRIP);
FTImpl.Vertex2f(16 * 16,16 * 16);
FTImpl.Vertex2f((FT_DispWidth*2/3) * 16,(FT_DispHeight*2/3) * 16);
FTImpl.Vertex2f((FT_DispWidth - 80) * 16,(FT_DispHeight - 20) * 16);
FTImpl.DLEnd();
FTImpl.Finish();
delay(1000);
}
void SAMAPP_GPU_EdgeStrips()
{
FTImpl.DLStart();
FTImpl.ClearColorRGB(5, 45, 10);
FTImpl.Clear(1,1,1);
FTImpl.ColorRGB(255, 168, 64);
FTImpl.Begin(FT_EDGE_STRIP_R);
FTImpl.Vertex2f(16 * 16,16 * 16);
FTImpl.Vertex2f((FT_DispWidth*2/3) * 16,(FT_DispHeight*2/3) * 16);
FTImpl.Vertex2f((FT_DispWidth - 80) * 16,(FT_DispHeight - 20) * 16);
FTImpl.DLEnd();
FTImpl.Finish();
delay(1000);
}
void SAMAPP_GPU_Scissor()
{
FTImpl.DLStart();
FTImpl.Clear(1,1,1);
FTImpl.ScissorXY(40, 20); // Scissor rectangle top left at (40, 20)
FTImpl.ScissorSize(40, 40); // Scissor rectangle is 40 x 40 pixels
FTImpl.ClearColorRGB(255, 255, 0);// Clear to yellow
FTImpl.Clear(1,1,1);
/* Download the DL into DL RAM */
FTImpl.DLEnd();
FTImpl.Finish();
delay(1000);
}
void SAMAPP_GPU_Stencil()
{
int16_t PointSize = 50,DispBtwPoints = 60;
FTImpl.DLStart();
FTImpl.Clear(1,1,1);
FTImpl.ScissorXY(40, 20); // Scissor rectangle top left at (40, 20)
FTImpl.StencilOp(FT_INCR,FT_INCR);
FTImpl.PointSize(PointSize * 16);
FTImpl.Begin(FT_POINTS);
FTImpl.Vertex2ii(((FT_DispWidth - DispBtwPoints)/2), (FT_DispHeight/2), 0, 0);
FTImpl.Vertex2ii(((FT_DispWidth + DispBtwPoints)/2), (FT_DispHeight/2), 0, 0);
FTImpl.StencilFunc(FT_EQUAL, 2, 255);
FTImpl.ColorRGB(128, 0, 0);
FTImpl.Vertex2ii((FT_DispWidth/2), (FT_DispHeight/2), 0, 0);
/* Download the DL into DL RAM */
FTImpl.DLEnd();
FTImpl.Finish();
delay(1000);
}
void SAMAPP_Gpu_Polygon()
{
FTImpl.DLStart();
FTImpl.Clear(1,1,1);
FTImpl.ColorRGB(255, 0, 0);
FTImpl.StencilOp(FT_INCR,FT_INCR);
FTImpl.ColorMask(0,0,0,0);//mask all the colors
FTImpl.Begin(FT_EDGE_STRIP_L);
FTImpl.Vertex2ii((FT_DispWidth/2),(FT_DispHeight/4),0,0);
FTImpl.Vertex2ii((FT_DispWidth*4/5),(FT_DispHeight*4/5),0,0);
FTImpl.Vertex2ii((FT_DispWidth/4),(FT_DispHeight/2),0,0);
FTImpl.Vertex2ii((FT_DispWidth/2),(FT_DispHeight/4),0,0);
FTImpl.End();
FTImpl.ColorMask(1,1,1,1);//enable all the colors
FTImpl.StencilFunc(FT_EQUAL,1,255);
FTImpl.Begin(FT_EDGE_STRIP_L);
FTImpl.Vertex2ii(FT_DispWidth,0,0,0);
FTImpl.Vertex2ii(FT_DispWidth,FT_DispHeight,0,0);
FTImpl.End();
/* Draw lines at the borders to make sure anti aliazing is also done */
FTImpl.StencilFunc(FT_ALWAYS,0,255);
FTImpl.LineWidth(1*16);
FTImpl.ColorRGB(0, 0, 0);
FTImpl.Begin(FT_LINES);
FTImpl.Vertex2ii((FT_DispWidth/2),(FT_DispHeight/4),0,0);
FTImpl.Vertex2ii((FT_DispWidth*4/5),(FT_DispHeight*4/5),0,0);
FTImpl.Vertex2ii((FT_DispWidth*4/5),(FT_DispHeight*4/5),0,0);
FTImpl.Vertex2ii((FT_DispWidth/4),(FT_DispHeight/2),0,0);
FTImpl.Vertex2ii((FT_DispWidth/4),(FT_DispHeight/2),0,0);
FTImpl.Vertex2ii((FT_DispWidth/2),(FT_DispHeight/4),0,0);
FTImpl.End();
/* Download the DL into DL RAM */
FTImpl.DLEnd();
FTImpl.Finish();
delay(1000);
}
void SAMAPP_Gpu_Cube()
{
uint32_t points[6*5],x,y,i,z;
int16_t xoffset,yoffset,CubeEdgeSz;
// color vertices
uint16_t colors[6][3] = { 255,0,0,
255,0,150,
0,255,0,
110,120,110,
0,0,255,
128,128,0
};
// Cube dimention is of 100*100*100
CubeEdgeSz = 100;
xoffset = (FT_DispWidth/2 - CubeEdgeSz);
yoffset=((FT_DispHeight - CubeEdgeSz)/2);
// xy plane(front)
points[0] = VERTEX2F(xoffset*16,yoffset*16);
points[1] = VERTEX2F((xoffset+CubeEdgeSz)*16,yoffset*16);
points[2] = VERTEX2F((xoffset+CubeEdgeSz)*16,(yoffset+CubeEdgeSz)*16);
points[3] = VERTEX2F(xoffset*16,(yoffset+CubeEdgeSz)*16);
points[4] = points[0];
//yz plane (left)
x = (xoffset+(CubeEdgeSz/2)); // xoff+w/2
y = (yoffset-(CubeEdgeSz/2)); // yoff-h/2
points[5] = points[0];
points[6] = VERTEX2F(x*16,y*16);
points[7] = VERTEX2F(x*16,(y+CubeEdgeSz)*16);
points[8] = points[3];
points[9] = points[5];
//xz plane(top)
points[10] = points[0];
points[11] = points[1];
points[12] = VERTEX2F((x+CubeEdgeSz)*16,(y)*16);
points[13] = points[6];
points[14] = points[10];
//xz plane(bottom)
points[15] = points[3];
points[16] = points[2];
points[17] = VERTEX2F((x+CubeEdgeSz)*16,(y+CubeEdgeSz)*16);
points[18] = points[7];
points[19] = points[15];
//yz plane (right)
points[20] = points[2];
points[21] = points[17];
points[22] = points[12];
points[23] = points[1];
points[24] = points[20];
//yz plane (back)
points[25] = points[6];
points[26] = points[7];
points[27] = points[17];
points[28] = points[12];
points[29] = points[25];
FTImpl.DLStart();
FTImpl.ClearColorRGB(255,255,255);
FTImpl.Clear(1,1,1);
FTImpl.LineWidth(16);
FTImpl.ColorRGB(255,255,255);
// Draw a cube
FTImpl.StencilOp(FT_INCR,FT_INCR);
FTImpl.ColorA(192);
for(z=0;z<6;z++)
{
FTImpl.Clear(0,1,1);
FTImpl.ColorMask(0,0,0,0);//mask all the colors and draw one surface
FTImpl.StencilFunc(FT_ALWAYS,0,255);//stencil function to increment all the values
FTImpl.Begin(FT_EDGE_STRIP_L);
for(i = 0;i<5;i++)
{
FTImpl.WriteCmd(points[z*5 + i]);
}
FTImpl.End();
/* set the color and draw a strip */
FTImpl.ColorMask(1,1,1,1);
FTImpl.StencilFunc(FT_EQUAL,1,255);
FTImpl.ColorRGB(colors[z][0],colors[z][1],colors[z][2]);
FTImpl.Begin(FT_RECTS);
FTImpl.Vertex2ii(xoffset,0,0,0);
FTImpl.Vertex2ii(xoffset + CubeEdgeSz*2,yoffset + CubeEdgeSz*2,0,0);
FTImpl.End();
}
/* Download the DL into DL RAM */
FTImpl.DLEnd();
FTImpl.Finish();
delay(1000);
}
float lerp(float t, float a, float b)
{
return (float)((1 - t) * a + t * b);
}
float smoothlerp(float t, float a, float b)
{
float lt = 3 * t * t - 2 * t * t * t;
return lerp(lt, a, b);
}
/* First draw points followed by lines to create 3d ball kind of effect */
void SAMAPP_GPU_Ball_Stencil()
{
int16_t xball = (FT_DispWidth/2),yball = 120,rball = (FT_DispWidth/8);
int16_t numpoints = 6,numlines = 8,i,asize,aradius,gridsize = 20;
int32_t asmooth,loopflag = 1,dispr = (FT_DispWidth - 10),displ = 10,dispa = 10,dispb = (FT_DispHeight - 10),xflag = 1,yflag = 1;
dispr -= ((dispr - displ)%gridsize);
dispb -= ((dispb - dispa)%gridsize);
/* write the play sound */
FTImpl.Write16(REG_SOUND,0x50);
loopflag = 100;
while(loopflag-- >0)
{
if(((xball + rball + 2) >= dispr) || ((xball - rball - 2) <= displ))
{
xflag ^= 1;
FTImpl.Write(REG_PLAY,1);
}
if(((yball + rball + 8) >= dispb) || ((yball - rball - 8) <= dispa))
{
yflag ^= 1;
FTImpl.Write(REG_PLAY,1);
}
if(xflag)
{
xball += 2;
}
else
{
xball -= 2;
}
if(yflag)
{
yball += 8 ;
}
else
{
yball -= 8;
}
FTImpl.DLStart();
FTImpl.ClearColorRGB(128, 128, 0);
FTImpl.Clear(1, 1, 1); // clear screen
FTImpl.StencilOp(FT_INCR,FT_INCR);
FTImpl.ColorRGB(0, 0, 0);
/* draw grid */
FTImpl.LineWidth(16);
FTImpl.Begin(FT_LINES);
for(i=0;i<=((dispr - displ)/gridsize);i++)
{
FTImpl.Vertex2f((displ + i*gridsize)*16,dispa*16);
FTImpl.Vertex2f((displ + i*gridsize)*16,dispb*16);
}
for(i=0;i<=((dispb - dispa)/gridsize);i++)
{
FTImpl.Vertex2f(displ*16,(dispa + i*gridsize)*16);
FTImpl.Vertex2f(dispr*16,(dispa + i*gridsize)*16);
}
FTImpl.End();
FTImpl.ColorMask(0,0,0,0);//mask all the colors
FTImpl.PointSize(rball*16);
FTImpl.Begin(FT_POINTS);
FTImpl.Vertex2f(xball*16,yball*16);
FTImpl.StencilOp(FT_INCR,FT_ZERO);
FTImpl.StencilFunc(FT_GEQUAL,1,255);
/* one side points */
for(i=1;i<=numpoints;i++)
{
asize = i*rball*2/(numpoints + 1);
asmooth = (int16_t)smoothlerp((float)((float)(asize)/(2*(float)rball)),0,2*(float)rball);
if(asmooth > rball)
{
//change the offset to -ve
int32_t tempsmooth;
tempsmooth = asmooth - rball;
aradius = (rball*rball + tempsmooth*tempsmooth)/(2*tempsmooth);
FTImpl.PointSize(aradius*16);
FTImpl.Vertex2f((xball - aradius + tempsmooth)*16,yball*16);
}
else
{
int32_t tempsmooth;
tempsmooth = rball - asmooth;
aradius = (rball*rball + tempsmooth*tempsmooth)/(2*tempsmooth);
FTImpl.PointSize(aradius*16);
FTImpl.Vertex2f((xball+ aradius - tempsmooth)*16,yball*16);
}
}
FTImpl.End();
FTImpl.Begin(FT_LINES);
/* draw lines - line should be at least radius diameter */
for(i=1;i<=numlines;i++)
{
asize = (i*rball*2/numlines);
asmooth = (int16_t)smoothlerp((float)((float)(asize)/(2*(float)rball)),0,2*(float)rball);
FTImpl.LineWidth(asmooth * 16);
FTImpl.Vertex2f((xball - rball)*16,(yball - rball )*16);
FTImpl.Vertex2f((xball + rball)*16,(yball - rball )*16);
}
FTImpl.End();
FTImpl.ColorMask(1,1,1,1);//enable all the colors
FTImpl.StencilFunc(FT_ALWAYS,1,255);
FTImpl.StencilOp(FT_KEEP,FT_KEEP);
FTImpl.ColorRGB(255, 255, 255);
FTImpl.PointSize(rball*16);
FTImpl.Begin(FT_POINTS);
FTImpl.Vertex2f((xball - 1)*16,(yball - 1)*16);
FTImpl.ColorRGB(0, 0, 0);//shadow
FTImpl.ColorA(160);
FTImpl.Vertex2f((xball+16)*16,(yball+8)*16);
FTImpl.ColorA(255);
FTImpl.ColorRGB(255, 255, 255);
FTImpl.Vertex2f(xball*16,yball*16);
FTImpl.ColorRGB(255, 0, 0);
FTImpl.StencilFunc(FT_GEQUAL,1,1);
FTImpl.StencilOp(FT_KEEP,FT_KEEP);
FTImpl.Vertex2f(xball*16,yball*16);
FTImpl.End();
/* Download the DL into DL RAM */
FTImpl.DLEnd();
FTImpl.Finish();
// delay(1000);
}
}
/* Call and return example - simple graph */
void SAMAPP_GPU_StreetMap()
{
FTImpl.DLStart();
FTImpl.ClearColorRGB(236,232,224); //light gray
FTImpl.Clear(1, 1, 1); // clear screen
FTImpl.ColorRGB(170,157,136);//medium gray
FTImpl.LineWidth(63);
FTImpl.Call(20);//draw the streets
FTImpl.ColorRGB(250,250,250);//white
FTImpl.LineWidth(48);
FTImpl.Call(20);//draw the streets
FTImpl.ColorRGB(0,0,0);
FTImpl.Begin(FT_BITMAPS);
FTImpl.Vertex2ii(240,91,27,77);
FTImpl.Vertex2ii(252,91,27,97);
FTImpl.Vertex2ii(260,91,27,105);
FTImpl.Vertex2ii(263,91,27,110);
FTImpl.Vertex2ii(275,91,27,115);
FTImpl.Vertex2ii(282,91,27,116);
FTImpl.Vertex2ii(286,91,27,46);
FTImpl.End();
FTImpl.Display();
FTImpl.Begin(FT_LINES);
FTImpl.Vertex2f(-160,-20 );
FTImpl.Vertex2f(320,4160 );
FTImpl.Vertex2f(800,-20 );
FTImpl.Vertex2f(1280,4160 );
FTImpl.Vertex2f(1920,-20 );
FTImpl.Vertex2f(2400,4160 );
FTImpl.Vertex2f(2560,-20 );
FTImpl.Vertex2f(3040,4160 );
FTImpl.Vertex2f(3200,-20 );
FTImpl.Vertex2f(3680,4160 );
FTImpl.Vertex2f(2880,-20 );
FTImpl.Vertex2f(3360,4160 );
FTImpl.Vertex2f(-20,0 );
FTImpl.Vertex2f(5440,-480 );
FTImpl.Vertex2f(-20,960 );
FTImpl.Vertex2f(5440,480 );
FTImpl.Vertex2f(-20,1920 );
FTImpl.Vertex2f(5440,1440 );
FTImpl.Vertex2f(-20,2880 );
FTImpl.Vertex2f(5440,2400 );
FTImpl.End();
FTImpl.Return();
/* Download the DL into DL RAM */
FTImpl.DLEnd();
FTImpl.Finish();
delay(1000);
}
/* usage of additive blending - draw 3 Gs*/
void SAMAPP_GPU_AdditiveBlendText()
{
FTImpl.DLStart();
FTImpl.Clear(1, 1, 1); // clear screen
FTImpl.Begin(FT_BITMAPS);
FTImpl.Vertex2ii(50, 30, 31, 0x47);
FTImpl.ColorA(128);
FTImpl.Vertex2ii(58, 38, 31, 0x47);
FTImpl.ColorA(64);
FTImpl.Vertex2ii(66, 46, 31, 0x47);
FTImpl.End();
/* Download the DL into DL RAM */
FTImpl.DLEnd();
FTImpl.Finish();
delay(1000);
}
void SAMAPP_GPU_MacroUsage()
{
int32_t xoffset,yoffset,xflag = 1,yflag = 1,flagloop = 1;
SAMAPP_Bitmap_header_t *p_bmhdr;
xoffset = FT_DispWidth/3;
yoffset = FT_DispHeight/2;
/* First write a valid macro instruction into macro0 */
FTImpl.Write32(REG_MACRO_0,VERTEX2F(xoffset*16,yoffset*16));
/* update lena face as bitmap 0 */
p_bmhdr = &SAMAPP_Bitmap_RawData_Header[0];
/* Copy raw data into address 0 followed by generation of bitmap */
FTImpl.Writefromflash(FT_RAM_G,&SAMAPP_Bitmap_RawData[p_bmhdr->Arrayoffset], p_bmhdr->Stride*p_bmhdr->Height);
FTImpl.DLStart();
FTImpl.Clear(1, 1, 1); // clear screen
FTImpl.BitmapSource(FT_RAM_G);
FTImpl.BitmapLayout(p_bmhdr->Format, p_bmhdr->Stride, p_bmhdr->Height);
FTImpl.BitmapSize(FT_NEAREST, FT_BORDER, FT_BORDER, p_bmhdr->Width, p_bmhdr->Height);
FTImpl.Begin(FT_BITMAPS); // start drawing bitmaps
FTImpl.Macro(0); // draw the image at (100,120)
FTImpl.End();
FTImpl.DLEnd();
FTImpl.Finish();
flagloop = 300;
while(flagloop-- > 0)
{
if(((xoffset + p_bmhdr->Width) >= FT_DispWidth) || (xoffset <= 0))
{
xflag ^= 1;
}
if(((yoffset + p_bmhdr->Height) >= FT_DispHeight) || (yoffset <= 0))
{
yflag ^= 1;
}
if(xflag)
{
xoffset++;
}
else
{
xoffset--;