-
Notifications
You must be signed in to change notification settings - Fork 38
/
IT8951.c
869 lines (720 loc) · 28.3 KB
/
IT8951.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
#include "IT8951.h"
//Global varivale
IT8951DevInfo gstI80DevInfo;
uint8_t* gpFrameBuf; //Host Source Frame buffer
uint32_t gulImgBufAddr; //IT8951 Image buffer address
//-----------------------------------------------------------
//Host controller function 1---Wait for host data Bus Ready
//-----------------------------------------------------------
void LCDWaitForReady()
{
uint8_t ulData = bcm2835_gpio_lev(HRDY);
while(ulData == 0)
{
ulData = bcm2835_gpio_lev(HRDY);
}
}
//-----------------------------------------------------------
//Host controller function 2---Write command code to host data Bus
//-----------------------------------------------------------
void LCDWriteCmdCode(uint16_t usCmdCode)
{
//Set Preamble for Write Command
uint16_t wPreamble = 0x6000;
LCDWaitForReady();
bcm2835_gpio_write(CS,LOW);
bcm2835_spi_transfer(wPreamble>>8);
bcm2835_spi_transfer(wPreamble);
LCDWaitForReady();
bcm2835_spi_transfer(usCmdCode>>8);
bcm2835_spi_transfer(usCmdCode);
bcm2835_gpio_write(CS,HIGH);
}
//-----------------------------------------------------------
//Host controller function 3---Write Data to host data Bus
//-----------------------------------------------------------
void LCDWriteData(uint16_t usData)
{
//Set Preamble for Write Data
uint16_t wPreamble = 0x0000;
LCDWaitForReady();
bcm2835_gpio_write(CS,LOW);
bcm2835_spi_transfer(wPreamble>>8);
bcm2835_spi_transfer(wPreamble);
LCDWaitForReady();
bcm2835_spi_transfer(usData>>8);
bcm2835_spi_transfer(usData);
bcm2835_gpio_write(CS,HIGH);
}
void LCDWriteNData(uint16_t* pwBuf, uint32_t ulSizeWordCnt)
{
uint32_t i;
uint16_t wPreamble = 0x0000;
LCDWaitForReady();
bcm2835_gpio_write(CS,LOW);
bcm2835_spi_transfer(wPreamble>>8);
bcm2835_spi_transfer(wPreamble);
LCDWaitForReady();
for(i=0;i<ulSizeWordCnt;i++)
{
bcm2835_spi_transfer(pwBuf[i]>>8);
bcm2835_spi_transfer(pwBuf[i]);
}
bcm2835_gpio_write(CS,HIGH);
}
//-----------------------------------------------------------
//Host controller function 4---Read Data from host data Bus
//-----------------------------------------------------------
uint16_t LCDReadData()
{
uint16_t wRData;
uint16_t wPreamble = 0x1000;
LCDWaitForReady();
bcm2835_gpio_write(CS,LOW);
bcm2835_spi_transfer(wPreamble>>8);
bcm2835_spi_transfer(wPreamble);
LCDWaitForReady();
wRData=bcm2835_spi_transfer(0x00);//dummy
wRData=bcm2835_spi_transfer(0x00);//dummy
LCDWaitForReady();
wRData = bcm2835_spi_transfer(0x00)<<8;
wRData |= bcm2835_spi_transfer(0x00);
bcm2835_gpio_write(CS,HIGH);
return wRData;
}
//-----------------------------------------------------------
// Read Burst N words Data
//-----------------------------------------------------------
void LCDReadNData(uint16_t* pwBuf, uint32_t ulSizeWordCnt)
{
uint32_t i;
uint16_t wPreamble = 0x1000;
LCDWaitForReady();
bcm2835_gpio_write(CS,LOW);
bcm2835_spi_transfer(wPreamble>>8);
bcm2835_spi_transfer(wPreamble);
LCDWaitForReady();
pwBuf[0]=bcm2835_spi_transfer(0x00);//dummy
pwBuf[0]=bcm2835_spi_transfer(0x00);//dummy
LCDWaitForReady();
for(i=0;i<ulSizeWordCnt;i++)
{
pwBuf[i] = bcm2835_spi_transfer(0x00)<<8;
pwBuf[i] |= bcm2835_spi_transfer(0x00);
}
bcm2835_gpio_write(CS,HIGH);
}
//-----------------------------------------------------------
//Host controller function 5---Write command to host data Bus with aruments
//-----------------------------------------------------------
void LCDSendCmdArg(uint16_t usCmdCode,uint16_t* pArg, uint16_t usNumArg)
{
uint16_t i;
//Send Cmd code
LCDWriteCmdCode(usCmdCode);
//Send Data
for(i=0;i<usNumArg;i++)
{
LCDWriteData(pArg[i]);
}
}
//-----------------------------------------------------------
//Host Cmd 1---SYS_RUN
//-----------------------------------------------------------
void IT8951SystemRun()
{
LCDWriteCmdCode(IT8951_TCON_SYS_RUN);
}
//-----------------------------------------------------------
//Host Cmd 2---STANDBY
//-----------------------------------------------------------
void IT8951StandBy()
{
LCDWriteCmdCode(IT8951_TCON_STANDBY);
}
//-----------------------------------------------------------
//Host Cmd 3---SLEEP
//-----------------------------------------------------------
void IT8951Sleep()
{
LCDWriteCmdCode(IT8951_TCON_SLEEP);
}
//-----------------------------------------------------------
//Host Cmd 4---REG_RD
//-----------------------------------------------------------
uint16_t IT8951ReadReg(uint16_t usRegAddr)
{
uint16_t usData;
//Send Cmd and Register Address
LCDWriteCmdCode(IT8951_TCON_REG_RD);
LCDWriteData(usRegAddr);
//Read data from Host Data bus
usData = LCDReadData();
return usData;
}
//-----------------------------------------------------------
//Host Cmd 5---REG_WR
//-----------------------------------------------------------
void IT8951WriteReg(uint16_t usRegAddr,uint16_t usValue)
{
//Send Cmd , Register Address and Write Value
LCDWriteCmdCode(IT8951_TCON_REG_WR);
LCDWriteData(usRegAddr);
LCDWriteData(usValue);
}
//-----------------------------------------------------------
//Host Cmd 6---MEM_BST_RD_T
//-----------------------------------------------------------
void IT8951MemBurstReadTrigger(uint32_t ulMemAddr , uint32_t ulReadSize)
{
uint16_t usArg[4];
//Setting Arguments for Memory Burst Read
usArg[0] = (uint16_t)(ulMemAddr & 0x0000FFFF); //addr[15:0]
usArg[1] = (uint16_t)( (ulMemAddr >> 16) & 0x0000FFFF ); //addr[25:16]
usArg[2] = (uint16_t)(ulReadSize & 0x0000FFFF); //Cnt[15:0]
usArg[3] = (uint16_t)( (ulReadSize >> 16) & 0x0000FFFF ); //Cnt[25:16]
//Send Cmd and Arg
LCDSendCmdArg(IT8951_TCON_MEM_BST_RD_T , usArg , 4);
}
//-----------------------------------------------------------
//Host Cmd 7---MEM_BST_RD_S
//-----------------------------------------------------------
void IT8951MemBurstReadStart()
{
LCDWriteCmdCode(IT8951_TCON_MEM_BST_RD_S);
}
//-----------------------------------------------------------
//Host Cmd 8---MEM_BST_WR
//-----------------------------------------------------------
void IT8951MemBurstWrite(uint32_t ulMemAddr , uint32_t ulWriteSize)
{
uint16_t usArg[4];
//Setting Arguments for Memory Burst Write
usArg[0] = (uint16_t)(ulMemAddr & 0x0000FFFF); //addr[15:0]
usArg[1] = (uint16_t)( (ulMemAddr >> 16) & 0x0000FFFF ); //addr[25:16]
usArg[2] = (uint16_t)(ulWriteSize & 0x0000FFFF); //Cnt[15:0]
usArg[3] = (uint16_t)( (ulWriteSize >> 16) & 0x0000FFFF ); //Cnt[25:16]
//Send Cmd and Arg
LCDSendCmdArg(IT8951_TCON_MEM_BST_WR , usArg , 4);
}
//-----------------------------------------------------------
//Host Cmd 9---MEM_BST_END
//-----------------------------------------------------------
void IT8951MemBurstEnd(void)
{
LCDWriteCmdCode(IT8951_TCON_MEM_BST_END);
}
uint16_t IT8951GetVCOM(void)
{
uint16_t vcom;
LCDWriteCmdCode(USDEF_I80_CMD_VCOM);
LCDWriteData(0);
//Read data from Host Data bus
vcom = LCDReadData();
return vcom;
}
void IT8951SetVCOM(uint16_t vcom)
{
LCDWriteCmdCode(USDEF_I80_CMD_VCOM);
LCDWriteData(1);
//Read data from Host Data bus
LCDWriteData(vcom);
}
//-----------------------------------------------------------
//Example of Memory Burst Write
//-----------------------------------------------------------
// ****************************************************************************************
// Function name: IT8951MemBurstWriteProc( )
//
// Description:
// IT8951 Burst Write procedure
//
// Arguments:
// uint32_t ulMemAddr: IT8951 Memory Target Address
// uint32_t ulWriteSize: Write Size (Unit: Word)
// uint8_t* pDestBuf - Buffer of Sent data
// Return Values:
// NULL.
// Note:
//
// ****************************************************************************************
void IT8951MemBurstWriteProc(uint32_t ulMemAddr , uint32_t ulWriteSize, uint16_t* pSrcBuf )
{
uint32_t i;
//Send Burst Write Start Cmd and Args
IT8951MemBurstWrite(ulMemAddr , ulWriteSize);
//Burst Write Data
for(i=0;i<ulWriteSize;i++)
{
LCDWriteData(pSrcBuf[i]);
}
//Send Burst End Cmd
IT8951MemBurstEnd();
}
// ****************************************************************************************
// Function name: IT8951MemBurstReadProc( )
//
// Description:
// IT8951 Burst Read procedure
//
// Arguments:
// uint32_t ulMemAddr: IT8951 Read Memory Address
// uint32_t ulReadSize: Read Size (Unit: Word)
// uint8_t* pDestBuf - Buffer for storing Read data
// Return Values:
// NULL.
// Note:
//
// ****************************************************************************************
void IT8951MemBurstReadProc(uint32_t ulMemAddr , uint32_t ulReadSize, uint16_t* pDestBuf )
{
//Send Burst Read Start Cmd and Args
IT8951MemBurstReadTrigger(ulMemAddr , ulReadSize);
//Burst Read Fire
IT8951MemBurstReadStart();
//Burst Read Request for SPI interface only
LCDReadNData(pDestBuf, ulReadSize);
//Send Burst End Cmd
IT8951MemBurstEnd(); //the same with IT8951MemBurstEnd()
}
//-----------------------------------------------------------
//Host Cmd 10---LD_IMG
//-----------------------------------------------------------
void IT8951LoadImgStart(IT8951LdImgInfo* pstLdImgInfo)
{
uint16_t usArg;
//Setting Argument for Load image start
usArg = (pstLdImgInfo->usEndianType << 8 )
|(pstLdImgInfo->usPixelFormat << 4)
|(pstLdImgInfo->usRotate);
//Send Cmd
LCDWriteCmdCode(IT8951_TCON_LD_IMG);
//Send Arg
LCDWriteData(usArg);
}
//-----------------------------------------------------------
//Host Cmd 11---LD_IMG_AREA
//-----------------------------------------------------------
void IT8951LoadImgAreaStart(IT8951LdImgInfo* pstLdImgInfo ,IT8951AreaImgInfo* pstAreaImgInfo)
{
uint16_t usArg[5];
//Setting Argument for Load image start
usArg[0] = (pstLdImgInfo->usEndianType << 8 )
|(pstLdImgInfo->usPixelFormat << 4)
|(pstLdImgInfo->usRotate);
usArg[1] = pstAreaImgInfo->usX;
usArg[2] = pstAreaImgInfo->usY;
usArg[3] = pstAreaImgInfo->usWidth;
usArg[4] = pstAreaImgInfo->usHeight;
//Send Cmd and Args
LCDSendCmdArg(IT8951_TCON_LD_IMG_AREA , usArg , 5);
}
//-----------------------------------------------------------
//Host Cmd 12---LD_IMG_END
//-----------------------------------------------------------
void IT8951LoadImgEnd(void)
{
LCDWriteCmdCode(IT8951_TCON_LD_IMG_END);
}
void GetIT8951SystemInfo(void* pBuf)
{
uint16_t* pusWord = (uint16_t*)pBuf;
IT8951DevInfo* pstDevInfo;
//Send I80 CMD
LCDWriteCmdCode(USDEF_I80_CMD_GET_DEV_INFO);
//Burst Read Request for SPI interface only
LCDReadNData(pusWord, sizeof(IT8951DevInfo)/2);//Polling HRDY for each words(2-bytes) if possible
//Show Device information of IT8951
pstDevInfo = (IT8951DevInfo*)pBuf;
printf("Panel(W,H) = (%d,%d)\r\n",
pstDevInfo->usPanelW, pstDevInfo->usPanelH );
printf("Image Buffer Address = %X\r\n",
pstDevInfo->usImgBufAddrL | (pstDevInfo->usImgBufAddrH << 16));
//Show Firmware and LUT Version
printf("FW Version = %s\r\n", (uint8_t*)pstDevInfo->usFWVersion);
printf("LUT Version = %s\r\n", (uint8_t*)pstDevInfo->usLUTVersion);
}
//-----------------------------------------------------------
//Initial function 2---Set Image buffer base address
//-----------------------------------------------------------
void IT8951SetImgBufBaseAddr(uint32_t ulImgBufAddr)
{
uint16_t usWordH = (uint16_t)((ulImgBufAddr >> 16) & 0x0000FFFF);
uint16_t usWordL = (uint16_t)( ulImgBufAddr & 0x0000FFFF);
//Write LISAR Reg
IT8951WriteReg(LISAR + 2 ,usWordH);
IT8951WriteReg(LISAR ,usWordL);
}
//-----------------------------------------------------------
// 3.6. Display Functions
//-----------------------------------------------------------
//-----------------------------------------------------------
//Display function 1---Wait for LUT Engine Finish
// Polling Display Engine Ready by LUTNo
//-----------------------------------------------------------
void IT8951WaitForDisplayReady()
{
//Check IT8951 Register LUTAFSR => NonZero Busy, 0 - Free
while(IT8951ReadReg(LUTAFSR));
}
//-----------------------------------------------------------
//Display function 2---Load Image Area process
//-----------------------------------------------------------
void IT8951HostAreaPackedPixelWrite(IT8951LdImgInfo* pstLdImgInfo,IT8951AreaImgInfo* pstAreaImgInfo)
{
uint32_t i,j;
//Source buffer address of Host
uint16_t* pusFrameBuf = (uint16_t*)pstLdImgInfo->ulStartFBAddr;
//Set Image buffer(IT8951) Base address
IT8951SetImgBufBaseAddr(pstLdImgInfo->ulImgBufBaseAddr);
//Send Load Image start Cmd
IT8951LoadImgAreaStart(pstLdImgInfo , pstAreaImgInfo);
//Host Write Data
for(j=0;j< pstAreaImgInfo->usHeight;j++)
{
for(i=0;i< pstAreaImgInfo->usWidth/2;i++)
{
//Write a Word(2-Bytes) for each time
LCDWriteData(*pusFrameBuf);
pusFrameBuf++;
}
}
//Send Load Img End Command
IT8951LoadImgEnd();
}
//-----------------------------------------------------------
//Display functions 3---Application for Display panel Area
//-----------------------------------------------------------
void IT8951DisplayArea(uint16_t usX, uint16_t usY, uint16_t usW, uint16_t usH, uint16_t usDpyMode)
{
//Send I80 Display Command (User defined command of IT8951)
LCDWriteCmdCode(USDEF_I80_CMD_DPY_AREA); //0x0034
//Write arguments
LCDWriteData(usX);
LCDWriteData(usY);
LCDWriteData(usW);
LCDWriteData(usH);
LCDWriteData(usDpyMode);
}
//Display Area with bitmap on EPD
//-----------------------------------------------------------
// Display Function 4---for Display Area for 1-bpp mode format
// the bitmap(1bpp) mode will be enable when Display
// and restore to Default setting (disable) after displaying finished
//-----------------------------------------------------------
void IT8951DisplayArea1bpp(uint16_t usX, uint16_t usY, uint16_t usW, uint16_t usH, uint16_t usDpyMode, uint8_t ucBGGrayVal, uint8_t ucFGGrayVal)
{
//Set Display mode to 1 bpp mode - Set 0x18001138 Bit[18](0x1800113A Bit[2])to 1
IT8951WriteReg(UP1SR+2, IT8951ReadReg(UP1SR+2) | (1<<2));
//Set BitMap color table 0 and 1 , => Set Register[0x18001250]:
//Bit[7:0]: ForeGround Color(G0~G15) for 1
//Bit[15:8]:Background Color(G0~G15) for 0
IT8951WriteReg(BGVR, (ucBGGrayVal<<8) | ucFGGrayVal);
//Display
IT8951DisplayArea( usX, usY, usW, usH, usDpyMode);
IT8951WaitForDisplayReady();
//Restore to normal mode
IT8951WriteReg(UP1SR+2, IT8951ReadReg(UP1SR+2) & ~(1<<2));
}
//-------------------------------------------------------------------------------------------------------------
// Command - 0x0037 for Display Base addr by User
// uint32_t ulDpyBufAddr - Host programmer need to indicate the Image buffer address of IT8951
// In current case, there is only one image buffer in IT8951 so far.
// So Please set the Image buffer address you got in initial stage.
// (gulImgBufAddr by Get device information 0x0302 command)
//
//-------------------------------------------------------------------------------------------------------------
void IT8951DisplayAreaBuf(uint16_t usX, uint16_t usY, uint16_t usW, uint16_t usH, uint16_t usDpyMode, uint32_t ulDpyBufAddr)
{
//Send I80 Display Command (User defined command of IT8951)
LCDWriteCmdCode(USDEF_I80_CMD_DPY_BUF_AREA); //0x0037
//Write arguments
LCDWriteData(usX);
LCDWriteData(usY);
LCDWriteData(usW);
LCDWriteData(usH);
LCDWriteData(usDpyMode);
LCDWriteData((uint16_t)ulDpyBufAddr); //Display Buffer Base address[15:0]
LCDWriteData((uint16_t)(ulDpyBufAddr>>16)); //Display Buffer Base address[26:16]
}
//-----------------------------------------------------------
//Test function 1---Software Initial
//-----------------------------------------------------------
uint8_t IT8951_Init()
{
if (!bcm2835_init())
{
printf("bcm2835_init error \n");
return 1;
}
bcm2835_spi_begin();
bcm2835_spi_setBitOrder(BCM2835_SPI_BIT_ORDER_MSBFIRST); //default
bcm2835_spi_setDataMode(BCM2835_SPI_MODE0); //default
bcm2835_spi_setClockDivider(BCM2835_SPI_CLOCK_DIVIDER_32); //default
bcm2835_gpio_fsel(CS, BCM2835_GPIO_FSEL_OUTP);
bcm2835_gpio_fsel(HRDY, BCM2835_GPIO_FSEL_INPT);
bcm2835_gpio_fsel(RESET, BCM2835_GPIO_FSEL_OUTP);
bcm2835_gpio_write(CS, HIGH);
printf("****** IT8951 ******\n");
bcm2835_gpio_write(RESET, LOW);
bcm2835_delay(100);
bcm2835_gpio_write(RESET, HIGH);
//Get Device Info
GetIT8951SystemInfo(&gstI80DevInfo);
gpFrameBuf = malloc(gstI80DevInfo.usPanelW * gstI80DevInfo.usPanelH);
if (!gpFrameBuf)
{
perror("malloc error!\n");
return 1;
}
gulImgBufAddr = gstI80DevInfo.usImgBufAddrL | (gstI80DevInfo.usImgBufAddrH << 16);
//Set to Enable I80 Packed mode
IT8951WriteReg(I80CPCR, 0x0001);
if (VCOM != IT8951GetVCOM())
{
IT8951SetVCOM(VCOM);
printf("VCOM = -%.02fV\n",(float)IT8951GetVCOM()/1000);
}
return 0;
}
void IT8951_Cancel()
{
free(gpFrameBuf);
bcm2835_spi_end();
bcm2835_close();
}
//-----------------------------------------------------------
//Test function 2---Example of Display Flow
//-----------------------------------------------------------
void IT8951DisplayExample()
{
IT8951LdImgInfo stLdImgInfo;
IT8951AreaImgInfo stAreaImgInfo;
//Prepare image
//Write pixel 0xF0(White) to Frame Buffer
memset(gpFrameBuf, 0xF0, gstI80DevInfo.usPanelW * gstI80DevInfo.usPanelH);
//Check TCon is free ? Wait TCon Ready (optional)
IT8951WaitForDisplayReady();
//--------------------------------------------------------------------------------------------
// initial display - Display white only
//--------------------------------------------------------------------------------------------
//Load Image and Display
//Setting Load image information
stLdImgInfo.ulStartFBAddr = (uint32_t)gpFrameBuf;
stLdImgInfo.usEndianType = IT8951_LDIMG_L_ENDIAN;
stLdImgInfo.usPixelFormat = IT8951_8BPP;
stLdImgInfo.usRotate = IT8951_ROTATE_0;
stLdImgInfo.ulImgBufBaseAddr = gulImgBufAddr;
//Set Load Area
stAreaImgInfo.usX = 0;
stAreaImgInfo.usY = 0;
stAreaImgInfo.usWidth = gstI80DevInfo.usPanelW;
stAreaImgInfo.usHeight = gstI80DevInfo.usPanelH;
//Load Image from Host to IT8951 Image Buffer
IT8951HostAreaPackedPixelWrite(&stLdImgInfo, &stAreaImgInfo);//Display function 2
//Display Area ?V (x,y,w,h) with mode 0 for initial White to clear Panel
IT8951DisplayArea(0,0, gstI80DevInfo.usPanelW, gstI80DevInfo.usPanelH, 0);
//--------------------------------------------------------------------------------------------
// Regular display - Display Any Gray colors with Mode 2 or others
//--------------------------------------------------------------------------------------------
//Preparing buffer to All black (8 bpp image)
//or you can create your image pattern here..
memset(gpFrameBuf, 0x00, gstI80DevInfo.usPanelW * gstI80DevInfo.usPanelH);
IT8951WaitForDisplayReady();
//Setting Load image information
stLdImgInfo.ulStartFBAddr = (uint32_t)gpFrameBuf;
stLdImgInfo.usEndianType = IT8951_LDIMG_L_ENDIAN;
stLdImgInfo.usPixelFormat = IT8951_8BPP;
stLdImgInfo.usRotate = IT8951_ROTATE_0;
stLdImgInfo.ulImgBufBaseAddr = gulImgBufAddr;
//Set Load Area
stAreaImgInfo.usX = 0;
stAreaImgInfo.usY = 0;
stAreaImgInfo.usWidth = gstI80DevInfo.usPanelW;
stAreaImgInfo.usHeight = gstI80DevInfo.usPanelH;
//Load Image from Host to IT8951 Image Buffer
IT8951HostAreaPackedPixelWrite(&stLdImgInfo, &stAreaImgInfo);//Display function 2
//Display Area ?V (x,y,w,h) with mode 2 for fast gray clear mode - depends on current waveform
IT8951DisplayArea(0,0, gstI80DevInfo.usPanelW, gstI80DevInfo.usPanelH, 2);
}
void IT8951DisplayExample2()
{
IT8951LdImgInfo stLdImgInfo;
IT8951AreaImgInfo stAreaImgInfo;
uint16_t width = gstI80DevInfo.usPanelW;
uint16_t high = gstI80DevInfo.usPanelH/16;
//--------------------------------------------------------------------------------------------
// Regular display - Display Any Gray colors with Mode 2 or others
//--------------------------------------------------------------------------------------------
//Preparing buffer to All black (8 bpp image)
//or you can create your image pattern here..
memset(gpFrameBuf , 0x00, width * high * 1);
memset(gpFrameBuf+width * high * 1, 0x11, width * high * 1);
memset(gpFrameBuf+width * high * 2, 0x22, width * high * 1);
memset(gpFrameBuf+width * high * 3, 0x33, width * high * 1);
memset(gpFrameBuf+width * high * 4, 0x44, width * high * 1);
memset(gpFrameBuf+width * high * 5, 0x55, width * high * 1);
memset(gpFrameBuf+width * high * 6, 0x66, width * high * 1);
memset(gpFrameBuf+width * high * 7, 0x77, width * high * 1);
memset(gpFrameBuf+width * high * 8, 0x88, width * high * 1);
memset(gpFrameBuf+width * high * 9, 0x99, width * high * 1);
memset(gpFrameBuf+width * high * 10, 0xaa, width * high * 1);
memset(gpFrameBuf+width * high * 11, 0xbb, width * high * 1);
memset(gpFrameBuf+width * high * 12, 0xcc, width * high * 1);
memset(gpFrameBuf+width * high * 13, 0xdd, width * high * 1);
memset(gpFrameBuf+width * high * 14, 0xee, width * high * 1);
memset(gpFrameBuf+width * high * 15, 0xff, gstI80DevInfo.usPanelW * gstI80DevInfo.usPanelH - width * high * 15);
IT8951WaitForDisplayReady();
//Setting Load image information
stLdImgInfo.ulStartFBAddr = (uint32_t)gpFrameBuf;
stLdImgInfo.usEndianType = IT8951_LDIMG_L_ENDIAN;
stLdImgInfo.usPixelFormat = IT8951_8BPP;
stLdImgInfo.usRotate = IT8951_ROTATE_0;
stLdImgInfo.ulImgBufBaseAddr = gulImgBufAddr;
//Set Load Area
stAreaImgInfo.usX = 0;
stAreaImgInfo.usY = 0;
stAreaImgInfo.usWidth = gstI80DevInfo.usPanelW;
stAreaImgInfo.usHeight = gstI80DevInfo.usPanelH;
//Load Image from Host to IT8951 Image Buffer
IT8951HostAreaPackedPixelWrite(&stLdImgInfo, &stAreaImgInfo);//Display function 2
//Display Area ?V (x,y,w,h) with mode 2 for fast gray clear mode - depends on current waveform
IT8951DisplayArea(0,0, gstI80DevInfo.usPanelW, gstI80DevInfo.usPanelH, 2);
}
extern uint16_t bmp01[];
void IT8951_GUI_Example()
{
IT8951LdImgInfo stLdImgInfo;
IT8951AreaImgInfo stAreaImgInfo;
Point point[4];
//memset(gpFrameBuf, 0xff, gstI80DevInfo.usPanelW * gstI80DevInfo.usPanelH);
uint16_t width = gstI80DevInfo.usPanelW;
uint16_t high = gstI80DevInfo.usPanelH;
EPD_Clear(0xff);
EPD_DrawLine(width/4, high/4, width/2, high/2, 0x40);
EPD_DrawLine(width/2, high/2, width*3/4, high/4, 0x40);
EPD_DrawLine(width*3/4, high/4, width/2, 0, 0x40);
EPD_DrawLine(width/2, 0, width/4, high/4, 0x40);
EPD_DrawRect(width/4, 0, width/2, high/2, 0x00);
EPD_DrawCircle(width/2, high/4, high/4, 0x00);
point[0].X = width/2;
point[0].Y = 0;
point[1].X = width/4;
point[1].Y = high/2;
point[2].X = width/2;
point[2].Y = high;
point[3].X = width*3/4;
point[3].Y = high/2;
EPD_DrawPolygon(point, 4, 0x00);
EPD_DrawEllipse(width/2, high/2, width/4, high/4, 0x00);
EPD_FillRect(width/12, high*8/10, width/10, high/10, 0x00);
EPD_FillCircle(width*10/12, high*8/10, width/10, 0x00);
EPD_Text(0, 0, (uint8_t*)"hello world",0x00, 0xff);
//EPD_DrawMatrix(0,0,550,412,bmp01);
IT8951WaitForDisplayReady();
//Setting Load image information
stLdImgInfo.ulStartFBAddr = (uint32_t)gpFrameBuf;
stLdImgInfo.usEndianType = IT8951_LDIMG_L_ENDIAN;
stLdImgInfo.usPixelFormat = IT8951_8BPP;
stLdImgInfo.usRotate = IT8951_ROTATE_0;
stLdImgInfo.ulImgBufBaseAddr = gulImgBufAddr;
//Set Load Area
stAreaImgInfo.usX = 0;
stAreaImgInfo.usY = 0;
stAreaImgInfo.usWidth = gstI80DevInfo.usPanelW;
stAreaImgInfo.usHeight = gstI80DevInfo.usPanelH;
//Load Image from Host to IT8951 Image Buffer
IT8951HostAreaPackedPixelWrite(&stLdImgInfo, &stAreaImgInfo);//Display function 2
IT8951DisplayArea(0,0, gstI80DevInfo.usPanelW, gstI80DevInfo.usPanelH, 2);
}
void IT8951_BMP_Example(uint32_t x, uint32_t y,char *path)
{
IT8951LdImgInfo stLdImgInfo;
IT8951AreaImgInfo stAreaImgInfo;
EPD_Clear(0xff);
//ÏÔʾͼÏñ
Show_bmp(x,y,path);
IT8951WaitForDisplayReady();
//Setting Load image information
stLdImgInfo.ulStartFBAddr = (uint32_t)gpFrameBuf;
stLdImgInfo.usEndianType = IT8951_LDIMG_L_ENDIAN;
stLdImgInfo.usPixelFormat = IT8951_8BPP;
stLdImgInfo.usRotate = IT8951_ROTATE_0;
stLdImgInfo.ulImgBufBaseAddr = gulImgBufAddr;
//Set Load Area
stAreaImgInfo.usX = 0;
stAreaImgInfo.usY = 0;
stAreaImgInfo.usWidth = gstI80DevInfo.usPanelW;
stAreaImgInfo.usHeight = gstI80DevInfo.usPanelH;
//Load Image from Host to IT8951 Image Buffer
IT8951HostAreaPackedPixelWrite(&stLdImgInfo, &stAreaImgInfo);//Display function 2
//Display Area ?V (x,y,w,h) with mode 2 for fast gray clear mode - depends on current waveform
IT8951DisplayArea(0,0, gstI80DevInfo.usPanelW, gstI80DevInfo.usPanelH, 2);
}
//-----------------------------------------------------------
// Load 1bpp image flow (must display with IT8951DisplayArea1bpp()
//-----------------------------------------------------------
void IT8951Load1bppImage(uint8_t* p1bppImgBuf, uint16_t usX, uint16_t usY, uint16_t usW, uint16_t usH)
{
IT8951LdImgInfo stLdImgInfo;
IT8951AreaImgInfo stAreaImgInfo;
//Setting Load image information
stLdImgInfo.ulStartFBAddr = (uint32_t) p1bppImgBuf;
stLdImgInfo.usEndianType = IT8951_LDIMG_L_ENDIAN;
stLdImgInfo.usPixelFormat = IT8951_8BPP; //we use 8bpp because IT8951 dose not support 1bpp mode for load image?Aso we use Load 8bpp mode ,but the transfer size needs to be reduced to Size/8
stLdImgInfo.usRotate = IT8951_ROTATE_0;
stLdImgInfo.ulImgBufBaseAddr = gulImgBufAddr;
//Set Load Area
stAreaImgInfo.usX = usX/8;
stAreaImgInfo.usY = usY;
stAreaImgInfo.usWidth = usW/8;//1bpp, Chaning Transfer size setting to 1/8X of 8bpp mode
stAreaImgInfo.usHeight = usH;
printf("IT8951HostAreaPackedPixelWrite [wait]\n\r");
//Load Image from Host to IT8951 Image Buffer
IT8951HostAreaPackedPixelWrite(&stLdImgInfo, &stAreaImgInfo);//Display function 2
}
//-----------------------------------------------------------
//Test function 3---Example of Display 1bpp Flow
//-----------------------------------------------------------
void IT8951Display1bppExample()
{
IT8951AreaImgInfo stAreaImgInfo;
//Prepare image
//Write pixel 0x00(Black) to Frame Buffer
//or you can create your image pattern here..
memset(gpFrameBuf, 0x00, (gstI80DevInfo.usPanelW * gstI80DevInfo.usPanelH)/8);//Host Frame Buffer(Source)
//Check TCon is free ? Wait TCon Ready (optional)
IT8951WaitForDisplayReady();
//Load Image and Display
//Set Load Area
stAreaImgInfo.usX = 0;
stAreaImgInfo.usY = 0;
stAreaImgInfo.usWidth = gstI80DevInfo.usPanelW;
stAreaImgInfo.usHeight = gstI80DevInfo.usPanelH;
//Load Image from Host to IT8951 Image Buffer
IT8951Load1bppImage(gpFrameBuf, stAreaImgInfo.usX, stAreaImgInfo.usY, stAreaImgInfo.usWidth, stAreaImgInfo.usHeight);//Display function 4, Arg
//Display Area - (x,y,w,h) with mode 2 for Gray Scale
//e.g. if we want to set b0(Background color) for Black-0x00 , Set b1(Foreground) for White-0xFF
IT8951DisplayArea1bpp(0,0, gstI80DevInfo.usPanelW, gstI80DevInfo.usPanelH, 0, 0x00, 0xFF);
}
void IT8951Display1bppExample2()
{
IT8951AreaImgInfo stAreaImgInfo;
//Prepare image
//Write pixel 0x00(Black) to Frame Buffer
//or you can create your image pattern here..
memset(gpFrameBuf, 0xff, (gstI80DevInfo.usPanelW * gstI80DevInfo.usPanelH)/8);//Host Frame Buffer(Source)
//Check TCon is free ? Wait TCon Ready (optional)
IT8951WaitForDisplayReady();
//Load Image and Display
//Set Load Area
stAreaImgInfo.usX = 0;
stAreaImgInfo.usY = 0;
stAreaImgInfo.usWidth = gstI80DevInfo.usPanelW;
stAreaImgInfo.usHeight = gstI80DevInfo.usPanelH;
//Load Image from Host to IT8951 Image Buffer
IT8951Load1bppImage(gpFrameBuf, stAreaImgInfo.usX, stAreaImgInfo.usY, stAreaImgInfo.usWidth, stAreaImgInfo.usHeight);//Display function 4, Arg
//Display Area - (x,y,w,h) with mode 2 for Gray Scale
//e.g. if we want to set b0(Background color) for Black-0x00 , Set b1(Foreground) for White-0xFF
IT8951DisplayArea1bpp(0,0, gstI80DevInfo.usPanelW, gstI80DevInfo.usPanelH, 0, 0x00, 0xFF);
}