-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEVE_base.cpp
2030 lines (1913 loc) · 88 KB
/
EVE_base.cpp
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
//============================================================================
//
// Low-Level routines for EVE accelerators.
//
// This is a simplified / refactored version of the code in FTDI's AN_275:
//
// http://brtchip.com/wp-content/uploads/Support/Documentation/Application_Notes/ICs/EVE/AN_275_FT800_Example_with_Arduino.pdf
//
// I have added support for the EVE series.
//
// The write offset into the write buffer is passed into and back from
// functions rather than being a global.
//
// In the spirit of AN_275:
//
// An “abstraction layer” concept was explicitly avoided in this
// example. Rather, direct use of the Arduino libraries demonstrates
// the simplicity of sending and receiving data through the FT800
// while producing a graphic output.
//
// My main goal here is to be transparent about what is really happening
// from the high to lowest levels, without obfuscation, while still
// at least giving a nod to good programming practices.
//
// Plus, you probably don't have RAM and flash for all those fancy
// programming layers.
//
// 2020-08-05 Brent A. Crosby / Crystalfontz America, Inc.
// https://www.crystalfontz.com/products/eve-accelerated-tft-displays.php
//---------------------------------------------------------------------------
//This is free and unencumbered software released into the public domain.
//
//Anyone is free to copy, modify, publish, use, compile, sell, or
//distribute this software, either in source code form or as a compiled
//binary, for any purpose, commercial or non-commercial, and by any
//means.
//
//In jurisdictions that recognize copyright laws, the author or authors
//of this software dedicate any and all copyright interest in the
//software to the public domain. We make this dedication for the benefit
//of the public at large and to the detriment of our heirs and
//successors. We intend this dedication to be an overt act of
//relinquishment in perpetuity of all present and future rights to this
//software under copyright law.
//
//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 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.
//
//For more information, please refer to <http://unlicense.org/>
//============================================================================
// Adapted from:
// FTDIChip AN_275 FT800 with Arduino - Version 1.0
//
// Copyright (c) Future Technology Devices International
//
// THIS SOFTWARE IS PROVIDED BY FUTURE TECHNOLOGY DEVICES INTERNATIONAL
// LIMITED "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
// PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL FUTURE TECHNOLOGY
// DEVICES INTERNATIONAL LIMITED BE LIABLE FOR ANY DIRECT, INDIRECT,
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
// NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES LOSS OF USE,
// DATA, OR PROFITS OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
// OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
// EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
// This code is provided as an example only and is not guaranteed by
// FTDI/BridgeTek. FTDI/BridgeTek accept no responsibility for any issues
// resulting from its use. By using this code, the developer of the final
// application incorporating any parts of this sample project agrees to take
// full responsible for ensuring its safe and correct operation and for any
// consequences resulting from its use.
//===========================================================================
#include <Arduino.h>
#include <SPI.h>
#include <stdarg.h>
// Definitions for our circuit board and display.
#include "CFA10118_defines.h"
#if BUILD_SD
#include <SD.h>
#endif
// The very simple EVE library files
#include "EVE_base.h"
#include "EVE_draw.h"
//============================================================================
// Don't call SerPrintFF() directly, use DBG_STAT() or DBG_GEEK() macros.
//
// ref http://playground.arduino.cc/Main/Printf
//
// Example to dump a uint32_t in hex and decimal
// SerPrintFF(F("RAM_G_Unused_Start: 0x%08lX = %lu\n"),RAM_G_Unused_Start,RAM_G_Unused_Start);
// Example to dump a uint16_t in hex and decimal
// SerPrintFF(F("Initial Offset Read: 0x%04X = %u\n"),FWo ,FWo);
void SerPrintFF(const __FlashStringHelper *fmt, ... )
{
char
tmp[128]; // resulting string limited to 128 chars
va_list
args;
va_start(args, fmt );
vsnprintf_P(tmp, 128, (const char *)fmt, args);
va_end (args);
Serial.print(tmp);
}
//============================================================================
void DBG_GEEK_Decode_Flash_Status(uint8_t EVE_flash_status)
{
#if (DEBUG_LEVEL == DEBUG_GEEK)
DBG_GEEK("REG_FLASH_STATUS = 0x%02X = %3d = \"FLASH_STATUS_",EVE_flash_status,EVE_flash_status);
switch(EVE_flash_status)
{
case EVE_FLASH_STATUS_INIT:
DBG_GEEK("INIT\"\n");
break;
case EVE_FLASH_STATUS_DETACHED:
DBG_GEEK("DETACHED\"\n");
break;
case EVE_FLASH_STATUS_BASIC:
DBG_GEEK("BASIC (slow)\"\n");
break;
case EVE_FLASH_STATUS_FULL:
DBG_GEEK("FULL (fast)\"\n");
break;
default:
DBG_GEEK("Error/Unknown\"\n");
break;
}
#endif // (DEBUG_LEVEL == DEBUG_GEEK)
}
//============================================================================
void DBG_GEEK_Decode_FastFlash_Status(uint32_t EVE_fast_flash_result)
{
#if (DEBUG_LEVEL == DEBUG_GEEK)
DBG_GEEK("CMD_FLASHFAST result: 0x%08lX = \"",EVE_fast_flash_result);
switch(EVE_fast_flash_result)
{
case 0x00000000:
DBG_GEEK("success, no error\"\n");
break;
case 0x0000E001:
DBG_GEEK("flash is not supported\"\n");
break;
case 0x0000E002:
DBG_GEEK("no header detected in sector 0\"\n");
break;
case 0x0000E003:
DBG_GEEK("sector 0 data failed integrity check\"\n");
break;
case 0x0000E004:
DBG_GEEK("device/blob mismatch\"\n");
break;
case 0x0000E005:
DBG_GEEK("failed full-speed test\"\n");
break;
default:
DBG_GEEK("invalid result returned\"\n");
break;
}
#endif // (DEBUG_LEVEL == DEBUG_GEEK)
}
//============================================================================
uint8_t Validate_and_Print_Chip_ID(uint32_t Chip_ID)
{
uint8_t
return_value;
//assume success
return_value=0;
//Chip Identification Code: 0x00011108
//First byte should be 0x00
uint8_t
this_byte;
this_byte=(Chip_ID>>24);
if(0x00 != this_byte)
{
DBG_GEEK("Chip ID first byte fail. Expected 0x00, got 0x%02X.\n",this_byte);
//indicate failure
return_value=0;
}
//Second byte should be 0x01
this_byte=(Chip_ID>>16) & 0x000000FFL;
if(0x01 != this_byte)
{
DBG_GEEK("Chip ID second byte fail. Expected 0x01, got 0x%02X.\n",this_byte);
//indicate failure
return_value=0;
}
//Fourth byte should be 0x08
this_byte=Chip_ID & 0x000000FFL;
if(0x08 != this_byte)
{
DBG_GEEK("Chip ID fourth byte fail. Expected 0x08, got 0x%02X.\n",this_byte);
//indicate failure
return_value=0;
}
//Third byte indicates the chip type.
this_byte=(Chip_ID>>8) & 0x000000FFL;
if(this_byte==EVE_DEVICE)
{
DBG_GEEK("Chip ID indicates %s8%02X as expected.\n",EVE_DEVICE<0x14?"FT":"BT",EVE_DEVICE);
}
else
{
DBG_STAT("Unexpected chip if of 0x%02X = %s8%02X, code compiled for %s8%02X\n",
this_byte,
this_byte<0x14?"FT":"BT",this_byte,
EVE_DEVICE<0x14?"FT":"BT",EVE_DEVICE);
return_value=0;
}
return(return_value);
}
//============================================================================
void _EVE_Select_and_Address(uint32_t Address, uint8_t Operation)
{
//Select the EVE
CLR_EVE_CS_NOT;
// Send Operation plus high address byte
SPI.transfer((uint8_t)(Address >> 16) | Operation);
// Send middle address byte
SPI.transfer((uint8_t)(Address >> 8));
// Send low address byte
SPI.transfer((uint8_t)(Address));
}
//============================================================================
void EVE_Command_Write(uint8_t Command, uint8_t Parameter)
{
//Select the EVE
CLR_EVE_CS_NOT;
// Send 1st (command) byte
SPI.transfer(Command);
// Send 2nd (parameter) byte
SPI.transfer(Parameter);
// Send 3rd (always 0)byte
SPI.transfer(0);
//End the transaction.
SET_EVE_CS_NOT;
}
//============================================================================
void _EVE_send_32(uint32_t Data)
{
// Send data low byte
SPI.transfer((uint8_t)(Data));
// Send data mid-low byte
SPI.transfer((uint8_t)(Data >> 8));
// Send data mid-high byte
SPI.transfer((uint8_t)(Data >> 16));
// Send data high byte
SPI.transfer((uint8_t)(Data >> 24));
}
//============================================================================
void EVE_REG_Write_8(uint32_t REG_Address, uint8_t ftData8)
{
//Select the EVE and send the 24-bit address and operation flag.
_EVE_Select_and_Address(REG_Address, EVE_MEM_WRITE);
// Send data byte
SPI.transfer(ftData8);
//De-select the EVE
SET_EVE_CS_NOT;
}
//============================================================================
void EVE_REG_Write_16(uint32_t REG_Address, uint16_t ftData16)
{
//Select the EVE and send the 24-bit address and operation flag.
_EVE_Select_and_Address(REG_Address, EVE_MEM_WRITE);
// Send data low byte
SPI.transfer((uint8_t)(ftData16));
// Send data high byte
SPI.transfer((uint8_t)(ftData16 >> 8));
//De-select the EVE
SET_EVE_CS_NOT;
}
//============================================================================
void EVE_REG_Write_32(uint32_t REG_Address, uint32_t ftData32)
{
//Select the EVE and send the 24-bit address and operation flag.
_EVE_Select_and_Address(REG_Address, EVE_MEM_WRITE);
//Send the uint32_t ftData32
_EVE_send_32(ftData32);
//De-select the EVE
SET_EVE_CS_NOT;
}
//----------------------------------------------------------------------------
uint16_t EVE_Cmd_Dat_0(uint16_t FWol,
uint32_t command)
{
//Combine Address_offset into then select the EVE
//and send the 24-bit address and operation flag.
_EVE_Select_and_Address(EVE_RAM_CMD|FWol,EVE_MEM_WRITE);
//Send the uint32_t data
_EVE_send_32(command);
//De-select the EVE
SET_EVE_CS_NOT;
//Increment address offset modulo 4096 and return it
return((FWol+4)&0xFFF);
}
//----------------------------------------------------------------------------
uint16_t EVE_Cmd_Dat_1(uint16_t FWol,
uint32_t command,uint32_t data0)
{
//Combine Address_offset into then select the EVE
//and send the 24-bit address and operation flag.
_EVE_Select_and_Address(EVE_RAM_CMD|FWol,EVE_MEM_WRITE);
//Send the uint32_t data
_EVE_send_32(command);
//Send the first uint32_t data
_EVE_send_32(data0);
//De-select the EVE
SET_EVE_CS_NOT;
//Increment address offset modulo 4096 and return it
return((FWol+8)&0xFFF);
}
//----------------------------------------------------------------------------
uint16_t EVE_Cmd_Dat_2(uint16_t FWol,
uint32_t command,uint32_t data0, uint32_t data1)
{
//Combine Address_offset into then select the EVE
//and send the 24-bit address and operation flag.
_EVE_Select_and_Address(EVE_RAM_CMD|FWol,EVE_MEM_WRITE);
//Send the uint32_t data
_EVE_send_32(command);
//Send the first uint32_t data
_EVE_send_32(data0);
//Send the second uint32_t data
_EVE_send_32(data1);
//De-select the EVE
SET_EVE_CS_NOT;
//Increment address offset modulo 4096 and return it
return((FWol+12)&0xFFF);
}
//----------------------------------------------------------------------------
uint16_t EVE_Cmd_Dat_3(uint16_t FWol,
uint32_t command,
uint32_t data0,
uint32_t data1,
uint32_t data2)
{
//Combine Address_offset into then select the EVE
//and send the 24-bit address and operation flag.
_EVE_Select_and_Address(EVE_RAM_CMD|FWol,EVE_MEM_WRITE);
//Send the uint32_t data
_EVE_send_32(command);
//Send the first uint32_t data
_EVE_send_32(data0);
//Send the second uint32_t data
_EVE_send_32(data1);
//Send the third uint32_t data
_EVE_send_32(data2);
//De-select the EVE
SET_EVE_CS_NOT;
//Increment address offset modulo 4096 and return it
return((FWol+16)&0xFFF);
}
//============================================================================
uint8_t EVE_REG_Read_8(uint32_t REG_Address)
{
uint8_t
ftData8;
//Select the EVE and send the 24-bit address and operation flag.
_EVE_Select_and_Address(REG_Address, EVE_MEM_READ);
// Send dummy byte
SPI.transfer(0);
// Send another dummy, but this time the EVE will reply with the goods.
ftData8 = SPI.transfer(0);
//De-select the EVE
SET_EVE_CS_NOT;
// Return uint8_t read
return(ftData8);
}
//============================================================================
uint16_t EVE_REG_Read_16(uint32_t REG_Address)
{
uint16_t
ftData16;
//Select the EVE and send the 24-bit address and operation flag.
_EVE_Select_and_Address(REG_Address, EVE_MEM_READ);
// Send dummy byte
SPI.transfer(0);
// Send more dummies, but now the EVE will reply with the goods.
// Read low byte
ftData16 = SPI.transfer(0);
// Read high byte
ftData16 |= (uint16_t)SPI.transfer(0) << 8;
//De-select the EVE
SET_EVE_CS_NOT;
// Return uint16_t read
return(ftData16);
}
//============================================================================
uint32_t EVE_REG_Read_32(uint32_t REG_Address)
{
uint32_t
ftData32;
//Select the EVE and send the 24-bit address and operation flag.
_EVE_Select_and_Address(REG_Address, EVE_MEM_READ);
// Send dummy byte
SPI.transfer(0);
// Send more dummies, but now the EVE will reply with the goods.
// Read low byte
ftData32 = (uint32_t)SPI.transfer(0);
// Read mid-low byte
ftData32 |= (uint32_t)SPI.transfer(0) << 8;
// Read mid-high byte
ftData32 |= (uint32_t)SPI.transfer(0) << 16;
// Read high byte
ftData32 |= (uint32_t)SPI.transfer(0) << 24;
//De-select the EVE
SET_EVE_CS_NOT;
// Return uint32_t read
return(ftData32);
}
//============================================================================
void EVE_Read_Array(uint32_t EVE_Address, uint16_t length, uint8_t *destination)
{
//Select the EVE and send the 24-bit address and operation flag.
_EVE_Select_and_Address(EVE_Address, EVE_MEM_READ);
// Send dummy byte
SPI.transfer(0);
while(0 != length)
{
*destination=SPI.transfer(0);
destination++;
length--;
}
//De-select the EVE
SET_EVE_CS_NOT;
}
//============================================================================
// ref: BRT_AN_033_BT81X_Series_Programming_Guide, page 101
// https://brtchip.com/wp-content/uploads/Support/Documentation/Programming_Guides/ICs/EVE/BRT_AN_033_BT81X_Series_Programming_Guide.pdf
// ref: EVE Series Programmer Guide, page 157
// http://www.ftdichip.com/Support/Documents/ProgramGuides/EVE_Series_Programmer_Guide.pdf
// ref: https://github.com/RudolphRiedel/FT800-FT813/blob/4.x/EVE_commands.c
#if (0 != ROBUST_EXECUTION_COMPLETE)
uint16_t Reset_EVE_Coprocessor(void)
{
#if ((EVE_DEVICE==BT815)||(EVE_DEVICE==BT816)||(EVE_DEVICE==BT817)||(EVE_DEVICE==BT818))
#if (DEBUG_LEVEL != DEBUG_NONE)
// If debug is on, and we are a BT81x, read the error string from
//the BT81x and spool to the console
uint8_t
BT81x_error_string[129];
//Make sure it is terminated.
BT81x_error_string[128]=0;
EVE_Read_Array(EVE_RAM_ERR_REPORT,128,BT81x_error_string);
DBG_GEEK(" %s\n",BT81x_error_string);
#endif // (DEBUG_LEVEL != DEBUG_NONE)
// If it is a BT81x then we need to read a pointer first.
uint16_t
copro_patch_pointer;
copro_patch_pointer = EVE_REG_Read_16(EVE_REG_COPRO_PATCH_PTR);
#endif //((EVE_DEVICE==BT815)||(EVE_DEVICE==BT816)||(EVE_DEVICE==BT817)||(EVE_DEVICE==BT818))
//NOTE: BridgeTek uses "EVE_REG_Write_32" for all
//these, RR uses 8, 16 and 32 . . .
//FTDI Write Offset Local
uint16_t
FWol;
// This part of the reset is common to all the FT8xx and BT81x chips
// hold co-processor engine in the reset condition
EVE_REG_Write_32(EVE_REG_CPURESET, 1);
// set EVE_REG_CMD_READ to 0
EVE_REG_Write_32(EVE_REG_CMD_READ, 0);
// set EVE_REG_CMD_WRITE to 0
EVE_REG_Write_32(EVE_REG_CMD_WRITE, 0);
// reset EVE_REG_CMD_DL to 0 as required by the BT81x programming
// guide. It is not specified for but should not hurt FT8xx.
EVE_REG_Write_32(EVE_REG_CMD_DL, 0);
// restore EVE_REG_PCLK in case it was set to zero by an error
EVE_REG_Write_8(EVE_REG_PCLK, LCD_PCLK);
// Keep our local Write Offset varaible in sync
FWol = 0;
// restart the co-processor engine
EVE_REG_Write_8(EVE_REG_CPURESET, 0);
// ! From Bridgetek CoprocessorFault_Recover() example
delay(100);
//experimental
//EVE_REG_Write_16(EVE_REG_CMD_READ,FWol);
//EVE_REG_Write_16(EVE_REG_CMD_WRITE,FWol);
#if ((EVE_DEVICE==BT815)||(EVE_DEVICE==BT816)||(EVE_DEVICE==BT817)||(EVE_DEVICE==BT818))
// Complete the BT81x steps.
// Write the patch address read earlier back to the chip.
EVE_REG_Write_16(EVE_REG_COPRO_PATCH_PTR, copro_patch_pointer);
// RR: "just to be safe"
delay(5);
#if 0
//This bit with getting the flash going again is broke.
//It is a little display list . . . not sure why it does not execute OK.
//It will probably make more sense once the flash is going.
uint32_t
ftAddress;
ftAddress = EVE_RAM_CMD + FWol;
_EVE_Select_and_Address(ftAddress, EVE_MEM_WRITE);
_EVE_send_32(CMD_FLASHATTACH);
_EVE_send_32(CMD_FLASHFAST);
SET_EVE_CS_NOT;
//Increment address offset modulo 4096
FWol=(FWol+8)&0xFFF;
// Update the ring buffer pointer so the graphics processor starts executing
EVE_REG_Write_16(EVE_REG_CMD_WRITE,FWol);
// RR: "just to be safe"
delay(5);
#endif // 0
#endif //((EVE_DEVICE==BT815)||(EVE_DEVICE==BT816)||(EVE_DEVICE==BT817)||(EVE_DEVICE==BT818))
//Return the current FTDI Write Offset.
return(FWol);
}
#endif // (0 != ROBUST_EXECUTION_COMPLETE)
//============================================================================
// Wait for graphics processor to complete executing the current command
// list. This happens when EVE_REG_CMD_READ matches EVE_REG_CMD_WRITE, indicating
// that all commands have been executed. We have a local copy of
// EVE_REG_CMD_WRITE in SW_write_offset.
//
// Additional Read / Write of a vector at idle. I would recommend not using
// this unless you are doing low-level SPI debugging with an oscilloscope.
// It seems to have some negative side effects.
#define WRITE_AND_READ_SPI_VECTOR (0)
//
#if (0 != ROBUST_EXECUTION_COMPLETE)
uint16_t Wait_for_EVE_Execution_Complete(uint16_t SW_write_offset)
{
uint32_t
timeout;
timeout=100000;
#if (0 != WRITE_AND_READ_SPI_VECTOR)
uint32_t
vector;
vector=0x0FAA55F0;
#endif
uint16_t
read_address;
uint16_t
write_address;
uint16_t
reported_read_address;
uint16_t
reported_write_address;
reported_read_address=0;
reported_write_address=0;
do
{
read_address=EVE_REG_Read_16(EVE_REG_CMD_READ);
//Check for a coprocessor fault.
if(0xFFF == read_address)
{
DBG_GEEK("Coprocessor Fault detected. Resetting coprocessor.\n");
//Return the new offset after resetting the coprocessor.
return(Reset_EVE_Coprocessor());
}
write_address=EVE_REG_Read_16(EVE_REG_CMD_WRITE);
if((read_address&0xF003)||(write_address&0xF003)||(SW_write_offset&0xF003)||(write_address!=SW_write_offset))
{
if((reported_read_address!=read_address)||(reported_write_address!=write_address))
{
if(write_address!=SW_write_offset)
{
DBG_GEEK("Write Mismatch: HDW_R=(%5u,0x%04X) HDW_W=(%5u,0x%04X) != SW_W=(%5u,0x%04X)\n",
read_address,read_address,
write_address,write_address,
SW_write_offset,SW_write_offset);
}
if((read_address&0xF003)||(write_address&0xF003)||(SW_write_offset&0xF003))
{
DBG_GEEK("DWORD Alignment: HDW_R=(%5u,0x%04X) HDW_W=(%5u,0x%04X) SW_W=(%5u,0x%04X)\n",
read_address,read_address,
write_address,write_address,
SW_write_offset,SW_write_offset);
}
reported_read_address=read_address;
reported_write_address=write_address;
}
}
#if (0 != WRITE_AND_READ_SPI_VECTOR)
//Write and read REG_MACRO_0 to debug SPI
//This appears to break at least the dot drawing of the touch calibrate routine.
//Best to leave it disabled unless you are using the scope to do low-level
//SPI hardware debugging.
//Write and read REG_MACRO_0 to debug SPI
uint32_t
readback;
SET_DEBUG_LED;
EVE_REG_Write_32(REG_MACRO_0, vector);
CLR_DEBUG_LED;
readback=EVE_REG_Read_32(REG_MACRO_0);
if(readback!=vector)
{
DBG_GEEK("WRITE_AND_READ_SPI_VECTOR: 0x%08lX read: 0x%08lX\n",vector,readback);
}
vector^=0xFFFFFFFF;
#endif
//Check timeout
if(0 != timeout)
{
timeout--;
}
else
{
DBG_GEEK("Wait_for_EVE_Execution_Complete: 100K tries, not complete.\n");
DBG_GEEK(" Pointers: HDW_R=(%5u,0x%04X) HDW_W=(%5u,0x%04X) != SW_W=(%5u,0x%04X)\n",
read_address,read_address,
write_address,write_address,
SW_write_offset,SW_write_offset);
//Experimental -- breaks touch calibration
// DBG_GEEK("Coprocessor Fault detected. Resetting coprocessor.\n");
// //Return the new offset after resetting the coprocessor.
// return(Reset_EVE_Coprocessor());
timeout=100000;
}
}while(read_address!=SW_write_offset);
//No error -- return the unmodified offset.
return(SW_write_offset);
}
#endif
//============================================================================
uint16_t Get_Free_CMD_Space(uint16_t FWol)
{
// (4K - 4) - (write-read)
return((4096-4)-((FWol-EVE_REG_Read_16(EVE_REG_CMD_READ))&0x0FFF));
}
//============================================================================
//from BRT_AN_014 EVE Simple PIC Library Examples:
// An optional step then follows to allow the end of the inflated data to be
// determined, which will be useful when loading data into subsequent RAM_G
// locations to make efficient use of the memory. Whilst the commands above
// define that the data will begin at 0, the end address is not known as the
// inflated data will be larger than the compressed data written to the
// EVE_ENC_CMD_INFLATE command. The EVE_ENC_CMD_GETPTR can be used to check
// the ending address. This command actually returns its value via the
// co-processor FIFO itself. The command (4 bytes) is sent with a dummy
// (4-byte) value as a parameter and so occupies two 32-bit locations in the
// command FIFO. On completion, the co-processor replaces the dummy value with
// the ending address. The application must then perform a read of this
// location (which can be obtained by checking the current EVE_REG_CMD_WRITE
// pointer and subtracting 4 taking account of any possible rollover at
// (EVE_RAM_CMD+0).
//----------------------------------------------------------------------------
uint16_t Get_RAM_G_Pointer_After_INFLATE(uint16_t FWol,
uint32_t *RAM_G_First_Available)
{
//Make sure that the chip is caught up.
FWol=Wait_for_EVE_Execution_Complete(FWol);
//Tell the chip to get the first free location in RAM_G
FWol=EVE_Cmd_Dat_1(FWol,
EVE_ENC_CMD_GETPTR,0);
// Update the ring buffer pointer so the graphics processor starts executing
EVE_REG_Write_16(EVE_REG_CMD_WRITE,FWol);
//Wait for the chip to catch up.
FWol=Wait_for_EVE_Execution_Complete(FWol);
//We know that the answer is 4 addresses lower than FWol
//Read the value and passs it back to the caller know what we found.
*RAM_G_First_Available=EVE_REG_Read_32(EVE_RAM_CMD+((FWol-4) & 0x0FFF));
return(FWol);
}
//============================================================================
uint16_t Get_RAM_G_Properties_After_LOADIMAGE(uint16_t FWol,
uint32_t *RAM_G_First_Available,
uint32_t *Width,
uint32_t *Height)
{
//Make sure that the chip is caught up.
FWol=Wait_for_EVE_Execution_Complete(FWol);
// Tell the chip to get the first free location in RAM_G
FWol=EVE_Cmd_Dat_3(FWol,
EVE_ENC_CMD_GETPROPS,0,0,0);
// Update the ring buffer pointer so the graphics processor starts executing
EVE_REG_Write_16(EVE_REG_CMD_WRITE,FWol);
//Wait for the chip to catch up.
FWol=Wait_for_EVE_Execution_Complete(FWol);
//We know that the height is 4 addresses lower than FWol
//Read the value and passs it back to the caller know what we found.
*Height=EVE_REG_Read_32(EVE_RAM_CMD+((FWol-4) & 0x0FFF));
//We know that the width is 8 addresses lower than FWol
//Read the value and passs it back to the caller know what we found.
*Width=EVE_REG_Read_32(EVE_RAM_CMD+((FWol-8) & 0x0FFF));
//We know that the answer is 12 addresses lower than FWol
//Read the value and passs it back to the caller know what we found.
*RAM_G_First_Available=EVE_REG_Read_32(EVE_RAM_CMD+((FWol-12) & 0x0FFF));
return(FWol);
}
//===========================================================================
uint32_t EVE_Set_Flash_to_Fast(uint16_t FWol)
{
//Make sure the EVE is caught up
FWol=Wait_for_EVE_Execution_Complete(FWol);
//Send the command to the coprocessor
FWol=EVE_Cmd_Dat_1(FWol,
EVE_ENC_CMD_FLASHFAST,
0);
// Update the ring buffer pointer so the coprocessor starts executing
EVE_REG_Write_16(EVE_REG_CMD_WRITE, (FWol));
//Now wait for the coprocessor to catch up
FWol=Wait_for_EVE_Execution_Complete(FWol);
//Read the result from EVE_ENC_CMD_FLASHFAST
uint32_t
CMD_FastFlash_Result;
//We know that the result is 4 addresses lower than FWol
//Read the value and passs it back to the caller know what we found.
CMD_FastFlash_Result=EVE_REG_Read_32(EVE_RAM_CMD+((FWol-4) & 0x0FFF));
#if (DEBUG_LEVEL == DEBUG_GEEK)
//Print out the flash status.
uint8_t
status;
status = EVE_REG_Read_8(EVE_REG_FLASH_STATUS);
DBG_GEEK_Decode_Flash_Status(status);
DBG_GEEK_Decode_FastFlash_Status(CMD_FastFlash_Result);
#endif // (DEBUG_LEVEL == DEBUG_GEEK)
return(FWol);
}
//---------------------------------------------------------------------------
// Switches the FLASH attached to a BT815/BT816 to full-speed
// mode, returns 0 for failing to do so
uint16_t EVE_Initialize_Flash(uint16_t FWol)
{
// We expect EVE_REG_FLASH_STATUS to return 0x02 - FLASH_STATUS_BASIC
// indicating power-up is done and the attached flash is detected
uint8_t
status;
status = EVE_REG_Read_8(EVE_REG_FLASH_STATUS);
DBG_GEEK("\n");
DBG_GEEK_Decode_Flash_Status(status);
//The goal is to get to fast . . . so let's give that a try.
switch(status)
{
case EVE_FLASH_STATUS_INIT:
DBG_STAT("EVE_init_flash(): Error - status is INIT, not BASIC.\n");
break;
case EVE_FLASH_STATUS_DETACHED:
DBG_STAT("EVE_init_flash(): Error - status is DETACHED, not BASIC.\n");
break;
case EVE_FLASH_STATUS_BASIC:
//This is what we expect. Switch to fast.
FWol=EVE_Set_Flash_to_Fast(FWol);
//Print out the flash size, since we can.
uint32_t
flash_size;
flash_size = EVE_REG_Read_32(EVE_REG_FLASH_SIZE);
DBG_STAT("EVE_init_flash(): EVE_REG_FLASH_SIZE = %lu MB\n",flash_size);
break;
case EVE_FLASH_STATUS_FULL:
DBG_STAT("EVE_init_flash(): Warning - status already FULL.\n");
break;
default:
DBG_STAT("EVE_init_flash(): Error - invalid status.\n");
break;
}
return(FWol);
}
//============================================================================
uint16_t Erase_Entire_Flash_Chip(uint16_t FWol)
{
DBG_GEEK("Erasing flash (takes a long time) . . . ");
//Make sure the EVE is caught up
FWol=Wait_for_EVE_Execution_Complete(FWol);
//Send the command to the coprocessor
FWol=EVE_Cmd_Dat_0(FWol,
EVE_ENC_CMD_FLASHERASE);
// Update the ring buffer pointer so the coprocessor starts executing
EVE_REG_Write_16(EVE_REG_CMD_WRITE, (FWol));
//Now wait for the coprocessor to catch up
FWol=Wait_for_EVE_Execution_Complete(FWol);
DBG_GEEK("done. ");
return(FWol);
}
//============================================================================
#if (EVE_TOUCH_TYPE==EVE_TOUCH_CAPACITIVE) && (EVE_TOUCH_CAP_DEVICE==EVE_CAP_DEV_GT911)
//Used to send Goodix GT911 cap-touch init code to EVE from progmem
//Magic binary data from "AN_336 FT8xx - Selecting an LCD Display"
#define GOODIX_GT911_INIT_DATA_LENGTH (1216)
const uint8_t Goodix_GT911_Init_Data[GOODIX_GT911_INIT_DATA_LENGTH] PROGMEM = {
0x1A,0xFF,0xFF,0xFF,0x20,0x20,0x30,0x00,0x04,0x00,0x00,0x00,0x02,0x00,0x00,0x00,
0x22,0xFF,0xFF,0xFF,0x00,0xB0,0x30,0x00,0x78,0xDA,0xED,0x54,0xDD,0x6F,0x54,0x45,
0x14,0x3F,0x33,0xB3,0x5D,0xA0,0x94,0x65,0x6F,0x4C,0x05,0x2C,0x8D,0x7B,0x6F,0xA1,
0x0B,0xDB,0x9A,0x10,0x09,0x10,0x11,0xE5,0x9C,0x4B,0x1A,0x0B,0x0D,0x15,0xE3,0x03,
0x10,0xFC,0xB8,0xB3,0x2D,0xDB,0x8F,0x2D,0x29,0x7D,0x90,0x48,0x43,0x64,0x96,0x47,
0xBD,0x71,0x12,0x24,0x11,0xA5,0x64,0xA5,0xC6,0x10,0x20,0x11,0x95,0xC4,0xF0,0x80,
0xA1,0x10,0xA4,0x26,0x36,0xF0,0x00,0xD1,0x48,0x82,0x0F,0x26,0x7D,0x30,0x42,0x52,
0x1E,0x4C,0x13,0x1F,0xAC,0x67,0x2E,0x8B,0x18,0xFF,0x04,0xE3,0x9D,0xCC,0x9C,0x33,
0x73,0x66,0xCE,0xE7,0xEF,0xDC,0x05,0xAA,0x5E,0x81,0x89,0x4B,0xC2,0xD8,0x62,0x5E,
0x67,0x75,0x73,0x79,0x4C,0x83,0xB1,0x7D,0x59,0x7D,0x52,0x7B,0x3C,0xF3,0x3A,0x8E,
0xF2,0xCC,0xB9,0xF3,0xBC,0x76,0x9C,0xE3,0x9B,0xCB,0xEE,0xEE,0xC3,0xFB,0xCD,0xE5,
0x47,0x5C,0x1C,0xA9,0xBE,0xB8,0x54,0x8F,0x71,0x89,0x35,0xF4,0x67,0xB5,0xED,0x57,
0xFD,0x71,0x89,0xE9,0x30,0x0C,0xC6,0xA5,0xB5,0x68,0x8B,0x19,0x54,0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,0x1A,0xAB,0xE4,0x45,0x3F,0x24,0x11,
0xFC,0xC8,0x11,0x74,0xF2,0xBB,0xE3,0x58,0x8F,0xF7,0x02,0x4B,0xBF,0x06,0x82,0x3B,
0xBC,0x0B,0x37,0xF0,0x1F,0xF3,0x7A,0x98,0xE2,0xB7,0xCF,0x9A,0x49,0xBC,0x27,0xDB,
0x2B,0x69,0xDE,0x57,0x29,0x8F,0x8D,0x8C,0xAF,0x49,0x70,0xB8,0xFC,0x3D,0xB8,0x10,
0x5A,0xFA,0x23,0xA8,0x52,0x77,0xB0,0x39,0x74,0x5E,0xC8,0x96,0x16,0xBE,0xB3,0x2C,
0x68,0x0C,0xEB,0x54,0x95,0x66,0xFC,0x59,0x9A,0xC1,0x63,0xE4,0x6A,0xF2,0x7D,0xF8,
0x40,0xC2,0xFF,0xDF,0x7F,0xF2,0x53,0x0B,0xFF,0x02,0x46,0xD6,0xE2,0x80,0x00,0x00,
0x1A,0xFF,0xFF,0xFF,0x14,0x21,0x30,0x00,0x04,0x00,0x00,0x00,0x0F,0x00,0x00,0x00,
0x1A,0xFF,0xFF,0xFF,0x20,0x20,0x30,0x00,0x04,0x00,0x00,0x00,0x00,0x00,0x00,0x00};
//----------------------------------------------------------------------------
uint16_t EVE_Init_Goodix_GT911(uint16_t FWol)
{
//Make sure that the chip is caught up.
FWol=Wait_for_EVE_Execution_Complete(FWol);
//Combine Address_offset into then select the EVE
//and send the 24-bit address and operation flag.
_EVE_Select_and_Address(EVE_RAM_CMD|FWol,EVE_MEM_WRITE);
//Pipe out data_length of data from data_address.
const uint8_t
*Flash_Data;
uint32_t
data_length;
Flash_Data=Goodix_GT911_Init_Data;
data_length=GOODIX_GT911_INIT_DATA_LENGTH;
while(0 != data_length)
{
SPI.transfer(pgm_read_byte(Flash_Data));
Flash_Data++;
data_length--;
}
//Remember that we sent GOODIX_GT911_INIT_DATA_LENGTH bytes
FWol=(FWol+GOODIX_GT911_INIT_DATA_LENGTH)&0xFFF;
//De-select the EVE
SET_EVE_CS_NOT;
//OK, the data is in the EVE_RAM_CMD circular buffer, ask the chip
//to process it.
EVE_REG_Write_16(EVE_REG_CMD_WRITE, FWol);
//Now wait for it to catch up
FWol=Wait_for_EVE_Execution_Complete(FWol);
//"Straight AN_336"
//"Hold the touch engine in reset (write EVE_REG_CPURESET=2)"
EVE_REG_Write_8(EVE_REG_CPURESET, 0x02);
//Rudolph's
//EVE_REG_Write_8(EVE_REG_TOUCH_OVERSAMPLE, 0x0f);
//"Write REG_TOUCH_CONFIG=0x05D0"
EVE_REG_Write_16(EVE_REG_TOUCH_CONFIG, 0x05D0);
// 0 5 D 0
// 0000 0101 1101 0000
// |||| |||| |||| ||||-sampler clocks
// |||| |||| |||| ||---supress 300ms startup
// |||| |||| |||| |----vendor: 0=FocalTech, 1 = Azoteq
// |||| |||| ||||------I2C address=0x5D
// |||| | ?? GT911 supports two I2C slave addresses:
// |||| | 0xBA/0xBB and 0x28/0x29. ??
// |||| | 0xBA is 1011 1010, bit reversed of 0x5D
// |||| |--------------enable low power
// ||||----------------ignore short circuit
// |||-----------------reserved
// |-------------------0 = capacitive, 1 = resistive
//"Set GPIO0 output LOW"
// Reset-Value is 0x8000 adding 0x0008 sets GPIO3 to output
// Default-value for EVE_REG_GPIOX is 0x8000 -> Low output on GPIO3
EVE_REG_Write_16(EVE_REG_GPIOX_DIR,0x8008);
// "Wait more than 100us"
delay(1);
// "Write EVE_REG_CPURESET=0"
EVE_REG_Write_8(EVE_REG_CPURESET, 0x00);
// "Wait more than 55ms"
// 2020-08-05 RR discovered that ~108ms is needed for multitouch
delay(110);
// "Set GPIO0 to input (floating)"
EVE_REG_Write_16(EVE_REG_GPIOX_DIR,0x8000);
//Return the updated address
return(FWol);
}
#endif // (TOUCH_TYPE==TOUCH_CAPACITIVE) && (TOUCH_CAP_DEVICE==CAP_DEV_GT911)
//============================================================================
//Apparently there is a "pen-up bug" in the FTDI.
#if (0 != EVE_PEN_UP_BUG_FIX)
//Magic binary data from FTDI supplied PC sample code
#define PEN_UP_BUG_FIX_INIT_DATA_LENGTH (1172)
const uint8_t Pen_Up_Bug_Fix_Init_Data[PEN_UP_BUG_FIX_INIT_DATA_LENGTH] PROGMEM = {
0x1A,0xFF,0xFF,0xFF,0x20,0x20,0x30,0x00,0x04,0x00,0x00,0x00,0x02,0x00,0x00,0x00,
0x22,0xFF,0xFF,0xFF,0x00,0xB0,0x30,0x00,0x78,0xDA,0xED,0x54,0xFF,0x6B,0x5C,0x45,
0x10,0x9F,0x7D,0x9B,0x6B,0x8D,0xC9,0x79,0xF7,0x6A,0x82,0x09,0xE1,0xF4,0xEE,0x25,
0xF6,0x92,0x34,0x3F,0x35,0x62,0xAC,0x35,0x30,0xF3,0x08,0x24,0xA6,0xB6,0x3F,0x88,
0xD8,0xF6,0x07,0xCD,0xDB,0x4B,0x7A,0x77,0xB9,0x8B,0xC4,0x80,0x22,0x21,0x88,0x7B,
0x41,0xF0,0x07,0x1F,0x2C,0x69,0x29,0x45,0x48,0x0C,0xD2,0xA6,0x06,0x11,0x0C,0x68,
0x40,0xA5,0x49,0x85,0x86,0x62,0x50,0x4A,0x2B,0x94,0x16,0x14,0x85,0x28,0x14,0x22,
0xE9,0x0F,0x52,0xFA,0x83,0x0A,0x71,0xF6,0xE5,0x6A,0xC5,0xBF,0xA1,0x6F,0xD9,0x37,
0xB3,0x3B,0x3B,0x3B,0xF3,0x99,0x2F,0xFB,0x87,0x0F,0x3A,0xCC,0x0B,0x6D,0x72,0x59,
0x95,0x54,0xA9,0xF2,0xAC,0x02,0x6D,0x0A,0x49,0x35,0xA7,0x5C,0x9E,0x59,0x15,0x06,
0x59,0xE6,0xEC,0x7E,0x56,0x59,0xCE,0xF2,0xA9,0xB2,0x3D,0xBB,0x73,0x3E,0x55,0xBE,
0xC7,0x85,0x81,0x2C,0x84,0xF9,0x5A,0x0C,0xF3,0x7C,0x43,0x31,0xA9,0x4C,0x51,0x16,
0xC3,0x3C,0xD3,0x71,0x28,0x85,0xF9,0xF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