-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAntares - Copy (2).h
1475 lines (1235 loc) · 48.2 KB
/
Antares - Copy (2).h
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
//Antares.h - FTDI/Bridgetek Eve 2,3,4 driver for Propeller2 and FlexSpin C
//Copyright 2020-2021 Raymond Allen, MIT licence (except parts from "gd2-lib", which have BSD-3 license)
//This code is based on "gd2-lib" by James Bowman (BSD-3 license) and "EVE2-Library" by Matrix Orbital (MIT license)
//We are very appreciative of these codes
//"gd2-lib" and license info can be found here: https://github.com/jamesbowman/gd2-lib
//"EVE2-Library" and license info can be found here: https://github.com/MatrixOrbital/EVE2-Library
#ifndef _ANTARES_H_
#define _ANTARES_H_
//RJA: Note: To make the build line simpler, Anteres.c is included below, near line 428
#include "Platform.h"
// Global Variables
uint16_t FifoWriteLocation = 0; // Don't allow this variable to get out of synch - be careful about manually constructing FIFO commands
typedef uint32_t COLORREF;
typedef uint32_t* LPCOLORREF;
#define WorkBuffSz 16//64 larger buffer doesn't seem to work with higher SPI speeds
#define MyDelay _waitms
#define Log printf
#define HCMD_ACTIVE 0x00
#define HCMD_STANDBY 0x41
#define HCMD_SLEEP 0x42
#define HCMD_PWRDOWN 0x50
#define HCMD_CLKINT 0x48
#define HCMD_CLKEXT 0x44
#define HCMD_CLK48M 0x62
#define HCMD_CLK36M 0x61
#define HCMD_CORERESET 0x68
#define CMD_APPEND 0xFFFFFF1E
#define CMD_BGCOLOR 0xFFFFFF09
#define CMD_BUTTON 0xFFFFFF0D
#define CMD_CALIBRATE 0xFFFFFF15 // 4294967061UL
#define CMD_CLOCK 0xFFFFFF14
#define CMD_COLDSTART 0xFFFFFF32
#define CMD_CRC 0xFFFFFF18
#define CMD_DIAL 0xFFFFFF2D
#define CMD_DLSTART 0xFFFFFF00
#define CMD_FGCOLOR 0xFFFFFF0A
#define CMD_GAUGE 0xFFFFFF13
#define CMD_GETMATRIX 0xFFFFFF33
#define CMD_GETPROPS 0xFFFFFF25
#define CMD_GETPTR 0xFFFFFF23
#define CMD_GRADCOLOR 0xFFFFFF34
#define CMD_GRADIENT 0xFFFFFF0B
#define CMD_INFLATE 0xFFFFFF22
#define CMD_INFLATE2 0xFFFFFF50
#define CMD_INTERRUPT 0xFFFFFF02
#define CMD_KEYS 0xFFFFFF0E
#define CMD_LOADIDENTITY 0xFFFFFF26
#define CMD_LOADIMAGE 0xFFFFFF24
#define CMD_LOGO 0xFFFFFF31
#define CMD_MEDIAFIFO 0xFFFFFF39
#define CMD_MEMCPY 0xFFFFFF1D
#define CMD_MEMCRC 0xFFFFFF18
#define CMD_MEMSET 0xFFFFFF1B
#define CMD_MEMWRITE 0xFFFFFF1A
#define CMD_MEMZERO 0xFFFFFF1C
#define CMD_NUMBER 0xFFFFFF2E//RJA fixed this 0xFFFFFF38
#define CMD_PLAYVIDEO 0xFFFFFF3A
#define CMD_PROGRESS 0xFFFFFF0F
#define CMD_REGREAD 0xFFFFFF19
#define CMD_ROTATE 0xFFFFFF29
#define CMD_SCALE 0xFFFFFF28
#define CMD_SCREENSAVER 0xFFFFFF2F
#define CMD_SCROLLBAR 0xFFFFFF11
#define CMD_SETBITMAP 0xFFFFFF43
#define CMD_SETFONT 0xFFFFFF2B
#define CMD_SETFONT2 0xFFFFFF3B //RJA
#define CMD_SETMATRIX 0xFFFFFF2A
#define CMD_SETROTATE 0xFFFFFF36
#define CMD_SKETCH 0xFFFFFF30
#define CMD_SLIDER 0xFFFFFF10
#define CMD_SNAPSHOT 0xFFFFFF1F
#define CMD_SPINNER 0xFFFFFF16
#define CMD_STOP 0xFFFFFF17
#define CMD_SWAP 0xFFFFFF01
#define CMD_TEXT 0xFFFFFF0C
#define CMD_TOGGLE 0xFFFFFF12
#define CMD_TRACK 0xFFFFFF2C
#define CMD_TRANSLATE 0xFFFFFF27
#define CMD_VIDEOFRAME 0xFFFFFF41
#define CMD_VIDEOSTART 0xFFFFFF40
// BT81X COMMANDS
#define CMD_FLASHERASE 0xFFFFFF44
#define CMD_FLASHWRITE 0xFFFFFF45
#define CMD_FLASHREAD 0xFFFFFF46
#define CMD_FLASHUPDATE 0xFFFFFF47
#define CMD_FLASHDETACH 0xFFFFFF48
#define CMD_FLASHATTACH 0xFFFFFF49
#define CMD_FLASHFAST 0xFFFFFF4A
#define CMD_FLASHSPIDESEL 0xFFFFFF4B
#define CMD_FLASHSPITX 0xFFFFFF4C
#define CMD_FLASHSPIRX 0xFFFFFF4D
#define CMD_FLASHSOURCE 0xFFFFFF4E
#define CMD_CLEARCACHE 0xFFFFFF4F
#define CMD_FLASHAPPENDF 0xFFFFFF59
#define CMD_VIDEOSTARTF 0xFFFFFF5F
#define CMD_ANIMSTART 0xFFFFFF53
#define CMD_ANIMSTOP 0xFFFFFF54
#define CMD_ANIMXY 0xFFFFFF55
#define CMD_ANIMDRAW 0xFFFFFF56
#define CMD_ANIMFRAME 0xFFFFFF5A
//RJA adding
#define CMD_ROMFONT 0xFFFFFF3F
#define CMD_GETIMAGE 0xFFFFFF64
#define DLSWAP_FRAME 2UL
#define OPT_CENTER 1536UL
#define OPT_CENTERX 512UL
#define OPT_CENTERY 1024UL
#define OPT_FLASH 64UL
#define OPT_FLAT 256UL
#define OPT_FULLSCREEN 8UL
#define OPT_MEDIAFIFO 16UL
#define OPT_MONO 1UL
#define OPT_NOBACK 4096UL
#define OPT_NODL 2UL
#define OPT_NOHANDS 49152UL
#define OPT_NOHM 16384UL
#define OPT_NOPOINTER 16384UL
#define OPT_NOSECS 32768UL
#define OPT_NOTEAR 4UL
#define OPT_NOTICKS 8192UL
#define OPT_RGB565 0UL
#define OPT_RIGHTX 2048UL
#define OPT_SIGNED 256UL
#define OPT_SOUND 32UL
// Definitions for FT8xx co processor command buffer
#define FT_DL_SIZE (8*1024) // 8KB Display List buffer size
#define FT_CMD_FIFO_SIZE (4*1024) // 4KB coprocessor Fifo size
#define FT_CMD_SIZE (4) // 4 byte per coprocessor command of EVE
// Memory base addresses
#define RAM_G 0x0
#define RAM_G_WORKING 0x0FF000 // This address may be used as the start of a 4K block to be used for copying data
#define RAM_DL 0x300000
#define RAM_REG 0x302000
#define RAM_CMD 0x308000
#define RAM_ERR_REPORT 0x309800 // max 128 bytes null terminated string
#define RAM_FLASH 0x800000
#define RAM_FLASH_POSTBLOB 0x801000
// Graphics Engine Registers - FT81x Series Programmers Guide Section 3.1
// Addresses defined as offsets from the base address called RAM_REG and located at 0x302000
// Discussion: Defining this way leads to an additional add operation in code that can be avoided by defining
// these addresses as 32 bit values, but this is easily paid for in clarity and coorelation to documentation.
// Further, you can add defines together in code and allow the precompiler to do the add operation (as here).
#define REG_CSPREAD 0x68
#define REG_DITHER 0x60
#define REG_DLSWAP 0x54
#define REG_HCYCLE 0x2C
#define REG_HOFFSET 0x30
#define REG_HSIZE 0x34
#define REG_HSYNC0 0x38
#define REG_HSYNC1 0x3C
#define REG_OUTBITS 0x5C
#define REG_PCLK 0x70
#define REG_PCLK_POL 0x6C
#define REG_PLAY 0x8C
#define REG_PLAYBACK_FORMAT 0xC4
#define REG_PLAYBACK_FREQ 0xC0
#define REG_PLAYBACK_LENGTH 0xB8
#define REG_PLAYBACK_LOOP 0xC8
#define REG_PLAYBACK_PLAY 0xCC
#define REG_PLAYBACK_READPTR 0xBC
#define REG_PLAYBACK_START 0xB4
#define REG_PWM_DUTY 0xD4
#define REG_ROTATE 0x58
#define REG_SOUND 0x88
#define REG_SWIZZLE 0x64
#define REG_TAG 0x7C
#define REG_TAG_X 0x74
#define REG_TAG_Y 0x78
#define REG_VCYCLE 0x40
#define REG_VOFFSET 0x44
#define REG_VOL_SOUND 0x84
#define REG_VOL_PB 0x80
#define REG_VSYNC0 0x4C
#define REG_VSYNC1 0x50
#define REG_VSIZE 0x48
// Touch Screen Engine Registers - FT81x Series Programmers Guide Section 3.3
// Addresses defined as offsets from the base address called RAM_REG and located at 0x302000
#define REG_TOUCH_CONFIG 0x168
#define REG_TOUCH_TRANSFORM_A 0x150
#define REG_TOUCH_TRANSFORM_B 0x154
#define REG_TOUCH_TRANSFORM_C 0x158
#define REG_TOUCH_TRANSFORM_D 0x15C
#define REG_TOUCH_TRANSFORM_E 0x160
#define REG_TOUCH_TRANSFORM_F 0x164
// Resistive Touch Engine Registers - FT81x Series Programmers Guide Section 3.3.3 - Document confused
// Addresses defined as offsets from the base address called RAM_REG and located at 0x302000
#define REG_TOUCH_ADC_MODE 0x108
#define REG_TOUCH_CHARGE 0x10C
#define REG_TOUCH_DIRECT_XY 0x18C
#define REG_TOUCH_DIRECT_Z1Z2 0x190
#define REG_TOUCH_MODE 0x104
#define REG_TOUCH_OVERSAMPLE 0x114
#define REG_TOUCH_RAW_XY 0x11C
#define REG_TOUCH_RZ 0x120
#define REG_TOUCH_RZTHRESH 0x118
#define REG_TOUCH_SCREEN_XY 0x124
#define REG_TOUCH_SETTLE 0x110
#define REG_TOUCH_TAG 0x12C
#define REG_TOUCH_TAG_XY 0x128
// Capacitive Touch Engine Registers - FT81x Series Programmers Guide Section 3.3.4
// Addresses defined as offsets from the base address called RAM_REG and located at 0x302000
#define REG_CTOUCH_MODE 0x104
#define REG_CTOUCH_EXTEND 0x108
#define REG_CTOUCH_RAW_XY 0x11C
#define REG_CTOUCH_TOUCH_XY 0x124
#define REG_CTOUCH_TOUCH1_XY 0x11C
#define REG_CTOUCH_TOUCH2_XY 0x18C
#define REG_CTOUCH_TOUCH3_XY 0x190
#define REG_CTOUCH_TOUCH4_X 0x16C
#define REG_CTOUCH_TOUCH4_Y 0x120
#define REG_CTOUCH_TAG 0x12C
#define REG_CTOUCH_TAG1 0x134
#define REG_CTOUCH_TAG2 0x13C
#define REG_CTOUCH_TAG3 0x144
#define REG_CTOUCH_TAG4 0x14C
#define REG_CTOUCH_TAG_XY 0x128
#define REG_CTOUCH_TAG1_XY 0x130
#define REG_CTOUCH_TAG2_XY 0x138
#define REG_CTOUCH_TAG3_XY 0x140
#define REG_CTOUCH_TAG4_XY 0x148
// Co-processor Engine Registers - FT81x Series Programmers Guide Section 3.4
// Addresses defined as offsets from the base address called RAM_REG and located at 0x302000
#define REG_CMD_DL 0x100
#define REG_CMD_READ 0xF8
#define REG_CMD_WRITE 0xFC
#define REG_CMDB_SPACE 0x574
#define REG_CMDB_WRITE 0x578
#define REG_COPRO_PATCH_PTR 0x7162
// Special Registers - FT81x Series Programmers Guide Section 3.5
// Addresses assumed to be defined as offsets from the base address called RAM_REG and located at 0x302000
#define REG_TRACKER 0x7000
#define REG_TRACKER_1 0x7004
#define REG_TRACKER_2 0x7008
#define REG_TRACKER_3 0x700C
#define REG_TRACKER_4 0x7010
#define REG_MEDIAFIFO_READ 0x7014
#define REG_MEDIAFIFO_WRITE 0x7018
// Flash related registers
#define REG_FLASH_STATUS 0x5F0
#define REG_FLASH_SIZE 0x7024
// Miscellaneous Registers - FT81x Series Programmers Guide Section 3.6 - Document inspecific about base address
// Addresses assumed to be defined as offsets from the base address called RAM_REG and located at 0x302000
#define REG_CPU_RESET 0x20
#define REG_PWM_DUTY 0xD4
#define REG_PWM_HZ 0xD0
#define REG_INT_MASK 0xB0
#define REG_INT_EN 0xAC
#define REG_INT_FLAGS 0xA8
#define REG_GPIO 0x94
#define REG_GPIO_DIR 0x90
#define REG_GPIOX 0x9C
#define REG_GPIOX_DIR 0x98
#define REG_FREQUENCY 0x0C
#define REG_CLOCK 0x08
#define REG_FRAMES 0x04
#define REG_ID 0x00
#define REG_TRIM 0x10256C
#define REG_SPI_WIDTH 0x180
#define REG_CHIP_ID 0xC0000 // Temporary Chip ID location in RAMG
//RJA adding
#define REG_PLAY_CONTROL 0x714E
// Primitive Type Reference Definitions - FT81x Series Programmers Guide Section 4.5 - Table 6
#define BITMAPS 1
#define POINTS 2
#define LINES 3
#define LINE_STRIP 4
#define EDGE_STRIP_R 5
#define EDGE_STRIP_L 6
#define EDGE_STRIP_A 7
#define EDGE_STRIP_B 8
#define RECTS 9
// Bitmap Layout Format Definitions - FT81x Series Programmers Guide Section 4.7 - Table 7
#define ARGB1555 0
#define L1 1
#define L4 2
#define L8 3
#define RGB332 4
#define ARGB2 5
#define ARGB4 6
#define RGB565 7
#define TEXT8X8 9
#define TEXTVGA 10
#define BARGRAPH 11
#define PALETTED565 14
#define PALETTED4444 15
#define PALETTED8 16
#define L2 17
// Bitmap Layout Format Definitions - BT81X Series Programming Guide Section 4.6
#define COMPRESSED_RGBA_ASTC_4x4_KHR 37808 // 8.00
#define COMPRESSED_RGBA_ASTC_5x4_KHR 37809 // 6.40
#define COMPRESSED_RGBA_ASTC_5x5_KHR 37810 // 5.12
#define COMPRESSED_RGBA_ASTC_6x5_KHR 37811 // 4.27
#define COMPRESSED_RGBA_ASTC_6x6_KHR 37812 // 3.56
#define COMPRESSED_RGBA_ASTC_8x5_KHR 37813 // 3.20
#define COMPRESSED_RGBA_ASTC_8x6_KHR 37814 // 2.67
#define COMPRESSED_RGBA_ASTC_8x8_KHR 37815 // 2.56
#define COMPRESSED_RGBA_ASTC_10x5_KHR 37816 // 2.13
#define COMPRESSED_RGBA_ASTC_10x6_KHR 37817 // 2.00
#define COMPRESSED_RGBA_ASTC_10x8_KHR 37818 // 1.60
#define COMPRESSED_RGBA_ASTC_10x10_KHR 37819 // 1.28
#define COMPRESSED_RGBA_ASTC_12x10_KHR 37820 // 1.07
#define COMPRESSED_RGBA_ASTC_12x12_KHR 37821 // 0.89
// Bitmap Parameters
#define REPEAT 1
#define BORDER 0
#define NEAREST 0
#define BILINEAR 1
// Animation Parameters
#define ANIM_HOLD 2UL
#define ANIM_LOOP 1UL
#define ANIM_ONCE 0UL
// Flash Status
#define FLASH_STATUS_INIT 0UL
#define FLASH_STATUS_DETACHED 1UL
#define FLASH_STATUS_BASIC 2UL
#define FLASH_STATUS_FULL 3UL
// These defined "macros" are supplied by FTDI - Manufacture command bit-fields from parameters
// FT81x Series Programmers Guide is refered to as "FT-PG"
#define CLEAR(c,s,t) ((38UL<<24)|(((c)&1UL)<<2)|(((s)&1UL)<<1)|(((t)&1UL)<<0)) // CLEAR - FT-PG Section 4.21
#define CLEAR_COLOR_RGB(red,green,blue) ((2UL<<24)|(((red)&255UL)<<16)|(((green)&255UL)<<8)|(((blue)&255UL)<<0))
#define CLEAR_COLOR_RGB24(RGBQUAD) ((2UL<<24)|RGBQUAD) // CLEAR_COLOR_RGB - FT-PG Section 4.23
#define COLOR_RGB(red,green,blue) ((4UL<<24)|(((red)&255UL)<<16)|(((green)&255UL)<<8)|(((blue)&255UL)<<0)) // COLOR_RGB - FT-PG Section 4.28
#define COLOR_RGB24(RGBQUAD) ((4UL<<24)|RGBQUAD) // COLOR_RGB - FT-PG Section 4.28
#define VERTEX2II(x,y,handle,cell) ((2UL<<30)|(((x)&511UL)<<21)|(((y)&511UL)<<12)|(((handle)&31UL)<<7)|(((cell)&127UL)<<0)) // VERTEX2II - FT-PG Section 4.48
#define VERTEX2F(x,y) ((1UL<<30)|(((x)&32767UL)<<15)|(((y)&32767UL)<<0)) // VERTEX2F - FT-PG Section 4.47
#define CELL(cell) ((6UL<<24)|(((cell)&127UL)<<0)) // CELL - FT-PG Section 4.20
#define BITMAP_HANDLE(handle) ((5UL<<24) | (((handle) & 31UL) << 0)) // BITMAP_HANDLE - FT-PG Section 4.06
#define BITMAP_SOURCE(addr) ((1UL<<24)|(((addr)&4194303UL)<<0)) // BITMAP_SOURCE - FT-PG Section 4.11
#define BITMAP_LAYOUT(format,linestride,height) ((7UL<<24)|(((format)&31UL)<<19)|(((linestride)&1023UL)<<9)|(((height)&511UL)<<0)) // BITMAP_LAYOUT - FT-PG Section 4.07
#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)) // BITMAP_SIZE - FT-PG Section 4.09
#define TAG(s) ((3UL<<24)|(((s)&255UL)<<0)) // TAG - FT-PG Section 4.43
#define POINT_SIZE(sighs) ((13UL<<24)|(((sighs)&8191UL)<<0)) // POINT_SIZE - FT-PG Section 4.36
#define BEGIN(PrimitiveTypeRef) ((31UL<<24)|(((PrimitiveTypeRef)&15UL)<<0)) // BEGIN - FT-PG Section 4.05
#define END() ((33UL<<24)) // END - FT-PG Section 4.30
#define DISPLAY() ((0UL<<24)) // DISPLAY - FT-PG Section 4.29
//RJA adding VERTEX_FORMAT
#define VERTEX_FORMAT(f) ((0x27<<24)|(f&0b111)) // VERTEX2F - FT-PG Section 4.47
#define VFORMAT_ONE (0)
#define VFORMAT_HALF (1)
#define VFORMAT_QUARTER (2)
#define VFORMAT_EIGTH (3)
#define VFORMAT_SIXTEENTH (4)
//RJA adding size h and layout h
#define BITMAP_SIZE_H(width,height) ((41UL<<24)|(((width)&3UL)<<2)|(((height)&3UL)<<0))
#define BITMAP_LAYOUT_H(linestride,height) ((40UL<<24)|(((linestride)&3UL)<<2)|(((height)&3UL)<<0))
//RJA adding translateX and translateY
#define VERTEX_TRANSLATE_X(x) ((0x2b<<24)|(x<<0))
#define VERTEX_TRANSLATE_Y(y) ((0x2c<<24)|(y<<0))
// Non FTDI Helper Macros
#define MAKE_COLOR(r,g,b) (( r << 16) | ( g << 8) | (b))
// Global Variables
//extern uint16_t FifoWriteLocation; //RJA
// Function Prototypes
void FT81x_Init(void);
void Eve_Reset(void);
void HostCommand(uint8_t HostCommand);
void wr32(uint32_t address, uint32_t parameter);
void wr16(uint32_t, uint16_t parameter);
void wr8(uint32_t, uint8_t parameter);
uint8_t rd8(uint32_t RegAddr);
uint16_t rd16(uint32_t RegAddr);
uint32_t rd32(uint32_t RegAddr);
void Send_CMD(uint32_t data);
void UpdateFIFO(void);
uint8_t Cmd_READ_REG_ID(void);
// Widgets and other significant screen objects
void Cmd_Slider(uint16_t x, uint16_t y, uint16_t w, uint16_t h, uint16_t options, uint16_t val, uint16_t range);
void Cmd_Spinner(uint16_t x, uint16_t y, uint16_t style, uint16_t scale);
void Cmd_Gauge(uint16_t x, uint16_t y, uint16_t r, uint16_t options, uint16_t major, uint16_t minor, uint16_t val, uint16_t range);
void Cmd_Dial(uint16_t x, uint16_t y, uint16_t r, uint16_t options, uint16_t val);
void Cmd_Track(uint16_t x, uint16_t y, uint16_t w, uint16_t h, uint16_t tag);
void Cmd_Number(uint16_t x, uint16_t y, uint16_t font, uint16_t options, uint32_t num);
void Cmd_Gradient(uint16_t x0, uint16_t y0, uint32_t rgb0, uint16_t x1, uint16_t y1, uint32_t rgb1);
void Cmd_AnimDraw(int8_t AnimID);
void Cmd_AnimDrawFrame(uint32_t addr, uint16_t Xpos, uint16_t Ypos, uint8_t Frame);
void Cmd_Button(uint16_t x, uint16_t y, uint16_t w, uint16_t h, uint16_t font, uint16_t options, const char* str);
void Cmd_Text(uint16_t x, uint16_t y, uint16_t font, uint16_t options, const char* str);
void Cmd_SetBitmap(uint32_t addr, uint16_t fmt, uint16_t width, uint16_t height);
void Cmd_Memcpy(uint32_t dest, uint32_t src, uint32_t num);
void Cmd_GetPtr(void);
void Cmd_GradientColor(uint32_t c);
void Cmd_FGcolor(uint32_t c);
void Cmd_BGcolor(uint32_t c);
void Cmd_Translate(uint32_t tx, uint32_t ty);
void Cmd_Rotate(uint32_t a);
void Cmd_SetRotate(uint32_t rotation);
void Cmd_Scale(uint32_t sx, uint32_t sy);
void Cmd_Calibrate(uint32_t result);
bool FlashAttach(void);
bool FlashDetach(void);
bool FlashFast(void);
bool FlashErase(void);
void Calibrate_Manual(uint16_t Width, uint16_t Height, uint16_t V_Offset, uint16_t H_Offset);
uint16_t CoProFIFO_FreeSpace(void);
void Wait4CoProFIFO(uint32_t room);
bool Wait4CoProFIFOEmpty(void);
void StartCoProTransfer(uint32_t address, uint8_t reading);
void CoProWrCmdBuf(const uint8_t* buffer, uint32_t count);
void LoadFile(uint32_t src, uint32_t dest, uint32_t num);
uint32_t WriteBlockRAM(uint32_t Add, const uint8_t* buff, uint32_t count);
int32_t CalcCoef(int32_t Q, int32_t K);
//Here starts stuff from process.h
uint32_t Load_JPG(uint32_t BaseAdd, uint32_t Options, char* filename);
//Defines for fonts
#define ROM_FONTROOT 0x2FFFFC
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//Add in the low level code here
#include "Antares.c"
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
int w = HSIZE;
int h = VSIZE;
byte vxf; // Vertex Format
#define F16(x) ((int32_t)((x) * 65536L))
uint32_t loadptr;
void begin()
{//Initialize EVE, make initial display list, and start another
_setbaud(_BAUD); //we are using a faster baud (2000000 bps) to speed this up
printf("ftinit..\n");
FT81x_Init();
//Make inital display list the prime swap()
//Cmd_SetBase(10);
Send_CMD(CMD_DLSTART); // Start a new display list
ClearColorRGB(0, 0, 0);
Clear();
swap();
//get filesystem ready
#if defined(USE_SD)
mount("/files", _vfs_open_sdcard());
chdir("/files");
#elif defined(USE_HOST)
mount("/files", _vfs_open_host());
chdir("/files");
#else
#warning no file system specified, I hope you are compiling for PC
#endif
}
void Clear()
{// Clear the screen and the current display list
Send_CMD(CLEAR(1, 1, 1));
}
void ClearColorRGB(int r, int g, int b)
{ // Determine the clear screen color
Send_CMD(CLEAR_COLOR_RGB(r, g, b));
}
void ClearColorRGB24(int RGBQUAD)
{ // Determine the clear screen color
Send_CMD(CLEAR_COLOR_RGB24(RGBQUAD));
}
void swap()
{//end and start this display list and then start another
Send_CMD(DISPLAY()); // End the display list
Send_CMD(CMD_SWAP); // Swap commands into RAM
UpdateFIFO(); // Trigger the CoProcessor to start processing the FIFO
Wait4CoProFIFOEmpty(); // wait here until the coprocessor has read and executed every pending command.
Send_CMD(CMD_DLSTART); // Start a new display list
}
void cmd_text(uint16_t x, uint16_t y, uint16_t font, uint16_t options, const char* str)
{//draw text
Cmd_Text(x, y, font, options, str);
}
void ColorRGB(byte red, byte green, byte blue)
{//change color
Send_CMD(COLOR_RGB(red, green, blue));
}
void ColorRGB24(int RGBQUAD)
{//change color
Send_CMD(COLOR_RGB24(RGBQUAD));
}
void PointSize(uint16_t size)
{// set point size to DotSize pixels. Points = (pixels x 16)
Send_CMD(POINT_SIZE(size));
}
void Begin(byte prim)
{// start drawing point
Send_CMD(BEGIN(prim));
}
void Tag(byte s)
{// Tag the blue dot with a touch ID
Send_CMD(TAG(s));
}
void Vertex2ii(uint16_t x, uint16_t y)//, byte handle, byte cell) //RJA: Note Gameduino does not apper to use handle and cell parameters...
{// place point
Send_CMD(VERTEX2II(x, y, 0, 0));// handle, cell));
}
void Vertex2ii3(uint16_t x, uint16_t y, byte handle)
{// place point
Send_CMD(VERTEX2II(x, y, handle, 0));
}
void Vertex2ii4(uint16_t x, uint16_t y, byte handle, byte cell)
{// place point
Send_CMD(VERTEX2II(x, y, handle, cell));
}
void End(void)
{// end drawing
Send_CMD(END());
}
// convert integer pixels to subpixels
#define PIXELS(x) (int)((x) * 16)
typedef struct xyStruct {
int x, y;
//void set(int _x, int _y);
//void rmove(int distance, int angle);
//int angleto(class xy& other);
void draw(byte offset)
{//RJA Special class-like construct in FlexC
Send_CMD(VERTEX2F(x - PIXELS(offset), y - PIXELS(offset)));
}
void set(int _x, int _y)
{
x = _x;
y = _y;
}
//void rotate(int angle);
//int onscreen(void);
//class xy operator<<=(int d);
//void LeftShiftEquals(int d);
//class xy operator+=(class xy &other);
//void PlusEquals(class xy& other);
//class xy operator-=(class xy &other);
//void MinusEquals(class xy& other);
//long operator*(class xy &other);
//int Times(class xy& other);
//class xy operator*=(int);
//void TimesEquals(int s);
//int nearer_than(int distance, class xy& other);
} xy;
struct {
uint16_t track_tag;
uint16_t track_val;
uint16_t rz;
uint16_t __dummy_1;
int16_t tag_y;
int16_t tag_x;
uint8_t tag;
uint8_t ptag;
uint8_t touching;
int16_t x;
int16_t y;
xy xytouch;
} inputs;
void get_inputs()
{//TODO: Fix this when have touchscreen
}
uint32_t BMPBaseAdd = RAM_G + 0x00000UL; // Hard-coded Address lacks panache
uint32_t load(char* filename)
{
return Load_JPG(BMPBaseAdd, 0, filename); // Load a bitmap into RAM_G
}
uint32_t rseed = 0x77777777;
void seed(uint16_t n)
{
rseed = n ? n : 7;
}
uint16_t random()
{
rseed ^= rseed << 2;
rseed ^= rseed >> 5;
rseed ^= rseed << 1;
return rseed;
}
uint16_t random1(uint16_t n)
{//RJA with one parameter
uint16_t p = random();
if (n == (n & -n))
return p & (n - 1);
return (((uint32_t) p) * n) >> 16;
}
uint16_t random2(uint16_t n0, uint16_t n1)
{//RJA with two parameters
return n0 + random1(n1 - n0);
}
void ColorA(byte alpha)
{
cI((16UL << 24) | ((alpha & 255L) << 0));
}
void cI(int cmd)
{
Send_CMD(cmd);
}
void Vertex2f(int16_t x, int16_t y)
{
// x = int(16 * x);
// y = int(16 * y);
cI((1UL << 30) | ((x & 32767L) << 15) | ((y & 32767L) << 0));
}
// 'instrument' argument to GD.play()
#define SILENCE 0x00
#define SQUAREWAVE 0x01
#define SINEWAVE 0x02
#define SAWTOOTH 0x03
#define TRIANGLE 0x04
#define BEEPING 0x05
#define ALARM 0x06
#define WARBLE 0x07
#define CAROUSEL 0x08
#define PIPS(n) (0x0f + (n))
#define HARP 0x40
#define XYLOPHONE 0x41
#define TUBA 0x42
#define GLOCKENSPIEL 0x43
#define ORGAN 0x44
#define TRUMPET 0x45
#define PIANO 0x46
#define CHIMES 0x47
#define MUSICBOX 0x48
#define BELL 0x49
#define CLICK 0x50
#define SWITCH 0x51
#define COWBELL 0x52
#define NOTCH 0x53
#define HIHAT 0x54
#define KICKDRUM 0x55
#define POP 0x56
#define CLACK 0x57
#define CHACK 0x58
#define MUTE 0x60
#define UNMUTE 0x61
void play(uint8_t instrument, uint8_t note) {
wr16(REG_SOUND, (note << 8) | instrument);
wr(REG_PLAY, 1);
}
void wr(uint32_t address, uint8_t parameter)
{
wr8(address, parameter);
}
void delay(int ms)
{//Arduino has this in milliseconds
usleep(ms * 1000);
}
// Generated by mk_bsod.py. Blue screen with 'ERROR' text
static uint8_t __bsod[48] = {
0, 255, 255, 255, 96, 0, 0, 2, 7, 0, 0, 38, 12, 255, 255, 255, 240, 0,
90, 0, 31, 0, 0, 6, 67, 111, 112, 114, 111, 99, 101, 115, 115, 111,
114, 32, 101, 120, 99, 101, 112, 116, 105, 111, 110, 0, 0, 0
};
static uint8_t __bsod_815[56] = {
0, 255, 255, 255, 96, 0, 0, 2, 7, 0, 0, 38, 12, 255, 255, 255, 240, 0,
136, 0, 28, 0, 0, 22, 67, 111, 112, 114, 111, 99, 101, 115, 115, 111,
114, 32, 101, 120, 99, 101, 112, 116, 105, 111, 110, 58, 10, 10, 37,
115, 0, 0, 0, 0, 0, 0
};
static uint8_t __bsod_badfile[44] = {
0, 255, 255, 255, 96, 0, 0, 2, 7, 0, 0, 38, 12, 255, 255, 255, 240, 0,
90, 0, 29, 0, 0, 6, 67, 97, 110, 110, 111, 116, 32, 111, 112, 101,
110, 32, 102, 105, 108, 101, 58, 0, 0, 0
};
void safeload(char* filename)
{
if (!Load_File(filename)) {// Load_File(0,filesize,filename)){ //load(filename)) {
__end();
begin();
copy(__bsod_badfile, sizeof(__bsod_badfile));
cmd_text(240, 190, 29, OPT_CENTER, filename);
swap();
for (;;);
}
}
typedef struct {
byte handle;
uint16_t w, h;
uint16_t size;
} shape_t;
void copy(const uint8_t* src, int count)
{
CoProWrCmdBuf(src, count);
}
byte cprim; // current primitive
void cmd_gradient(int16_t x0, int16_t y0, uint32_t rgb0, int16_t x1, int16_t y1, uint32_t rgb1)
{
Cmd_Gradient(x0, y0, rgb0, x1, y1, rgb1);
cprim = 0xff;
}
void BlendFunc(byte src, byte dst)
{
cI((11UL << 24) | ((src & 7L) << 3) | ((dst & 7L) << 0));
}
#define ZERO 0
#define ONE 1
#define SRC_ALPHA 2
#define DST_ALPHA 3
#define ONE_MINUS_SRC_ALPHA 4
#define ONE_MINUS_DST_ALPHA 5
void RestoreContext(void) {
cI((35UL << 24));
}
//send commands from a file
uint32_t Load_File(char* filename)
{
uint32_t Remaining;
uint16_t ReadBlockSize = 0;
// Open the file on SD card by name
FILE* f = fopen(filename, "rb");
if (!f)
{
Log("%s not open\n", filename);
fclose(f);
return false;
}
//printf("copying data to eve...\n");
int n;
while ((n = fread(LogBuf, 1, 1000, f)) > 0) //RJA we seem to have a limit somewhere between 1000 and 2000
{
n = 4*((n + 3) / 4);
CoProWrCmdBuf(LogBuf, n);
}
fclose(f);
//printf("copy complete.\n");
Wait4CoProFIFOEmpty(); // wait here until the coprocessor has read and executed every pending command.
return true;
}
// *** CoProWrCmdBuf() - Transfer a buffer into the CoPro FIFO as part of an ongoing command operation ***********
void CoProWrCmdBuf2(const uint8_t* buff, uint32_t count)
{
uint32_t TransferSize = 0;
int32_t Remaining = count; // signed
do {
// Here is the situation: You have up to about a megabyte of data to transfer into the FIFO
// Your buffer is LogBuf - limited to 64 bytes (or some other value, but always limited).
// You need to go around in loops taking 64 bytes at a time until all the data is gone.
//
// Most interactions with the FIFO are started and finished in one operation in an obvious fashion, but
// here it is important to understand the difference between Eve RAM registers and Eve FIFO. Even though
// you are in the middle of a FIFO operation and filling the FIFO is an ongoing task, you are still free
// to write and read non-FIFO registers on the Eve chip.
//
// Since the FIFO is 4K in size, but the RAM_G space is 1M in size, you can not, obviously, send all
// the possible RAM_G data through the FIFO in one step. Also, since the Eve is not capable of updating
// it's own FIFO pointer as data is written, you will need to intermittently tell Eve to go process some
// FIFO in order to make room in the FIFO for more RAM_G data.
Wait4CoProFIFO(WorkBuffSz); // It is reasonable to wait for a small space instead of firing data piecemeal
if (Remaining > WorkBuffSz) // Remaining data exceeds the size of our buffer
TransferSize = WorkBuffSz; // So set the transfer size to that of our buffer
else
{
TransferSize = Remaining; // Set size to this last dribble of data
TransferSize = (TransferSize + 3) & 0xFFC; // 4 byte alignment
}
//TransferSize = count;
StartCoProTransfer(FifoWriteLocation + RAM_CMD, false);// Base address of the Command Buffer plus our offset into it - Start SPI transaction
SPI_WriteBuffer((uint8_t*)buff, TransferSize); // write the little bit for which we found space
buff += TransferSize; // move the working data read pointer to the next fresh data
FifoWriteLocation = (FifoWriteLocation + TransferSize) % FT_CMD_FIFO_SIZE;
SPI_Disable(); // End SPI transaction with the FIFO
wr16(REG_CMD_WRITE + RAM_REG, FifoWriteLocation); // Manually update the write position pointer to initiate processing of the FIFO
Remaining -= TransferSize; // reduce what we want by what we sent
} while (Remaining > 0); // keep going as long as we still want more
}
void BitmapSize(byte filter, byte wrapx, byte wrapy, uint16_t width, uint16_t height)
{
Send_CMD(BITMAP_SIZE(filter, wrapx, wrapy, width, height));
}
void BitmapHandle(byte handle)
{
Send_CMD(BITMAP_HANDLE(handle));
}
void ColorMask(byte r, byte g, byte b, byte a) {
Send_CMD((32UL << 24) | ((r & 1L) << 3) | ((g & 1L) << 2) | ((b & 1L) << 1) | ((a & 1L) << 0));
}
void cmd_translate(uint32_t tx, uint32_t ty)
{
Cmd_Translate(tx, ty);
}
void cmd_scale(uint32_t sx, uint32_t sy)
{
Cmd_Scale(sx, sy);
}
void cmd_setmatrix(void) {
Send_CMD(CMD_SETMATRIX);
}
void LineWidth(uint16_t width) {
Send_CMD((14UL << 24) | ((width & 4095L) << 0));
}
void cmd_rotate(uint32_t a)
{
Cmd_Rotate(a);
}
typedef struct BitmapStruct {
xy size, center;
uint32_t source;
uint16_t format;
int8_t handle;
//void fromtext(int font, const char* s);
//void fromfile(const char* filename, int format = 7);
//void bind(uint8_t handle);
//void wallpaper();
//void draw(int x, int y, int16_t angle = 0);
//void draw(const class xy& pos, int16_t angle = 0);
//void defaults(uint8_t f);
//void setup(void);
} Bitmap;
#define KEEP 1
#define REPLACE 2
#define INCR 3
#define DECR 4
#define INVERT 5
#define NEVER 0
#define LESS 1
#define LEQUAL 2
#define GREATER 3
#define GEQUAL 4
#define EQUAL 5
#define NOTEQUAL 6
#define ALWAYS 7
typedef struct PolyStruct {
int x0, y0, x1, y1;
int x[8], y[8];
byte n;
int w; //RJA added these locally as FlexSpin does not recognize global variables in this "class"
int h;
byte vxf; // Vertex Format
void restart() {
n = 0;
x0 = (1 << vxf) * w;
x1 = 0;
y0 = (1 << vxf) * h;
y1 = 0;
}
void perim() {
for (byte i = 0; i < n; i++)
Vertex2f(x[i], y[i]);
Vertex2f(x[0], y[0]);
}
void begin() {
restart();
ColorMask(0, 0, 0, 0);
StencilOp(KEEP, INVERT);
StencilFunc(ALWAYS, 255, 255);
}
void v(int _x, int _y) {
x0 = min(x0, _x >> vxf);
x1 = max(x1, _x >> vxf);
y0 = min(y0, _y >> vxf);
y1 = max(y1, _y >> vxf);
x[n] = _x;
y[n] = _y;
n++;
}
void paint() {
x0 = max(0, x0);
y0 = max(0, y0);
x1 = min((1 << vxf) * w, x1);
y1 = min((1 << vxf) * h, y1);
ScissorXY(x0, y0);
ScissorSize(x1 - x0 + 1, y1 - y0 + 1);