-
Notifications
You must be signed in to change notification settings - Fork 0
/
EVE_commands.c
3131 lines (2525 loc) · 96.6 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 5.0
@date 2021-05-14
@author Rudolph Riedel
@section info
This file needs to be renamed to EVE_command.cpp for use with Arduino.
At least for ATSAM I had the best result with -O2.
The c-standard is C99.
@section LICENSE
MIT License
Copyright (c) 2016-2021 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
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 active
- 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
- removed writing of REG_CSSPREAD from EVE_init() so it is per default activated now for all displays
- changed the "len" parameter for loadimage, inflate, inflate2 and EVE_memWrite_flash_buffer() to uint32_t
- quick workaround for FT813/GT911: in order to use multi-touch a much longer delay is necessary as the >55ms from AN_336
5.0
- added EVE_cmd_pclkfreq()
- put back writing of REG_CSSPREAD as it needs to be deactivated for higher frequencies
- added the configuration of the second PLL for the pixel clock in BT817/BT818 to EVE_init() in case the display config has EVE_PCLK_FREQ defined
- replaced BT81X_ENABLE with "EVE_GEN > 2"
- removed FT81X_ENABLE as FT81x already is the lowest supported chip revision now
- removed the formerly as deprected marked EVE_get_touch_tag()
- changed EVE_color_rgb() to use a 32 bit value like the rest of the color commands
- removed the meta-commands EVE_cmd_point(), EVE_cmd_line() and EVE_cmd_rect()
- split all display-list commands into two functions: EVE_cmd_XXX() and EVE_cmd_XXX_burst()
- switched from using EVE_RAM_CMD + cmdOffset to REG_CMDB_WRITE
- as a side effect from switching to REG_CMDB_WRITE, every co-processor command is automatically executed now
- renamed EVE_LIB_GetProps() back to EVE_cmd_getprops() since it does not do anything special to justify a special name
- added helper function EVE_memWrite_sram_buffer()
- added EVE_cmd_bitmap_transform() and EVE_cmd_bitmap_transform_burst()
- added zero-pointer protection to commands using block_transfer()
- added EVE_cmd_playvideo()
- changed EVE_cmd_setfont() to a display-list command and added EVE_cmd_setfont_burst()
- changed EVE_cmd_setfont2() to a display-list command and added EVE_cmd_setfont2_burst()
- added EVE_cmd_videoframe()
- restructured: functions are sorted by chip-generation and within their group in alphabetical order
- reimplementedEVE_cmd_getmatrix() again, it needs to read values, not write them
- added EVE_cmd_fontcache() and EVE_cmd_fontcachequery()
- added EVE_cmd_calibratesub()
- added EVE_cmd_animframeram(), EVE_cmd_animframeram_burst(), EVE_cmd_animstartram(), EVE_cmd_animstartram_burst()
- added EVE_cmd_apilevel(), EVE_cmd_apilevel_burst()
- added EVE_cmd_calllist(), EVE_cmd_calllist_burst()
- added EVE_cmd_hsf(), EVE_cmd_hsf_burst()
- added EVE_cmd_linetime()
- added EVE_cmd_newlist(), EVE_cmd_newlist_burst()
- added EVE_cmd_runanim(), EVE_cmd_runanim_burst()
- added a safeguard to EVE_start_cmd_burst() to protect it from overlapping transfers with DMA and segmented lists
- used spi_transmit_32() to shorten this file by around 600 lines with no functional change
- removed the history from before 4.0
- removed a couple of spi_transmit_32() calls from EVE_cmd_getptr() to make it work again
- Bugfix: EVE_cmd_setfont2_burst() was using CMD_SETFONT instead of CMD_SETFONT2
- removed a check for cmd_burst from EVE_cmd_getimage() as it is in the group of commands that are not used for display lists
- moved EVE_cmd_newlist() to the group of commands that are not used for display lists
- removed EVE_cmd_newlist_burst()
- renamed spi_flash_write() to private_block_write() and made it static
- renamed EVE_write_string() to private_string_write() and made it static
- made EVE_start_command() static
- Bugfix: ESP8266 needs 32 bit alignment for 32 bit pointers, changed private_string_write() for burst-mode to read 8-bit values
- Bugfix: somehow messed up private_string_write() for burst-mode but only for 8-Bit controllers
- changed EVE_memRead8(), EVE_memRead16() and EVE_memRead32() to use spi_transmit_32() for the initial address+zero byte transfer
This speeds up ESP32/ESP8266 by several µs, has no measureable effect for ATSAMD51 and is a little slower for AVR.
- Bugfix: not sure why but setting private_block_write() to static broke it, without "static" it works
- Bugfix: EVE_cmd_flashspirx() was using CMD_FLASHREAD
- fixed a warning in EVE_init() when compiling for EVE4
- renamed internal function EVE_begin_cmd() to eve_begin_cmd() and made it static
- changed all the EVE_start_command() calls to eve_begin_cmd() calls following the report on Github from
Michael Wachs that these are identical - they weren't prior to V5
- removed EVE_start_command()
- Bugfix: EVE_init() was only checking the first two bits of REG_CPURESET and ignored the bit for the audio-engine, not an issue but not correct either.
*/
#include "EVE.h"
#if EVE_GEN > 2
#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 uint8_t cmd_burst = 0; /* flag to indicate cmd-burst is active */
/*----------------------------------------------------------------------------------------------------------------------------*/
/*---- helper functions ------------------------------------------------------------------------------------------------------*/
/*----------------------------------------------------------------------------------------------------------------------------*/
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_32(0x00000000 + ((uint8_t)(ftAddress >> 16) | MEM_READ) + (ftAddress & 0x0000ff00) + ( (ftAddress & 0x000000ff) << 16) );
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_32(0x00000000 + ((uint8_t)(ftAddress >> 16) | MEM_READ) + (ftAddress & 0x0000ff00) + ( (ftAddress & 0x000000ff) << 16) );
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_32(0x00000000 + ((uint8_t)(ftAddress >> 16) | MEM_READ) + (ftAddress & 0x0000ff00) + ( (ftAddress & 0x000000ff) << 16) );
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();
}
/* helper function, write a block of memory from the FLASH of the host controller to EVE */
void EVE_memWrite_flash_buffer(uint32_t ftAddress, const uint8_t *data, uint32_t len)
{
uint32_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();
}
/* helper function, write a block of memory from the SRAM of the host controller to EVE */
void EVE_memWrite_sram_buffer(uint32_t ftAddress, const uint8_t *data, uint32_t len)
{
uint32_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(data[count]);
}
EVE_cs_clear();
}
/* Check if the graphics processor completed executing the current command list. */
/* REG_CMDB_SPACE == 0xffc -> command fifo is empty */
/* (REG_CMDB_SPACE & 0x03) != 0 -> we have a co-processor fault */
uint8_t EVE_busy(void)
{
uint16_t space;
#if defined (EVE_DMA)
if(EVE_dma_busy)
{
return 1;
}
#endif
space = EVE_memRead16(REG_CMDB_SPACE);
if((space & 0x3) != 0) /* we have a co-processor fault, make EVE play with us again */
{
#if EVE_GEN > 2
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 */
EVE_memWrite8(REG_CPURESET, 0); /* set REG_CMD_WRITE to 0 to restart the co-processor engine*/
#if EVE_GEN > 2
EVE_memWrite16(REG_COPRO_PATCH_DTR, copro_patch_pointer);
DELAY_MS(5); /* just to be safe */
ftAddress = REG_CMDB_WRITE;
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_32(CMD_FLASHATTACH);
spi_transmit_32(CMD_FLASHFAST);
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(space != 0xffc)
{
return 1;
}
else
{
return 0;
}
}
/* deprecated, with using REG_CMDB_WRITE commands will be automatically excecuted on the rising edge of chip select */
/* order the command co-processor to start processing its FIFO queue and do not wait for completion */
void EVE_cmd_start(void)
{
#if defined (EVE_DMA)
if(EVE_dma_busy)
{
return; /* just do nothing if a dma transfer is in progress */
}
#endif
}
/* wait for the co-processor to complete the FIFO queue */
void EVE_cmd_execute(void)
{
while (EVE_busy());
}
/* begin a co-processor command, this is used for non-display-list and non-burst-mode commands */
static void eve_begin_cmd(uint32_t command)
{
uint32_t ftAddress;
ftAddress = REG_CMDB_WRITE;
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_32(command);
}
void private_block_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--;
}
}
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 = REG_CMDB_WRITE;
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 */
private_block_write(data,block_len);
EVE_cs_clear();
data += block_len;
bytes_left -= block_len;
while (EVE_busy());
}
}
/*----------------------------------------------------------------------------------------------------------------------------*/
/*---- co-processor commands that are not used in displays lists, these are not to be used with burst transfers --------------*/
/*----------------------------------------------------------------------------------------------------------------------------*/
/* BT817 / BT818 */
#if EVE_GEN > 3
/* this is meant to be called outside display-list building, it includes executing the command and waiting for completion, does not support cmd-burst */
/* write "num" bytes from src in RAM_G to to the external flash on a BT81x board at address dest */
/* note: dest must be 4096-byte aligned, src must be 4-byte aligned, num must be a multiple of 4096 */
/* note: EVE will not do anything if the alignment requirements are not met */
/* note: the address ptr is relative to the flash so the first address is 0x00000000 not 0x800000 */
/* note: this looks exactly the same as EVE_cmd_flashupdate() but it needs the flash to be empty */
void EVE_cmd_flashprogram(uint32_t dest, uint32_t src, uint32_t num)
{
eve_begin_cmd(CMD_FLASHPROGRAM);
spi_transmit_32(dest);
spi_transmit_32(src);
spi_transmit_32(num);
EVE_cs_clear();
while (EVE_busy());
}
/* 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_fontcache(uint32_t font, int32_t ptr, uint32_t num)
{
eve_begin_cmd(CMD_FONTCACHE);
spi_transmit_32(font);
spi_transmit_32(ptr);
spi_transmit_32(num);
EVE_cs_clear();
while (EVE_busy());
}
/* 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_fontcachequery(uint32_t *total, int32_t *used)
{
uint16_t cmdoffset;
eve_begin_cmd(CMD_FONTCACHEQUERY);
spi_transmit_32(0);
spi_transmit_32(0);
EVE_cs_clear();
while (EVE_busy());
cmdoffset = EVE_memRead16(REG_CMD_WRITE); /* read the graphics processor write pointer */
if(total)
{
*total = EVE_memRead32(EVE_RAM_CMD + ((cmdoffset - 8) & 0xfff));
}
if(used)
{
*used = EVE_memRead32(EVE_RAM_CMD + ((cmdoffset - 4) & 0xfff));
}
}
/* 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_getimage(uint32_t *source, uint32_t *fmt, uint32_t *width, uint32_t *height, uint32_t *palette)
{
uint16_t cmdoffset;
eve_begin_cmd(CMD_GETIMAGE);
spi_transmit_32(0);
spi_transmit_32(0);
spi_transmit_32(0);
spi_transmit_32(0);
spi_transmit_32(0);
EVE_cs_clear();
while (EVE_busy());
cmdoffset = EVE_memRead16(REG_CMD_WRITE); /* read the graphics processor write pointer */
if(palette)
{
*palette = EVE_memRead32(EVE_RAM_CMD + ((cmdoffset - 4) & 0xfff));
}
if(height)
{
*height = EVE_memRead32(EVE_RAM_CMD + ((cmdoffset - 8) & 0xfff));
}
if(width)
{
*width = EVE_memRead32(EVE_RAM_CMD + ((cmdoffset - 12) & 0xfff));
}
if(fmt)
{
*fmt = EVE_memRead32(EVE_RAM_CMD + ((cmdoffset - 16) & 0xfff));
}
if(source)
{
*source = EVE_memRead32(EVE_RAM_CMD + ((cmdoffset - 20) & 0xfff));
}
}
/* 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_linetime(uint32_t dest)
{
eve_begin_cmd(CMD_LINETIME);
spi_transmit_32(dest);
EVE_cs_clear();
while (EVE_busy());
}
/* 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_newlist(uint32_t adr)
{
eve_begin_cmd(CMD_NEWLIST);
spi_transmit_32(adr);
EVE_cs_clear();
while (EVE_busy());
}
/* this is meant to be called outside display-list building, it includes executing the command and waiting for completion, does not support cmd-burst */
/* This command sets REG_PCLK_FREQ to generate the closest possible frequency to the one requested. */
/* Returns the frequency achieved or zero if no frequency was found. */
uint32_t EVE_cmd_pclkfreq(uint32_t ftarget, int32_t rounding)
{
uint16_t cmdoffset;
eve_begin_cmd(CMD_PCLKFREQ);
spi_transmit_32(ftarget);
spi_transmit_32(rounding);
spi_transmit_32(0);
EVE_cs_clear();
while (EVE_busy());
cmdoffset = EVE_memRead16(REG_CMD_WRITE); /* read the graphics processor write pointer */
cmdoffset -= 4;
cmdoffset &= 0x0fff;
return (EVE_memRead32(EVE_RAM_CMD + cmdoffset));
}
/* 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_wait(uint32_t us)
{
eve_begin_cmd(CMD_WAIT);
spi_transmit_32(us);
EVE_cs_clear();
while (EVE_busy());
}
#endif /* EVE_GEN > 3 */
/* BT815 / BT816 */
#if EVE_GEN > 2
/* this is meant to be called outside display-list building, it includes executing the command and waiting for completion, does not support cmd-burst */
/* this command clears the graphics systems flash cache and to do so it needs to be executed with empty display lists */
/* note: looks like overkill to clear both display lists but this is taken from BRT sample code */
void EVE_cmd_clearcache(void)
{
EVE_cmd_dl(CMD_DLSTART);
EVE_cmd_dl(CMD_SWAP);
while (EVE_busy());
EVE_cmd_dl(CMD_DLSTART);
EVE_cmd_dl(CMD_SWAP);
while (EVE_busy());
EVE_cmd_dl(CMD_CLEARCACHE);
while (EVE_busy());
}
/* this is meant to be called outside display-list building, it includes executing the command and waiting for completion, does not support cmd-burst */
/* this is added for conveniance, using EVE_cmd_dl(CMD_FLASHATTACH); followed by EVE_cmd_execute(); would work as well */
void EVE_cmd_flashattach(void)
{
eve_begin_cmd(CMD_FLASHATTACH);
EVE_cs_clear();
while (EVE_busy());
}
/* this is meant to be called outside display-list building, it includes executing the command and waiting for completion, does not support cmd-burst */
/* this is added for conveniance, using EVE_cmd_dl(CMD_FLASHDETACH); followed by EVE_cmd_execute(); would work as well */
void EVE_cmd_flashdetach(void)
{
eve_begin_cmd(CMD_FLASHDETACH);
EVE_cs_clear();
while (EVE_busy());
}
/* this is meant to be called outside display-list building, it includes executing the command and waiting for completion, does not support cmd-burst */
/* this is added for conveniance, using EVE_cmd_dl(CMD_FLASHERASE); followed by EVE_cmd_execute(); would work as well */
void EVE_cmd_flasherase(void)
{
eve_begin_cmd(CMD_FLASHERASE);
EVE_cs_clear();
while (EVE_busy());
}
/* this is meant to be called outside display-list building, it includes executing the command and waiting for completion, does not support cmd-burst */
uint32_t EVE_cmd_flashfast(void)
{
uint16_t cmdoffset;
eve_begin_cmd(CMD_FLASHFAST);
spi_transmit_32(0);
EVE_cs_clear();
while (EVE_busy());
cmdoffset = EVE_memRead16(REG_CMD_WRITE); /* read the graphics processor write pointer */
cmdoffset -= 4;
cmdoffset &= 0x0fff;
return (EVE_memRead32(EVE_RAM_CMD + cmdoffset));
}
/* this is meant to be called outside display-list building, it includes executing the command and waiting for completion, does not support cmd-burst */
/* this is added for conveniance, using EVE_cmd_dl(CMD_FLASHSPIDESEL); followed by EVE_cmd_execute(); would work as well */
void EVE_cmd_flashspidesel(void)
{
eve_begin_cmd(CMD_FLASHSPIDESEL);
EVE_cs_clear();
while (EVE_busy());
}
/* this is meant to be called outside display-list building, it includes executing the command and waiting for completion, does not support cmd-burst */
/* write "num" bytes from src in the external flash on a BT81x board to dest in RAM_G */
/* note: src must be 64-byte aligned, dest must be 4-byte aligned, num must be a multiple of 4 */
/* note: EVE will not do anything if the alignment requirements are not met */
/* note: the src pointer is relative to the flash so the first address is 0x00000000 not 0x800000 */
void EVE_cmd_flashread(uint32_t dest, uint32_t src, uint32_t num)
{
eve_begin_cmd(CMD_FLASHREAD);
spi_transmit_32(dest);
spi_transmit_32(src);
spi_transmit_32(num);
EVE_cs_clear();
while (EVE_busy());
}
/* 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_flashsource(uint32_t ptr)
{
eve_begin_cmd(CMD_FLASHSOURCE);
spi_transmit_32(ptr);
EVE_cs_clear();
while (EVE_busy());
}
/* this is meant to be called outside display-list building, it includes executing the command and waiting for completion, does not support cmd-burst */
/* write "num" bytes from the BT81x SPI interface dest in RAM_G */
/* note: raw direct access, not really useful for anything */
void EVE_cmd_flashspirx(uint32_t dest, uint32_t num)
{
eve_begin_cmd(CMD_FLASHSPIRX);
spi_transmit_32(dest);
spi_transmit_32(num);
EVE_cs_clear();
while (EVE_busy());
}
/* this is meant to be called outside display-list building, it includes executing the command and waiting for completion, does not support cmd-burst */
/* write "num" bytes from *data to the BT81x SPI interface */
/* note: raw direct access, not really useful for anything */
void EVE_cmd_flashspitx(uint32_t num, const uint8_t *data)
{
eve_begin_cmd(CMD_FLASHSPITX);
spi_transmit_32(num);
EVE_cs_clear();
block_transfer(data, num);
}
/* this is meant to be called outside display-list building, it includes executing the command and waiting for completion, does not support cmd-burst */
/* write "num" bytes from src in RAM_G to to the external flash on a BT81x board at address dest */
/* note: dest must be 4096-byte aligned, src must be 4-byte aligned, num must be a multiple of 4096 */
/* note: EVE will not do anything if the alignment requirements are not met */
/* note: the address ptr is relative to the flash so the first address is 0x00000000 not 0x800000 */
void EVE_cmd_flashupdate(uint32_t dest, uint32_t src, uint32_t num)
{
eve_begin_cmd(CMD_FLASHUPDATE);
spi_transmit_32(dest);
spi_transmit_32(src);
spi_transmit_32(num);
EVE_cs_clear();
while (EVE_busy());
}
/* this is meant to be called outside display-list building, it includes executing the command and waiting for completion, does not support cmd-burst */
/* write "num" bytes from *data to the external flash on a BT81x board at address ptr */
/* note: ptr must be 256 byte aligned, num must be a multiple of 256 */
/* note: EVE will not do anything if the alignment requirements are not met */
/* note: the address ptr is relative to the flash so the first address is 0x00000000 not 0x800000 */
/* note: on AVR controllers this expects the data to be located in the controllers flash memory */
void EVE_cmd_flashwrite(uint32_t ptr, uint32_t num, const uint8_t *data)
{
eve_begin_cmd(CMD_FLASHWRITE);
spi_transmit_32(ptr);
spi_transmit_32(num);
EVE_cs_clear();
if(data)
{
block_transfer(data, num);
}
}
/* 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, uint32_t len)
{
eve_begin_cmd(CMD_INFLATE2);
spi_transmit_32(ptr);
spi_transmit_32(options);
EVE_cs_clear();
if(options == 0) /* direct data, not by Media-FIFO or Flash */
{
if(data)
{
block_transfer(data, len);
}
}
}
#endif /* EVE_GEN > 2 */
/* this is meant to be called outside display-list building, it includes executing the command and waiting for completion, does not support cmd-burst */
/* get the properties of an image after a CMD_LOADIMAGE operation and write the values to the variables that are supplied by pointers
uint32 pointer, width, height;
EVE_LIB_GetProps(&pointer, &width, &height);
uint32 width, height;
EVE_LIB_GetProps(0, &width, &height);
*/
void EVE_cmd_getprops(uint32_t *pointer, uint32_t *width, uint32_t *height)
{
uint16_t cmdoffset;
eve_begin_cmd(CMD_GETPROPS);
spi_transmit_32(0);
spi_transmit_32(0);
spi_transmit_32(0);
EVE_cs_clear();
while (EVE_busy());
cmdoffset = EVE_memRead16(REG_CMD_WRITE); /* read the graphics processor write pointer */
if(pointer)
{
*pointer = EVE_memRead32(EVE_RAM_CMD + ((cmdoffset - 12) & 0xfff));
}
if(width)
{
*width = EVE_memRead32(EVE_RAM_CMD + ((cmdoffset - 8) & 0xfff));
}
if(height)
{
*height = EVE_memRead32(EVE_RAM_CMD + ((cmdoffset - 4) & 0xfff));
}
}
/* 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 cmdoffset;
eve_begin_cmd(CMD_GETPTR);
spi_transmit_32(0);
EVE_cs_clear();
while (EVE_busy());
cmdoffset = EVE_memRead16(REG_CMD_WRITE); /* read the graphics processor write pointer */
cmdoffset -= 4;
cmdoffset &= 0x0fff;
return (EVE_memRead32(EVE_RAM_CMD + cmdoffset));
}
/* 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, uint32_t len)
{
eve_begin_cmd(CMD_INFLATE);
spi_transmit_32(ptr);
EVE_cs_clear();
if(data)
{
block_transfer(data, len);
}
}
/* 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_32(ms);
EVE_cs_clear();
}
/* 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, uint32_t len)
{
eve_begin_cmd(CMD_LOADIMAGE);
spi_transmit_32(ptr);
spi_transmit_32(options);
EVE_cs_clear();
#if EVE_GEN > 2
if( ((options & EVE_OPT_MEDIAFIFO) == 0) && ((options & EVE_OPT_FLASH) == 0) )/* direct data, neither by Media-FIFO or from Flash */
#else
if((options & EVE_OPT_MEDIAFIFO) == 0) /* direct data, not by Media-FIFO */
#endif
{
if(data)
{
block_transfer(data, len);
}
}
}
/* 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_32(ptr);
spi_transmit_32(size);
EVE_cs_clear();
}
/* 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_memcpy(uint32_t dest, uint32_t src, uint32_t num)
{
eve_begin_cmd(CMD_MEMCPY);
spi_transmit_32(dest);
spi_transmit_32(src);
spi_transmit_32(num);
EVE_cs_clear();
while (EVE_busy());
}
/* 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 cmdoffset;
eve_begin_cmd(CMD_MEMCRC);
spi_transmit_32(ptr);
spi_transmit_32(num);
spi_transmit_32(0);
EVE_cs_clear();
while (EVE_busy());
cmdoffset = EVE_memRead16(REG_CMD_WRITE); /* read the graphics processor write pointer */
cmdoffset -= 4;
cmdoffset &= 0x0fff;
return (EVE_memRead32(EVE_RAM_CMD + cmdoffset));
}
/* 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_32(ptr);
spi_transmit_32((uint32_t) value);
spi_transmit_32(num);
EVE_cs_clear();
}
/* this is meant to be called outside display-list building, it includes executing the command and waiting for completion, does not support cmd-burst */
/* this is a pointless command, just use one of the EVE_memWrite* helper functions instead to directly write to EVEs memory */
/*
void EVE_cmd_memwrite(uint32_t dest, uint32_t num, const uint8_t *data)
{
eve_begin_cmd(CMD_MEMWRITE);
spi_transmit_32(dest);
spi_transmit_32(num);
num = (num + 3)&(~3);
for(count=0;count<len;count++)
{
spi_transmit(pgm_read_byte_far(data+count));
}
EVE_cs_clear();
while (EVE_busy());
}
*/
/* 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_memzero(uint32_t ptr, uint32_t num)
{
eve_begin_cmd(CMD_MEMZERO);
spi_transmit_32(ptr);
spi_transmit_32(num);
EVE_cs_clear();
while (EVE_busy());
}
/* this is meant to be called outside display-list building, it includes executing the command, does not support cmd-burst */
/* it does not wait for completion in order to allow the video to be paused or terminated by REG_PLAY_CONTROL */
void EVE_cmd_playvideo(uint32_t options, const uint8_t *data, uint32_t len)
{
eve_begin_cmd(CMD_PLAYVIDEO);
spi_transmit_32(options);
EVE_cs_clear();
#if EVE_GEN > 2
if( ((options & EVE_OPT_MEDIAFIFO) == 0) && ((options & EVE_OPT_FLASH) == 0) )/* direct data, neither by Media-FIFO or from Flash */
#else
if((options & EVE_OPT_MEDIAFIFO) == 0) /* direct data, not by Media-FIFO */
#endif
{
if(data)
{
block_transfer(data, len);
}
}
}
/* 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)
{
uint16_t cmdoffset;
eve_begin_cmd(CMD_REGREAD);
spi_transmit_32(ptr);
spi_transmit_32(0);
EVE_cs_clear();
while (EVE_busy());
cmdoffset = EVE_memRead16(REG_CMD_WRITE); /* read the graphics processor write pointer */
cmdoffset -= 4;
cmdoffset &= 0x0fff;
return (EVE_memRead32(EVE_RAM_CMD + cmdoffset));
}