-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEVE_API.c
More file actions
2287 lines (1956 loc) · 57.4 KB
/
EVE_API.c
File metadata and controls
2287 lines (1956 loc) · 57.4 KB
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_API.c
*/
/*
* ============================================================================
* (C) Copyright, Bridgetek Pte. Ltd.
* ============================================================================
*
* This source code ("the Software") is provided by Bridgetek Pte Ltd
* ("Bridgetek") subject to the licence terms set out
* https://brtchip.com/wp-content/uploads/2021/11/BRT_Software_License_Agreement.pdf ("the Licence Terms").
* You must read the Licence Terms before downloading or using the Software.
* By installing or using the Software you agree to the Licence Terms. If you
* do not agree to the Licence Terms then do not download or use the Software.
*
* Without prejudice to the Licence Terms, here is a summary of some of the key
* terms of the Licence Terms (and in the event of any conflict between this
* summary and the Licence Terms then the text of the Licence Terms will
* prevail).
*
* The Software is provided "as is".
* There are no warranties (or similar) in relation to the quality of the
* Software. You use it at your own risk.
* The Software should not be used in, or for, any medical device, system or
* appliance. There are exclusions of Bridgetek liability for certain types of loss
* such as: special loss or damage; incidental loss or damage; indirect or
* consequential loss or damage; loss of income; loss of business; loss of
* profits; loss of revenue; loss of contracts; business interruption; loss of
* the use of money or anticipated savings; loss of information; loss of
* opportunity; loss of goodwill or reputation; and/or loss of, damage to or
* corruption of data.
* There is a monetary cap on Bridgetek's liability.
* The Software may have subsequently been amended by another user and then
* distributed by that other user ("Adapted Software"). If so that user may
* have additional licence terms that apply to those amendments. However, Bridgetek
* has no liability in relation to those amendments.
* ============================================================================
*/
#include <string.h>
#include <stdint.h> // for Uint8/16/32 and Int8/16/32 data types
#include <stdarg.h>
#include <EVE4.h>
#include <HAL.h>
#include <MCU.h>
#if IS_EVE_API(5)
#include "patch_base.h"
#endif
//##############################################################################
// Library functions
//##############################################################################
void EVE_Init(void)
{
uint8_t i;
HAL_EVE_Init();
// ------------------------- Display settings ------------------------------
// LCD display parameters
#if IS_EVE_API(1, 2, 3, 4)
uint8_t regGpio;
// Active width of LCD display
HAL_MemWrite16(EVE_REG_HSIZE, (uint16_t)EVE_DISP_WIDTH);
// Total number of clocks per line
HAL_MemWrite16(EVE_REG_HCYCLE, (uint16_t)EVE_DISP_HCYCLE);
// Start of active line
HAL_MemWrite16(EVE_REG_HOFFSET, (uint16_t)EVE_DISP_HOFFSET);
// Start of horizontal sync pulse
HAL_MemWrite16(EVE_REG_HSYNC0, (uint16_t)EVE_DISP_HSYNC0);
// End of horizontal sync pulse
HAL_MemWrite16(EVE_REG_HSYNC1, (uint16_t)EVE_DISP_HSYNC1);
// Active height of LCD display
HAL_MemWrite16(EVE_REG_VSIZE, (uint16_t)EVE_DISP_HEIGHT);
// Total number of lines per screen
HAL_MemWrite16(EVE_REG_VCYCLE, (uint16_t)EVE_DISP_VCYCLE);
// Start of active screen
HAL_MemWrite16(EVE_REG_VOFFSET, (uint16_t)EVE_DISP_VOFFSET);
// Start of vertical sync pulse
HAL_MemWrite16(EVE_REG_VSYNC0, (uint16_t)EVE_DISP_VSYNC0);
// End of vertical sync pulse
HAL_MemWrite16(EVE_REG_VSYNC1, (uint16_t)EVE_DISP_VSYNC1);
// Define active edge of PCLK
HAL_MemWrite8(EVE_REG_PCLK_POL, (uint16_t)EVE_DISP_PCLKPOL);
// Define RGB output pins
HAL_MemWrite8(EVE_REG_SWIZZLE, (uint16_t)EVE_DISP_SWIZZLE);
// Turn on or off CSpread
HAL_MemWrite8(EVE_REG_CSPREAD, (uint16_t)EVE_DISP_CSPREAD);
// Turn on or off Dither
HAL_MemWrite8(EVE_REG_DITHER, (uint16_t)EVE_DISP_DITHER);
#if defined(EVE_TOUCH_ADDR) && defined(EVE_REG_TOUCH_CONFIG)
HAL_MemWrite16(EVE_REG_TOUCH_CONFIG, (uint16_t)EVE_TOUCH_ADDR << 4);
#endif
// Write first display list
HAL_MemWrite32((EVE_RAM_DL + 0), EVE_ENC_CLEAR_COLOR_RGB(0,0,0));
HAL_MemWrite32((EVE_RAM_DL + 4), EVE_ENC_CLEAR(1,1,1));
HAL_MemWrite32((EVE_RAM_DL + 8), EVE_ENC_DISPLAY());
HAL_MemWrite8(EVE_REG_DLSWAP, EVE_DLSWAP_FRAME);
// Read the GPIO register for a read/modify/write operation
regGpio = HAL_MemRead8(EVE_REG_GPIO);
// set bit 7 of GPIO register (DISP) - others are inputs
regGpio = regGpio | 0x80u;
// Enable the DISP signal to the LCD panel
HAL_MemWrite8(EVE_REG_GPIO, regGpio);
// Write the PCLK or PCLK_FREQ register
// If setting PCLK_FREQ then also set REG_PCLK to 1 to enable extsync mode
#if IS_EVE_API(4) && (defined SET_PCLK_FREQ)
HAL_MemWrite16(EVE_REG_PCLK_FREQ, (uint16_t)EVE_DISP_PCLK_FREQ);
HAL_MemWrite8(EVE_REG_PCLK, 1);
#else
// Now start clocking data to the LCD panel
HAL_MemWrite8(EVE_REG_PCLK, (uint16_t)EVE_DISP_PCLK);
#endif
HAL_MemWrite8(EVE_REG_PWM_DUTY, 127u);
// ---------------------- Touch and Audio settings -------------------------
// Eliminate any false touches
HAL_MemWrite16(EVE_REG_TOUCH_RZTHRESH, 1200);
// turn recorded audio volume down
HAL_MemWrite8(EVE_REG_VOL_PB, EVE_VOL_ZERO);
// turn synthesizer volume down
HAL_MemWrite8(EVE_REG_VOL_SOUND, EVE_VOL_ZERO);
// set synthesizer to mute
HAL_MemWrite16(EVE_REG_SOUND, 0x6000);
#ifndef EVE_USE_CMDB_METHOD
HAL_MemWrite32(EVE_REG_CMD_READ, 0);
HAL_ResetCmdPointer();
HAL_WriteCmdPointer();
#endif
#elif IS_EVE_API(5)
EVE_LIB_BeginCoProList();
EVE_CMD_REGWRITE(EVE_REG_SC0_SIZE, 2);
EVE_CMD_REGWRITE(EVE_REG_SC0_PTR0, (EVE_RAM_G_SIZE - 0x280000UL - ((uint32_t)EVE_DISP_WIDTH * (uint32_t)EVE_DISP_HEIGHT * 3UL)));
EVE_CMD_REGWRITE(EVE_REG_SC0_PTR1, (EVE_RAM_G_SIZE - 0x280000UL - (2UL * (uint32_t)EVE_DISP_WIDTH * (uint32_t)EVE_DISP_HEIGHT * 3UL)));
EVE_LIB_EndCoProList();
EVE_LIB_AwaitCoProEmpty();
EVE_LIB_BeginCoProList();
EVE_CMD_RENDERTARGET(EVE_SWAPCHAIN_0, (uint32_t)EVE_DISP_LVDSTXFORMAT, (uint32_t)EVE_DISP_WIDTH, (uint32_t)EVE_DISP_HEIGHT);
EVE_CLEAR(1,1,1);
EVE_CMD_SWAP();
EVE_CMD_GRAPHICSFINISH();
EVE_LIB_EndCoProList();
EVE_LIB_AwaitCoProEmpty();
EVE_LIB_BeginCoProList();
EVE_CMD_REGWRITE(EVE_REG_GPIO, 0x80ul);
EVE_CMD_REGWRITE(EVE_REG_DISP, 1ul);
// Total number of clocks per line
EVE_CMD_REGWRITE(EVE_REG_HCYCLE, (uint32_t)EVE_DISP_HCYCLE);
// Active width of LCD display
EVE_CMD_REGWRITE(EVE_REG_HSIZE, (uint32_t)EVE_DISP_WIDTH);
// Start of active line
EVE_CMD_REGWRITE(EVE_REG_HOFFSET, (uint32_t)EVE_DISP_HOFFSET);
// Start of horizontal sync pulse
EVE_CMD_REGWRITE(EVE_REG_HSYNC0, (uint32_t)EVE_DISP_HSYNC0);
// End of horizontal sync pulse
EVE_CMD_REGWRITE(EVE_REG_HSYNC1, (uint32_t)EVE_DISP_HSYNC1);
// Total number of lines per screen
EVE_CMD_REGWRITE(EVE_REG_VCYCLE, (uint32_t)EVE_DISP_VCYCLE);
// Active height of LCD display
EVE_CMD_REGWRITE(EVE_REG_VSIZE, (uint32_t)EVE_DISP_HEIGHT);
// Start of active screen
EVE_CMD_REGWRITE(EVE_REG_VOFFSET, (uint32_t)EVE_DISP_VOFFSET);
// Start of vertical sync pulse
EVE_CMD_REGWRITE(EVE_REG_VSYNC0, (uint32_t)EVE_DISP_VSYNC0);
// End of vertical sync pulse
EVE_CMD_REGWRITE(EVE_REG_VSYNC1, (uint32_t)EVE_DISP_VSYNC1);
// Define active edge of PCLK
EVE_CMD_REGWRITE(EVE_REG_PCLK_POL, 0ul);
EVE_CMD_REGWRITE(EVE_REG_RE_DITHER, 1ul);
#if defined(EVE_TOUCH_ADDR) && defined(EVE_TOUCH_TYPE)
EVE_CMD_REGWRITE(EVE_REG_TOUCH_CONFIG, ((uint32_t)EVE_TOUCH_ADDR << 4) | ((uint32_t)EVE_TOUCH_TYPE) | (1 << 11));
#endif
// 0: 1 pixel single // 1: 2 pixel single // 2: 2 pixel dual // 3: 4 pixel dual
uint32_t extsyncmode = 3;
uint32_t lvdstlldiv = EVE_DISP_LVDSTXCLKDIV;
uint32_t pllcfg = 0;
if (lvdstlldiv > 4) pllcfg = 0x00300870 + lvdstlldiv;
else pllcfg = 0x00301070 + lvdstlldiv;
EVE_CMD_APBWRITE(EVE_REG_LVDSTX_PLLCFG, pllcfg);
EVE_CMD_APBWRITE(EVE_REG_LVDSTX_EN, 6ul); // Enable PLLs for LVDS CH1 and CH2
EVE_CMD_REGWRITE(EVE_REG_SO_MODE, extsyncmode);
EVE_CMD_REGWRITE(EVE_REG_SO_SOURCE, EVE_SWAPCHAIN_0);
EVE_CMD_REGWRITE(EVE_REG_SO_FORMAT, (uint32_t)EVE_DISP_LVDSTXFORMAT);
EVE_CMD_REGWRITE(EVE_REG_SO_EN, 1ul);
EVE_LIB_EndCoProList();
EVE_LIB_AwaitCoProEmpty();
// Load base patch or project defined patch if overriden
eve_loadpatch();
#endif
// --------------------- Clear screen ready to start -----------------------
EVE_LIB_BeginCoProList();
EVE_CMD_DLSTART();
EVE_CLEAR_COLOR_RGB(0, 0, 0);
EVE_CLEAR(1,1,1);
EVE_DISPLAY();
EVE_CMD_SWAP();
EVE_LIB_EndCoProList();
EVE_LIB_AwaitCoProEmpty();
#if IS_EVE_API(1)
// ---------------------- Reset all bitmap properties ------------------------
EVE_LIB_BeginCoProList();
EVE_CMD_DLSTART();
EVE_CLEAR_COLOR_RGB(0, 0, 0);
EVE_CLEAR(1,1,1);
for (i = 0; i < 16; i++)
{
EVE_BITMAP_HANDLE(i);
//EVE_CMD_SETBITMAP(0,0,0,0);
EVE_BITMAP_LAYOUT(0, 0, 0);
EVE_BITMAP_SIZE(0, 0, 0, 0, 0);
}
EVE_DISPLAY();
EVE_CMD_SWAP();
EVE_LIB_EndCoProList();
EVE_LIB_AwaitCoProEmpty();
#elif IS_EVE_API(2, 3, 4, 5)
// ---------------------- Reset all bitmap properties ------------------------
EVE_LIB_BeginCoProList();
EVE_CMD_DLSTART();
EVE_CLEAR_COLOR_RGB(0, 0, 0);
EVE_CLEAR(1,1,1);
for (i = 0; i < 16; i++)
{
EVE_BITMAP_HANDLE(i);
EVE_CMD_SETBITMAP(0,0,0,0);
}
EVE_DISPLAY();
EVE_CMD_SWAP();
EVE_LIB_EndCoProList();
EVE_LIB_AwaitCoProEmpty();
#endif
}
// Begins co-pro list for display creation
void EVE_LIB_BeginCoProList(void)
{
// Wait for command FIFO to be empty and record current position in FIFO
EVE_LIB_AwaitCoProEmpty();
// Begins SPI transaction
HAL_ChipSelect(1);
#if IS_EVE_API(1)
// Send address for writing as the next free location in the co-pro buffer
HAL_SetWriteAddress(EVE_RAM_CMD + HAL_GetCmdPointer());
#else
// Send address for writing
HAL_SetWriteAddress(EVE_REG_CMDB_WRITE);
#endif
}
// Ends co-pro list for display creation
void EVE_LIB_EndCoProList(void)
{
// End SPI transaction
HAL_ChipSelect(0);
// Update the ring buffer pointer to start decode
#ifndef EVE_USE_CMDB_METHOD
HAL_WriteCmdPointer();
#endif
}
// Waits for the read and write pointers to become equal
int EVE_LIB_AwaitCoProEmpty(void)
{
// Await completion of processing
return HAL_WaitCmdFifoEmpty();
}
// Gets a result from the command buffer
uint32_t EVE_LIB_GetResult(int offset)
{
uint32_t wp, rp;
do {
rp = HAL_MemRead32(EVE_REG_CMD_READ);
wp = HAL_GetCmdPointer();//HAL_MemRead32(EVE_REG_CMD_WRITE);
}
while (rp != wp);
uint32_t CmdBufPointer = (rp - (offset * sizeof(uint32_t))) & (EVE_RAM_CMD_SIZE - 1);
uint32_t r = HAL_MemRead32(EVE_RAM_CMD + CmdBufPointer);
return r;
}
#if IS_EVE_API(5)
// Obtain the co-processor exception description (up-to 128 characters)
void EVE_LIB_GetCoProException(char* desc)
{
uint8_t j;
uint8_t i;
char c;
for (j = 0; j < 128; j += 4)
{
// Read the text from the report register
uint32_t w = HAL_MemRead32(EVE_COPROC_REPORT + j);
// Immediately clear the report register
HAL_MemWrite32(EVE_COPROC_REPORT + j, 0);
// Add the 4 characters to the report string
for (i = 0; i < 4; i++)
{
c = (w >> (i * 8)) & 0x7f;
*desc++ = c;
// Break at the end of the report
if (c == '\0') break;
}
if (c == '\0') break;
}
}
#endif
// Writes a block of data to the RAM_G
void EVE_LIB_WriteDataToRAMG(const uint8_t *ImgData, uint32_t DataSize, uint32_t DestAddress)
{
uint32_t CurrentIndex = 0;
uint32_t ChunkSize = 0;
const uint32_t MaxChunkSize = 1024;
uint8_t IsLastChunk = 0;
// Pad data length to multiple of 4.
DataSize = (DataSize + 3) & (~3);
// While not all data is sent
while (CurrentIndex < DataSize)
{
// If more than ChunkSize bytes to send
if ((DataSize - CurrentIndex) > MaxChunkSize)
{
// ... then add ChunkSize to the current target index to make new target
ChunkSize = MaxChunkSize;
// ... and this is not the last chunk
IsLastChunk = 0;
}
// or if all remaining bytes can fit in one chunk
else
{
// ... then add the amount of data to the current target
ChunkSize = DataSize - CurrentIndex;
// .. and this is the last chunk
IsLastChunk = 1;
}
// Begin an SPI burst write
HAL_ChipSelect(1);
// Send address to which first value will be written
HAL_SetWriteAddress(DestAddress + CurrentIndex);
HAL_Write(ImgData, ChunkSize);
ImgData += ChunkSize;
CurrentIndex += ChunkSize;
// End the SPI burst
HAL_ChipSelect(0);
// If this is the last chunk of the data,
if (IsLastChunk)
{
break;
}
}
}
// Reads a block of data from the RAM_G
void EVE_LIB_ReadDataFromRAMG(uint8_t *ImgData, uint32_t DataSize, uint32_t SrcAddress)
{
uint32_t CurrentIndex = 0;
uint32_t ChunkSize = 0;
const uint32_t MaxChunkSize = 1024;
uint8_t IsLastChunk = 0;
// While not all data is received
while (CurrentIndex < DataSize)
{
// If more than ChunkSize bytes to receive
if ((DataSize - CurrentIndex) > MaxChunkSize)
{
// ... then add ChunkSize to the current target index to make new target
ChunkSize = MaxChunkSize;
// ... and this is not the last chunk
IsLastChunk = 0;
}
// or if all remaining bytes can fit in one chunk
else
{
// ... then add the amount of data to the current target
ChunkSize = DataSize - CurrentIndex;
// .. and this is the last chunk
IsLastChunk = 1;
}
// Begin an SPI burst read
HAL_ChipSelect(1);
// Send address to which first value will be read
HAL_SetReadAddress(SrcAddress + CurrentIndex);
HAL_Read(ImgData, ChunkSize);
ImgData += ChunkSize;
CurrentIndex += ChunkSize;
// End the SPI burst
HAL_ChipSelect(0);
// If this is the last chunk of the data,
if (IsLastChunk)
{
break;
}
}
}
// Write a block of data to the co-processor
void EVE_LIB_WriteDataToCMD(const uint8_t *ImgData, uint32_t DataSize)
{
uint32_t CurrentIndex = 0;
uint32_t ChunkSize = 0;
const uint32_t MaxChunkSize = 128;
uint8_t IsLastChunk = 0;
uint32_t Freespace = 0;
HAL_ChipSelect(0);
// This code works by sending the data in a series of one or more bursts.
// If the data is more than MaxChunkSize bytes, it is sent as a series of
// one or more bursts and then the remainder. MaxChunkSize is a size which
// is smaller than the command buffer on the EVE and small enough to gain
// maximum buffering effect from the MCU SPI hardware.
// Pad data length to multiple of 4.
DataSize = (DataSize + 3) & (~3);
// While not all data is sent
while (CurrentIndex < DataSize)
{
// If more than ChunkSize bytes to send
if ((DataSize - CurrentIndex) > MaxChunkSize)
{
// ... then add ChunkSize to the current target index to make new target
ChunkSize = MaxChunkSize;
// ... and this is not the last chunk
IsLastChunk = 0;
}
// or if all remaining bytes can fit in one chunk
else
{
// ... then add the amount of data to the current target
ChunkSize = DataSize - CurrentIndex;
// .. and this is the last chunk
IsLastChunk = 1;
}
// Wait until there is space
Freespace = 0;
while (Freespace < MaxChunkSize)
{
Freespace = HAL_CheckCmdFreeSpace();
}
// Begin an SPI burst write
HAL_ChipSelect(1);
// to the next location in the FIFO
#ifndef EVE_USE_CMDB_METHOD
HAL_SetWriteAddress(EVE_RAM_CMD + HAL_GetCmdPointer());
#else
HAL_SetWriteAddress(EVE_REG_CMDB_WRITE);
#endif
HAL_Write(ImgData, ChunkSize);
ImgData += ChunkSize;
CurrentIndex += ChunkSize;
// End the SPI burst
HAL_ChipSelect(0);
// Calculate where end of data lies
HAL_IncCmdPointer(ChunkSize);
#ifndef EVE_USE_CMDB_METHOD
HAL_WriteCmdPointer();
#endif
// If this is the last chunk of the data,
if (IsLastChunk)
{
break;
}
}
}
void EVE_LIB_MemWrite32(uint32_t addr, uint32_t value)
{
HAL_MemWrite32(addr, value);
}
uint32_t EVE_LIB_MemRead32(uint32_t address)
{
return HAL_MemRead32(address);
}
#if IS_EVE_API(1, 2, 3, 4) // Not supported on BT82x
void EVE_LIB_MemWrite16(uint32_t addr, uint16_t value)
{
HAL_MemWrite16(addr, value);
}
uint16_t EVE_LIB_MemRead16(uint32_t address)
{
return HAL_MemRead16(address);
}
void EVE_LIB_MemWrite8(uint32_t addr, uint8_t value)
{
HAL_MemWrite8(addr, value);
}
uint8_t EVE_LIB_MemRead8(uint32_t address)
{
return HAL_MemRead8(address);
}
#endif // IS_EVE_API(1, 2, 3, 4)
// Writes a string over SPI
uint16_t EVE_LIB_SendString(const char* string)
{
uint16_t length;
uint16_t CommandSize;
// Include the terminating null character in the string length.
// Pad string length to a multiple of 4.
length = ((strlen(string) + 1) + 3) & (~3);
// Store command length to return.
CommandSize = length;
#if MCU_UNALIGNED_ACCESSES
// Send string as 32 bit data.
while (length)
{
HAL_Write32(*(uint32_t *)string);
string += 4;
length -= 4;
}
#else
uint32_t val32;
while (length)
{
val32 = *string++;
val32 |= ((uint32_t)*string++ << 8);
val32 |= ((uint32_t)*string++ << 16);
val32 |= ((uint32_t)*string++ << 24);
HAL_Write32(val32);
length -= 4;
}
#endif
return CommandSize;
}
void EVE_LIB_GetProps(uint32_t *addr, uint32_t *width, uint32_t *height)
{
// To read the result from CMD_GETPROPS we need to be clever and find out
// where the CoProcessor is writing the command. We can then retrieve the
// results from the place where they were written.
// Send the command to the CoProcessor.
EVE_LIB_BeginCoProList();
EVE_CMD_GETPROPS(0, 0, 0);
// Wait for it to finish.
// TODO For BT82x (EVE5_API) use EVE_ENC_CMD_RESULT to retrive these results.
EVE_LIB_EndCoProList();
EVE_LIB_AwaitCoProEmpty();
// Obtain the results from the EVE_RAM_CMD in the CoProcessor.
*addr = EVE_LIB_GetResult(3);
*width = EVE_LIB_GetResult(2);
*height = EVE_LIB_GetResult(1);
}
void EVE_LIB_GetPtr(uint32_t *addr)
{
EVE_LIB_BeginCoProList();
// Send the command to the CoProcessor.
EVE_CMD_GETPTR(0);
// Wait for it to finish.
EVE_LIB_EndCoProList();
EVE_LIB_AwaitCoProEmpty();
// Obtain the results from the EVE_RAM_CMD in the CoProcessor.
*addr = EVE_LIB_GetResult(1);
}
void EVE_LIB_GetMatrix(uint32_t *a, uint32_t *b, uint32_t *c, uint32_t *d, uint32_t *e, uint32_t *f)
{
EVE_LIB_BeginCoProList();
// Send the command to the CoProcessor.
EVE_CMD_GETMATRIX(0, 0, 0, 0, 0, 0);
// Wait for it to finish.
EVE_LIB_EndCoProList();
EVE_LIB_AwaitCoProEmpty();
// Obtain the results from the EVE_RAM_CMD in the CoProcessor.
*a = EVE_LIB_GetResult(6);
*b = EVE_LIB_GetResult(5);
*c = EVE_LIB_GetResult(4);
*d = EVE_LIB_GetResult(3);
*e = EVE_LIB_GetResult(2);
*f = EVE_LIB_GetResult(1);
}
void EVE_LIB_MemCrc(uint32_t ptr, uint32_t num, uint32_t *result)
{
EVE_LIB_BeginCoProList();
// Send the command to the CoProcessor.
EVE_CMD_MEMCRC(ptr, num, 0);
// Wait for it to finish.
EVE_LIB_EndCoProList();
EVE_LIB_AwaitCoProEmpty();
// Obtain the results from the EVE_RAM_CMD in the CoProcessor.
*result = EVE_LIB_GetResult(1);
}
#if IS_EVE_API(2, 3, 4, 5)
void EVE_LIB_BitmapTransform( int32_t x0, int32_t y0, int32_t x1, int32_t y1, int32_t x2, int32_t y2,
int32_t tx0, int32_t ty0, int32_t tx1, int32_t ty1, int32_t tx2, int32_t ty2,
uint32_t *result )
{
EVE_LIB_BeginCoProList();
// Send the command to the CoProcessor.
EVE_CMD_BITMAP_TRANSFORM(x0, y0, x1, y1, x2, y2, tx0, ty0, tx1, ty1, tx2, ty2, 0);
// Wait for it to finish.
EVE_LIB_EndCoProList();
EVE_LIB_AwaitCoProEmpty();
// Obtain the results from the EVE_RAM_CMD in the CoProcessor.
*result = EVE_LIB_GetResult(1);
}
#endif
#if IS_EVE_API(4, 5)
void EVE_LIB_GetImage(uint32_t *addr, uint32_t *fmt, uint32_t *width, uint32_t *height, uint32_t *palette)
{
EVE_LIB_BeginCoProList();
// Send the command to the CoProcessor.
EVE_CMD_GETIMAGE(0, 0, 0, 0, 0);
// Wait for it to finish.
EVE_LIB_EndCoProList();
EVE_LIB_AwaitCoProEmpty();
// Obtain the results from the EVE_RAM_CMD in the CoProcessor.
*addr = EVE_LIB_GetResult(5);
*fmt = EVE_LIB_GetResult(4);
*width = EVE_LIB_GetResult(3);
*height = EVE_LIB_GetResult(2);
*palette = EVE_LIB_GetResult(1);
}
#endif
#if IS_EVE_API(5)
void EVE_LIB_RegRead(uint32_t addr, uint32_t *value)
{
EVE_LIB_BeginCoProList();
// Send the command to the CoProcessor.
EVE_CMD_REGREAD(addr, 0);
// Wait for it to finish.
EVE_LIB_EndCoProList();
EVE_LIB_AwaitCoProEmpty();
// Obtain the results from the EVE_RAM_CMD in the CoProcessor.
*value = EVE_LIB_GetResult(1);
}
#endif
//##############################################################################
// Display List commands for co-processor
//##############################################################################
void EVE_CMD(uint32_t c)
{
HAL_Write32(c);
HAL_IncCmdPointer(4);
}
void EVE_CLEAR_COLOR_RGB(uint8_t R, uint8_t G, uint8_t B)
{
HAL_Write32(EVE_ENC_CLEAR_COLOR_RGB(R, G, B));
HAL_IncCmdPointer(4);
}
void EVE_CLEAR_COLOR(uint32_t c)
{
HAL_Write32(EVE_ENC_CLEAR_COLOR(c));
HAL_IncCmdPointer(4);
}
void EVE_CLEAR(uint8_t C, uint8_t S, uint8_t T)
{
HAL_Write32(EVE_ENC_CLEAR((C & 0x01),(S & 0x01),(T & 0x01)));
HAL_IncCmdPointer(4);
}
void EVE_COLOR_RGB(uint8_t R, uint8_t G, uint8_t B)
{
HAL_Write32(EVE_ENC_COLOR_RGB(R, G, B));
HAL_IncCmdPointer(4);
}
void EVE_COLOR(uint32_t c)
{
HAL_Write32(EVE_ENC_COLOR(c));
HAL_IncCmdPointer(4);
}
void EVE_VERTEX2F(int16_t x, int16_t y)
{
HAL_Write32(EVE_ENC_VERTEX2F(x, y));
HAL_IncCmdPointer(4);
}
void EVE_VERTEX2II(uint16_t x, uint16_t y, uint8_t handle, uint8_t cell)
{
HAL_Write32(EVE_ENC_VERTEX2II(x, y, handle, cell));
HAL_IncCmdPointer(4);
}
void EVE_BITMAP_HANDLE(uint8_t handle)
{
HAL_Write32(EVE_ENC_BITMAP_HANDLE(handle));
HAL_IncCmdPointer(4);
}
void EVE_BITMAP_SOURCE(int32_t addr)
{
HAL_Write32(EVE_ENC_BITMAP_SOURCE((int32_t)addr));
HAL_IncCmdPointer(4);
}
#if IS_EVE_API(3, 4)
void EVE_BITMAP_SOURCE2(uint8_t flash_or_ram, int32_t addr)
{
HAL_Write32(EVE_ENC_BITMAP_SOURCE2((uint32_t)flash_or_ram, (int32_t)addr));
HAL_IncCmdPointer(4);
}
#endif
void EVE_BITMAP_LAYOUT(uint8_t format, uint16_t linestride, uint16_t height )
{
HAL_Write32(EVE_ENC_BITMAP_LAYOUT(format, linestride, height));
HAL_IncCmdPointer(4);
}
void EVE_BITMAP_SIZE(uint8_t filter, uint8_t wrapx, uint8_t wrapy, uint16_t width, uint16_t height)
{
HAL_Write32(EVE_ENC_BITMAP_SIZE(filter, wrapx, wrapy, width, height));
HAL_IncCmdPointer(4);
}
void EVE_CELL(uint8_t cell)
{
HAL_Write32(EVE_ENC_CELL(cell));
HAL_IncCmdPointer(4);
}
void EVE_TAG(uint8_t s)
{
HAL_Write32(EVE_ENC_TAG(s));
HAL_IncCmdPointer(4);
}
void EVE_ALPHA_FUNC(uint8_t func, uint8_t ref)
{
HAL_Write32(EVE_ENC_ALPHA_FUNC(func, ref));
HAL_IncCmdPointer(4);
}
void EVE_STENCIL_FUNC(uint8_t func, uint8_t ref, uint8_t mask)
{
HAL_Write32(EVE_ENC_STENCIL_FUNC(func, ref, mask));
HAL_IncCmdPointer(4);
}
void EVE_BLEND_FUNC(uint8_t src, uint8_t dst)
{
HAL_Write32(EVE_ENC_BLEND_FUNC(src, dst));
HAL_IncCmdPointer(4);
}
void EVE_STENCIL_OP(uint8_t sfail, uint8_t spass)
{
HAL_Write32(EVE_ENC_STENCIL_OP(sfail, spass));
HAL_IncCmdPointer(4);
}
void EVE_POINT_SIZE(uint16_t size)
{
HAL_Write32(EVE_ENC_POINT_SIZE(size));
HAL_IncCmdPointer(4);
}
void EVE_LINE_WIDTH(uint16_t width)
{
HAL_Write32(EVE_ENC_LINE_WIDTH(width));
HAL_IncCmdPointer(4);
}
void EVE_CLEAR_COLOR_A(uint8_t alpha)
{
HAL_Write32(EVE_ENC_CLEAR_COLOR_A(alpha));
HAL_IncCmdPointer(4);
}
void EVE_COLOR_A(uint8_t alpha)
{
HAL_Write32(EVE_ENC_COLOR_A(alpha));
HAL_IncCmdPointer(4);
}
void EVE_CLEAR_STENCIL(uint8_t s)
{
HAL_Write32(EVE_ENC_CLEAR_STENCIL(s));
HAL_IncCmdPointer(4);
}
void EVE_CLEAR_TAG(uint8_t s)
{
HAL_Write32(EVE_ENC_CLEAR_TAG(s));
HAL_IncCmdPointer(4);
}
void EVE_STENCIL_MASK(uint8_t mask)
{
HAL_Write32(EVE_ENC_STENCIL_MASK(mask));
HAL_IncCmdPointer(4);
}
void EVE_TAG_MASK(uint8_t mask)
{
HAL_Write32(EVE_ENC_TAG_MASK(mask));
HAL_IncCmdPointer(4);
}
void EVE_SCISSOR_XY(uint16_t x, uint16_t y)
{
HAL_Write32(EVE_ENC_SCISSOR_XY(x, y));
HAL_IncCmdPointer(4);
}
void EVE_SCISSOR_SIZE(uint16_t width, uint16_t height)
{
HAL_Write32(EVE_ENC_SCISSOR_SIZE(width, height));
HAL_IncCmdPointer(4);
}
void EVE_CALL(uint16_t dest)
{
HAL_Write32(EVE_ENC_CALL(dest));
HAL_IncCmdPointer(4);
}
void EVE_JUMP(uint16_t dest)
{
HAL_Write32(EVE_ENC_JUMP(dest));
HAL_IncCmdPointer(4);
}
void EVE_BEGIN(uint8_t prim)
{
HAL_Write32(EVE_ENC_BEGIN(prim));
HAL_IncCmdPointer(4);
}
void EVE_COLOR_MASK(uint8_t r, uint8_t g, uint8_t b, uint8_t a)
{
HAL_Write32(EVE_ENC_COLOR_MASK(r, g, b, a));
HAL_IncCmdPointer(4);
}
void EVE_END(void)
{
HAL_Write32(EVE_ENC_END());
HAL_IncCmdPointer(4);
}
void EVE_SAVE_CONTEXT(void)
{
HAL_Write32(EVE_ENC_SAVE_CONTEXT());
HAL_IncCmdPointer(4);
}
void EVE_RESTORE_CONTEXT(void)
{
HAL_Write32(EVE_ENC_RESTORE_CONTEXT());
HAL_IncCmdPointer(4);
}
void EVE_RETURN(void)
{
HAL_Write32(EVE_ENC_RETURN());
HAL_IncCmdPointer(4);
}
void EVE_MACRO(uint8_t m)
{
HAL_Write32(EVE_ENC_MACRO(m));
HAL_IncCmdPointer(4);
}
void EVE_DISPLAY(void)
{
HAL_Write32(EVE_ENC_DISPLAY());
HAL_IncCmdPointer(4);
}
void EVE_BITMAP_TRANSFORM_A(long a)
{
HAL_Write32(EVE_ENC_BITMAP_TRANSFORM_A(a)); // ((21UL << 24) | (((a)&131071UL)<<0))
HAL_IncCmdPointer(4);
}
void EVE_BITMAP_TRANSFORM_B(long b)
{
HAL_Write32(EVE_ENC_BITMAP_TRANSFORM_B(b)); // ((22UL << 24) | (((b)&131071UL)<<0))
HAL_IncCmdPointer(4);
}
void EVE_BITMAP_TRANSFORM_C(long c)
{
HAL_Write32(EVE_ENC_BITMAP_TRANSFORM_C(c)); // ((23UL << 24) | (((c)&16777215UL)<<0))
HAL_IncCmdPointer(4);
}
void EVE_BITMAP_TRANSFORM_D(long d)
{
HAL_Write32(EVE_ENC_BITMAP_TRANSFORM_D(d)); // ((24UL << 24) | (((d)&131071UL)<<0))
HAL_IncCmdPointer(4);
}
void EVE_BITMAP_TRANSFORM_E(long e)
{
HAL_Write32(EVE_ENC_BITMAP_TRANSFORM_E(e)); // ((25UL << 24) | (((e)&131071UL)<<0))
HAL_IncCmdPointer(4);
}
void EVE_BITMAP_TRANSFORM_F(long f)
{
HAL_Write32(EVE_ENC_BITMAP_TRANSFORM_F(f)); // ((26UL << 24) | (((f)&16777215UL)<<0))
HAL_IncCmdPointer(4);
}
#if IS_EVE_API(2, 3, 4, 5) // FT81x API change
void EVE_VERTEX_FORMAT(uint8_t frac)
{
HAL_Write32(EVE_ENC_VERTEX_FORMAT(frac));
HAL_IncCmdPointer(4);
}
void EVE_BITMAP_LAYOUT_H(uint8_t linestride, uint8_t height)
{
HAL_Write32(EVE_ENC_BITMAP_LAYOUT_H(linestride, height));
HAL_IncCmdPointer(4);
}
void EVE_BITMAP_SIZE_H(uint8_t width, uint8_t height)
{
HAL_Write32(EVE_ENC_BITMAP_SIZE_H(width, height));
HAL_IncCmdPointer(4);
}
void EVE_PALETTE_SOURCE(uint32_t addr)
{
HAL_Write32(EVE_ENC_PALETTE_SOURCE(addr));
HAL_IncCmdPointer(4);
}
void EVE_VERTEX_TRANSLATE_X(uint32_t x)
{
HAL_Write32(EVE_ENC_VERTEX_TRANSLATE_X(x));
HAL_IncCmdPointer(4);
}
void EVE_VERTEX_TRANSLATE_Y(uint32_t y)
{
HAL_Write32(EVE_ENC_VERTEX_TRANSLATE_Y(y));
HAL_IncCmdPointer(4);