-
Notifications
You must be signed in to change notification settings - Fork 3
/
ILI948x_t4_mm.cpp
1695 lines (1397 loc) · 59.2 KB
/
ILI948x_t4_mm.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
#include "ILI948x_t4_mm.h"
//DMAMEM uint32_t framebuff[DATABUFBYTES];
#if !defined(ARDUINO_TEENSY_MICROMOD)
#error This library only supports the Teensy Micromod!
#endif
FLASHMEM ILI948x_t4_mm::ILI948x_t4_mm(int8_t dc, int8_t cs, int8_t rst)
{
_dc = dc;
_cs = cs;
_rst = rst;
}
FLASHMEM void ILI948x_t4_mm::begin(uint8_t buad_div)
{
//Serial.printf("Bus speed: %d Mhz \n", buad_div);
switch (buad_div) {
case 2: _buad_div = 120;
break;
case 4: _buad_div = 60;
break;
case 8: _buad_div = 30;
break;
case 12: _buad_div = 20;
break;
case 20: _buad_div = 12;
break;
case 24: _buad_div = 10;
break;
case 30: _buad_div = 8;
break;
case 40: _buad_div = 6;
break;
default: _buad_div = 20; // 12Mhz
break;
}
pinMode(_cs, OUTPUT); // CS
pinMode(_dc, OUTPUT); // DC
pinMode(_rst, OUTPUT); // RST
*(portControlRegister(_cs)) = 0xFF;
*(portControlRegister(_dc)) = 0xFF;
*(portControlRegister(_rst)) = 0xFF;
digitalWriteFast(_cs, HIGH);
digitalWriteFast(_dc, HIGH);
digitalWriteFast(_rst, HIGH);
delay(15);
digitalWrite(_rst, LOW);
delay(15);
digitalWriteFast(_rst, HIGH);
delay(100);
FlexIO_Init();
displayInit();
/*
setBitDepth(_bitDepth);
setTearingEffect(_bTearingOn);
if (_bTearingOn == true) {
setTearingScanLine(_tearingScanLine);
}
setFrameRate(_frameRate);
*/
_width = _TFTWIDTH;
_height = _TFTHEIGHT;
}
FLASHMEM uint8_t ILI948x_t4_mm::setBitDepth(uint8_t bitDepth)
{
uint8_t bd;
switch (bitDepth) {
case 16: _bitDepth = 16;
bd = 0x55;
break;
case 18: _bitDepth = 18;
bd = 0x66;
break;
case 24: //Unsupported
return _bitDepth;
break;
default: //Unsupported
return _bitDepth;
break;
}
SglBeatWR_nPrm_8(ILI9488_COLMOD, &bd, 1);
//Insert small delay here as rapid calls appear to fail
delay(10);
return _bitDepth;
}
FLASHMEM uint8_t ILI948x_t4_mm::getBitDepth()
{
return _bitDepth;
}
FLASHMEM void ILI948x_t4_mm::setFrameRate(uint8_t frRate)
{
_frameRate = frRate;
uint8_t fr28Hz[2] = {0x00, 0x11}; // 28.78fps, 17 clocks
uint8_t fr30Hz[2] = {0x10, 0x11}; // 30.38fps, 17 clocks
uint8_t fr39Hz[2] = {0x50, 0x11}; // 39.06fps, 17 clocks
uint8_t fr45Hz[2] = {0x70, 0x11}; // 45.57fps, 17 clocks
uint8_t fr54Hz[2] = {0x90, 0x11}; // 54.69ps, 17 clocks
uint8_t fr60Hz[2] = {0xA0, 0x11}; // 60.76fps, 17 clocks
uint8_t fr68Hz[2] = {0xB0, 0x11}; // 68.36fps, 17 clocks (ILI9488 default)
uint8_t fr78Hz[2] = {0xC0, 0x11}; // 78.13fps, 17 clocks
uint8_t fr91Hz[2] = {0xD0, 0x11}; // 91.15fps, 17 clocks
uint8_t frData[2];
//Select parameters for frame rate
switch (frRate) {
case 28: memcpy(frData, fr28Hz, sizeof fr28Hz); break;
case 30: memcpy(frData, fr30Hz, sizeof fr30Hz); break;
case 39: memcpy(frData, fr39Hz, sizeof fr39Hz); break;
case 45: memcpy(frData, fr45Hz, sizeof fr45Hz); break;
case 54: memcpy(frData, fr54Hz, sizeof fr54Hz); break;
case 60: memcpy(frData, fr60Hz, sizeof fr60Hz); break;
case 68: memcpy(frData, fr68Hz, sizeof fr68Hz); break;
case 78: memcpy(frData, fr78Hz, sizeof fr78Hz); break;
case 91: memcpy(frData, fr91Hz, sizeof fr91Hz); break;
default: memcpy(frData, fr60Hz, sizeof fr60Hz); _frameRate = 60; break;
}
SglBeatWR_nPrm_8(ILI9488_FRMCTR1, frData, 2);
}
FLASHMEM uint8_t ILI948x_t4_mm::getFrameRate()
{
return _frameRate;
}
FLASHMEM void ILI948x_t4_mm::setTearingEffect(bool tearingOn)
{
_bTearingOn = tearingOn;
uint8_t mode = 0x00;
CSLow();
if (_bTearingOn == true) {
SglBeatWR_nPrm_8(ILI9488_TEON, &mode, 1); //Tearing effect line on, mode 0 (V-Blanking)
} else {
SglBeatWR_nPrm_8(ILI9488_TEOFF,0,0);
}
CSHigh();
}
FLASHMEM bool ILI948x_t4_mm::getTearingEffect()
{
return _bTearingOn;
}
FLASHMEM void ILI948x_t4_mm::setTearingScanLine(uint16_t scanLine)
{
_tearingScanLine = scanLine;
uint8_t params[2] = {(uint8_t)(_tearingScanLine << 8), (uint8_t)(_tearingScanLine & 0xFF)};
SglBeatWR_nPrm_8(ILI9488_TESLWR, params, 2); //Tearing effect write scan line : 0x00 0x00 = line 0 (default), 0x00 0xA0 = line 160, 0x00 0xF0 = line 240
}
FLASHMEM uint16_t ILI948x_t4_mm::getTearingScanLine()
{
return _tearingScanLine;
}
FLASHMEM void ILI948x_t4_mm::setRotation(uint8_t r)
{
_rotation = r & 3;
switch (_rotation) {
case 0:
case 2: _width = _TFTWIDTH;
_height = _TFTHEIGHT;
break;
case 1:
case 3: _width = _TFTHEIGHT;
_height = _TFTWIDTH;
break;
}
SglBeatWR_nPrm_8(ILI9488_MADCTL, &MADCTL[_rotation], 1);
}
FLASHMEM void ILI948x_t4_mm::invertDisplay(bool invert)
{
SglBeatWR_nPrm_8(invert ? ILI9488_INVON : ILI9488_INVOFF,0,0);
}
FLASHMEM void ILI948x_t4_mm::onCompleteCB(CBF callback)
{
_callback = callback;
isCB = true;
}
FASTRUN void ILI948x_t4_mm::setAddrWindow(uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2)
{
uint8_t Command;
uint8_t CommandValue[4];
Command = 0x2A;
CommandValue[0U] = x1 >> 8U;
CommandValue[1U] = x1 & 0xFF;
CommandValue[2U] = x2 >> 8U;
CommandValue[3U] = x2 & 0xFF;
SglBeatWR_nPrm_8(Command, CommandValue, 4U);
Command = 0x2B;
CommandValue[0U] = y1 >> 8U;
CommandValue[1U] = y1 & 0xFF;
CommandValue[2U] = y2 >> 8U;
CommandValue[3U] = y2 & 0xFF;
SglBeatWR_nPrm_8(Command, CommandValue, 4U);
}
FASTRUN void ILI948x_t4_mm::displayInfo(){
CSLow();
Serial.printf("Manufacturer ID: 0x%02X\n", readCommand(ILI9488_RDID1));
Serial.printf("Module Version ID: 0x%02X\n", readCommand(ILI9488_RDID2));
Serial.printf("Module ID: 0x%02X\n", readCommand(ILI9488_RDID3));
Serial.printf("Display Power Mode: 0x%02X\n", readCommand(ILI9488_RDMODE));
Serial.printf("MADCTL Mode: 0x%02X\n", readCommand(ILI9488_RDMADCTL));
Serial.printf("Pixel Format: 0x%02X\n", readCommand(ILI9488_RDCOLMOD));
Serial.printf("Image Format: 0x%02X\n", readCommand(ILI9488_RDIMGFMT));
Serial.printf("Signal Mode: 0x%02X\n", readCommand(ILI9488_RDDSM));
uint8_t sdRes = readCommand(ILI9488_RDSELFDIAG);
Serial.printf("Self Diagnostic: %s (0x%02X)\n", sdRes == 0xc0 ? "OK" : "Failed", sdRes);
CSHigh();
}
FASTRUN void ILI948x_t4_mm::pushPixels16bit(const uint16_t * pcolors, uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2)
{
while(WR_DMATransferDone == false)
{
//Wait for any DMA transfers to complete
}
uint32_t area = (x2-x1+1)*(y2-y1+1);
if (!((_lastx1 == x1) && (_lastx2 == x2) && (_lasty1 == y1) && (_lasty2 == y2))) {
setAddrWindow( x1, y1, x2, y2);
_lastx1 = x1; _lastx2 = x2; _lasty1 = y1; _lasty2 = y2;
}
SglBeatWR_nPrm_16(ILI9488_RAMWR, pcolors, area);
}
FASTRUN void ILI948x_t4_mm::pushPixels16bitDMA(const uint16_t * pcolors, uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2){
while(WR_DMATransferDone == false)
{
//Wait for any DMA transfers to complete
}
uint32_t area = (x2-x1+1)*(y2-y1+1);
if (!((_lastx1 == x1) && (_lastx2 == x2) && (_lasty1 == y1) && (_lasty2 == y2))) {
setAddrWindow(x1, y1, x2, y2);
_lastx1 = x1; _lastx2 = x2; _lasty1 = y1; _lasty2 = y2;
}
MulBeatWR_nPrm_DMA(ILI9488_RAMWR, pcolors, area);
}
///////////////////
//Private functions
///////////////////
FLASHMEM void ILI948x_t4_mm::displayInit()
{
uint8_t Command;
uint8_t CommandValue[25];
#if defined (ILI9481_1)
Command = 0x01; //SW RST
SglBeatWR_nPrm_8(Command,0 ,0);
delay(120);
Command = 0x11;
SglBeatWR_nPrm_8(Command, 0, 0);
delay(20);
Command = 0xD0;
CommandValue[0U] = 0x07;
CommandValue[1U] = 0x41;
CommandValue[2U] = 0x1D;
SglBeatWR_nPrm_8(Command, CommandValue, 3U);
Command = 0xD1;
CommandValue[0U] = 0x00;
CommandValue[1U] = 0x2B;
CommandValue[2U] = 0x1F;
SglBeatWR_nPrm_8(Command, CommandValue, 3U);
Command = 0xD2;
CommandValue[0U] = 0x01;
CommandValue[1U] = 0x11;
SglBeatWR_nPrm_8(Command, CommandValue, 2U);
Command = 0xC0;
CommandValue[0U] = 0x10;
CommandValue[1U] = 0x3B;
CommandValue[2U] = 0x00;
CommandValue[3U] = 0x02;
CommandValue[4U] = 0x11;
CommandValue[5U] = 0x00;
SglBeatWR_nPrm_8(Command, CommandValue, 6U);
Command = 0xC5;
CommandValue[0U] = 0x03;
SglBeatWR_nPrm_8(Command, CommandValue, 1U);
Command = 0xC6;
CommandValue[0U] = 0x80;
SglBeatWR_nPrm_8(Command, CommandValue, 1U);
Command = 0xC8;
CommandValue[0U] = 0x00;
CommandValue[1U] = 0x14;
CommandValue[2U] = 0x33;
CommandValue[3U] = 0x10;
CommandValue[4U] = 0x00;
CommandValue[5U] = 0x16;
CommandValue[6U] = 0x44;
CommandValue[7U] = 0x36;
CommandValue[8U] = 0x77;
CommandValue[9U] = 0x00;
CommandValue[10U] = 0x0F;
CommandValue[11U] = 0x00;
SglBeatWR_nPrm_8(Command, CommandValue, 12U);
Command = 0xB0;
CommandValue[0U] = 0x00;
SglBeatWR_nPrm_8(Command, CommandValue, 1U);
Command = 0xE4;
CommandValue[0U] = 0xA0;
SglBeatWR_nPrm_8(Command, CommandValue, 1U);
Command = 0xF0;
CommandValue[0U] = 0x08;
SglBeatWR_nPrm_8(Command, CommandValue, 1U);
Command = 0xF3;
CommandValue[0U] = 0x40;
CommandValue[1U] = 0x0A;
SglBeatWR_nPrm_8(Command, CommandValue, 2U);
Command = 0xF6;
CommandValue[0U] = 0x84;
SglBeatWR_nPrm_8(Command, CommandValue, 1U);
Command = 0xF7;
CommandValue[0U] = 0x80;
SglBeatWR_nPrm_8(Command, CommandValue, 1U);
Command = 0xB3;
CommandValue[0U] = 0x00;
CommandValue[1U] = 0x01;
CommandValue[2U] = 0x06;
CommandValue[3U] = 0x30;
SglBeatWR_nPrm_8(Command, CommandValue, 4U);
Command = 0xB4;
CommandValue[0U] = 0x00;
SglBeatWR_nPrm_8(Command, CommandValue, 1U);
Command = 0x0C;
CommandValue[0U] = 0x00;
CommandValue[1U] = 0x55;
SglBeatWR_nPrm_8(Command, CommandValue, 2U);
Command = 0x36; // Memory Access Control
CommandValue[0U] = 0x48;
SglBeatWR_nPrm_8(Command, CommandValue, 1U);
Command = 0x3A; // Set bit depth
CommandValue[0U] = 0x55;
SglBeatWR_nPrm_8(Command, CommandValue, 1U);
Command = 0x21; // Display Inversion On
SglBeatWR_nPrm_8(Command, 0, 0U);
delay(120);
Command = 0x29; // Display On
SglBeatWR_nPrm_8(Command,0 ,0);
delay(120);
Serial.println("ILI9481 Initialized");
#elif defined (ILI9481_2)
Command = 0x01; //Soft_reset
SglBeatWR_nPrm_8(Command, 0, 0);
delay(150);
Command = 0x11;
SglBeatWR_nPrm_8(Command, 0, 0);
delay(150);
Command = 0xd0; //Power_Setting
CommandValue[0U] =0x07;//07 VC[2:0] Sets the ratio factor of Vci to generate the reference voltages Vci1
CommandValue[1U] =0x44;//41 BT[2:0] Sets the Step up factor and output voltage level from the reference voltages Vci1
CommandValue[2U] =0x1E;//1f 17 1C VRH[3:0]: Sets the factor to generate VREG1OUT from VCILVL
SglBeatWR_nPrm_8(Command, CommandValue, 3);
delay(150);
Command = 0xd1; //VCOM Control
CommandValue[0U] =0x00;//00
CommandValue[1U] =0x0C;//1A VCM [6:0] is used to set factor to generate VCOMH voltage from the reference voltage VREG1OUT 15 09
CommandValue[2U] =0x1A;//1F VDV[4:0] is used to set the VCOM alternating amplitude in the range of VREG1OUT x 0.70 to VREG1OUT 1F 18
SglBeatWR_nPrm_8(Command, CommandValue, 3);
Command =0xC5; //Frame Rate
CommandValue[0U] = 0x03; // 03 02
SglBeatWR_nPrm_8(Command, CommandValue, 1);
Command = 0xd2; //Power_Setting for Normal Mode
CommandValue[0U] =0x01; //01
CommandValue[1U] =0x11; //11
SglBeatWR_nPrm_8(Command, CommandValue, 2);
Command = 0xE4; //?
CommandValue[0U] =0xa0;
SglBeatWR_nPrm_8(Command, CommandValue, 1);
Command = 0xf3;
CommandValue[0U] =0x00;
CommandValue[1U] =0x2a;
SglBeatWR_nPrm_8(Command, CommandValue, 2);
//1 OK
Command =0xc8;
CommandValue[0U] = 0x00;
CommandValue[1U] = 0x26;
CommandValue[2U] = 0x21;
CommandValue[3U] = 0x00;
CommandValue[4U] = 0x00;
CommandValue[5U] = 0x1f;
CommandValue[6U] = 0x65;
CommandValue[7U] = 0x23;
CommandValue[8U] = 0x77;
CommandValue[9U] = 0x00;
CommandValue[10U] = 0x0f;
CommandValue[11U] = 0x00;
SglBeatWR_nPrm_8(Command, CommandValue, 12);
//GAMMA SETTING
Command = 0xC0; //Panel Driving Setting
CommandValue[0U] =0x00; //1//00 REV SM GS
CommandValue[1U] =0x3B; //2//NL[5:0]: Sets the number of lines to drive the LCD at an interval of 8 lines.
CommandValue[2U] =0x00; //3//SCN[6:0]
CommandValue[3U] =0x02; //4//PTV: Sets the Vcom output in non-display area drive period
CommandValue[4U] =0x11; //5//NDL: Sets the source output level in non-display area. PTG: Sets the scan mode in non-display area.
SglBeatWR_nPrm_8(Command, CommandValue, 5);
Command = 0xc6; //Interface Control
CommandValue[0U] =0x83;
SglBeatWR_nPrm_8(Command, CommandValue, 1);
//GAMMA SETTING
Command = 0xf0; //?
CommandValue[0U] =0x01;
SglBeatWR_nPrm_8(Command, CommandValue, 1);
Command = 0xE4;//?
CommandValue[0U] =0xa0;
SglBeatWR_nPrm_8(Command, CommandValue, 1);
///��װ����OK 20180510
//Command = 0x36);
//CommandValue[0U] = 0x0A); //0A
////20180510 FPC�����ұ�:CCH:03, 36H:20 OK
//Command = 0xCC);//SetPanel
//CommandValue[0U] = 0x03);//BGR_Panel 03
//Command = 0x36);
//CommandValue[0U] = 0x20); // MY MX MV ML BGR MH HF VF 4A 48 08 00
// MY MX MV ML BGR MH X X
// MY(B7) Row Address Order
// MX(B6) Column Address Order
// MV(B5) Row / Column Exchange
// ML(B4) Vertical Refresh Order
// BGR(B3)(0=RGB color filter panel, 1=BGR color filter panel)
// SS(B2) Horizontal ORDER (SS),LCD horizontal refresh direction control
// -
// -
////20180510 FPC�������: 36H:F8
//Command = 0x36);
//CommandValue[0U] = 0xF8);
//////��װ���� NG
Command = 0x36;
CommandValue[0U] = 0x8C; // 8C:�������� CA������һ����
SglBeatWR_nPrm_8(Command, CommandValue, 1);
Command = 0x3a;
CommandValue[0U] =0x55;
SglBeatWR_nPrm_8(Command, CommandValue, 1);
Command = 0xb4;//Display Mode and Frame Memory Write Mode Setting
CommandValue[0U] =0x02;
CommandValue[1U] =0x00; //?
CommandValue[2U] =0x00;
CommandValue[3U] =0x01;
SglBeatWR_nPrm_8(Command, CommandValue, 4);
delay(280);
Command = 0x2a;
CommandValue[0U] =0x00;
CommandValue[1U] =0x00;
CommandValue[2U] =0x01;
CommandValue[3U] =0x3F; //3F
SglBeatWR_nPrm_8(Command, CommandValue, 4);
Command = 0x2b;
CommandValue[0U] =0x00;
CommandValue[1U] =0x00;
CommandValue[2U] =0x01;
CommandValue[3U] =0xDf; //DF
SglBeatWR_nPrm_8(Command, CommandValue, 4);
delay(10);
//Command = 0x21;
Command = 0x29;
SglBeatWR_nPrm_8(Command, 0, 0);
Command = 0x2c;
SglBeatWR_nPrm_8(Command, 0, 0);
#elif defined (ILI9486)
Command = 0x01; //SW RST
SglBeatWR_nPrm_8(Command,0 ,0);
delay(120);
Command = 0x11; // Sleep out, also SW reset
SglBeatWR_nPrm_8(Command, 0, 0);
delay(20);
Command = 0x3A; // Set bit depth
CommandValue[0U] = 0x55;
SglBeatWR_nPrm_8(Command, CommandValue, 1U);
Command = 0xC2; // Power Control 3
CommandValue[0U] = 0x44;
SglBeatWR_nPrm_8(Command, CommandValue, 1U);
Command = 0xC5; // VCOM control
CommandValue[0U] = 0x00;
CommandValue[1U] = 0x00;
CommandValue[2U] = 0x00;
CommandValue[3U] = 0x00;
SglBeatWR_nPrm_8(Command, CommandValue, 4U);
Command = 0xE0; // Gamma Setting
CommandValue[0U] = 0x0F;
CommandValue[1U] = 0x1F;
CommandValue[2U] = 0x1C;
CommandValue[3U] = 0x0C;
CommandValue[4U] = 0x0C;
CommandValue[5U] = 0x08;
CommandValue[6U] = 0x48;
CommandValue[7U] = 0x98;
CommandValue[8U] = 0x37;
CommandValue[9U] = 0x0A;
CommandValue[10U] = 0x13;
CommandValue[11U] = 0x04;
CommandValue[12U] = 0x11;
CommandValue[13U] = 0x0D;
CommandValue[14U] = 0x00;
SglBeatWR_nPrm_8(Command, CommandValue, 15U);
Command = 0xE1; // Negative Gamma Setting
CommandValue[0U] = 0x0F;
CommandValue[1U] = 0x32;
CommandValue[2U] = 0x2E;
CommandValue[3U] = 0x0B;
CommandValue[4U] = 0x0D;
CommandValue[5U] = 0x05;
CommandValue[6U] = 0x47;
CommandValue[7U] = 0x75;
CommandValue[8U] = 0x37;
CommandValue[9U] = 0x06;
CommandValue[10U] = 0x10;
CommandValue[11U] = 0x03;
CommandValue[12U] = 0x24;
CommandValue[13U] = 0x20;
CommandValue[14U] = 0x00;
SglBeatWR_nPrm_8(Command, CommandValue, 15U);
Command = 0x36; // Memory Access Control
CommandValue[0U] = 0x48;
SglBeatWR_nPrm_8(Command, CommandValue, 1U);
Command = 0x20; // Display Inversion OFF
SglBeatWR_nPrm_8(Command, 0, 0);
Command = 0x29; // Display ON
SglBeatWR_nPrm_8(Command, 0, 0);
delay(120);
Serial.println("ILI9486 Initialized");
#elif defined (ILI9488)
Command = 0x01; //SW RST
SglBeatWR_nPrm_8(Command,0 ,0);
delay(120);
Command = 0x11; //Exit sleep
SglBeatWR_nPrm_8(Command ,0 ,0);
delay(15);
Command = 0x28; //Display Off
SglBeatWR_nPrm_8(Command ,0 ,0);
delay(15);
Command = 0xC0; // Power Control 1
CommandValue[0U] = 0x19;
CommandValue[1U] = 0x1A;
SglBeatWR_nPrm_8(Command, CommandValue, 2U);
Command = 0xC1; // Power Control 2
CommandValue[0U] = 0x45;
CommandValue[1U] = 0x00;
SglBeatWR_nPrm_8(Command, CommandValue, 2U);
Command = 0xC2; // Power Control 3
CommandValue[0U] = 0x33;
SglBeatWR_nPrm_8(Command, CommandValue, 1U);
Command = 0xC5; // VCOM control
CommandValue[0U] = 0x00;
CommandValue[1U] = 0x12;
CommandValue[2U] = 0x80;
SglBeatWR_nPrm_8(Command, CommandValue, 3U);
Command = 0xB4; // Display Inversion Control
CommandValue[0U] = 0x02;
SglBeatWR_nPrm_8(Command, CommandValue, 1U);
Command = 0xB6; // Display Function Control RGB/MCU Interface Control
CommandValue[0U] = 0x00;
CommandValue[1U] = 0x02;
CommandValue[2U] = 0x3B;
SglBeatWR_nPrm_8(Command, CommandValue, 3U);
Command = 0xB7; // Entry Mode Set
CommandValue[0U] = 0x07;
SglBeatWR_nPrm_8(Command, CommandValue, 1U);
Command = 0xE0; // Gamma Setting
CommandValue[0U] = 0x00;
CommandValue[1U] = 0x03;
CommandValue[2U] = 0x09;
CommandValue[3U] = 0x08;
CommandValue[4U] = 0x16;
CommandValue[5U] = 0x0A;
CommandValue[6U] = 0x3F;
CommandValue[7U] = 0x78;
CommandValue[8U] = 0x4C;
CommandValue[9U] = 0x09;
CommandValue[10U] = 0x0A;
CommandValue[11U] = 0x08;
CommandValue[12U] = 0x16;
CommandValue[13U] = 0x1A;
CommandValue[14U] = 0x0F;
SglBeatWR_nPrm_8(Command, CommandValue, 15U);
Command = 0xE1; // Negative Gamma Setting
CommandValue[0U] = 0x00;
CommandValue[1U] = 0x16;
CommandValue[2U] = 0x19;
CommandValue[3U] = 0x03;
CommandValue[4U] = 0x0F;
CommandValue[5U] = 0x05;
CommandValue[6U] = 0x32;
CommandValue[7U] = 0x45;
CommandValue[8U] = 0x46;
CommandValue[9U] = 0x04;
CommandValue[10U] = 0x0E;
CommandValue[11U] = 0x0D;
CommandValue[12U] = 0x35;
CommandValue[13U] = 0x37;
CommandValue[14U] = 0x0F;
SglBeatWR_nPrm_8(Command, CommandValue, 15U);
Command = 0x36; // Memory Access Control
CommandValue[0U] = 0x48;
SglBeatWR_nPrm_8(Command, CommandValue, 1U);
//delay(10);
Command = 0x29; // Display On
SglBeatWR_nPrm_8(Command,0 ,0);
//delay(15);
/*
Command = 0x3A; // Set bit depth
CommandValue[0U] = 0x55;
SglBeatWR_nPrm_8(Command, CommandValue, 1U);
Command = 0x36; // Set rotation
CommandValue[0U] = 0x40|0x80|0x20|0x08; //Landscape
SglBeatWR_nPrm_8(Command, CommandValue, 1U);
*/
delay(120);
Serial.println("ILI9488 Initialized");
#elif defined(R61529)
Command = 0x01; //SW RST
SglBeatWR_nPrm_8(Command,0 ,0);
delay(120);
Command = 0x11; //TFT_SLPOUT
SglBeatWR_nPrm_8(Command, 0, 0);
delay(20);
Command = 0xB0;
CommandValue[0U] = 0x04;
SglBeatWR_nPrm_8(Command, CommandValue, 1U);
delay(2);
Command = 0xB8; //lcd pwm
CommandValue[0U] = 0x02;
CommandValue[1U] = 0x00;
CommandValue[2U] = 0x00;
CommandValue[3U] = 0x00;
CommandValue[4U] = 0x00;
CommandValue[5U] = 0x00;
CommandValue[6U] = 0x00;
CommandValue[7U] = 0x00;
CommandValue[8U] = 0x00;
CommandValue[9U] = 0x00;
CommandValue[10U] = 0x00;
CommandValue[11U] = 0x00;
CommandValue[12U] = 0x00;
CommandValue[13U] = 0x00;
CommandValue[14U] = 0x00;
CommandValue[15U] = 0x00;
CommandValue[16U] = 0x00;
CommandValue[17U] = 0x00;
CommandValue[18U] = 0x00;
CommandValue[19U] = 0x00;
SglBeatWR_nPrm_8(Command, CommandValue, 20U);
Command = 0xB9; //lcd pwm
CommandValue[0U] = 0x01; // PWMON = 1;
CommandValue[1U] = 0x00; // BDCV = 255;
CommandValue[2U] = 0xff; // pwm freq = 13.7 kHz
CommandValue[3U] = 0x18; // PWMWM = 1; LEDPWME = 1;
SglBeatWR_nPrm_8(Command, CommandValue, 4U);
//additional commands:
Command = 0xB3; //Frame Memory Access and Interface Setting
CommandValue[0U] = 0x00; // reset start position of a window area address...
CommandValue[1U] = 0x00; //TE pin is used. TE signal is output every frame.
CommandValue[2U] = 0x00; // empty according to the datasheet - does nothing;
CommandValue[3U] = 0x00; // convert 16/18 bits to 24bits data by writing zeroes to LSBs. Sets image data write/read format(?)
//CommandValue[4U] = 0x0C; // ???? (not needed?)
SglBeatWR_nPrm_8(Command, CommandValue, 5U);
delay(2);
Command = 0xB4; //Display Mode
CommandValue[0U] = 0x00; //Uses internal oscillator
SglBeatWR_nPrm_8(Command, CommandValue, 1U);
Command = 0xC0; // Panel Driving Setting;
CommandValue[0U] = 0x03; // Output polarity is inverted. Left/right interchanging scan. Forward scan. BGR mode (depends on other settings). S960 → S1 (depends)
CommandValue[1U] = 0xDF; // Number of lines for driver to drive - 480.
CommandValue[2U] = 0x40; // Scan start position - Gate1. (depend on other param);
CommandValue[3U] = 0x10; // Dot inversion. Dot inversion in not-lit display area. If 0x13 - both will be set to 'column inversion'.
CommandValue[4U] = 0x00; // settings for non-lit display area...
CommandValue[5U] = 0x01; // 3 frame scan interval in non-display area...
CommandValue[6U] = 0x00; // Source output level in retrace period...
CommandValue[7U] = 0x55;//54 . Internal clock divider = 5 (low and high periods).
SglBeatWR_nPrm_8(Command, CommandValue, 8U);
Command = 0xC1; //Display Timing Setting for Normal Mode
CommandValue[0U] = 0x07; // Clock devider = 12. 14MHz/12. Used by display circuit and step-up circuit.
CommandValue[1U] = 0x27; // These bits set the number of clocks in 1 line period. 0x27 - 39 clocks.
CommandValue[2U] = 0x08; // Number of back porch lines. 0x08 - 8 lines.
CommandValue[3U] = 0x08; // Number of front porch lines. 0x08 - 8lines.
CommandValue[4U] = 0x00; // Spacial configuriation mode 1 (?). 1 line inversion mode (?).
SglBeatWR_nPrm_8(Command, CommandValue, 5U);
Command = 0xC4; // Source/Gate Driving Timing Setting
CommandValue[0U] = 0x57; // falling position (stop) of gate driver - 4 clocks... gate start position - 8 clocks...
CommandValue[1U] = 0x00; // nothing to set up according to the datasheet
CommandValue[2U] = 0x05; // Source precharge period (GND) - 5 clocks.
CommandValue[3U] = 0x03; // source precharge period (VCI) - 3 clocks.
SglBeatWR_nPrm_8(Command, CommandValue, 4U);
Command = 0xC6; //DPI polarity control
CommandValue[0U] = 0x04; // VSYNC -Active Low. HSYNC - Active Low. DE pin enable data write in when DE=1. Reads data on the rising edge of the PCLK signal.
SglBeatWR_nPrm_8(Command, CommandValue, 1U);
//----Gamma setting start-----
Command = 0xC8;
CommandValue[0U] = 0x03;
CommandValue[1U] = 0x12;
CommandValue[2U] = 0x1A;
CommandValue[3U] = 0x24;
CommandValue[4U] = 0x32;
CommandValue[5U] = 0x4B;
CommandValue[6U] = 0x3B;
CommandValue[7U] = 0x29;
CommandValue[8U] = 0x1F;
CommandValue[9U] = 0x18;
CommandValue[10U] = 0x12;
CommandValue[11U] = 0x04;
CommandValue[12U] = 0x03;
CommandValue[13U] = 0x12;
CommandValue[14U] = 0x1A;
CommandValue[15U] = 0x24;
CommandValue[16U] = 0x32;
CommandValue[17U] = 0x4B;
CommandValue[18U] = 0x3B;
CommandValue[19U] = 0x29;
CommandValue[20U] = 0x1F;
CommandValue[21U] = 0x18;
CommandValue[22U] = 0x12;
CommandValue[23U] = 0x04;
SglBeatWR_nPrm_8(Command, CommandValue, 24);
Command = 0xC9;
CommandValue[0U] = 0x03;
CommandValue[1U] = 0x12;
CommandValue[2U] = 0x1A;
CommandValue[3U] = 0x24;
CommandValue[4U] = 0x32;
CommandValue[5U] = 0x4B;
CommandValue[6U] = 0x3B;
CommandValue[7U] = 0x29;
CommandValue[8U] = 0x1F;
CommandValue[9U] = 0x18;
CommandValue[10U] = 0x12;
CommandValue[11U] = 0x04;
CommandValue[12U] = 0x03;
CommandValue[13U] = 0x12;
CommandValue[14U] = 0x1A;
CommandValue[15U] = 0x24;
CommandValue[16U] = 0x32;
CommandValue[17U] = 0x4B;
CommandValue[18U] = 0x3B;
CommandValue[19U] = 0x29;
CommandValue[20U] = 0x1F;
CommandValue[21U] = 0x18;
CommandValue[22U] = 0x12;
CommandValue[23U] = 0x04;
SglBeatWR_nPrm_8(Command, CommandValue, 24);
Command = 0xCA;
CommandValue[0U] = 0x03;
CommandValue[1U] = 0x12;
CommandValue[2U] = 0x1A;
CommandValue[3U] = 0x24;
CommandValue[4U] = 0x32;
CommandValue[5U] = 0x4B;
CommandValue[6U] = 0x3B;
CommandValue[7U] = 0x29;
CommandValue[8U] = 0x1F;
CommandValue[9U] = 0x18;
CommandValue[10U] = 0x12;
CommandValue[11U] = 0x04;
CommandValue[12U] = 0x03;
CommandValue[13U] = 0x12;
CommandValue[14U] = 0x1A;
CommandValue[15U] = 0x24;
CommandValue[16U] = 0x32;
CommandValue[17U] = 0x4B;
CommandValue[18U] = 0x3B;
CommandValue[19U] = 0x29;
CommandValue[20U] = 0x1F;
CommandValue[21U] = 0x18;
CommandValue[22U] = 0x12;
CommandValue[23U] = 0x04;
SglBeatWR_nPrm_8(Command, CommandValue, 24);
//---Gamma setting end--------
//old ones:
Command = 0xD0;
CommandValue[0U] = 0x99;//DC4~1//A5. Set up clock cycle of the internal step up controller.
CommandValue[1U] = 0x06;//BT // Set Voltage step up factor.
CommandValue[2U] = 0x08;// default according to the datasheet - does nothing.
CommandValue[3U] = 0x20;// VCN step up cycles.
CommandValue[4U] = 0x29;//VC1, VC2// VCI3 voltage = 2.70V; VCI2 voltage = 3.8V.
CommandValue[5U] = 0x04;// default
CommandValue[6U] = 0x01;// default
CommandValue[7U] = 0x00;// default
CommandValue[8U] = 0x08;// default
CommandValue[9U] = 0x01;// default
CommandValue[10U]= 0x00;// default
CommandValue[11U]= 0x06;// default
CommandValue[12U]= 0x01;// default
CommandValue[13U]= 0x00;// default
CommandValue[14U]= 0x00;// default
CommandValue[15U]= 0x20;// default
SglBeatWR_nPrm_8(Command, CommandValue, 16);
Command = 0xD1;//VCOM setting
CommandValue[0U] = 0x00;//disable write to VDC[7:0]
CommandValue[1U] = 0x20;//45 38 VPLVL// voltage of γ correction registers for positive polarity
CommandValue[2U] = 0x20;//45 38 VNLVL// voltage of γ correction registers for negative polarity
CommandValue[3U] = 0x15;//32 2A VCOMDC// VNLVL x 0.063
SglBeatWR_nPrm_8(Command, CommandValue, 4);
Command = 0xE0;//NVM Access Control
CommandValue[0U] = 0x00;//NVM access is disabled
CommandValue[1U] = 0x00;//Erase operation (disabled).
CommandValue[2U] = 0x00;//TE pin works as tearing effect pin.
CommandValue[3U] = 0x00; //according to the datasheet.
SglBeatWR_nPrm_8(Command, CommandValue, 4);
Command = 0xE1; //set_DDB_write_control
CommandValue[0U] = 0x00;
CommandValue[1U] = 0x00;
CommandValue[2U] = 0x00;
CommandValue[3U] = 0x00;
CommandValue[4U] = 0x00;
CommandValue[5U] = 0x00;
SglBeatWR_nPrm_8(Command, CommandValue, 6);
Command = 0xE2; //NVM Load Control
CommandValue[0U] = 0x00; // does not execute data load from the NVM to each command
SglBeatWR_nPrm_8(Command, CommandValue, 1);
//Command = 0x36; //MADCTL
//CommandValue[0U] = 0x00;
//SglBeatWR_nPrm_8(Command, CommandValue, 1);
Command = 0x3A; // set_pixel_format
CommandValue[0U] = 0x55; // 16-Bit/pixel = 55h, 24-bit/pixel = 77h
SglBeatWR_nPrm_8(Command, CommandValue, 1);
Command = 0x2A; // TFT_CASET
CommandValue[0U] = 0x00;
CommandValue[1U] = 0x00;
CommandValue[2U] = 0x01;
CommandValue[3U] = 0x3F;
SglBeatWR_nPrm_8(Command, CommandValue, 4);
Command = 0x2B; //TFT_PASET
CommandValue[0U] = 0x00;
CommandValue[1U] = 0x00;
CommandValue[2U] = 0x01;
CommandValue[3U] = 0xDF;
SglBeatWR_nPrm_8(Command, CommandValue, 4);
delay(120);
Command = 0x29; //TFT_DISPON
SglBeatWR_nPrm_8(Command, CommandValue, 0);
delay(120);
Serial.println("R61519 Initialized");
#endif
}
FASTRUN void ILI948x_t4_mm::CSLow()
{
digitalWriteFast(_cs, LOW); //Select TFT
}
FASTRUN void ILI948x_t4_mm::CSHigh()
{
digitalWriteFast(_cs, HIGH); //Deselect TFT
}
FASTRUN void ILI948x_t4_mm::DCLow()
{
digitalWriteFast(_dc, LOW); //Writing command to TFT
}