forked from RudolphRiedel/FT800-FT813
-
Notifications
You must be signed in to change notification settings - Fork 0
/
EVE_commands.c
3877 lines (2993 loc) · 112 KB
/
EVE_commands.c
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
/*
@file EVE_commands.c
@brief contains FT8xx / BT8xx functions
@version 4.0
@date 2020-04-13
@author Rudolph Riedel
@section info
This file needs to be renamed to EVE_command.cpp for use with Arduino.
At least für ATSAM I had the best result with -O2.
The c-standard is C99.
@section LICENSE
MIT License
Copyright (c) 2016-2020 Rudolph Riedel
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"),
to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute,
sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@section History
2.1
- removed the REG_ROTATE line from EVE_init()
- simplified EVE_busy() slightly
- implemented EVE_cmd_mediafifo(), EVE_cmd_setrotate(), EVE_cmd_setbitmap() (FT81x)
2.2
- moved hardware abstraction functions over to EVE_config.c
2.3
- changes to this header
2.3
- added "EVE_cmdWrite(EVE_CLKINT);" to top of EVE_init() to switch easier
between displays with and without crystal populated
note: need to add a define for internal/external clock to
- added a EVE_get_cmdoffset() call to the end of EVE_init() as it must be called
after init anyways
2.4
- added a few lines in EVE_init() for the new config define EVE_HAS_CRYSTAL
- EVE_init() does a timeout now instead of an endless loop when waiting for the FT8xx to complete
it's power-on selftest and returns 0x00 in case of failure'
- added EVE_cmd_romfont() (FT81x only)
- added millis option to EVE_cmd_clock()
- switched to standard-C compliant comment-style
2.5
- added EVE_memWrite_flash_buffer()
- modified EVE_cmd_loadimage() to ignore data when EVE_OPT_MEDIAFIFO is given (FT81x only)
2.6
- deleted a "#define EVE_HAS_CRYSTAL 0" line from EVE_init() which should have been long gone...
2.7
- modified EVE_cmd_loadimage() to load bigger files in chunks of 4000
3.0
- renamed from FT800_commands.c to EVE_commands.c
- changed FT_ prefixes to EVE_
- changed ft800_ prefixes to EVE_
- removed test-function EVE_cmd_loadimage_mf()
- added while (EVE_busy()); to the end of EVE_cmd_execute()
- removed while (EVE_busy()); from EVE_cmd_loadimage()
3.1
- added EVE_cmd_setfont() and EVE_cmd_setfont2() as pointed out missing by Rafael Drzewiecki
3.2
- Bugfix: EVE_cmd_interrupt() was using CMD_SNAPSHOT instead of CMD_INTERRUPT
- removed several functions for commands that do not need a function of their own:
EVE_cmd_stop(), EVE_cmd_loadidentity(), EVE_cmd_setmatrix(), EVE_cmd_screensaver(),
EVE_cmd_logo(), EVE_cmd_coldstart()
These all do not have any arguments and can be used with EVE_cmd_dl(), for example:
EVE_cmd_dl(CMD_SCREENSAVER);
EVE_cmd_dl(CMD_SETMATRIX);
- added EVE_cmd_snapshot2()
- added EVE_cmd_setscratch()
3.3
- implemented EVE_cmd_memcrc(), EVE_cmd_getptr(), EVE_cmd_regread(), EVE_cmd_getprops()
3.4
- implemented functions EVE_start_cmd_burst() and EVE_end_cmd_burst()
3.5
- Bugifx: EVE_cmd_setbase() was incrementing the command-offset by 12 instead of 4
3.6
- Bugifix: EVE_cmd_getptr() was using CMD_MEMCRC instead of CMD_GETPTR
3.7
- Added EVE_cmd_start(), a non-blocking variant of EVE_cmd_execute() to be used at the end of a display-list update.
Thanks for pointing out that oversight to user "Peter" of Mikrocontroller.net!
3.8
- Added setting of REG_CSPRED to EVE_init() as new parameter, some Matrix Orbital modules use '0' instead of the reset-default '1'.
3.9
- Added patching of the touch-interface for GT911 to EVE_init() if required by the module attached
- simplified EVE_init() a bit
- some house-keeping, fixing typos in comments left and right
3.10
- EVE_cmd_inflate() supports binaries >4k now and does not need to be executed anymore
3.11
- added fault-detection and co-processor reset to EVE_busy(), this allows the FT8xx to continue to work even after beeing supplied with bad image data for example
3.12
- changed the way EVE_HAS_CRYSTAL works
- added special treatment for switching on and off the backlight in EVE_init() for ADAM101 modules.
- default backlight value after EVE_init() is 25% now
3.13
- divided functions into utility and display-list groups, for sync transfers and async transfers
- changed #ifdef to #if defined for consistency
- changed all spi_transmit() calls in the display-list functions to spi_transmit_async() calls, preparing for DMA display-list buffer transfer
4.0
- renamed from EVE_commands.c to EVE_commands.c
- changed FT8_ prefixes to EVE_
- apparently BT815 supports Goodix touch-controller directly, so changed EVE_init() accordingly
- added EVE_cmd_flashsource()
- added EVE_init_flash() - empty for now
- added EVE_cmd_flashwrite(), EVE_cmd_flashread(), EVE_cmd_flashupdate(), EVE_cmd_flashfast(), EVE_cmd_flashspitx(), EVE_cmd_flashspirx()
- changed block_transfer() that is used by EVE_cmd_inflate() and EVE_cmd_loadimage() to transfer the data in chunks of
a maximum of 3840 bytes instead of 4000 bytes.
The new EVE_cmd_flashwrite() uses block_transfer() as well and it needs the data in multiples of 256 bytes.
Breaking the data down to any number should be ok, as long as the total is a multiple of 256 - but better safe than sorry...
- Bugfix, sort of: in order to add padding bytes for 4-byte alignment spi_flash_write() was reading up to 3 bytes past the supplied buffer, now 1, 2 or 3 zero-bytes are send
- extended the maximum timeout in EVE_init() to 400ms as at least according to the datasheets "The boot-up may take up to 300ms to complete"
- tried to fill in EVE_init_flash() - nothing to test it with, yet
- added DMA
- reworked all commands that support burst to use spi_transmit() in non burst mode and spi_transmit_async() when burst is aktive
- added a conditional reset to the init for the BT816 test-config
- implemented EVE_cmd_inflate2()
- made EVE_cmd_loadimage() aware of EVE_OPT_FLASH when compiled for BT81x
- implemented EVE_cmd_rotatearound(), EVE_cmd_animstart(), EVE_cmd_animstop(), EVE_cmd_animxy(), EVE_cmd_animdraw(),
EVE_cmd_animframe(), EVE_cmd_gradienta(), EVE_cmd_fillwidth() and EVE_cmd_appendf()
- upgraded EVE_get_touch_tag() to multi-touch
- made a few changes to EVE_write_string(), the char * is cast into a uint8_t pointer now since regardless what the string is encoded like
it needs to be send over SPI as a sequence of bytes
also it will leave the loop now after 249 bytes without detecting a zero to terminate the string
- sped up EVE_write_string() at the cost of a few bytes more code by moving the if(cmd_burst) out of the loops
- broke up a potentially endless loop at the end of EVE_init() - it had close to zero chance to fail this far through the init and I never saw it fail
- expanded EVE_cmdWrite() from command only to command+parameter
- EVE_init() sets BT81x to 72MHz now
- sped up EVE_cmd_dl() for burst operations by avoiding a call to EVE_start_cmd()
- sped up EVE_cmd_text() and EVE_cmd_number() for burst operations a little by avoiding a call to EVE_start_cmd()
- removed a redundant #include "EVE_config.h", EVE.h already includes it
- changed EVE_cmd_getptr(), it includes execution now and directly returns the end memory address of data inflated by EVE_cmd_inflate()
- changed EVE_cmd_memcrc(), it includes execution now and directly returns the calculated crc32
- changed EVE_cmd_regread(), it includes execution now and directly returns the 32 bit value
- rewrote EVE_cmd_getprops(), it returns a struct now with pointer, width and height
- rewrote EVE_cmd_getmatrix(), it returns a struct now with matrix coefficent a...f
- added EVE_cmd_text_var() after struggeling with varargs, this function adds a single paramter for string conversion if EVE_OPT_FORMAT is given
- "optimized" EVE_init() to only read REG_ID in the loop and to use DELAY_MS(1); before reading REG_ID
- added waiting for REG_CPURESET to be 0x00 to EVE_init() to follow the initialization sequence more strictly, turned out that the touch-controller needs 10+ms extra
- added updating of REG_FREQUENCY to 72MHz for BT81x to EVE_init(), the programming guide states that it must be updated if the hosts selects an alternative frequency
- rephrased the comment for the meta-commands into a warning and put it in front of each function, do not use these functions for several objects at once
- changed EVE_cmd_text_var() to a varargs function with the number of arguments as additional argument
- added EVE_cmd_button_var() and EVE_cmd_toggle_var() functions
- added EVE_calibrate_manual()
- removed the second updating of REG_FREQUENCY for BT81x in EVE_init() that I overlooked earlier
- added a couple lines of comments to the EVE3 flash commands
- reworked EVE_busy() to match the coprocessor fault recovery for BT81x as described in the BT81x programming guide
- added EVE_cmd_flasherase(), EVE_cmd_flashattach(), EVE_cmd_flashdetach() and EVE_cmd_flashspidesel()
- sent it thru Cppcheck and removed a couple of "issues" with severity "style"
- bugifx: EVE_cmd_flasherase(), EVE_cmd_flashattach(), EVE_cmd_flashdetach() and EVE_cmd_flashspidesel() were missing a EVE_cs_clear();
- changed block_transfer() to use 32bit for the number of bytes to be transferred
- minor housekeeping, no functional changes
- Bugfix: EVE_get_touch_tag() failed to compile for FT80x as there is only one REG_TOUCH_TAG
- removed include for "EVE_target.h" since "EVE.h" already includes it now
- changed EVE_cmd_getprops() again, inspired by BRTs AN_025, changed the name to EVE_LIB_GetProps() and got rid of the returning data-structure
- replaced EVE_cmd_getmatrix() with an earlier implementation again, looks like it is supposed to write, not read.
- added function EVE_color_rgb()
- added a fixed 40ms delay in EVE_init() between ACTIVE and the first reading of 0x7c as a compromise to comply with AN033 V1.2
*/
#include "EVE.h"
#if defined (BT81X_ENABLE)
#include <stdarg.h>
#endif
/* EVE Memory Commands - used with EVE_memWritexx and EVE_memReadxx */
#define MEM_WRITE 0x80 /* EVE Host Memory Write */
#define MEM_READ 0x00 /* EVE Host Memory Read */
volatile uint16_t cmdOffset = 0x0000; /* offset for the 4k co-processor FIFO */
volatile uint8_t cmd_burst = 0; /* flag to indicate cmd-burst is active */
void EVE_cmdWrite(uint8_t command, uint8_t parameter)
{
EVE_cs_set();
spi_transmit(command);
spi_transmit(parameter);
spi_transmit(0x00);
EVE_cs_clear();
}
uint8_t EVE_memRead8(uint32_t ftAddress)
{
uint8_t ftData8;
EVE_cs_set();
spi_transmit((uint8_t)(ftAddress >> 16) | MEM_READ); /* send Memory Write plus high address byte */
spi_transmit((uint8_t)(ftAddress >> 8)); /* send middle address byte */
spi_transmit((uint8_t)(ftAddress)); /* send low address byte */
spi_transmit(0x00); /* send dummy byte */
ftData8 = spi_receive(0x00); /* read data byte by sending another dummy byte */
EVE_cs_clear();
return ftData8; /* return byte read */
}
uint16_t EVE_memRead16(uint32_t ftAddress)
{
uint16_t ftData16 = 0;
EVE_cs_set();
spi_transmit((uint8_t)(ftAddress >> 16) | MEM_READ); /* send Memory Write plus high address byte */
spi_transmit((uint8_t)(ftAddress >> 8)); /* send middle address byte */
spi_transmit((uint8_t)(ftAddress)); /* send low address byte */
spi_transmit(0x00); /* send dummy byte */
ftData16 = (spi_receive(0x00)); /* read low byte */
ftData16 = (spi_receive(0x00) << 8) | ftData16; /* read high byte */
EVE_cs_clear();
return ftData16; /* return integer read */
}
uint32_t EVE_memRead32(uint32_t ftAddress)
{
uint32_t ftData32= 0;
EVE_cs_set();
spi_transmit((uint8_t)(ftAddress >> 16) | MEM_READ); /* send Memory Write plus high address byte */
spi_transmit((uint8_t)(ftAddress >> 8)); /* send middle address byte */
spi_transmit((uint8_t)(ftAddress)); /* send low address byte */
spi_transmit(0x00); /* send dummy byte */
ftData32 = ((uint32_t)spi_receive(0x00)); /* read low byte */
ftData32 = ((uint32_t)spi_receive(0x00) << 8) | ftData32;
ftData32 = ((uint32_t)spi_receive(0x00) << 16) | ftData32;
ftData32 = ((uint32_t)spi_receive(0x00) << 24) | ftData32; /* read high byte */
EVE_cs_clear();
return ftData32; /* return long read */
}
void EVE_memWrite8(uint32_t ftAddress, uint8_t ftData8)
{
EVE_cs_set();
spi_transmit((uint8_t)(ftAddress >> 16) | MEM_WRITE);
spi_transmit((uint8_t)(ftAddress >> 8));
spi_transmit((uint8_t)(ftAddress));
spi_transmit(ftData8);
EVE_cs_clear();
}
void EVE_memWrite16(uint32_t ftAddress, uint16_t ftData16)
{
EVE_cs_set();
spi_transmit((uint8_t)(ftAddress >> 16) | MEM_WRITE); /* send Memory Write plus high address byte */
spi_transmit((uint8_t)(ftAddress >> 8)); /* send middle address byte */
spi_transmit((uint8_t)(ftAddress)); /* send low address byte */
spi_transmit((uint8_t)(ftData16)); /* send data low byte */
spi_transmit((uint8_t)(ftData16 >> 8)); /* send data high byte */
EVE_cs_clear();
}
void EVE_memWrite32(uint32_t ftAddress, uint32_t ftData32)
{
EVE_cs_set();
spi_transmit((uint8_t)(ftAddress >> 16) | MEM_WRITE); /* send Memory Write plus high address byte */
spi_transmit((uint8_t)(ftAddress >> 8)); /* send middle address byte */
spi_transmit((uint8_t)(ftAddress)); /* send low address byte */
spi_transmit((uint8_t)(ftData32)); /* send data low byte */
spi_transmit((uint8_t)(ftData32 >> 8));
spi_transmit((uint8_t)(ftData32 >> 16));
spi_transmit((uint8_t)(ftData32 >> 24)); /* send data high byte */
EVE_cs_clear();
}
void EVE_memWrite_flash_buffer(uint32_t ftAddress, const uint8_t *data, uint16_t len)
{
uint16_t count;
EVE_cs_set();
spi_transmit((uint8_t)(ftAddress >> 16) | MEM_WRITE);
spi_transmit((uint8_t)(ftAddress >> 8));
spi_transmit((uint8_t)(ftAddress));
len = (len + 3)&(~3);
for(count=0;count<len;count++)
{
spi_transmit(fetch_flash_byte(data+count));
}
EVE_cs_clear();
}
/* Check if the graphics processor completed executing the current command list. */
/* This is the case when REG_CMD_READ matches cmdOffset, indicating that all commands have been executed. */
uint8_t EVE_busy(void)
{
uint16_t cmdBufferRead;
#if defined (EVE_DMA)
if(EVE_dma_busy)
{
return 1;
}
#endif
cmdBufferRead = EVE_memRead16(REG_CMD_READ); /* read the graphics processor read pointer */
if(cmdBufferRead == 0xFFF) /* we have a co-processor fault, make EVE play with us again */
{
#if defined (BT81X_ENABLE)
uint16_t copro_patch_pointer;
uint32_t ftAddress;
copro_patch_pointer = EVE_memRead16(REG_COPRO_PATCH_DTR);
#endif
EVE_memWrite8(REG_CPURESET, 1); /* hold co-processor engine in the reset condition */
EVE_memWrite16(REG_CMD_READ, 0); /* set REG_CMD_READ to 0 */
EVE_memWrite16(REG_CMD_WRITE, 0); /* set REG_CMD_WRITE to 0 */
EVE_memWrite32(REG_CMD_DL, 0); /* reset REG_CMD_DL to 0 as required by the BT81x programming guide, should not hurt FT8xx */
cmdOffset = 0;
EVE_memWrite8(REG_CPURESET, 0); /* set REG_CMD_WRITE to 0 to restart the co-processor engine*/
#if defined (BT81X_ENABLE)
EVE_memWrite16(REG_COPRO_PATCH_DTR, copro_patch_pointer);
DELAY_MS(5); /* just to be safe */
ftAddress = EVE_RAM_CMD + cmdOffset;
EVE_cs_set();
spi_transmit((uint8_t)(ftAddress >> 16) | MEM_WRITE); /* send Memory Write plus high address byte */
spi_transmit((uint8_t)(ftAddress >> 8)); /* send middle address byte */
spi_transmit((uint8_t)(ftAddress)); /* send low address byte */
spi_transmit((uint8_t)(CMD_FLASHATTACH));
spi_transmit((uint8_t)(CMD_FLASHATTACH >> 8));
spi_transmit((uint8_t)(CMD_FLASHATTACH >> 16));
spi_transmit((uint8_t)(CMD_FLASHATTACH >> 24));
spi_transmit((uint8_t)(CMD_FLASHFAST));
spi_transmit((uint8_t)(CMD_FLASHFAST >> 8));
spi_transmit((uint8_t)(CMD_FLASHFAST >> 16));
spi_transmit((uint8_t)(CMD_FLASHFAST >> 24));
EVE_cs_clear();
cmdOffset = 8;
EVE_cs_set();
spi_transmit(MEM_WRITE | 0x30); /* send Memory Write plus high address byte of REG_CMD_WRITE for EVE81x */
spi_transmit(0x20); /* send middle address byte of REG_CMD_WRITE for EVE81x */
spi_transmit(0xfc); /* send low address byte of REG_CMD_WRITE for EVE81x */
spi_transmit((uint8_t)(cmdOffset));
spi_transmit((uint8_t)(cmdOffset >> 8));
EVE_cs_clear();
EVE_memWrite8(REG_PCLK, EVE_PCLK); /* restore REG_PCLK in case it was set to zero by an error */
DELAY_MS(5); /* just to be safe */
#endif
}
if(cmdOffset != cmdBufferRead)
{
return 1;
}
else
{
return 0;
}
}
uint32_t EVE_get_touch_tag(uint8_t num)
{
uint32_t value;
#if defined (EVE_DMA)
if(EVE_dma_busy)
{
return 0; /* just do nothing if a dma transfer is in progress */
}
#endif
switch(num)
{
case 1:
value = EVE_memRead32(REG_TOUCH_TAG); /* read the value for the first touch point */
break;
#if defined (FT81X_ENABLE)
case 2:
value = EVE_memRead32(REG_TOUCH_TAG1);
break;
case 3:
value = EVE_memRead32(REG_TOUCH_TAG2);
break;
case 4:
value = EVE_memRead32(REG_TOUCH_TAG3);
break;
case 5:
value = EVE_memRead32(REG_TOUCH_TAG4);
break;
#endif
default:
value = EVE_memRead32(REG_TOUCH_TAG);
break;
}
return value;
}
void EVE_get_cmdoffset(void)
{
cmdOffset = EVE_memRead16(REG_CMD_WRITE);
}
/* make current value of cmdOffset available while limiting access to that var to the EVE_commands module */
uint16_t EVE_report_cmdoffset(void)
{
return (cmdOffset);
}
void EVE_inc_cmdoffset(uint16_t increment)
{
cmdOffset += increment;
cmdOffset &= 0x0fff;
}
/* order the command co-processor to start processing its FIFO queue and do not wait for completion */
void EVE_cmd_start(void)
{
uint32_t ftAddress;
#if defined (EVE_DMA)
if(EVE_dma_busy)
{
return; /* just do nothing if a dma transfer is in progress */
}
#endif
ftAddress = REG_CMD_WRITE; /* this changes between EVE 80x and 81x, so as a constant at compile-time the compiler should happily optimize away the following bit-shifting */
EVE_cs_set();
spi_transmit((uint8_t)(ftAddress >> 16) | MEM_WRITE); /* send Memory Write plus high address byte */
spi_transmit((uint8_t)(ftAddress >> 8)); /* send middle address byte */
spi_transmit((uint8_t)(ftAddress)); /* send low address byte */
spi_transmit((uint8_t)(cmdOffset)); /* send data low byte */
spi_transmit((uint8_t)(cmdOffset >> 8)); /* send data high byte */
EVE_cs_clear();
}
/* order the command co-processor to start processing its FIFO queue and wait for completion */
void EVE_cmd_execute(void)
{
EVE_cmd_start();
while (EVE_busy());
}
/* begin a co-processor command, this is used for all non-display-list commands */
void EVE_begin_cmd(uint32_t command)
{
uint32_t ftAddress;
ftAddress = EVE_RAM_CMD + cmdOffset;
EVE_cs_set();
spi_transmit((uint8_t)(ftAddress >> 16) | MEM_WRITE); /* send Memory Write plus high address byte */
spi_transmit((uint8_t)(ftAddress >> 8)); /* send middle address byte */
spi_transmit((uint8_t)(ftAddress)); /* send low address byte */
spi_transmit((uint8_t)(command)); /* send data low byte */
/* current commands are 0xffffff00 to ffffff5f, so sending directly 0xff for the upper three bytes could be faster */
/* but as it turned out the code with this "optimization" in place is not a single byte shorter */
spi_transmit((uint8_t)(command >> 8));
spi_transmit((uint8_t)(command >> 16));
spi_transmit((uint8_t)(command >> 24)); /* send data high byte */
EVE_inc_cmdoffset(4);
}
/* co-processor commands that are not used in displays lists, these are no to be used with async transfers */
/* this is meant to be called outside display-list building, does not support cmd-burst */
void EVE_cmd_memzero(uint32_t ptr, uint32_t num)
{
EVE_begin_cmd(CMD_MEMZERO);
spi_transmit((uint8_t)(ptr));
spi_transmit((uint8_t)(ptr >> 8));
spi_transmit((uint8_t)(ptr >> 16));
spi_transmit((uint8_t)(ptr >> 24));
spi_transmit((uint8_t)(num));
spi_transmit((uint8_t)(num >> 8));
spi_transmit((uint8_t)(num >> 16));
spi_transmit((uint8_t)(num >> 24));
EVE_inc_cmdoffset(8);
EVE_cs_clear();
}
/* this is meant to be called outside display-list building, does not support cmd-burst */
void EVE_cmd_memset(uint32_t ptr, uint8_t value, uint32_t num)
{
EVE_begin_cmd(CMD_MEMSET);
spi_transmit((uint8_t)(ptr));
spi_transmit((uint8_t)(ptr >> 8));
spi_transmit((uint8_t)(ptr >> 16));
spi_transmit((uint8_t)(ptr >> 24));
spi_transmit(value);
spi_transmit(0);
spi_transmit(0);
spi_transmit(0);
spi_transmit((uint8_t)(num));
spi_transmit((uint8_t)(num >> 8));
spi_transmit((uint8_t)(num >> 16));
spi_transmit((uint8_t)(num >> 24));
EVE_inc_cmdoffset(12);
EVE_cs_clear();
}
/* this is meant to be called outside display-list building, does not support cmd-burst */
/*
void EVE_cmd_memwrite(uint32_t dest, uint32_t num, const uint8_t *data)
{
EVE_begin_cmd(CMD_MEMWRITE);
spi_transmit((uint8_t)(dest));
spi_transmit((uint8_t)(dest >> 8));
spi_transmit((uint8_t)(dest >> 16));
spi_transmit((uint8_t)(dest >> 24));
spi_transmit((uint8_t)(num));
spi_transmit((uint8_t)(num >> 8));
spi_transmit((uint8_t)(num >> 16));
spi_transmit((uint8_t)(num >> 24));
num = (num + 3)&(~3);
for(count=0;count<len;count++)
{
spi_transmit(pgm_read_byte_far(data+count));
}
EVE_inc_cmdoffset(8+len);
EVE_cs_clear();
}
*/
/* this is meant to be called outside display-list building, does not support cmd-burst */
void EVE_cmd_memcpy(uint32_t dest, uint32_t src, uint32_t num)
{
EVE_begin_cmd(CMD_MEMCPY);
spi_transmit((uint8_t)(dest));
spi_transmit((uint8_t)(dest >> 8));
spi_transmit((uint8_t)(dest >> 16));
spi_transmit((uint8_t)(dest >> 24));
spi_transmit((uint8_t)(src));
spi_transmit((uint8_t)(src >> 8));
spi_transmit((uint8_t)(src >> 16));
spi_transmit((uint8_t)(src >> 24));
spi_transmit((uint8_t)(num));
spi_transmit((uint8_t)(num >> 8));
spi_transmit((uint8_t)(num >> 16));
spi_transmit((uint8_t)(num >> 24));
EVE_inc_cmdoffset(12);
EVE_cs_clear();
}
/* commands for loading image data into FT8xx memory: */
void spi_flash_write(const uint8_t *data, uint16_t len)
{
uint16_t count;
uint8_t padding;
padding = len & 0x03; /* 0, 1, 2 or 3 */
padding = 4-padding; /* 4, 3, 2 or 1 */
padding &= 3; /* 3, 2 or 1 */
for(count=0;count<len;count++)
{
spi_transmit(fetch_flash_byte(data+count));
}
len += padding;
while(padding > 0)
{
spi_transmit(0);
padding--;
}
EVE_inc_cmdoffset(len);
}
void block_transfer(const uint8_t *data, uint32_t len)
{
uint32_t bytes_left;
bytes_left = len;
while(bytes_left > 0)
{
uint32_t block_len;
uint32_t ftAddress;
block_len = bytes_left>3840 ? 3840:bytes_left;
ftAddress = EVE_RAM_CMD + cmdOffset;
EVE_cs_set();
spi_transmit((uint8_t)(ftAddress >> 16) | MEM_WRITE); /* send Memory Write plus high address byte */
spi_transmit((uint8_t)(ftAddress >> 8)); /* send middle address byte */
spi_transmit((uint8_t)(ftAddress)); /* send low address byte */
spi_flash_write(data,block_len);
EVE_cs_clear();
data += block_len;
bytes_left -= block_len;
EVE_cmd_execute();
}
}
/* this is meant to be called outside display-list building, it includes executing the command and waiting for completion, does not support cmd-burst */
void EVE_cmd_inflate(uint32_t ptr, const uint8_t *data, uint16_t len)
{
EVE_begin_cmd(CMD_INFLATE);
spi_transmit((uint8_t)(ptr));
spi_transmit((uint8_t)(ptr >> 8));
spi_transmit((uint8_t)(ptr >> 16));
spi_transmit((uint8_t)(ptr >> 24));
EVE_inc_cmdoffset(4);
EVE_cs_clear();
block_transfer(data, len);
}
#if defined (BT81X_ENABLE)
/* this is meant to be called outside display-list building, it includes executing the command and waiting for completion, does not support cmd-burst */
void EVE_cmd_inflate2(uint32_t ptr, uint32_t options, const uint8_t *data, uint16_t len)
{
EVE_begin_cmd(CMD_INFLATE2);
spi_transmit((uint8_t)(ptr));
spi_transmit((uint8_t)(ptr >> 8));
spi_transmit((uint8_t)(ptr >> 16));
spi_transmit((uint8_t)(ptr >> 24));
spi_transmit((uint8_t)(options));
spi_transmit((uint8_t)(options >> 8));
spi_transmit((uint8_t)(options >> 16));
spi_transmit((uint8_t)(options >> 24));
EVE_inc_cmdoffset(8);
EVE_cs_clear();
if(options == 0) /* direct data, not by Media-FIFO or Flash */
{
block_transfer(data, len);
}
}
#endif
/* this is meant to be called outside display-list building, it includes executing the command and waiting for completion, does not support cmd-burst */
void EVE_cmd_loadimage(uint32_t ptr, uint32_t options, const uint8_t *data, uint16_t len)
{
EVE_begin_cmd(CMD_LOADIMAGE);
spi_transmit((uint8_t)(ptr));
spi_transmit((uint8_t)(ptr >> 8));
spi_transmit((uint8_t)(ptr >> 16));
spi_transmit((uint8_t)(ptr >> 24));
spi_transmit((uint8_t)(options));
spi_transmit((uint8_t)(options >> 8));
spi_transmit((uint8_t)(options >> 16));
spi_transmit((uint8_t)(options >> 24));
EVE_inc_cmdoffset(8);
EVE_cs_clear();
#if defined (BT81X_ENABLE)
if( ((options & EVE_OPT_MEDIAFIFO) == 0) && ((options & EVE_OPT_FLASH) == 0) )/* direct data, neither by Media-FIFO or from Flash */
#elif defined (FT81X_ENABLE)
if((options & EVE_OPT_MEDIAFIFO) == 0) /* direct data, not by Media-FIFO */
#endif
{
block_transfer(data, len);
}
}
#if defined (FT81X_ENABLE)
/* this is meant to be called outside display-list building, does not support cmd-burst */
void EVE_cmd_mediafifo(uint32_t ptr, uint32_t size)
{
EVE_begin_cmd(CMD_MEDIAFIFO);
spi_transmit((uint8_t)(ptr));
spi_transmit((uint8_t)(ptr >> 8));
spi_transmit((uint8_t)(ptr >> 16));
spi_transmit((uint8_t)(ptr >> 24));
spi_transmit((uint8_t)(size));
spi_transmit((uint8_t)(size >> 8));
spi_transmit((uint8_t)(size >> 16));
spi_transmit((uint8_t)(size >> 24));
EVE_inc_cmdoffset(8);
EVE_cs_clear();
}
#endif
/* this is meant to be called outside display-list building, does not support cmd-burst */
void EVE_cmd_interrupt(uint32_t ms)
{
EVE_begin_cmd(CMD_INTERRUPT);
spi_transmit((uint8_t)(ms));
spi_transmit((uint8_t)(ms >> 8));
spi_transmit((uint8_t)(ms >> 16));
spi_transmit((uint8_t)(ms >> 24));
EVE_inc_cmdoffset(4);
EVE_cs_clear();
}
/* this is meant to be called outside display-list building, does not support cmd-burst */
void EVE_cmd_setfont(uint32_t font, uint32_t ptr)
{
EVE_begin_cmd(CMD_SETFONT);
spi_transmit((uint8_t)(font));
spi_transmit((uint8_t)(font >> 8));
spi_transmit((uint8_t)(font >> 16));
spi_transmit((uint8_t)(font >> 24));
spi_transmit((uint8_t)(ptr));
spi_transmit((uint8_t)(ptr >> 8));
spi_transmit((uint8_t)(ptr >> 16));
spi_transmit((uint8_t)(ptr >> 24));
EVE_inc_cmdoffset(8);
EVE_cs_clear();
}
#if defined (FT81X_ENABLE)
/* this is meant to be called outside display-list building, does not support cmd-burst */
void EVE_cmd_setfont2(uint32_t font, uint32_t ptr, uint32_t firstchar)
{
EVE_begin_cmd(CMD_SETFONT2);
spi_transmit((uint8_t)(font));
spi_transmit((uint8_t)(font >> 8));
spi_transmit((uint8_t)(font >> 16));
spi_transmit((uint8_t)(font >> 24));
spi_transmit((uint8_t)(ptr));
spi_transmit((uint8_t)(ptr >> 8));
spi_transmit((uint8_t)(ptr >> 16));
spi_transmit((uint8_t)(ptr >> 24));
spi_transmit((uint8_t)(firstchar));
spi_transmit((uint8_t)(firstchar >> 8));
spi_transmit((uint8_t)(firstchar >> 16));
spi_transmit((uint8_t)(firstchar >> 24));
EVE_inc_cmdoffset(12);
EVE_cs_clear();
}
#endif
#if defined (FT81X_ENABLE)
/* this is meant to be called outside display-list building, does not support cmd-burst */
void EVE_cmd_setrotate(uint32_t r)
{
EVE_begin_cmd(CMD_SETROTATE);
spi_transmit((uint8_t)(r));
spi_transmit((uint8_t)(r >> 8));
spi_transmit((uint8_t)(r >> 16));
spi_transmit((uint8_t)(r >> 24));
EVE_inc_cmdoffset(4);
EVE_cs_clear();
}
#endif
/* this is meant to be called outside display-list building, does not support cmd-burst */
void EVE_cmd_snapshot(uint32_t ptr)
{
EVE_begin_cmd(CMD_SNAPSHOT);
spi_transmit((uint8_t)(ptr));
spi_transmit((uint8_t)(ptr >> 8));
spi_transmit((uint8_t)(ptr >> 16));
spi_transmit((uint8_t)(ptr >> 24));
EVE_inc_cmdoffset(4);
EVE_cs_clear();
}
#if defined (FT81X_ENABLE)
/* this is meant to be called outside display-list building, does not support cmd-burst */
void EVE_cmd_snapshot2(uint32_t fmt, uint32_t ptr, int16_t x0, int16_t y0, int16_t w0, int16_t h0)
{
EVE_begin_cmd(CMD_SNAPSHOT2);
spi_transmit((uint8_t)(fmt));
spi_transmit((uint8_t)(fmt >> 8));
spi_transmit((uint8_t)(fmt >> 16));
spi_transmit((uint8_t)(fmt >> 24));
spi_transmit((uint8_t)(ptr));
spi_transmit((uint8_t)(ptr >> 8));
spi_transmit((uint8_t)(ptr >> 16));
spi_transmit((uint8_t)(ptr >> 24));
spi_transmit((uint8_t)(x0));
spi_transmit((uint8_t)(x0 >> 8));
spi_transmit((uint8_t)(y0));
spi_transmit((uint8_t)(y0 >> 8));
spi_transmit((uint8_t)(w0));
spi_transmit((uint8_t)(w0 >> 8));
spi_transmit((uint8_t)(h0));
spi_transmit((uint8_t)(h0 >> 8));
EVE_inc_cmdoffset(16);
EVE_cs_clear();
}
#endif
/* this is meant to be called outside display-list building, does not support cmd-burst */
void EVE_cmd_track(int16_t x0, int16_t y0, int16_t w0, int16_t h0, int16_t tag)
{
EVE_begin_cmd(CMD_TRACK);
spi_transmit((uint8_t)(x0));
spi_transmit((uint8_t)(x0 >> 8));
spi_transmit((uint8_t)(y0));
spi_transmit((uint8_t)(y0 >> 8));
spi_transmit((uint8_t)(w0));
spi_transmit((uint8_t)(w0 >> 8));
spi_transmit((uint8_t)(h0));
spi_transmit((uint8_t)(h0 >> 8));
spi_transmit((uint8_t)(tag));
spi_transmit((uint8_t)(tag >> 8));
spi_transmit(0);
spi_transmit(0);
EVE_inc_cmdoffset(12);
EVE_cs_clear();
}
/* commands that return values by writing to the command-fifo */
/* note: yes, these are different than the functions in the Programmers Guide from FTDI,
this is because I have no idea why anyone would want to pass "result" as an actual argument to these functions
when this only marks the offset the command-processor is writing to */
/* this is meant to be called outside display-list building, it includes executing the command and waiting for completion, does not support cmd-burst */
/* crc32 = EVE_cmd_memcrc(my_ptr_to_some_memory_region, some_amount_of_bytes); */
uint32_t EVE_cmd_memcrc(uint32_t ptr, uint32_t num)
{
uint16_t offset;
EVE_begin_cmd(CMD_MEMCRC);
spi_transmit((uint8_t)(ptr));
spi_transmit((uint8_t)(ptr >> 8));
spi_transmit((uint8_t)(ptr >> 16));
spi_transmit((uint8_t)(ptr >> 24));
spi_transmit((uint8_t)(num));
spi_transmit((uint8_t)(num >> 8));
spi_transmit((uint8_t)(num >> 16));
spi_transmit((uint8_t)(num >> 24));
spi_transmit(0);
spi_transmit(0);
spi_transmit(0);
spi_transmit(0);
EVE_inc_cmdoffset(8);
offset = cmdOffset;
EVE_inc_cmdoffset(4);
EVE_cs_clear();
EVE_cmd_execute();
return (EVE_memRead32(EVE_RAM_CMD + offset));
}
/* this is meant to be called outside display-list building, it includes executing the command and waiting for completion, does not support cmd-burst */
/* address = EVE_cmd_getpr(); */
uint32_t EVE_cmd_getptr(void)
{
uint16_t offset;
EVE_begin_cmd(CMD_GETPTR);
offset = cmdOffset;
EVE_inc_cmdoffset(4);
EVE_cs_clear();
EVE_cmd_execute();
return (EVE_memRead32(EVE_RAM_CMD + offset));
}
/* this is meant to be called outside display-list building, it includes executing the command and waiting for completion, does not support cmd-burst */
/* regvalue = EVE_cmd_regread(ptr); */
/* this seems to be completely pointless, there is no real use for it outside a display-list since the register could be read directly */
/* and for what purpose would this be implemented to be used in a display list?? */
uint32_t EVE_cmd_regread(uint32_t ptr)