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
66
69
70
73
74
78
79
82
85
86
89
90
91
94
95
98
99
102
103
106
107
108
109
110
111
112
113
114
117
118
121
122
123
124
125
128
129
132
133
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
220
224
225
229
233
234
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
274
278
279
285
297
298
299
300
301
302
303
304
305
306
307
319
320
326
330
331
338
342
343
348
352
353
359
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
404
410
411
417
423
424
428
433
434
439
444
445
452
456
457
461
465
466
470
474
475
479
483
484
488
492
493
497
501
502
506
510
511
517
518
519
520
521
526
531
538
543
544
545
546
547
551
557
558
562
563
564
565
566
567
568
569
570
571
572
573
574
575
581
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
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
653
657
658
664
665
666
667
668
669
670
671
672
673
674
675
681
682
683
684
685
686
687
688
689
690
691
692
699
700
701
702
703
704
705
706
707
708
709
710
711
715
720
721
722
726
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
761
762
763
764
765
766
773
774
775
776
777
778
779
780
781
782
783
784
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
815
820
821
822
823
824
829
830
831
832
833
837
838
839
840
847
848
849
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
879
880
881
882
883
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
915
919
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
987
988
993
997
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1034
1039
1040
1041
1045
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1081
1082
1083
1084
1085
1086
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1107
1111
1112
1113
1117
1121
1122
1123
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1179
1180
1181
1182
1183
1186
1193
1194
1197
1204
1205
1208
1209
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1289
1290
1296
1301
1302
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1331
1335
1336
1339
1340
1341
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1424
1425
1426
1429
1430
1433
1434
1437
1438
/* ... */
/* ... */
#include "stm32f429i_discovery_lcd.h"
#include "../../../Utilities/Fonts/fonts.h"
#include "../../../Utilities/Fonts/font24.c"
#include "../../../Utilities/Fonts/font20.c"
#include "../../../Utilities/Fonts/font16.c"
#include "../../../Utilities/Fonts/font12.c"
#include "../../../Utilities/Fonts/font8.c"
7 includes
/* ... */
/* ... */
/* ... */
/* ... */
/* ... */
/* ... */
#define POLY_X(Z) ((int32_t)((Points + Z)->X))
#define POLY_Y(Z) ((int32_t)((Points + Z)->Y))
/* ... */
/* ... */
#define ABS(X) ((X) > 0 ? (X) : -(X))
/* ... */
/* ... */
LTDC_HandleTypeDef LtdcHandler;
static DMA2D_HandleTypeDef Dma2dHandler;
static RCC_PeriphCLKInitTypeDef PeriphClkInitStruct;
static uint32_t ActiveLayer = 0;
static LCD_DrawPropTypeDef DrawProp[MAX_LAYER_NUMBER];
LCD_DrvTypeDef *LcdDrv;
/* ... */
/* ... */
static void DrawChar(uint16_t Xpos, uint16_t Ypos, const uint8_t *c);
static void FillBuffer(uint32_t LayerIndex, void *pDst, uint32_t xSize, uint32_t ySize, uint32_t OffLine,
uint32_t ColorIndex);
static void ConvertLineToARGB8888(void *pSrc, void *pDst, uint32_t xSize, uint32_t ColorMode);
/* ... */
/* ... */
/* ... */
uint8_t BSP_LCD_Init(void)
{
LtdcHandler.Instance = LTDC;
/* ... */
LtdcHandler.Init.HorizontalSync = ILI9341_HSYNC;
LtdcHandler.Init.VerticalSync = ILI9341_VSYNC;
LtdcHandler.Init.AccumulatedHBP = ILI9341_HBP;
LtdcHandler.Init.AccumulatedVBP = ILI9341_VBP;
LtdcHandler.Init.AccumulatedActiveW = 269;
LtdcHandler.Init.AccumulatedActiveH = 323;
LtdcHandler.Init.TotalWidth = 279;
LtdcHandler.Init.TotalHeigh = 327;
LtdcHandler.Init.Backcolor.Red = 0;
LtdcHandler.Init.Backcolor.Blue = 0;
LtdcHandler.Init.Backcolor.Green = 0;
PeriphClkInitStruct.PeriphClockSelection = RCC_PERIPHCLK_LTDC;
PeriphClkInitStruct.PLLSAI.PLLSAIN = 192;
PeriphClkInitStruct.PLLSAI.PLLSAIR = 4;
PeriphClkInitStruct.PLLSAIDivR = RCC_PLLSAIDIVR_8;
HAL_RCCEx_PeriphCLKConfig(&PeriphClkInitStruct);
LtdcHandler.Init.HSPolarity = LTDC_HSPOLARITY_AL;
LtdcHandler.Init.VSPolarity = LTDC_VSPOLARITY_AL;
LtdcHandler.Init.DEPolarity = LTDC_DEPOLARITY_AL;
LtdcHandler.Init.PCPolarity = LTDC_PCPOLARITY_IPC;
BSP_LCD_MspInit();
HAL_LTDC_Init(&LtdcHandler);
LcdDrv = &ili9341_drv;
LcdDrv->Init();
BSP_SDRAM_Init();
BSP_LCD_SetFont(&LCD_DEFAULT_FONT);
return LCD_OK;
}{ ... }
/* ... */
uint32_t BSP_LCD_GetXSize(void)
{
return LcdDrv->GetLcdPixelWidth();
}{ ... }
/* ... */
uint32_t BSP_LCD_GetYSize(void)
{
return LcdDrv->GetLcdPixelHeight();
}{ ... }
/* ... */
void BSP_LCD_LayerDefaultInit(uint16_t LayerIndex, uint32_t FB_Address)
{
LCD_LayerCfgTypeDef Layercfg;
Layercfg.WindowX0 = 0;
Layercfg.WindowX1 = BSP_LCD_GetXSize();
Layercfg.WindowY0 = 0;
Layercfg.WindowY1 = BSP_LCD_GetYSize();
Layercfg.PixelFormat = LTDC_PIXEL_FORMAT_ARGB8888;
Layercfg.FBStartAdress = FB_Address;
Layercfg.Alpha = 255;
Layercfg.Alpha0 = 0;
Layercfg.Backcolor.Blue = 0;
Layercfg.Backcolor.Green = 0;
Layercfg.Backcolor.Red = 0;
Layercfg.BlendingFactor1 = LTDC_BLENDING_FACTOR1_PAxCA;
Layercfg.BlendingFactor2 = LTDC_BLENDING_FACTOR2_PAxCA;
Layercfg.ImageWidth = BSP_LCD_GetXSize();
Layercfg.ImageHeight = BSP_LCD_GetYSize();
HAL_LTDC_ConfigLayer(&LtdcHandler, &Layercfg, LayerIndex);
DrawProp[LayerIndex].BackColor = LCD_COLOR_WHITE;
DrawProp[LayerIndex].pFont = &Font24;
DrawProp[LayerIndex].TextColor = LCD_COLOR_BLACK;
HAL_LTDC_EnableDither(&LtdcHandler);
}{ ... }
/* ... */
void BSP_LCD_SelectLayer(uint32_t LayerIndex)
{
ActiveLayer = LayerIndex;
}{ ... }
/* ... */
void BSP_LCD_SetLayerVisible(uint32_t LayerIndex, FunctionalState state)
{
if (state == ENABLE)
{
__HAL_LTDC_LAYER_ENABLE(&LtdcHandler, LayerIndex);
}if (state == ENABLE) { ... }
else
{
__HAL_LTDC_LAYER_DISABLE(&LtdcHandler, LayerIndex);
}else { ... }
__HAL_LTDC_RELOAD_CONFIG(&LtdcHandler);
}{ ... }
/* ... */
void BSP_LCD_SetLayerVisible_NoReload(uint32_t LayerIndex, FunctionalState State)
{
if (State == ENABLE)
{
__HAL_LTDC_LAYER_ENABLE(&LtdcHandler, LayerIndex);
}if (State == ENABLE) { ... }
else
{
__HAL_LTDC_LAYER_DISABLE(&LtdcHandler, LayerIndex);
}else { ... }
}{ ... }
/* ... */
void BSP_LCD_SetTransparency(uint32_t LayerIndex, uint8_t Transparency)
{
HAL_LTDC_SetAlpha(&LtdcHandler, Transparency, LayerIndex);
}{ ... }
/* ... */
void BSP_LCD_SetTransparency_NoReload(uint32_t LayerIndex, uint8_t Transparency)
{
HAL_LTDC_SetAlpha_NoReload(&LtdcHandler, Transparency, LayerIndex);
}{ ... }
/* ... */
void BSP_LCD_SetLayerAddress(uint32_t LayerIndex, uint32_t Address)
{
HAL_LTDC_SetAddress(&LtdcHandler, Address, LayerIndex);
}{ ... }
/* ... */
void BSP_LCD_SetLayerAddress_NoReload(uint32_t LayerIndex, uint32_t Address)
{
HAL_LTDC_SetAddress_NoReload(&LtdcHandler, Address, LayerIndex);
}{ ... }
/* ... */
void BSP_LCD_SetLayerWindow(uint16_t LayerIndex, uint16_t Xpos, uint16_t Ypos, uint16_t Width, uint16_t Height)
{
HAL_LTDC_SetWindowSize(&LtdcHandler, Width, Height, LayerIndex);
HAL_LTDC_SetWindowPosition(&LtdcHandler, Xpos, Ypos, LayerIndex);
}{ ... }
/* ... */
void BSP_LCD_SetLayerWindow_NoReload(uint16_t LayerIndex, uint16_t Xpos, uint16_t Ypos, uint16_t Width, uint16_t Height)
{
HAL_LTDC_SetWindowSize_NoReload(&LtdcHandler, Width, Height, LayerIndex);
HAL_LTDC_SetWindowPosition_NoReload(&LtdcHandler, Xpos, Ypos, LayerIndex);
}{ ... }
/* ... */
void BSP_LCD_SetColorKeying(uint32_t LayerIndex, uint32_t RGBValue)
{
HAL_LTDC_ConfigColorKeying(&LtdcHandler, RGBValue, LayerIndex);
HAL_LTDC_EnableColorKeying(&LtdcHandler, LayerIndex);
}{ ... }
/* ... */
void BSP_LCD_SetColorKeying_NoReload(uint32_t LayerIndex, uint32_t RGBValue)
{
HAL_LTDC_ConfigColorKeying_NoReload(&LtdcHandler, RGBValue, LayerIndex);
HAL_LTDC_EnableColorKeying_NoReload(&LtdcHandler, LayerIndex);
}{ ... }
/* ... */
void BSP_LCD_ResetColorKeying(uint32_t LayerIndex)
{
HAL_LTDC_DisableColorKeying(&LtdcHandler, LayerIndex);
}{ ... }
/* ... */
void BSP_LCD_ResetColorKeying_NoReload(uint32_t LayerIndex)
{
HAL_LTDC_DisableColorKeying_NoReload(&LtdcHandler, LayerIndex);
}{ ... }
/* ... */
void BSP_LCD_Relaod(uint32_t ReloadType)
{
HAL_LTDC_Relaod(&LtdcHandler, ReloadType);
}{ ... }
/* ... */
uint32_t BSP_LCD_GetTextColor(void)
{
return DrawProp[ActiveLayer].TextColor;
}{ ... }
/* ... */
uint32_t BSP_LCD_GetBackColor(void)
{
return DrawProp[ActiveLayer].BackColor;
}{ ... }
/* ... */
void BSP_LCD_SetTextColor(uint32_t Color)
{
DrawProp[ActiveLayer].TextColor = Color;
}{ ... }
/* ... */
void BSP_LCD_SetBackColor(uint32_t Color)
{
DrawProp[ActiveLayer].BackColor = Color;
}{ ... }
/* ... */
void BSP_LCD_SetFont(sFONT *pFonts)
{
DrawProp[ActiveLayer].pFont = pFonts;
}{ ... }
/* ... */
sFONT *BSP_LCD_GetFont(void)
{
return DrawProp[ActiveLayer].pFont;
}{ ... }
/* ... */
uint32_t BSP_LCD_ReadPixel(uint16_t Xpos, uint16_t Ypos)
{
uint32_t ret = 0;
if (LtdcHandler.LayerCfg[ActiveLayer].PixelFormat == LTDC_PIXEL_FORMAT_ARGB8888)
{
ret = *(__IO uint32_t *)(LtdcHandler.LayerCfg[ActiveLayer].FBStartAdress + (4 * (Ypos * BSP_LCD_GetXSize() + Xpos)));
}if (LtdcHandler.LayerCfg[ActiveLayer].PixelFormat == LTDC_PIXEL_FORMAT_ARGB8888) { ... }
else if (LtdcHandler.LayerCfg[ActiveLayer].PixelFormat == LTDC_PIXEL_FORMAT_RGB888)
{
ret = (*(__IO uint32_t *)(LtdcHandler.LayerCfg[ActiveLayer].FBStartAdress + (4 * (Ypos * BSP_LCD_GetXSize() + Xpos))) & 0x00FFFFFF);
}else if (LtdcHandler.LayerCfg[ActiveLayer].PixelFormat == LTDC_PIXEL_FORMAT_RGB888) { ... }
else if ((LtdcHandler.LayerCfg[ActiveLayer].PixelFormat == LTDC_PIXEL_FORMAT_RGB565) || \
(LtdcHandler.LayerCfg[ActiveLayer].PixelFormat == LTDC_PIXEL_FORMAT_ARGB4444) || \
(LtdcHandler.LayerCfg[ActiveLayer].PixelFormat == LTDC_PIXEL_FORMAT_AL88))
{
ret = *(__IO uint16_t *)(LtdcHandler.LayerCfg[ActiveLayer].FBStartAdress + (2 * (Ypos * BSP_LCD_GetXSize() + Xpos)));
}else if ((LtdcHandler.LayerCfg[ActiveLayer].PixelFormat == LTDC_PIXEL_FORMAT_RGB565) || \ (LtdcHandler.LayerCfg[ActiveLayer].PixelFormat == LTDC_PIXEL_FORMAT_ARGB4444) || \ (LtdcHandler.LayerCfg[ActiveLayer].PixelFormat == LTDC_PIXEL_FORMAT_AL88)) { ... }
else
{
ret = *(__IO uint8_t *)(LtdcHandler.LayerCfg[ActiveLayer].FBStartAdress + (2 * (Ypos * BSP_LCD_GetXSize() + Xpos)));
}else { ... }
return ret;
}{ ... }
/* ... */
void BSP_LCD_Clear(uint32_t Color)
{
FillBuffer(ActiveLayer, (uint32_t *)(LtdcHandler.LayerCfg[ActiveLayer].FBStartAdress), BSP_LCD_GetXSize(),
BSP_LCD_GetYSize(), 0, Color);
}{ ... }
/* ... */
void BSP_LCD_ClearStringLine(uint32_t Line)
{
uint32_t colorbackup = DrawProp[ActiveLayer].TextColor;
DrawProp[ActiveLayer].TextColor = DrawProp[ActiveLayer].BackColor;
BSP_LCD_FillRect(0, (Line * DrawProp[ActiveLayer].pFont->Height), BSP_LCD_GetXSize(),
DrawProp[ActiveLayer].pFont->Height);
DrawProp[ActiveLayer].TextColor = colorbackup;
BSP_LCD_SetTextColor(DrawProp[ActiveLayer].TextColor);
}{ ... }
/* ... */
void BSP_LCD_DisplayChar(uint16_t Xpos, uint16_t Ypos, uint8_t Ascii)
{
DrawChar(Xpos, Ypos, &DrawProp[ActiveLayer].pFont->table[(Ascii - ' ') *\
DrawProp[ActiveLayer].pFont->Height * ((DrawProp[ActiveLayer].pFont->Width + 7) / 8)]);
}{ ... }
/* ... */
void BSP_LCD_DisplayStringAt(uint16_t X, uint16_t Y, uint8_t *pText, Text_AlignModeTypdef mode)
{
uint16_t refcolumn = 1, i = 0;
uint32_t size = 0, xsize = 0;
uint8_t *ptr = pText;
while (*ptr++) { size ++ ; }
xsize = (BSP_LCD_GetXSize() / DrawProp[ActiveLayer].pFont->Width);
switch (mode)
{
case CENTER_MODE:
{
refcolumn = X + ((xsize - size) * DrawProp[ActiveLayer].pFont->Width) / 2;
break;
...}case CENTER_MODE:
case LEFT_MODE:
{
refcolumn = X;
break;
...}case LEFT_MODE:
case RIGHT_MODE:
{
refcolumn = X + ((xsize - size) * DrawProp[ActiveLayer].pFont->Width);
break;
...}case RIGHT_MODE:
default:
{
refcolumn = X;
break;
...}default
}switch (mode) { ... }
while ((*pText != 0) & (((BSP_LCD_GetXSize() - (i * DrawProp[ActiveLayer].pFont->Width)) & 0xFFFF) >=
DrawProp[ActiveLayer].pFont->Width))
{
BSP_LCD_DisplayChar(refcolumn, Y, *pText);
refcolumn += DrawProp[ActiveLayer].pFont->Width;
pText++;
i++;
}while ((*pText != 0) & (((BSP_LCD_GetXSize() - (i * DrawProp[ActiveLayer].pFont->Width)) & 0xFFFF) >= DrawProp[ActiveLayer].pFont->Width)) { ... }
}{ ... }
/* ... */
void BSP_LCD_DisplayStringAtLine(uint16_t Line, uint8_t *ptr)
{
BSP_LCD_DisplayStringAt(0, LINE(Line), ptr, LEFT_MODE);
}{ ... }
/* ... */
void BSP_LCD_DrawHLine(uint16_t Xpos, uint16_t Ypos, uint16_t Length)
{
uint32_t xaddress = 0;
xaddress = (LtdcHandler.LayerCfg[ActiveLayer].FBStartAdress) + 4 * (BSP_LCD_GetXSize() * Ypos + Xpos);
FillBuffer(ActiveLayer, (uint32_t *)xaddress, Length, 1, 0, DrawProp[ActiveLayer].TextColor);
}{ ... }
/* ... */
void BSP_LCD_DrawVLine(uint16_t Xpos, uint16_t Ypos, uint16_t Length)
{
uint32_t xaddress = 0;
xaddress = (LtdcHandler.LayerCfg[ActiveLayer].FBStartAdress) + 4 * (BSP_LCD_GetXSize() * Ypos + Xpos);
FillBuffer(ActiveLayer, (uint32_t *)xaddress, 1, Length, (BSP_LCD_GetXSize() - 1), DrawProp[ActiveLayer].TextColor);
}{ ... }
/* ... */
void BSP_LCD_DrawLine(uint16_t X1, uint16_t Y1, uint16_t X2, uint16_t Y2)
{
int16_t deltax = 0, deltay = 0, x = 0, y = 0, xinc1 = 0, xinc2 = 0,
yinc1 = 0, yinc2 = 0, den = 0, num = 0, numadd = 0, numpixels = 0,
curpixel = 0;
deltax = ABS(X2 - X1);
deltay = ABS(Y2 - Y1);
x = X1;
y = Y1;
if (X2 >= X1)
{
xinc1 = 1;
xinc2 = 1;
...}
else
{
xinc1 = -1;
xinc2 = -1;
}else { ... }
if (Y2 >= Y1)
{
yinc1 = 1;
yinc2 = 1;
...}
else
{
yinc1 = -1;
yinc2 = -1;
}else { ... }
if (deltax >= deltay)
{
xinc1 = 0;
yinc2 = 0;
den = deltax;
num = deltax / 2;
numadd = deltay;
numpixels = deltax;
...}
else
{
xinc2 = 0;
yinc1 = 0;
den = deltay;
num = deltay / 2;
numadd = deltax;
numpixels = deltay;
}else { ... }
for (curpixel = 0; curpixel <= numpixels; curpixel++)
{
BSP_LCD_DrawPixel(x, y, DrawProp[ActiveLayer].TextColor);
num += numadd;
if (num >= den)
{
num -= den;
x += xinc1;
y += yinc1;
...}
x += xinc2;
y += yinc2;
}for (curpixel = 0; curpixel <= numpixels; curpixel++) { ... }
}{ ... }
/* ... */
void BSP_LCD_DrawRect(uint16_t Xpos, uint16_t Ypos, uint16_t Width, uint16_t Height)
{
BSP_LCD_DrawHLine(Xpos, Ypos, Width);
BSP_LCD_DrawHLine(Xpos, (Ypos + Height), Width);
BSP_LCD_DrawVLine(Xpos, Ypos, Height);
BSP_LCD_DrawVLine((Xpos + Width), Ypos, Height);
}{ ... }
/* ... */
void BSP_LCD_DrawCircle(uint16_t Xpos, uint16_t Ypos, uint16_t Radius)
{
int32_t d;
uint32_t curx;
uint32_t cury;
d = 3 - (Radius << 1);
curx = 0;
cury = Radius;
while (curx <= cury)
{
BSP_LCD_DrawPixel((Xpos + curx), (Ypos - cury), DrawProp[ActiveLayer].TextColor);
BSP_LCD_DrawPixel((Xpos - curx), (Ypos - cury), DrawProp[ActiveLayer].TextColor);
BSP_LCD_DrawPixel((Xpos + cury), (Ypos - curx), DrawProp[ActiveLayer].TextColor);
BSP_LCD_DrawPixel((Xpos - cury), (Ypos - curx), DrawProp[ActiveLayer].TextColor);
BSP_LCD_DrawPixel((Xpos + curx), (Ypos + cury), DrawProp[ActiveLayer].TextColor);
BSP_LCD_DrawPixel((Xpos - curx), (Ypos + cury), DrawProp[ActiveLayer].TextColor);
BSP_LCD_DrawPixel((Xpos + cury), (Ypos + curx), DrawProp[ActiveLayer].TextColor);
BSP_LCD_DrawPixel((Xpos - cury), (Ypos + curx), DrawProp[ActiveLayer].TextColor);
if (d < 0)
{
d += (curx << 2) + 6;
}if (d < 0) { ... }
else
{
d += ((curx - cury) << 2) + 10;
cury--;
}else { ... }
curx++;
}while (curx <= cury) { ... }
}{ ... }
/* ... */
void BSP_LCD_DrawPolygon(pPoint Points, uint16_t PointCount)
{
int16_t x = 0, y = 0;
if (PointCount < 2)
{
return;
}if (PointCount < 2) { ... }
BSP_LCD_DrawLine(Points->X, Points->Y, (Points + PointCount - 1)->X, (Points + PointCount - 1)->Y);
while (--PointCount)
{
x = Points->X;
y = Points->Y;
Points++;
BSP_LCD_DrawLine(x, y, Points->X, Points->Y);
}while (--PointCount) { ... }
}{ ... }
/* ... */
void BSP_LCD_DrawEllipse(int Xpos, int Ypos, int XRadius, int YRadius)
{
int x = 0, y = -YRadius, err = 2 - 2 * XRadius, e2;
float k = 0, rad1 = 0, rad2 = 0;
rad1 = XRadius;
rad2 = YRadius;
k = (float)(rad2 / rad1);
do
{
BSP_LCD_DrawPixel((Xpos - (uint16_t)(x / k)), (Ypos + y), DrawProp[ActiveLayer].TextColor);
BSP_LCD_DrawPixel((Xpos + (uint16_t)(x / k)), (Ypos + y), DrawProp[ActiveLayer].TextColor);
BSP_LCD_DrawPixel((Xpos + (uint16_t)(x / k)), (Ypos - y), DrawProp[ActiveLayer].TextColor);
BSP_LCD_DrawPixel((Xpos - (uint16_t)(x / k)), (Ypos - y), DrawProp[ActiveLayer].TextColor);
e2 = err;
if (e2 <= x)
{
err += ++x * 2 + 1;
if (-y == x && e2 <= y) { e2 = 0; }
}if (e2 <= x) { ... }
if (e2 > y) { err += ++y * 2 + 1; }
...} while (y <= 0);
}{ ... }
/* ... */
void BSP_LCD_DrawBitmap(uint32_t X, uint32_t Y, uint8_t *pBmp)
{
uint32_t index = 0, width = 0, height = 0, bitpixel = 0;
uint32_t address;
uint32_t inputcolormode = 0;
index = pBmp[10] + (pBmp[11] << 8) + (pBmp[12] << 16) + (pBmp[13] << 24);
width = pBmp[18] + (pBmp[19] << 8) + (pBmp[20] << 16) + (pBmp[21] << 24);
height = pBmp[22] + (pBmp[23] << 8) + (pBmp[24] << 16) + (pBmp[25] << 24);
bitpixel = pBmp[28] + (pBmp[29] << 8);
address = LtdcHandler.LayerCfg[ActiveLayer].FBStartAdress + (((BSP_LCD_GetXSize() * Y) + X) * (4));
if ((bitpixel / 8) == 4)
{
inputcolormode = CM_ARGB8888;
}if ((bitpixel / 8) == 4) { ... }
else if ((bitpixel / 8) == 2)
{
inputcolormode = CM_RGB565;
}else if ((bitpixel / 8) == 2) { ... }
else
{
inputcolormode = CM_RGB888;
}else { ... }
pBmp += (index + (width * (height - 1) * (bitpixel / 8)));
for (index = 0; index < height; index++)
{
ConvertLineToARGB8888((uint32_t *)pBmp, (uint32_t *)address, width, inputcolormode);
address += ((BSP_LCD_GetXSize() - width + width) * 4);
pBmp -= width * (bitpixel / 8);
}for (index = 0; index < height; index++) { ... }
}{ ... }
/* ... */
void BSP_LCD_FillRect(uint16_t Xpos, uint16_t Ypos, uint16_t Width, uint16_t Height)
{
uint32_t xaddress = 0;
BSP_LCD_SetTextColor(DrawProp[ActiveLayer].TextColor);
xaddress = (LtdcHandler.LayerCfg[ActiveLayer].FBStartAdress) + 4 * (BSP_LCD_GetXSize() * Ypos + Xpos);
FillBuffer(ActiveLayer, (uint32_t *)xaddress, Width, Height, (BSP_LCD_GetXSize() - Width),
DrawProp[ActiveLayer].TextColor);
}{ ... }
/* ... */
void BSP_LCD_FillCircle(uint16_t Xpos, uint16_t Ypos, uint16_t Radius)
{
int32_t d;
uint32_t curx;
uint32_t cury;
d = 3 - (Radius << 1);
curx = 0;
cury = Radius;
BSP_LCD_SetTextColor(DrawProp[ActiveLayer].TextColor);
while (curx <= cury)
{
if (cury > 0)
{
BSP_LCD_DrawHLine(Xpos - cury, Ypos + curx, 2 * cury);
BSP_LCD_DrawHLine(Xpos - cury, Ypos - curx, 2 * cury);
}if (cury > 0) { ... }
if (curx > 0)
{
BSP_LCD_DrawHLine(Xpos - curx, Ypos - cury, 2 * curx);
BSP_LCD_DrawHLine(Xpos - curx, Ypos + cury, 2 * curx);
}if (curx > 0) { ... }
if (d < 0)
{
d += (curx << 2) + 6;
}if (d < 0) { ... }
else
{
d += ((curx - cury) << 2) + 10;
cury--;
}else { ... }
curx++;
}while (curx <= cury) { ... }
BSP_LCD_SetTextColor(DrawProp[ActiveLayer].TextColor);
BSP_LCD_DrawCircle(Xpos, Ypos, Radius);
}{ ... }
/* ... */
void BSP_LCD_FillTriangle(uint16_t X1, uint16_t X2, uint16_t X3, uint16_t Y1, uint16_t Y2, uint16_t Y3)
{
int16_t deltax = 0, deltay = 0, x = 0, y = 0, xinc1 = 0, xinc2 = 0,
yinc1 = 0, yinc2 = 0, den = 0, num = 0, numadd = 0, numpixels = 0,
curpixel = 0;
deltax = ABS(X2 - X1);
deltay = ABS(Y2 - Y1);
x = X1;
y = Y1;
if (X2 >= X1)
{
xinc1 = 1;
xinc2 = 1;
...}
else
{
xinc1 = -1;
xinc2 = -1;
}else { ... }
if (Y2 >= Y1)
{
yinc1 = 1;
yinc2 = 1;
...}
else
{
yinc1 = -1;
yinc2 = -1;
}else { ... }
if (deltax >= deltay)
{
xinc1 = 0;
yinc2 = 0;
den = deltax;
num = deltax / 2;
numadd = deltay;
numpixels = deltax;
...}
else
{
xinc2 = 0;
yinc1 = 0;
den = deltay;
num = deltay / 2;
numadd = deltax;
numpixels = deltay;
}else { ... }
for (curpixel = 0; curpixel <= numpixels; curpixel++)
{
BSP_LCD_DrawLine(x, y, X3, Y3);
num += numadd;
if (num >= den)
{
num -= den;
x += xinc1;
y += yinc1;
...}
x += xinc2;
y += yinc2;
}for (curpixel = 0; curpixel <= numpixels; curpixel++) { ... }
}{ ... }
/* ... */
void BSP_LCD_FillPolygon(pPoint Points, uint16_t PointCount)
{
int16_t x = 0, y = 0, x2 = 0, y2 = 0, xcenter = 0, ycenter = 0, xfirst = 0, yfirst = 0, pixelx = 0, pixely = 0, counter = 0;
uint16_t imageleft = 0, imageright = 0, imagetop = 0, imagebottom = 0;
imageleft = imageright = Points->X;
imagetop = imagebottom = Points->Y;
for (counter = 1; counter < PointCount; counter++)
{
pixelx = POLY_X(counter);
if (pixelx < imageleft)
{
imageleft = pixelx;
}if (pixelx < imageleft) { ... }
if (pixelx > imageright)
{
imageright = pixelx;
}if (pixelx > imageright) { ... }
pixely = POLY_Y(counter);
if (pixely < imagetop)
{
imagetop = pixely;
}if (pixely < imagetop) { ... }
if (pixely > imagebottom)
{
imagebottom = pixely;
}if (pixely > imagebottom) { ... }
}for (counter = 1; counter < PointCount; counter++) { ... }
if (PointCount < 2)
{
return;
}if (PointCount < 2) { ... }
xcenter = (imageleft + imageright) / 2;
ycenter = (imagebottom + imagetop) / 2;
xfirst = Points->X;
yfirst = Points->Y;
while (--PointCount)
{
x = Points->X;
y = Points->Y;
Points++;
x2 = Points->X;
y2 = Points->Y;
BSP_LCD_FillTriangle(x, x2, xcenter, y, y2, ycenter);
BSP_LCD_FillTriangle(x, xcenter, x2, y, ycenter, y2);
BSP_LCD_FillTriangle(xcenter, x2, x, ycenter, y2, y);
}while (--PointCount) { ... }
BSP_LCD_FillTriangle(xfirst, x2, xcenter, yfirst, y2, ycenter);
BSP_LCD_FillTriangle(xfirst, xcenter, x2, yfirst, ycenter, y2);
BSP_LCD_FillTriangle(xcenter, x2, xfirst, ycenter, y2, yfirst);
}{ ... }
/* ... */
void BSP_LCD_FillEllipse(int Xpos, int Ypos, int XRadius, int YRadius)
{
int x = 0, y = -YRadius, err = 2 - 2 * XRadius, e2;
float K = 0, rad1 = 0, rad2 = 0;
rad1 = XRadius;
rad2 = YRadius;
K = (float)(rad2 / rad1);
do
{
BSP_LCD_DrawHLine((Xpos - (uint16_t)(x / K)), (Ypos + y), (2 * (uint16_t)(x / K) + 1));
BSP_LCD_DrawHLine((Xpos - (uint16_t)(x / K)), (Ypos - y), (2 * (uint16_t)(x / K) + 1));
e2 = err;
if (e2 <= x)
{
err += ++x * 2 + 1;
if (-y == x && e2 <= y) { e2 = 0; }
}if (e2 <= x) { ... }
if (e2 > y) { err += ++y * 2 + 1; }
...} while (y <= 0);
}{ ... }
/* ... */
void BSP_LCD_DisplayOn(void)
{
if (LcdDrv->DisplayOn != NULL)
{
LcdDrv->DisplayOn();
}if (LcdDrv->DisplayOn != NULL) { ... }
}{ ... }
/* ... */
void BSP_LCD_DisplayOff(void)
{
if (LcdDrv->DisplayOff != NULL)
{
LcdDrv->DisplayOff();
}if (LcdDrv->DisplayOff != NULL) { ... }
}{ ... }
/* ... */
/* ... */
__weak void BSP_LCD_MspInit(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
__HAL_RCC_LTDC_CLK_ENABLE();
__HAL_RCC_DMA2D_CLK_ENABLE();
__HAL_RCC_GPIOA_CLK_ENABLE();
__HAL_RCC_GPIOB_CLK_ENABLE();
__HAL_RCC_GPIOC_CLK_ENABLE();
__HAL_RCC_GPIOD_CLK_ENABLE();
__HAL_RCC_GPIOF_CLK_ENABLE();
__HAL_RCC_GPIOG_CLK_ENABLE();
/* ... */
GPIO_InitStructure.Pin = GPIO_PIN_3 | GPIO_PIN_4 | GPIO_PIN_6 |
GPIO_PIN_11 | GPIO_PIN_12;
GPIO_InitStructure.Mode = GPIO_MODE_AF_PP;
GPIO_InitStructure.Pull = GPIO_NOPULL;
GPIO_InitStructure.Speed = GPIO_SPEED_FAST;
GPIO_InitStructure.Alternate = GPIO_AF14_LTDC;
HAL_GPIO_Init(GPIOA, &GPIO_InitStructure);
GPIO_InitStructure.Pin = GPIO_PIN_8 | \
GPIO_PIN_9 | GPIO_PIN_10 | GPIO_PIN_11;
HAL_GPIO_Init(GPIOB, &GPIO_InitStructure);
GPIO_InitStructure.Pin = GPIO_PIN_6 | GPIO_PIN_7 | GPIO_PIN_10;
HAL_GPIO_Init(GPIOC, &GPIO_InitStructure);
GPIO_InitStructure.Pin = GPIO_PIN_3 | GPIO_PIN_6;
HAL_GPIO_Init(GPIOD, &GPIO_InitStructure);
GPIO_InitStructure.Pin = GPIO_PIN_10;
HAL_GPIO_Init(GPIOF, &GPIO_InitStructure);
GPIO_InitStructure.Pin = GPIO_PIN_6 | GPIO_PIN_7 | \
GPIO_PIN_11;
HAL_GPIO_Init(GPIOG, &GPIO_InitStructure);
GPIO_InitStructure.Pin = GPIO_PIN_0 | GPIO_PIN_1;
GPIO_InitStructure.Alternate = GPIO_AF9_LTDC;
HAL_GPIO_Init(GPIOB, &GPIO_InitStructure);
GPIO_InitStructure.Pin = GPIO_PIN_10 | GPIO_PIN_12;
HAL_GPIO_Init(GPIOG, &GPIO_InitStructure);
}{ ... }
/* ... */
/* ... */
void BSP_LCD_DrawPixel(uint16_t Xpos, uint16_t Ypos, uint32_t RGB_Code)
{
*(__IO uint32_t *)(LtdcHandler.LayerCfg[ActiveLayer].FBStartAdress + (4 * (Ypos * BSP_LCD_GetXSize() + Xpos))) = RGB_Code;
}{ ... }
/* ... */
static void DrawChar(uint16_t Xpos, uint16_t Ypos, const uint8_t *c)
{
uint32_t i = 0, j = 0;
uint16_t height, width;
uint8_t offset;
uint8_t *pchar;
uint32_t line = 0;
height = DrawProp[ActiveLayer].pFont->Height;
width = DrawProp[ActiveLayer].pFont->Width;
offset = 8 * ((width + 7) / 8) - width ;
for (i = 0; i < height; i++)
{
pchar = ((uint8_t *)c + (width + 7) / 8 * i);
switch (((width + 7) / 8))
{
case 1:
line = pchar[0];
break;
case 1:
case 2:
line = (pchar[0] << 8) | pchar[1];
break;
case 2:
case 3:
default:
line = (pchar[0] << 16) | (pchar[1] << 8) | pchar[2];
break;default
}switch (((width + 7) / 8)) { ... }
for (j = 0; j < width; j++)
{
if (line & (1 << (width - j + offset - 1)))
{
BSP_LCD_DrawPixel((Xpos + j), Ypos, DrawProp[ActiveLayer].TextColor);
}if (line & (1 << (width - j + offset - 1))) { ... }
else
{
BSP_LCD_DrawPixel((Xpos + j), Ypos, DrawProp[ActiveLayer].BackColor);
}else { ... }
}for (j = 0; j < width; j++) { ... }
Ypos++;
}for (i = 0; i < height; i++) { ... }
}{ ... }
/* ... */
static void FillBuffer(uint32_t LayerIndex, void *pDst, uint32_t xSize, uint32_t ySize, uint32_t OffLine,
uint32_t ColorIndex)
{
Dma2dHandler.Init.Mode = DMA2D_R2M;
Dma2dHandler.Init.ColorMode = DMA2D_ARGB8888;
Dma2dHandler.Init.OutputOffset = OffLine;
Dma2dHandler.Instance = DMA2D;
if (HAL_DMA2D_Init(&Dma2dHandler) == HAL_OK)
{
if (HAL_DMA2D_ConfigLayer(&Dma2dHandler, LayerIndex) == HAL_OK)
{
if (HAL_DMA2D_Start(&Dma2dHandler, ColorIndex, (uint32_t)pDst, xSize, ySize) == HAL_OK)
{
HAL_DMA2D_PollForTransfer(&Dma2dHandler, 10);
}if (HAL_DMA2D_Start(&Dma2dHandler, ColorIndex, (uint32_t)pDst, xSize, ySize) == HAL_OK) { ... }
}if (HAL_DMA2D_ConfigLayer(&Dma2dHandler, LayerIndex) == HAL_OK) { ... }
}if (HAL_DMA2D_Init(&Dma2dHandler) == HAL_OK) { ... }
}{ ... }
/* ... */
static void ConvertLineToARGB8888(void *pSrc, void *pDst, uint32_t xSize, uint32_t ColorMode)
{
Dma2dHandler.Init.Mode = DMA2D_M2M_PFC;
Dma2dHandler.Init.ColorMode = DMA2D_ARGB8888;
Dma2dHandler.Init.OutputOffset = 0;
Dma2dHandler.LayerCfg[1].AlphaMode = DMA2D_NO_MODIF_ALPHA;
Dma2dHandler.LayerCfg[1].InputAlpha = 0xFF;
Dma2dHandler.LayerCfg[1].InputColorMode = ColorMode;
Dma2dHandler.LayerCfg[1].InputOffset = 0;
Dma2dHandler.Instance = DMA2D;
if (HAL_DMA2D_Init(&Dma2dHandler) == HAL_OK)
{
if (HAL_DMA2D_ConfigLayer(&Dma2dHandler, 1) == HAL_OK)
{
if (HAL_DMA2D_Start(&Dma2dHandler, (uint32_t)pSrc, (uint32_t)pDst, xSize, 1) == HAL_OK)
{
HAL_DMA2D_PollForTransfer(&Dma2dHandler, 10);
}if (HAL_DMA2D_Start(&Dma2dHandler, (uint32_t)pSrc, (uint32_t)pDst, xSize, 1) == HAL_OK) { ... }
}if (HAL_DMA2D_ConfigLayer(&Dma2dHandler, 1) == HAL_OK) { ... }
}if (HAL_DMA2D_Init(&Dma2dHandler) == HAL_OK) { ... }
}{ ... }
/* ... */
/* ... */
/* ... */
/* ... */