forked from RudolphRiedel/FT800-FT813
-
Notifications
You must be signed in to change notification settings - Fork 0
/
EVE_commands.cpp
3315 lines (2983 loc) · 119 KB
/
EVE_commands.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
/*
@file EVE_commands.c
@brief contains FT8xx / BT8xx functions
@version 5.0
@date 2022-12-30
@author Rudolph Riedel
@section info
At least for Arm Cortex-M0 and Cortex-M4 I have fastest execution with -O2.
The c-standard is C99.
@section LICENSE
MIT License
Copyright (c) 2016-2022 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
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.
- fixed a few clang-tidy warnings
- fixed a few cppcheck warnings
- fixed a few CERT warnings
- converted all TABs to SPACEs
- made EVE_TOUCH_RZTHRESH in EVE_init() optional to a) remove it from EVE_config.h and b) make it configureable
externally
- changed EVE_init() to write 1200U to REG_TOUCH_RZTHRESH if EVE_TOUCH_RZTHRESH is not defined
- changed EVE_init() to return E_OK = 0x00 in case of success and more meaningfull values in case of failure
- changed EVE_busy() to return EVE_IS_BUSY if EVE is busy and E_OK = 0x00 if EVE is not busy - no real change in
functionality
- finally removed EVE_cmd_start() after setting it to deprecatd with the first 5.0 release
- renamed EVE_cmd_execute() to EVE_execute_cmd() to be more consistent, this is is not an EVE command
- changed EVE_init_flash() to return E_OK in case of success and more meaningfull values in case of failure
- added the return-value of EVE_FIFO_HALF_EMPTY to EVE_busy() to indicate there is more than 2048 bytes available
- minor cleanup, less break and else statements
- added the burst code back into all the functions for which there is a _burst version, this allows to use the version
without the traling _burst in the name when exceution speed is not an issue - e.g. with all targets supporting DMA
- removed the 4.0 history
- added the optional parameter EVE_ROTATE as define to EVE_init() to allow for screen rotation during init
thanks for the idea to AndrejValand on Github!
- added the optional parameter EVE_BACKLIGHT_PWM to EVE_init() to allow setting the backlight during init
- modified EVE_calibrate_manual() to work better with bar type displays
- fixed a large number of MISRA-C issues - mostly more casts for explicit type conversion and more brackets
- changed the varargs versions of cmd_button, cmd_text and cmd_toggle to use an array of uint32_t values to comply with MISRA-C
- basic maintenance: checked for violations of white space and indent rules
- more linter fixes for minor issues like variables shorter than 3 characters
- added EVE_color_a() / EVE_color_a_burst()
- more minor tweaks and fixes to make the static analyzer happy
- changed the burst variant of private_string_write() back to the older and faster version
*/
#include "EVE.hpp"
/* EVE Memory Commands - used with EVE_memWritexx and EVE_memReadxx */
#define MEM_WRITE 0x80U /* EVE Host Memory Write */
/* #define MEM_READ 0x00U */ /* EVE Host Memory Read */
/* define NULL if it not already is */
#ifndef NULL
#include <stdio.h>
#include <stdint.h>
#endif
static volatile uint8_t cmd_burst = 0U; /* 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(0U);
EVE_cs_clear();
}
uint8_t EVE_memRead8(uint32_t ft_address)
{
uint8_t data;
EVE_cs_set();
spi_transmit_32(((ft_address >> 16U) & 0x0000007fUL) + (ft_address & 0x0000ff00UL) + ((ft_address & 0x000000ffUL) << 16U));
data = spi_receive(0U); /* read data byte by sending another dummy byte */
EVE_cs_clear();
return data;
}
uint16_t EVE_memRead16(uint32_t ft_address)
{
uint16_t data;
EVE_cs_set();
spi_transmit_32(((ft_address >> 16U) & 0x0000007fUL) + (ft_address & 0x0000ff00UL) + ((ft_address & 0x000000ffUL) << 16U));
data = ((uint16_t) spi_receive(0U)); /* read low byte */
data = (((uint16_t) spi_receive(0U)) << 8U) | data; /* read high byte */
EVE_cs_clear();
return data;
}
uint32_t EVE_memRead32(uint32_t ft_address)
{
uint32_t data;
EVE_cs_set();
spi_transmit_32(((ft_address >> 16U) & 0x0000007fUL) + (ft_address & 0x0000ff00UL) + ((ft_address & 0x000000ffUL) << 16U));
data = ((uint32_t) spi_receive(0U)); /* read low byte */
data = ((uint32_t) spi_receive(0U) << 8U) | data;
data = ((uint32_t) spi_receive(0U) << 16U) | data;
data = ((uint32_t) spi_receive(0U) << 24U) | data; /* read high byte */
EVE_cs_clear();
return data;
}
void EVE_memWrite8(uint32_t ft_address, uint8_t ft_data)
{
EVE_cs_set();
spi_transmit((uint8_t)(ft_address >> 16U) | MEM_WRITE);
spi_transmit((uint8_t)(ft_address >> 8U));
spi_transmit((uint8_t)(ft_address & 0x000000ffUL));
spi_transmit(ft_data);
EVE_cs_clear();
}
void EVE_memWrite16(uint32_t ft_address, uint16_t ft_data)
{
EVE_cs_set();
spi_transmit((uint8_t)(ft_address >> 16U) | MEM_WRITE); /* send Memory Write plus high address byte */
spi_transmit((uint8_t)(ft_address >> 8U)); /* send middle address byte */
spi_transmit((uint8_t)(ft_address & 0x000000ffUL)); /* send low address byte */
spi_transmit((uint8_t)(ft_data & 0x00ffU)); /* send data low byte */
spi_transmit((uint8_t)(ft_data >> 8U)); /* send data high byte */
EVE_cs_clear();
}
void EVE_memWrite32(uint32_t ft_address, uint32_t ft_data)
{
EVE_cs_set();
spi_transmit((uint8_t)(ft_address >> 16U) | MEM_WRITE); /* send Memory Write plus high address byte */
spi_transmit((uint8_t)(ft_address >> 8U)); /* send middle address byte */
spi_transmit((uint8_t)(ft_address & 0x000000ffUL)); /* send low address byte */
spi_transmit_32(ft_data);
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 ft_address, const uint8_t *p_data, uint32_t len)
{
EVE_cs_set();
spi_transmit((uint8_t)(ft_address >> 16U) | MEM_WRITE);
spi_transmit((uint8_t)(ft_address >> 8U));
spi_transmit((uint8_t)(ft_address & 0x000000ffUL));
uint32_t length = (len + 3U) & (~3U);
for (uint32_t count = 0U; count < length; count++)
{
spi_transmit(fetch_flash_byte(&p_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 ft_address, const uint8_t *p_data, uint32_t len)
{
EVE_cs_set();
spi_transmit((uint8_t)(ft_address >> 16U) | MEM_WRITE);
spi_transmit((uint8_t)(ft_address >> 8U));
spi_transmit((uint8_t)(ft_address & 0x000000ffUL));
uint32_t length = (len + 3U) & (~3U);
for (uint32_t count = 0U; count < length; count++)
{
spi_transmit(p_data[count]);
}
EVE_cs_clear();
}
/* Check if the co-processor completed executing the current command list. */
/* Returns E_OK in case EVE is not busy (no DMA transfer active and REG_CMDB_SPACE has the value 0xffc, meaning the
* CMD-FIFO is empty. */
/* Returns EVE_FIFO_HALF_EMPTY if no DMA transfer is active and REG_CMDB_SPACE shows more than 2048 bytes available. */
/* Returns EVE_IS_BUSY if a DMA transfer is active or REG_CMDB_SPACE has a value smaller than 0xffc. */
uint8_t EVE_busy(void)
{
uint16_t space;
uint8_t ret = EVE_IS_BUSY;
#if defined(EVE_DMA)
if (0 == EVE_dma_busy)
{
#endif
space = EVE_memRead16(REG_CMDB_SPACE);
/* (REG_CMDB_SPACE & 0x03) != 0 -> we have a co-processor fault */
if ((space & 3U) != 0U) /* we have a co-processor fault, make EVE play with us again */
{
#if EVE_GEN > 2
uint16_t copro_patch_pointer;
copro_patch_pointer = EVE_memRead16(REG_COPRO_PATCH_DTR);
#endif
EVE_memWrite8(REG_CPURESET, 1U); /* hold co-processor engine in the reset condition */
EVE_memWrite16(REG_CMD_READ, 0U); /* set REG_CMD_READ to 0 */
EVE_memWrite16(REG_CMD_WRITE, 0U); /* set REG_CMD_WRITE to 0 */
EVE_memWrite32(REG_CMD_DL, 0U); /* reset REG_CMD_DL to 0 as required by the BT81x programming guide, should not hurt FT8xx */
EVE_memWrite8(REG_CPURESET, 0U); /* 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(5U); /* just to be safe */
EVE_cs_set();
spi_transmit((uint8_t) 0xB0U); /* high-byte of REG_CMDB_WRITE + MEM_WRITE */
spi_transmit((uint8_t) 0x25U); /* middle-byte of REG_CMDB_WRITE */
spi_transmit((uint8_t) 0x78U); /* low-byte of REG_CMDB_WRITE */
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(5U); /* just to be safe */
#endif
}
if (0xffcU == space)
{
ret = E_OK;
}
else if (space > 0x800U)
{
ret = EVE_FIFO_HALF_EMPTY;
}
else
{
ret = EVE_IS_BUSY;
}
#if defined(EVE_DMA)
}
#endif
return ret;
}
/* Wait for the co-processor to complete the FIFO queue.*/
void EVE_execute_cmd(void)
{
while (EVE_busy() != E_OK)
{
}
}
/* 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)
{
EVE_cs_set();
spi_transmit((uint8_t) 0xB0U); /* high-byte of REG_CMDB_WRITE + MEM_WRITE */
spi_transmit((uint8_t) 0x25U); /* middle-byte of REG_CMDB_WRITE */
spi_transmit((uint8_t) 0x78U); /* low-byte of REG_CMDB_WRITE */
spi_transmit_32(command);
}
void private_block_write(const uint8_t *p_data, uint16_t len); /* prototype to comply with MISRA */
void private_block_write(const uint8_t *p_data, uint16_t len)
{
uint8_t padding;
padding = (uint8_t) (len & 3U); /* 0, 1, 2 or 3 */
padding = 4U - padding; /* 4, 3, 2 or 1 */
padding &= 3U; /* 3, 2 or 1 */
for (uint16_t count = 0U; count < len; count++)
{
spi_transmit(fetch_flash_byte(&p_data[count]));
}
while (padding > 0U)
{
spi_transmit(0U);
padding--;
}
}
void block_transfer(const uint8_t *p_data, uint32_t len); /* prototype to comply with MISRA */
void block_transfer(const uint8_t *p_data, uint32_t len)
{
uint32_t bytes_left;
bytes_left = len;
while (bytes_left > 0U)
{
uint32_t block_len;
block_len = (bytes_left > 3840UL) ? 3840UL : bytes_left;
EVE_cs_set();
spi_transmit((uint8_t) 0xB0U); /* high-byte of REG_CMDB_WRITE + MEM_WRITE */
spi_transmit((uint8_t) 0x25U); /* middle-byte of REG_CMDB_WRITE */
spi_transmit((uint8_t) 0x78U); /* low-byte of REG_CMDB_WRITE */
private_block_write(p_data, (uint16_t) block_len);
EVE_cs_clear();
p_data = &p_data[block_len];
bytes_left -= block_len;
EVE_execute_cmd();
}
}
/* ##################################################################
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();
EVE_execute_cmd();
}
/* 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((uint32_t) ptr);
spi_transmit_32(num);
EVE_cs_clear();
EVE_execute_cmd();
}
/* 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 *p_total, int32_t *p_used)
{
uint16_t cmdoffset;
eve_begin_cmd(CMD_FONTCACHEQUERY);
spi_transmit_32(0UL);
spi_transmit_32(0UL);
EVE_cs_clear();
EVE_execute_cmd();
cmdoffset = EVE_memRead16(REG_CMD_WRITE); /* read the co-processor write pointer */
if (p_total != NULL)
{
*p_total = EVE_memRead32(EVE_RAM_CMD + ((cmdoffset - 8U) & 0xfffU));
}
if (p_used != NULL)
{
*p_used = (int32_t) EVE_memRead32(EVE_RAM_CMD + ((cmdoffset - 4U) & 0xfffU));
}
}
/* 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 *p_source, uint32_t *p_fmt, uint32_t *p_width, uint32_t *p_height, uint32_t *p_palette)
{
uint16_t cmdoffset;
eve_begin_cmd(CMD_GETIMAGE);
spi_transmit_32(0UL);
spi_transmit_32(0UL);
spi_transmit_32(0UL);
spi_transmit_32(0UL);
spi_transmit_32(0UL);
EVE_cs_clear();
EVE_execute_cmd();
cmdoffset = EVE_memRead16(REG_CMD_WRITE); /* read the co-processor write pointer */
if (p_palette != NULL)
{
*p_palette = EVE_memRead32(EVE_RAM_CMD + ((cmdoffset - 4U) & 0xfffU));
}
if (p_height != NULL)
{
*p_height = EVE_memRead32(EVE_RAM_CMD + ((cmdoffset - 8U) & 0xfffU));
}
if (p_width != NULL)
{
*p_width = EVE_memRead32(EVE_RAM_CMD + ((cmdoffset - 12U) & 0xfffU));
}
if (p_fmt != NULL)
{
*p_fmt = EVE_memRead32(EVE_RAM_CMD + ((cmdoffset - 16U) & 0xfffU));
}
if (p_source != NULL)
{
*p_source = EVE_memRead32(EVE_RAM_CMD + ((cmdoffset - 20U) & 0xfffU));
}
}
/* 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();
EVE_execute_cmd();
}
/* 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();
EVE_execute_cmd();
}
/* 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((uint32_t) rounding);
spi_transmit_32(0UL);
EVE_cs_clear();
EVE_execute_cmd();
cmdoffset = EVE_memRead16(REG_CMD_WRITE); /* read the co-processor write pointer */
cmdoffset -= 4U;
cmdoffset &= 0x0fffU;
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 usec)
{
eve_begin_cmd(CMD_WAIT);
spi_transmit_32(usec);
EVE_cs_clear();
EVE_execute_cmd();
}
#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);
EVE_execute_cmd();
EVE_cmd_dl(CMD_DLSTART);
EVE_cmd_dl(CMD_SWAP);
EVE_execute_cmd();
EVE_cmd_dl(CMD_CLEARCACHE);
EVE_execute_cmd();
}
/* 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_execute_cmd(); would work as well
*/
void EVE_cmd_flashattach(void)
{
eve_begin_cmd(CMD_FLASHATTACH);
EVE_cs_clear();
EVE_execute_cmd();
}
/* 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_execute_cmd(); would work as well
*/
void EVE_cmd_flashdetach(void)
{
eve_begin_cmd(CMD_FLASHDETACH);
EVE_cs_clear();
EVE_execute_cmd();
}
/* 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_execute_cmd(); would work as well */
void EVE_cmd_flasherase(void)
{
eve_begin_cmd(CMD_FLASHERASE);
EVE_cs_clear();
EVE_execute_cmd();
}
/* 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(0UL);
EVE_cs_clear();
EVE_execute_cmd();
cmdoffset = EVE_memRead16(REG_CMD_WRITE); /* read the co-processor write pointer */
cmdoffset -= 4U;
cmdoffset &= 0x0fffU;
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_execute_cmd(); would work as well
*/
void EVE_cmd_flashspidesel(void)
{
eve_begin_cmd(CMD_FLASHSPIDESEL);
EVE_cs_clear();
EVE_execute_cmd();
}
/* 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();
EVE_execute_cmd();
}
/* 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();
EVE_execute_cmd();
}
/* 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();
EVE_execute_cmd();
}
/* 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 *p_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 *p_data)
{
eve_begin_cmd(CMD_FLASHSPITX);
spi_transmit_32(num);
EVE_cs_clear();
block_transfer(p_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();
EVE_execute_cmd();
}
/* 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 *p_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 *p_data)
{
eve_begin_cmd(CMD_FLASHWRITE);
spi_transmit_32(ptr);
spi_transmit_32(num);
EVE_cs_clear();
if (p_data != NULL)
{
block_transfer(p_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 *p_data, uint32_t len)
{
eve_begin_cmd(CMD_INFLATE2);
spi_transmit_32(ptr);
spi_transmit_32(options);
EVE_cs_clear();
if (0UL == options) /* direct data, not by Media-FIFO or Flash */
{
if (p_data != NULL)
{
block_transfer(p_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*/
void EVE_cmd_getprops(uint32_t *p_pointer, uint32_t *p_width, uint32_t *p_height)
{
uint16_t cmdoffset;
eve_begin_cmd(CMD_GETPROPS);
spi_transmit_32(0UL);
spi_transmit_32(0UL);
spi_transmit_32(0UL);
EVE_cs_clear();
EVE_execute_cmd();
cmdoffset = EVE_memRead16(REG_CMD_WRITE); /* read the co-processor write pointer */
if (p_pointer != NULL)
{
*p_pointer = EVE_memRead32(EVE_RAM_CMD + ((cmdoffset - 12U) & 0xfffU));
}
if (p_width != NULL)
{
*p_width = EVE_memRead32(EVE_RAM_CMD + ((cmdoffset - 8U) & 0xfffU));
}
if (p_height != NULL)
{
*p_height = EVE_memRead32(EVE_RAM_CMD + ((cmdoffset - 4U) & 0xfffU));
}
}
/* 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_getptr(void)
{
uint16_t cmdoffset;
eve_begin_cmd(CMD_GETPTR);
spi_transmit_32(0UL);
EVE_cs_clear();
EVE_execute_cmd();
cmdoffset = EVE_memRead16(REG_CMD_WRITE); /* read the co-processor write pointer */
cmdoffset -= 4U;
cmdoffset &= 0x0fffU;
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 *p_data, uint32_t len)
{
eve_begin_cmd(CMD_INFLATE);
spi_transmit_32(ptr);
EVE_cs_clear();
if (p_data != NULL)
{
block_transfer(p_data, len);
}
}
/* This is meant to be called outside display-list building, does not support cmd-burst.*/
void EVE_cmd_interrupt(uint32_t msec)
{
eve_begin_cmd(CMD_INTERRUPT);
spi_transmit_32(msec);
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 *p_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 ((0UL == (options & EVE_OPT_MEDIAFIFO)) &&
(0UL == (options & EVE_OPT_FLASH))) /* direct data, neither by Media-FIFO or from Flash */
#else
if (0UL == (options & EVE_OPT_MEDIAFIFO)) /* direct data, not by Media-FIFO */
#endif
{
if (p_data != NULL)
{
block_transfer(p_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();
EVE_execute_cmd();
}
/* 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_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(0UL);
EVE_cs_clear();
EVE_execute_cmd();
cmdoffset = EVE_memRead16(REG_CMD_WRITE); /* read the co-processor write pointer */
cmdoffset -= 4U;
cmdoffset &= 0x0fffU;
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 to directly write to EVEs memory */
/*
void EVE_cmd_memwrite(uint32_t dest, uint32_t num, const uint8_t *p_data)
{
eve_begin_cmd(CMD_MEMWRITE);
spi_transmit_32(dest);
spi_transmit_32(num);
num = (num + 3U) & (~3U);
for (uint32_t count = 0U; count<len; count++)
{
spi_transmit(pgm_read_byte_far(p_data + count));
}
EVE_cs_clear();
EVE_execute_cmd();
}
*/
/* 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();
EVE_execute_cmd();
}
/* 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 *p_data, uint32_t len)
{
eve_begin_cmd(CMD_PLAYVIDEO);
spi_transmit_32(options);
EVE_cs_clear();
#if EVE_GEN > 2
if ((0UL == (options & EVE_OPT_MEDIAFIFO)) &&
(0UL == (options & EVE_OPT_FLASH))) /* direct data, neither by Media-FIFO or from Flash */
#else
if (0UL == (options & EVE_OPT_MEDIAFIFO)) /* direct data, not by Media-FIFO */
#endif
{
if (p_data != NULL)
{
block_transfer(p_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(0UL);
EVE_cs_clear();
EVE_execute_cmd();
cmdoffset = EVE_memRead16(REG_CMD_WRITE); /* read the co-processor write pointer */
cmdoffset -= 4U;
cmdoffset &= 0x0fffU;
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_setrotate(uint32_t rotation)
{
eve_begin_cmd(CMD_SETROTATE);
spi_transmit_32(rotation);
EVE_cs_clear();
EVE_execute_cmd();
}
/* 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_snapshot(uint32_t ptr)
{
eve_begin_cmd(CMD_SNAPSHOT);
spi_transmit_32(ptr);
EVE_cs_clear();
EVE_execute_cmd();
}
/* 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_snapshot2(uint32_t fmt, uint32_t ptr, int16_t xc0, int16_t yc0, int16_t wid, int16_t hgt)
{
eve_begin_cmd(CMD_SNAPSHOT2);
spi_transmit_32(fmt);
spi_transmit_32(ptr);
spi_transmit((uint8_t) ((uint16_t) xc0));
spi_transmit((uint8_t) (((uint16_t) xc0) >> 8U));
spi_transmit((uint8_t) ((uint16_t) yc0));
spi_transmit((uint8_t) (((uint16_t) yc0) >> 8U));
spi_transmit((uint8_t) ((uint16_t) wid));
spi_transmit((uint8_t) (((uint16_t) wid) >> 8U));
spi_transmit((uint8_t) ((uint16_t) hgt));
spi_transmit((uint8_t) (((uint16_t) hgt) >> 8U));
EVE_cs_clear();
EVE_execute_cmd();
}
/* 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_track(int16_t xc0, int16_t yc0, int16_t wid, int16_t hgt, int16_t tag)
{
eve_begin_cmd(CMD_TRACK);
spi_transmit((uint8_t) ((uint16_t) xc0));
spi_transmit((uint8_t) (((uint16_t) xc0) >> 8U));
spi_transmit((uint8_t) ((uint16_t) yc0));
spi_transmit((uint8_t) (((uint16_t) yc0) >> 8U));
spi_transmit((uint8_t) ((uint16_t) wid));
spi_transmit((uint8_t) (((uint16_t) wid) >> 8U));
spi_transmit((uint8_t) ((uint16_t) hgt));
spi_transmit((uint8_t) (((uint16_t) hgt) >> 8U));
spi_transmit((uint8_t) ((uint16_t) tag));
spi_transmit((uint8_t) (((uint16_t) tag) >> 8U));
spi_transmit(0U);
spi_transmit(0U);
EVE_cs_clear();
EVE_execute_cmd();
}
/* 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_videoframe(uint32_t dest, uint32_t result_ptr)
{
eve_begin_cmd(CMD_VIDEOFRAME);
spi_transmit_32(dest);
spi_transmit_32(result_ptr);
EVE_cs_clear();
EVE_execute_cmd();
}
/* ##################################################################
patching and initialization
#################################################################### */
#if EVE_GEN > 2
/**
* @brief EVE flash initialization for BT81x, switches the FLASH attached to a BT81x to full-speed mode
*
* @return returns E_OK in case of success, EVE_FAIL_FLASH_STATUS_INIT if the status remains init,
* EVE_FAIL_FLASH_STATUS_DETACHED if no flash chip was found, a number of different values for failures with
* cmd_flashfast and E_NOT_OK if a not supported status is returned in REG_FLASH_STATUS.
*/
uint8_t EVE_init_flash(void)