1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
25
26
29
30
35
36
39
44
45
48
49
52
53
56
57
60
61
64
65
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
93
94
97
98
99
100
103
104
107
108
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
189
194
195
200
207
208
213
217
218
223
227
228
233
239
240
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
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
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
328
329
330
331
332
333
334
335
336
340
341
342
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
373
377
378
382
386
387
391
395
396
400
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
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
470
471
472
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
535
536
542
543
544
545
546
547
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
620
621
622
623
624
625
626
629
630
633
634
637
638
/* ... */
#include "ls016b8uy.h"
/* ... */
/* ... */
/* ... */
/* ... */
typedef struct {
uint8_t red;
uint8_t green;
uint8_t blue;
...} LS016B8UY_Rgb888;
/* ... */
/* ... */
/* ... */
/* ... */
/* ... */
/* ... */
LCD_DrvTypeDef ls016b8uy_drv =
{
ls016b8uy_Init,
ls016b8uy_ReadID,
ls016b8uy_DisplayOn,
ls016b8uy_DisplayOff,
ls016b8uy_SetCursor,
ls016b8uy_WritePixel,
ls016b8uy_ReadPixel,
ls016b8uy_SetDisplayWindow,
ls016b8uy_DrawHLine,
ls016b8uy_DrawVLine,
ls016b8uy_GetLcdPixelWidth,
ls016b8uy_GetLcdPixelHeight,
ls016b8uy_DrawBitmap,
ls016b8uy_DrawRGBImage,
...};
static uint16_t WindowsXstart = 0;
static uint16_t WindowsYstart = 0;
static uint16_t WindowsXend = LS016B8UY_LCD_PIXEL_WIDTH-1;
static uint16_t WindowsYend = LS016B8UY_LCD_PIXEL_HEIGHT-1;
/* ... */
/* ... */
static LS016B8UY_Rgb888 ls016b8uy_ReadPixel_rgb888(uint16_t Xpos, uint16_t Ypos);
static void ls016b8uy_DrawRGBHLine(uint16_t Xpos, uint16_t Ypos, uint16_t Xsize, uint8_t *pdata);
/* ... */
/* ... */
/* ... */
void ls016b8uy_Init(void)
{
uint8_t parameter[4];
LCD_IO_Init();
parameter[0] = 0x00;
ls016b8uy_WriteReg(LCD_CMD_VSYNC_OUTPUT, parameter, 1);
parameter[0] = 0x06;
ls016b8uy_WriteReg(LCD_CMD_COLOR_MODE, parameter, 1);
parameter[0] = 0x01;
parameter[1] = 0xFE;
ls016b8uy_WriteReg(LCD_CMD_PANEL_SETTING_1, parameter, 2);
parameter[0] = 0xDE;
parameter[1] = 0x21;
ls016b8uy_WriteReg(LCD_CMD_PANEL_SETTING_2, parameter, 2);
parameter[0] = 0x05;
parameter[1] = 0x33;
ls016b8uy_WriteReg(LCD_CMD_PANEL_V_PORCH, parameter, 2);
parameter[0] = 0x05;
parameter[1] = 0x33;
ls016b8uy_WriteReg(LCD_CMD_PANEL_IDLE_V_PORCH, parameter, 2);
parameter[0] = 0x04;
parameter[1] = 0x03;
ls016b8uy_WriteReg(LCD_CMD_PANEL_TIMING_1, parameter, 2);
parameter[0] = 0x5E;
parameter[1] = 0x08;
ls016b8uy_WriteReg(LCD_CMD_PANEL_TIMING_2, parameter, 2);
parameter[0] = 0x0A;
parameter[1] = 0x0C;
parameter[2] = 0x02;
ls016b8uy_WriteReg(LCD_CMD_PANEL_TIMING_3, parameter, 3);
parameter[0] = 0x03;
parameter[1] = 0x04;
ls016b8uy_WriteReg(LCD_CMD_PANEL_TIMING_4, parameter, 2);
parameter[0] = 0x0C;
ls016b8uy_WriteReg(LCD_CMD_PANEL_POWER, parameter, 1);
parameter[0] = 0x02;
ls016b8uy_WriteReg(LCD_CMD_OSCILLATOR, parameter, 1);
parameter[0] = 0x53;
ls016b8uy_WriteReg(LCD_CMD_GVDD, parameter, 1);
parameter[0] = 0x00;
parameter[1] = 0x45;
ls016b8uy_WriteReg(LCD_CMD_RELOAD_MTP_VCOMH, parameter, 2);
parameter[0] = 0x03;
parameter[1] = 0x12;
ls016b8uy_WriteReg(LCD_CMD_OPAMP, parameter, 2);
parameter[0] = 0x00;
ls016b8uy_WriteReg(LCD_CMD_TEARING_EFFECT, parameter, 1);
ls016b8uy_WriteReg(LCD_CMD_PANEL_SETTING_LOCK, parameter, 0);
ls016b8uy_WriteReg(LCD_CMD_SLEEP_OUT, parameter, 0);
LCD_IO_Delay(150);
parameter[0] = 0x00;
parameter[1] = 0x1E;
parameter[2] = 0x00;
parameter[3] = 0xD1;
ls016b8uy_WriteReg(LCD_CMD_CASET, parameter, 4);
parameter[0] = 0x00;
parameter[1] = 0x00;
parameter[2] = 0x00;
parameter[3] = 0xB3;
ls016b8uy_WriteReg(LCD_CMD_RASET, parameter, 4);
parameter[0] = 0x83;
ls016b8uy_WriteReg(LCD_CMD_NORMAL_DISPLAY, parameter, 1);
ls016b8uy_DisplayOn();
}{ ... }
/* ... */
void ls016b8uy_DisplayOn(void)
{
ls016b8uy_WriteReg(LCD_CMD_DISPLAY_ON, (uint8_t*)NULL, 0);
ls016b8uy_WriteReg(LCD_CMD_IDLE_MODE_OFF, (uint8_t*)NULL, 0);
}{ ... }
/* ... */
void ls016b8uy_DisplayOff(void)
{
ls016b8uy_WriteReg(LCD_CMD_DISPLAY_OFF, (uint8_t*)NULL, 0);
LCD_IO_Delay(20);
ls016b8uy_WriteReg(LCD_CMD_SLEEP_IN, (uint8_t*)NULL, 0);
LCD_IO_Delay(150);
}{ ... }
/* ... */
uint16_t ls016b8uy_GetLcdPixelWidth(void)
{
return (uint16_t)LS016B8UY_LCD_PIXEL_WIDTH;
}{ ... }
/* ... */
uint16_t ls016b8uy_GetLcdPixelHeight(void)
{
return (uint16_t)LS016B8UY_LCD_PIXEL_HEIGHT;
}{ ... }
/* ... */
uint16_t ls016b8uy_ReadID(void)
{
LCD_IO_Init();
return (LS016B8UY_ID);
}{ ... }
/* ... */
void ls016b8uy_SetCursor(uint16_t Xpos, uint16_t Ypos)
{
uint8_t parameter[4];
parameter[0] = 0x00;
parameter[1] = 0x1E + Xpos;
parameter[2] = 0x00;
parameter[3] = 0xD1 + Xpos;
ls016b8uy_WriteReg(LCD_CMD_CASET, parameter, 4);
parameter[0] = 0x00;
parameter[1] = 0x00 + Ypos;
parameter[2] = 0x00;
parameter[3] = 0xB3 + Ypos;
ls016b8uy_WriteReg(LCD_CMD_RASET, parameter, 4);
}{ ... }
/* ... */
void ls016b8uy_WritePixel(uint16_t Xpos, uint16_t Ypos, uint16_t RGBCode)
{
uint16_t r, g, b;
uint16_t rgb888_part1, rgb888_part2;
r = (RGBCode & 0xF800) >> 11;
g = (RGBCode & 0x07E0) >> 5;
b = (RGBCode & 0x001F) >> 0;
rgb888_part1 = (r << 11) + (g << 2);
rgb888_part2 = (b << 11);
ls016b8uy_SetCursor(Xpos, Ypos);
ls016b8uy_WriteReg(LCD_CMD_WRITE_RAM, (uint8_t*)NULL, 0);
LCD_IO_WriteData(rgb888_part1);
LCD_IO_WriteData(rgb888_part2);
}{ ... }
/* ... */
uint16_t ls016b8uy_ReadPixel(uint16_t Xpos, uint16_t Ypos)
{
LS016B8UY_Rgb888 rgb888;
uint8_t r, g, b;
uint16_t rgb565;
ls016b8uy_SetCursor(Xpos, Ypos);
rgb888 = ls016b8uy_ReadPixel_rgb888(Xpos, Ypos);
r = ((rgb888.red & 0xF8) >> 3);
g = ((rgb888.green & 0xFC) >> 2);
b = ((rgb888.blue & 0xF8) >> 3);
rgb565 = ((uint16_t)(r) << 11) + ((uint16_t)(g) << 5) + ((uint16_t)(b) << 0);
return (rgb565);
}{ ... }
/* ... */
void ls016b8uy_WriteReg(uint8_t Command, uint8_t *Parameters, uint8_t NbParameters)
{
uint8_t i;
LCD_IO_WriteReg(Command);
for (i=0; i<NbParameters; i++)
{
LCD_IO_WriteData(Parameters[i]);
}for (i=0; i
}{ ... }
/* ... */
uint8_t ls016b8uy_ReadReg(uint8_t Command)
{
LCD_IO_WriteReg(Command);
LCD_IO_ReadData();
return (LCD_IO_ReadData());
}{ ... }
/* ... */
void ls016b8uy_SetDisplayWindow(uint16_t Xpos, uint16_t Ypos, uint16_t Width, uint16_t Height)
{
if (Xpos < LS016B8UY_LCD_PIXEL_WIDTH)
{
WindowsXstart = Xpos;
}if (Xpos < LS016B8UY_LCD_PIXEL_WIDTH) { ... }
else
{
WindowsXstart = 0;
}else { ... }
if (Ypos < LS016B8UY_LCD_PIXEL_HEIGHT)
{
WindowsYstart = Ypos;
}if (Ypos < LS016B8UY_LCD_PIXEL_HEIGHT) { ... }
else
{
WindowsYstart = 0;
}else { ... }
if (Width + Xpos <= LS016B8UY_LCD_PIXEL_WIDTH)
{
WindowsXend = Width + Xpos - 1;
}if (Width + Xpos <= LS016B8UY_LCD_PIXEL_WIDTH) { ... }
else
{
WindowsXend = LS016B8UY_LCD_PIXEL_WIDTH - 1;
}else { ... }
if (Height + Ypos <= LS016B8UY_LCD_PIXEL_HEIGHT)
{
WindowsYend = Height + Ypos - 1;
}if (Height + Ypos <= LS016B8UY_LCD_PIXEL_HEIGHT) { ... }
else
{
WindowsYend = LS016B8UY_LCD_PIXEL_HEIGHT-1;
}else { ... }
}{ ... }
/* ... */
void ls016b8uy_DrawHLine(uint16_t RGBCode, uint16_t Xpos, uint16_t Ypos, uint16_t Length)
{
uint16_t counter = 0;
uint16_t r, g, b;
uint16_t rgb888_part1, rgb888_part2, rgb888_part3;
r = (RGBCode & 0xF800) >> 11;
g = (RGBCode & 0x07E0) >> 5;
b = (RGBCode & 0x001F) >> 0;
rgb888_part1 = (r << 11) + (g << 2);
rgb888_part2 = (b << 11) + (r << 3);
rgb888_part3 = (g << 10) + (b << 3);
ls016b8uy_SetCursor(Xpos, Ypos);
ls016b8uy_WriteReg(LCD_CMD_WRITE_RAM, (uint8_t*)NULL, 0);
for(counter = 0; counter < Length; counter+=2)
{
LCD_IO_WriteData(rgb888_part1);
LCD_IO_WriteData(rgb888_part2);
if (counter != (Length-1))
{
LCD_IO_WriteData(rgb888_part3);
...}
}for (counter = 0; counter < Length; counter+=2) { ... }
}{ ... }
/* ... */
void ls016b8uy_DrawVLine(uint16_t RGBCode, uint16_t Xpos, uint16_t Ypos, uint16_t Length)
{
uint16_t counter = 0;
ls016b8uy_SetCursor(Xpos, Ypos);
ls016b8uy_WriteReg(LCD_CMD_WRITE_RAM, (uint8_t*)NULL, 0);
for(counter = 0; counter < Length; counter++)
{
ls016b8uy_WritePixel(Xpos, Ypos + counter, RGBCode);
}for (counter = 0; counter < Length; counter++) { ... }
}{ ... }
/* ... */
void ls016b8uy_DrawBitmap(uint16_t Xpos, uint16_t Ypos, uint8_t *pbmp)
{
uint32_t index = 0, size = 0;
uint32_t posY;
uint32_t nb_line = 0;
uint16_t Xsize = WindowsXend - WindowsXstart + 1;
uint16_t Ysize = WindowsYend - WindowsYstart + 1;
size = *(volatile uint16_t *) (pbmp + 2);
size |= (*(volatile uint16_t *) (pbmp + 4)) << 16;
index = *(volatile uint16_t *) (pbmp + 10);
index |= (*(volatile uint16_t *) (pbmp + 12)) << 16;
size = (size - index)/2;
pbmp += index;
for (posY = (Ypos + Ysize); posY > Ypos; posY--)
{
ls016b8uy_SetCursor(Xpos, posY - 1);
ls016b8uy_DrawRGBHLine(Xpos, posY - 1, Xsize, (pbmp + (nb_line * Xsize * 2)));
nb_line++;
...}
}{ ... }
/* ... */
void ls016b8uy_DrawRGBImage(uint16_t Xpos, uint16_t Ypos, uint16_t Xsize, uint16_t Ysize, uint8_t *pdata)
{
uint32_t posY;
uint32_t nb_line = 0;
for (posY = Ypos; posY < (Ypos + Ysize); posY ++)
{
ls016b8uy_SetCursor(Xpos, posY);
ls016b8uy_DrawRGBHLine(Xpos, posY, Xsize, (pdata + (nb_line * Xsize * 2)));
nb_line++;
}for (posY = Ypos; posY < (Ypos + Ysize); posY ++) { ... }
}{ ... }
/* ... */
/* ... */
static LS016B8UY_Rgb888 ls016b8uy_ReadPixel_rgb888(uint16_t Xpos, uint16_t Ypos)
{
LS016B8UY_Rgb888 rgb888;
uint16_t rgb888_part1, rgb888_part2;
/* ... */
ls016b8uy_SetCursor(Xpos, Ypos);
ls016b8uy_WriteReg(LCD_CMD_READ_RAM, (uint8_t*)NULL, 0);
LCD_IO_ReadData();
rgb888_part1 = LCD_IO_ReadData();
rgb888_part2 = LCD_IO_ReadData();
rgb888.red = (rgb888_part1 & 0xFC00) >> 8;
rgb888.green = (rgb888_part1 & 0x00FC) >> 0;
rgb888.blue = (rgb888_part2 & 0xFC00) >> 8;
return rgb888;
}{ ... }
/* ... */
static void ls016b8uy_DrawRGBHLine(uint16_t Xpos, uint16_t Ypos, uint16_t Xsize, uint8_t *pdata)
{
uint32_t i = 0;
uint32_t posX;
uint16_t r, g, b;
uint16_t rgb888_part;
uint16_t *rgb565 = (uint16_t*)pdata;
ls016b8uy_WriteReg(LCD_CMD_WRITE_RAM, (uint8_t*)NULL, 0);
for (posX = Xpos; posX < (Xsize + Xpos); posX += 2)
{
if ((posX >= WindowsXstart) && (Ypos >= WindowsYstart) &&
(posX <= WindowsXend) && (Ypos <= WindowsYend))
{
r = (rgb565[i] & 0xF800) >> 11;
g = (rgb565[i] & 0x07E0) >> 5;
rgb888_part = (r << 11) + (g << 2);
LCD_IO_WriteData(rgb888_part);
b = (rgb565[i] & 0x001F) >> 0;
r = (rgb565[i+1] & 0xF800) >> 11;
rgb888_part = (b << 11) + (r << 3);
LCD_IO_WriteData(rgb888_part);
if (posX != (Xsize + Xpos - 1))
{
g = (rgb565[i+1] & 0x07E0) >> 5;
b = (rgb565[i+1] & 0x001F) >> 0;
rgb888_part = (g << 10) + (b << 3);
LCD_IO_WriteData(rgb888_part);
...}
i += 2;
}if ((posX >= WindowsXstart) && (Ypos >= WindowsYstart) && /* Check we are in the defined window */ (posX <= WindowsXend) && (Ypos <= WindowsYend)) { ... }
}for (posX = Xpos; posX < (Xsize + Xpos); posX += 2) { ... }
}{ ... }
/* ... */
/* ... */
/* ... */
/* ... */