-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstm32l4r9i_eval_dsi_lcd.c
1931 lines (1688 loc) · 61.3 KB
/
stm32l4r9i_eval_dsi_lcd.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
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/**
******************************************************************************
* @file stm32l4r9i_eval_dsi_lcd.c
* @author MCD Application Team
* @brief This file includes the driver for DSI Liquid Crystal Display (LCD)
* module mounted on STM32L4R9I_EVAL evaluation board.
******************************************************************************
* @attention
*
* Copyright (c) 2017 STMicroelectronics.
* All rights reserved.
*
* This software is licensed under terms that can be found in the LICENSE file
* in the root directory of this software component.
* If no LICENSE file comes with this software, it is provided AS-IS.
*
******************************************************************************
*/
/* File Info: ------------------------------------------------------------------
User NOTES
1. How To use this driver:
--------------------------
- This driver is used to drive directly in command mode a LCD TFT using the
DSI interface.
The following IPs are implied : DSI Host IP block working
in conjunction to the LTDC controller.
- This driver is linked by construction to LCD.
2. Driver description:
----------------------
+ Initialization steps:
o Initialize the LCD using the BSP_DSI_LCD_Init() function.
Please note that LCD display will be turned on at the end of this function.
o De-inietialize the LCD using BSP_DSI_LCD_DeInit() function.
+ Options
o Modify in the fly the display properties using the following functions:
- BSP_DSI_LCD_SetTransparency().
- BSP_DSI_LCD_SetColorKeying().
- BSP_DSI_LCD_ResetColorKeying().
- BSP_DSI_LCD_SetFont().
- BSP_DSI_LCD_SetBackColor().
- BSP_DSI_LCD_SetTextColor().
- BSP_DSI_LCD_SetBrightness().
o You can set display on/off using following functions:
- BSP_DSI_LCD_DisplayOn().
- BSP_DSI_LCD_DisplayOff().
+ Display on LCD
o First, check that frame buffer is available using BSP_DSI_LCD_IsFrameBufferAvailable().
o When frame buffer is available, modify it using following functions:
- BSP_DSI_LCD_Clear().
- BSP_DSI_LCD_ClearStringLine().
- BSP_DSI_LCD_DisplayChar().
- BSP_DSI_LCD_DisplayStringAt().
- BSP_DSI_LCD_DisplayStringAtLine().
- BSP_DSI_LCD_DrawBitmap().
- BSP_DSI_LCD_DrawCircle().
- BSP_DSI_LCD_DrawEllipse().
- ....
o Call BSP_DSI_LCD_Refresh() to refresh LCD display.
------------------------------------------------------------------------------*/
/* Includes ------------------------------------------------------------------*/
#include "stm32l4r9i_eval_lcd.h"
#include "stm32l4r9i_eval_dsi_lcd.h"
#include "stm32l4r9i_eval_gfxmmu_lut.h"
#include "stm32l4r9i_eval_io.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"
/** @addtogroup BSP
* @{
*/
/** @addtogroup STM32L4R9I_EVAL
* @{
*/
/** @defgroup STM32L4R9I_EVAL_LCD STM32L4R9I_EVAL LCD
* @{
*/
/** @defgroup STM32L4R9I_EVAL_DSI_LCD STM32L4R9I_EVAL DSI LCD
* @{
*/
/** @defgroup STM32L4R9I_EVAL_DSI_LCD_Private_Macros Private Macros
* @{
*/
#define ABS(X) ((X) > 0 ? (X) : -(X))
#define POLY_X(Z) ((int32_t)((Points + (Z))->X))
#define POLY_Y(Z) ((int32_t)((Points + (Z))->Y))
/**
* @}
*/
/** @defgroup STM32L4R9I_EVAL_DSI_LCD_Exported_Variables Exported Variables
* @{
*/
/* DMA2D handle */
DMA2D_HandleTypeDef hdma2d_eval;
/**
* @}
*/
/** @defgroup STM32L4R9I_EVAL_DSI_LCD_Private_Variables Private Variables
* @{
*/
/* LCD initialization status */
static uint32_t bsp_lcd_initialized = 0;
/* Flag to indicate if HSE has to be disabled during de-initialization */
static uint32_t bsp_lcd_hse_to_disable = 0;
/* Default Active LTDC Layer in which drawing is made is LTDC Layer Background */
static uint32_t ActiveLayer = LTDC_ACTIVE_LAYER_BACKGROUND;
/* Current Drawing Layer properties variable */
static LCD_DrawPropTypeDef DrawProp[LTDC_MAX_LAYER_NUMBER];
/* Physical frame buffer for active layer */
/* 390*390 pixels with 32bpp - 20% */
#if defined ( __ICCARM__ ) /* IAR Compiler */
#pragma data_alignment = 16
uint32_t PhysFrameBuffer[121680];
#elif defined (__GNUC__) /* GNU Compiler */
uint32_t PhysFrameBuffer[121680] __attribute__ ((aligned (16)));
#else /* ARM Compiler */
__align(16) uint32_t PhysFrameBuffer[121680];
#endif
/* Global variable used to know if frame buffer is available (1) or not because refresh is on going (0) */
__IO uint32_t FrameBufferAvailable = 1;
/* LCD size */
uint32_t lcd_x_size = 390;
uint32_t lcd_y_size = 390;
/* GFXMMU, LTDC and DSI handles */
GFXMMU_HandleTypeDef hgfxmmu_eval;
LTDC_HandleTypeDef hltdc_eval;
DSI_HandleTypeDef hdsi_eval;
/**
* @}
*/
/** @defgroup STM32L4R9I_EVAL_DSI_LCD_Private_FunctionPrototypes Private FunctionPrototypes
* @{
*/
static void LCD_Reset(void);
static void DrawChar(uint16_t Xpos, uint16_t Ypos, const uint8_t *c);
static void FillTriangle(uint16_t x1, uint16_t x2, uint16_t x3, uint16_t y1, uint16_t y2, uint16_t y3);
static void LL_FillBuffer(uint32_t LayerIndex, void *pDst, uint32_t xSize, uint32_t ySize, uint32_t OffLine, uint32_t ColorIndex);
static void LL_ConvertLineToARGB8888(void * pSrc, void *pDst, uint32_t xSize, uint32_t ColorMode);
/**
* @}
*/
/** @defgroup STM32L4R9I_EVAL_DSI_LCD_Exported_Functions Exported Functions
* @{
*/
/**
* @brief Initialize the DSI LCD.
* The initialization is done as below:
* - GFXMMU initialization
* - DSI PLL initialization
* - DSI initialization
* - LTDC initialization
* - RM67162 LCD Display IC Driver initialization
* @retval LCD state
*/
uint8_t BSP_DSI_LCD_Init(void)
{
if(bsp_lcd_initialized == 0)
{
LTDC_LayerCfgTypeDef LayerCfg;
DSI_PLLInitTypeDef dsiPllInit;
DSI_PHY_TimerTypeDef PhyTimings;
DSI_HOST_TimeoutTypeDef HostTimeouts;
DSI_LPCmdTypeDef LPCmd;
DSI_CmdCfgTypeDef CmdCfg;
/* Toggle Hardware Reset of the DSI LCD using its XRES signal (active low) */
LCD_Reset();
/* Call first MSP Initialize
* This will set IP blocks LTDC, DSI and DMA2D
* - out of reset
* - clocked
* - NVIC IRQ related to IP blocks enabled
*/
BSP_DSI_LCD_MspInit();
/************************/
/* GFXMMU CONFIGURATION */
/************************/
hgfxmmu_eval.Instance = GFXMMU;
__HAL_GFXMMU_RESET_HANDLE_STATE(&hgfxmmu_eval);
hgfxmmu_eval.Init.BlocksPerLine = GFXMMU_192BLOCKS;
hgfxmmu_eval.Init.DefaultValue = 0xFFFFFFFF;
hgfxmmu_eval.Init.Buffers.Buf0Address = (uint32_t) PhysFrameBuffer;
hgfxmmu_eval.Init.Buffers.Buf1Address = 0; /* NU */
hgfxmmu_eval.Init.Buffers.Buf2Address = 0; /* NU */
hgfxmmu_eval.Init.Buffers.Buf3Address = 0; /* NU */
hgfxmmu_eval.Init.Interrupts.Activation = DISABLE;
hgfxmmu_eval.Init.Interrupts.UsedInterrupts = GFXMMU_AHB_MASTER_ERROR_IT; /* NU */
if(HAL_OK != HAL_GFXMMU_Init(&hgfxmmu_eval))
{
return(LCD_ERROR);
}
/* Initialize LUT */
if(HAL_OK != HAL_GFXMMU_ConfigLut(&hgfxmmu_eval, 0, 390, (uint32_t) gfxmmu_lut_config_argb8888))
{
return(LCD_ERROR);
}
/* Disable non visible lines : from line 390 to 1023 */
if(HAL_OK != HAL_GFXMMU_DisableLutLines(&hgfxmmu_eval, 390, 634))
{
return(LCD_ERROR);
}
/**********************/
/* LTDC CONFIGURATION */
/**********************/
/* LTDC initialization */
hltdc_eval.Instance = LTDC;
__HAL_LTDC_RESET_HANDLE_STATE(&hltdc_eval);
hltdc_eval.Init.HSPolarity = LTDC_HSPOLARITY_AL;
hltdc_eval.Init.VSPolarity = LTDC_VSPOLARITY_AL;
hltdc_eval.Init.DEPolarity = LTDC_DEPOLARITY_AL;
hltdc_eval.Init.PCPolarity = LTDC_PCPOLARITY_IPC;
hltdc_eval.Init.HorizontalSync = 0; /* HSYNC width - 1 */
hltdc_eval.Init.VerticalSync = 0; /* VSYNC width - 1 */
hltdc_eval.Init.AccumulatedHBP = 1; /* HSYNC width + HBP - 1 */
hltdc_eval.Init.AccumulatedVBP = 1; /* VSYNC width + VBP - 1 */
hltdc_eval.Init.AccumulatedActiveW = 391; /* HSYNC width + HBP + Active width - 1 */
hltdc_eval.Init.AccumulatedActiveH = 391; /* VSYNC width + VBP + Active height - 1 */
hltdc_eval.Init.TotalWidth = 392; /* HSYNC width + HBP + Active width + HFP - 1 */
hltdc_eval.Init.TotalHeigh = 392; /* VSYNC width + VBP + Active height + VFP - 1 */
hltdc_eval.Init.Backcolor.Red = 255;
hltdc_eval.Init.Backcolor.Green = 255;
hltdc_eval.Init.Backcolor.Blue = 0;
hltdc_eval.Init.Backcolor.Reserved = 0xFF;
if(HAL_LTDC_Init(&hltdc_eval) != HAL_OK)
{
return(LCD_ERROR);
}
/* LTDC layers configuration */
LayerCfg.WindowX0 = 0;
LayerCfg.WindowX1 = 390;
LayerCfg.WindowY0 = 0;
LayerCfg.WindowY1 = 390;
LayerCfg.PixelFormat = LTDC_PIXEL_FORMAT_ARGB8888;
LayerCfg.Alpha = 0xFF; /* NU default value */
LayerCfg.Alpha0 = 0; /* NU default value */
LayerCfg.BlendingFactor1 = LTDC_BLENDING_FACTOR1_PAxCA; /* NU default value */
LayerCfg.BlendingFactor2 = LTDC_BLENDING_FACTOR2_PAxCA; /* NU default value */
LayerCfg.FBStartAdress = GFXMMU_VIRTUAL_BUFFER0_BASE;
LayerCfg.ImageWidth = 768; /* virtual frame buffer contains 768 pixels per line for 32bpp */
LayerCfg.ImageHeight = 390;
LayerCfg.Backcolor.Red = 0; /* NU default value */
LayerCfg.Backcolor.Green = 0; /* NU default value */
LayerCfg.Backcolor.Blue = 0; /* NU default value */
LayerCfg.Backcolor.Reserved = 0xFF;
if(HAL_LTDC_ConfigLayer(&hltdc_eval, &LayerCfg, 0) != HAL_OK)
{
return(LCD_ERROR);
}
DrawProp[0].BackColor = LCD_COLOR_WHITE;
DrawProp[0].pFont = &Font24;
DrawProp[0].TextColor = LCD_COLOR_BLACK;
/*********************/
/* DSI CONFIGURATION */
/*********************/
/* DSI initialization */
hdsi_eval.Instance = DSI;
__HAL_DSI_RESET_HANDLE_STATE(&hdsi_eval);
hdsi_eval.Init.AutomaticClockLaneControl = DSI_AUTO_CLK_LANE_CTRL_DISABLE;
/* We have 1 data lane at 500Mbps => lane byte clock at 500/8 = 62,5 MHZ */
/* We want TX escape clock at around 20MHz and under 20MHz so clock division is set to 4 */
hdsi_eval.Init.TXEscapeCkdiv = 4;
hdsi_eval.Init.NumberOfLanes = DSI_ONE_DATA_LANE;
/* We have HSE value at 25MHz or 16MHz and we want data lane at 500Mbps */
dsiPllInit.PLLNDIV = (HSE_VALUE == 25000000) ? 100 : 125;
dsiPllInit.PLLIDF = (HSE_VALUE == 25000000) ? DSI_PLL_IN_DIV5 : DSI_PLL_IN_DIV4;
dsiPllInit.PLLODF = DSI_PLL_OUT_DIV1;
if(HAL_DSI_Init(&hdsi_eval, &dsiPllInit) != HAL_OK)
{
return(LCD_ERROR);
}
PhyTimings.ClockLaneHS2LPTime = 33; /* Tclk-post + Tclk-trail + Ths-exit = [(60ns + 52xUI) + (60ns) + (300ns)]/16ns */
PhyTimings.ClockLaneLP2HSTime = 30; /* Tlpx + (Tclk-prepare + Tclk-zero) + Tclk-pre = [150ns + 300ns + 8xUI]/16ns */
PhyTimings.DataLaneHS2LPTime = 11; /* Ths-trail + Ths-exit = [(60ns + 4xUI) + 100ns]/16ns */
PhyTimings.DataLaneLP2HSTime = 21; /* Tlpx + (Ths-prepare + Ths-zero) + Ths-sync = [150ns + (145ns + 10xUI) + 8xUI]/16ns */
PhyTimings.DataLaneMaxReadTime = 0;
PhyTimings.StopWaitTime = 7;
if(HAL_DSI_ConfigPhyTimer(&hdsi_eval, &PhyTimings) != HAL_OK)
{
return(LCD_ERROR);
}
HostTimeouts.TimeoutCkdiv = 1;
HostTimeouts.HighSpeedTransmissionTimeout = 0;
HostTimeouts.LowPowerReceptionTimeout = 0;
HostTimeouts.HighSpeedReadTimeout = 0;
HostTimeouts.LowPowerReadTimeout = 0;
HostTimeouts.HighSpeedWriteTimeout = 0;
HostTimeouts.HighSpeedWritePrespMode = 0;
HostTimeouts.LowPowerWriteTimeout = 0;
HostTimeouts.BTATimeout = 0;
if(HAL_DSI_ConfigHostTimeouts(&hdsi_eval, &HostTimeouts) != HAL_OK)
{
return(LCD_ERROR);
}
LPCmd.LPGenShortWriteNoP = DSI_LP_GSW0P_ENABLE;
LPCmd.LPGenShortWriteOneP = DSI_LP_GSW1P_ENABLE;
LPCmd.LPGenShortWriteTwoP = DSI_LP_GSW2P_ENABLE;
LPCmd.LPGenShortReadNoP = DSI_LP_GSR0P_ENABLE;
LPCmd.LPGenShortReadOneP = DSI_LP_GSR1P_ENABLE;
LPCmd.LPGenShortReadTwoP = DSI_LP_GSR2P_ENABLE;
LPCmd.LPGenLongWrite = DSI_LP_GLW_DISABLE;
LPCmd.LPDcsShortWriteNoP = DSI_LP_DSW0P_ENABLE;
LPCmd.LPDcsShortWriteOneP = DSI_LP_DSW1P_ENABLE;
LPCmd.LPDcsShortReadNoP = DSI_LP_DSR0P_ENABLE;
LPCmd.LPDcsLongWrite = DSI_LP_DLW_DISABLE;
LPCmd.LPMaxReadPacket = DSI_LP_MRDP_DISABLE;
LPCmd.AcknowledgeRequest = DSI_ACKNOWLEDGE_DISABLE;
if(HAL_DSI_ConfigCommand(&hdsi_eval, &LPCmd) != HAL_OK)
{
return(LCD_ERROR);
}
CmdCfg.VirtualChannelID = 0;
CmdCfg.ColorCoding = DSI_RGB888;
CmdCfg.CommandSize = 390;
CmdCfg.TearingEffectSource = DSI_TE_DSILINK;
CmdCfg.TearingEffectPolarity = DSI_TE_FALLING_EDGE;
CmdCfg.HSPolarity = DSI_HSYNC_ACTIVE_LOW;
CmdCfg.VSPolarity = DSI_VSYNC_ACTIVE_LOW;
CmdCfg.DEPolarity = DSI_DATA_ENABLE_ACTIVE_HIGH;
CmdCfg.VSyncPol = DSI_VSYNC_FALLING;
CmdCfg.AutomaticRefresh = DSI_AR_ENABLE;
CmdCfg.TEAcknowledgeRequest = DSI_TE_ACKNOWLEDGE_ENABLE;
if(HAL_DSI_ConfigAdaptedCommandMode(&hdsi_eval, &CmdCfg) != HAL_OK)
{
return(LCD_ERROR);
}
/* Disable the Tearing Effect interrupt activated by default on previous function */
__HAL_DSI_DISABLE_IT(&hdsi_eval, DSI_IT_TE);
if(HAL_DSI_ConfigFlowControl(&hdsi_eval, DSI_FLOW_CONTROL_BTA) != HAL_OK)
{
return(LCD_ERROR);
}
/* Enable DSI */
__HAL_DSI_ENABLE(&hdsi_eval);
/*************************/
/* LCD POWER ON SEQUENCE */
/*************************/
/* Step 1 */
/* Go to command 2 */
HAL_DSI_ShortWrite(&hdsi_eval, 0, DSI_DCS_SHORT_PKT_WRITE_P1, 0xFE, 0x01);
/* IC Frame rate control, set power, sw mapping, mux switch timing command */
HAL_DSI_ShortWrite(&hdsi_eval, 0, DSI_DCS_SHORT_PKT_WRITE_P1, 0x06, 0x62);
HAL_DSI_ShortWrite(&hdsi_eval, 0, DSI_DCS_SHORT_PKT_WRITE_P1, 0x0E, 0x80);
HAL_DSI_ShortWrite(&hdsi_eval, 0, DSI_DCS_SHORT_PKT_WRITE_P1, 0x0F, 0x80);
HAL_DSI_ShortWrite(&hdsi_eval, 0, DSI_DCS_SHORT_PKT_WRITE_P1, 0x10, 0x71);
HAL_DSI_ShortWrite(&hdsi_eval, 0, DSI_DCS_SHORT_PKT_WRITE_P1, 0x13, 0x81);
HAL_DSI_ShortWrite(&hdsi_eval, 0, DSI_DCS_SHORT_PKT_WRITE_P1, 0x14, 0x81);
HAL_DSI_ShortWrite(&hdsi_eval, 0, DSI_DCS_SHORT_PKT_WRITE_P1, 0x15, 0x82);
HAL_DSI_ShortWrite(&hdsi_eval, 0, DSI_DCS_SHORT_PKT_WRITE_P1, 0x16, 0x82);
HAL_DSI_ShortWrite(&hdsi_eval, 0, DSI_DCS_SHORT_PKT_WRITE_P1, 0x18, 0x88);
HAL_DSI_ShortWrite(&hdsi_eval, 0, DSI_DCS_SHORT_PKT_WRITE_P1, 0x19, 0x55);
HAL_DSI_ShortWrite(&hdsi_eval, 0, DSI_DCS_SHORT_PKT_WRITE_P1, 0x1A, 0x10);
HAL_DSI_ShortWrite(&hdsi_eval, 0, DSI_DCS_SHORT_PKT_WRITE_P1, 0x1C, 0x99);
HAL_DSI_ShortWrite(&hdsi_eval, 0, DSI_DCS_SHORT_PKT_WRITE_P1, 0x1D, 0x03);
HAL_DSI_ShortWrite(&hdsi_eval, 0, DSI_DCS_SHORT_PKT_WRITE_P1, 0x1E, 0x03);
HAL_DSI_ShortWrite(&hdsi_eval, 0, DSI_DCS_SHORT_PKT_WRITE_P1, 0x1F, 0x03);
HAL_DSI_ShortWrite(&hdsi_eval, 0, DSI_DCS_SHORT_PKT_WRITE_P1, 0x20, 0x03);
HAL_DSI_ShortWrite(&hdsi_eval, 0, DSI_DCS_SHORT_PKT_WRITE_P1, 0x25, 0x03);
HAL_DSI_ShortWrite(&hdsi_eval, 0, DSI_DCS_SHORT_PKT_WRITE_P1, 0x26, 0x8D);
HAL_DSI_ShortWrite(&hdsi_eval, 0, DSI_DCS_SHORT_PKT_WRITE_P1, 0x2A, 0x03);
HAL_DSI_ShortWrite(&hdsi_eval, 0, DSI_DCS_SHORT_PKT_WRITE_P1, 0x2B, 0x8D);
HAL_DSI_ShortWrite(&hdsi_eval, 0, DSI_DCS_SHORT_PKT_WRITE_P1, 0x36, 0x00);
HAL_DSI_ShortWrite(&hdsi_eval, 0, DSI_DCS_SHORT_PKT_WRITE_P1, 0x37, 0x10);
HAL_DSI_ShortWrite(&hdsi_eval, 0, DSI_DCS_SHORT_PKT_WRITE_P1, 0x3A, 0x00);
HAL_DSI_ShortWrite(&hdsi_eval, 0, DSI_DCS_SHORT_PKT_WRITE_P1, 0x3B, 0x00);
HAL_DSI_ShortWrite(&hdsi_eval, 0, DSI_DCS_SHORT_PKT_WRITE_P1, 0x3D, 0x20);
HAL_DSI_ShortWrite(&hdsi_eval, 0, DSI_DCS_SHORT_PKT_WRITE_P1, 0x3F, 0x3A);
HAL_DSI_ShortWrite(&hdsi_eval, 0, DSI_DCS_SHORT_PKT_WRITE_P1, 0x40, 0x30);
HAL_DSI_ShortWrite(&hdsi_eval, 0, DSI_DCS_SHORT_PKT_WRITE_P1, 0x41, 0x1A);
HAL_DSI_ShortWrite(&hdsi_eval, 0, DSI_DCS_SHORT_PKT_WRITE_P1, 0x42, 0x33);
HAL_DSI_ShortWrite(&hdsi_eval, 0, DSI_DCS_SHORT_PKT_WRITE_P1, 0x43, 0x22);
HAL_DSI_ShortWrite(&hdsi_eval, 0, DSI_DCS_SHORT_PKT_WRITE_P1, 0x44, 0x11);
HAL_DSI_ShortWrite(&hdsi_eval, 0, DSI_DCS_SHORT_PKT_WRITE_P1, 0x45, 0x66);
HAL_DSI_ShortWrite(&hdsi_eval, 0, DSI_DCS_SHORT_PKT_WRITE_P1, 0x46, 0x55);
HAL_DSI_ShortWrite(&hdsi_eval, 0, DSI_DCS_SHORT_PKT_WRITE_P1, 0x47, 0x44);
HAL_DSI_ShortWrite(&hdsi_eval, 0, DSI_DCS_SHORT_PKT_WRITE_P1, 0x4C, 0x33);
HAL_DSI_ShortWrite(&hdsi_eval, 0, DSI_DCS_SHORT_PKT_WRITE_P1, 0x4D, 0x22);
HAL_DSI_ShortWrite(&hdsi_eval, 0, DSI_DCS_SHORT_PKT_WRITE_P1, 0x4E, 0x11);
HAL_DSI_ShortWrite(&hdsi_eval, 0, DSI_DCS_SHORT_PKT_WRITE_P1, 0x4F, 0x66);
HAL_DSI_ShortWrite(&hdsi_eval, 0, DSI_DCS_SHORT_PKT_WRITE_P1, 0x50, 0x55);
HAL_DSI_ShortWrite(&hdsi_eval, 0, DSI_DCS_SHORT_PKT_WRITE_P1, 0x51, 0x44);
HAL_DSI_ShortWrite(&hdsi_eval, 0, DSI_DCS_SHORT_PKT_WRITE_P1, 0x57, 0x33);
HAL_DSI_ShortWrite(&hdsi_eval, 0, DSI_DCS_SHORT_PKT_WRITE_P1, 0x6B, 0x1B);
HAL_DSI_ShortWrite(&hdsi_eval, 0, DSI_DCS_SHORT_PKT_WRITE_P1, 0x70, 0x55);
HAL_DSI_ShortWrite(&hdsi_eval, 0, DSI_DCS_SHORT_PKT_WRITE_P1, 0x74, 0x0C);
/* Go to command 3 */
HAL_DSI_ShortWrite(&hdsi_eval, 0, DSI_DCS_SHORT_PKT_WRITE_P1, 0xFE, 0x02);
/* Set the VGMP/VGSP coltage control */
HAL_DSI_ShortWrite(&hdsi_eval, 0, DSI_DCS_SHORT_PKT_WRITE_P1, 0x9B, 0x40);
HAL_DSI_ShortWrite(&hdsi_eval, 0, DSI_DCS_SHORT_PKT_WRITE_P1, 0x9C, 0x00);
HAL_DSI_ShortWrite(&hdsi_eval, 0, DSI_DCS_SHORT_PKT_WRITE_P1, 0x9D, 0x20);
/* Go to command 4 */
HAL_DSI_ShortWrite(&hdsi_eval, 0, DSI_DCS_SHORT_PKT_WRITE_P1, 0xFE, 0x03);
/* Set the VGMP/VGSP coltage control */
HAL_DSI_ShortWrite(&hdsi_eval, 0, DSI_DCS_SHORT_PKT_WRITE_P1, 0x9B, 0x40);
HAL_DSI_ShortWrite(&hdsi_eval, 0, DSI_DCS_SHORT_PKT_WRITE_P1, 0x9C, 0x00);
HAL_DSI_ShortWrite(&hdsi_eval, 0, DSI_DCS_SHORT_PKT_WRITE_P1, 0x9D, 0x20);
/* Go to command 5 */
HAL_DSI_ShortWrite(&hdsi_eval, 0, DSI_DCS_SHORT_PKT_WRITE_P1, 0xFE, 0x04);
/* VSR command */
HAL_DSI_ShortWrite(&hdsi_eval, 0, DSI_DCS_SHORT_PKT_WRITE_P1, 0x5D, 0x10);
/* VSR1 timing set */
HAL_DSI_ShortWrite(&hdsi_eval, 0, DSI_DCS_SHORT_PKT_WRITE_P1, 0x00, 0x8D);
HAL_DSI_ShortWrite(&hdsi_eval, 0, DSI_DCS_SHORT_PKT_WRITE_P1, 0x01, 0x00);
HAL_DSI_ShortWrite(&hdsi_eval, 0, DSI_DCS_SHORT_PKT_WRITE_P1, 0x02, 0x01);
HAL_DSI_ShortWrite(&hdsi_eval, 0, DSI_DCS_SHORT_PKT_WRITE_P1, 0x03, 0x01);
HAL_DSI_ShortWrite(&hdsi_eval, 0, DSI_DCS_SHORT_PKT_WRITE_P1, 0x04, 0x10);
HAL_DSI_ShortWrite(&hdsi_eval, 0, DSI_DCS_SHORT_PKT_WRITE_P1, 0x05, 0x01);
HAL_DSI_ShortWrite(&hdsi_eval, 0, DSI_DCS_SHORT_PKT_WRITE_P1, 0x06, 0xA7);
HAL_DSI_ShortWrite(&hdsi_eval, 0, DSI_DCS_SHORT_PKT_WRITE_P1, 0x07, 0x20);
HAL_DSI_ShortWrite(&hdsi_eval, 0, DSI_DCS_SHORT_PKT_WRITE_P1, 0x08, 0x00);
/* VSR2 timing set */
HAL_DSI_ShortWrite(&hdsi_eval, 0, DSI_DCS_SHORT_PKT_WRITE_P1, 0x09, 0xC2);
HAL_DSI_ShortWrite(&hdsi_eval, 0, DSI_DCS_SHORT_PKT_WRITE_P1, 0x0A, 0x00);
HAL_DSI_ShortWrite(&hdsi_eval, 0, DSI_DCS_SHORT_PKT_WRITE_P1, 0x0B, 0x02);
HAL_DSI_ShortWrite(&hdsi_eval, 0, DSI_DCS_SHORT_PKT_WRITE_P1, 0x0C, 0x01);
HAL_DSI_ShortWrite(&hdsi_eval, 0, DSI_DCS_SHORT_PKT_WRITE_P1, 0x0D, 0x40);
HAL_DSI_ShortWrite(&hdsi_eval, 0, DSI_DCS_SHORT_PKT_WRITE_P1, 0x0E, 0x06);
HAL_DSI_ShortWrite(&hdsi_eval, 0, DSI_DCS_SHORT_PKT_WRITE_P1, 0x0F, 0x01);
HAL_DSI_ShortWrite(&hdsi_eval, 0, DSI_DCS_SHORT_PKT_WRITE_P1, 0x10, 0xA7);
HAL_DSI_ShortWrite(&hdsi_eval, 0, DSI_DCS_SHORT_PKT_WRITE_P1, 0x11, 0x00);
/* VSR3 timing set */
HAL_DSI_ShortWrite(&hdsi_eval, 0, DSI_DCS_SHORT_PKT_WRITE_P1, 0x12, 0xC2);
HAL_DSI_ShortWrite(&hdsi_eval, 0, DSI_DCS_SHORT_PKT_WRITE_P1, 0x13, 0x00);
HAL_DSI_ShortWrite(&hdsi_eval, 0, DSI_DCS_SHORT_PKT_WRITE_P1, 0x14, 0x02);
HAL_DSI_ShortWrite(&hdsi_eval, 0, DSI_DCS_SHORT_PKT_WRITE_P1, 0x15, 0x01);
HAL_DSI_ShortWrite(&hdsi_eval, 0, DSI_DCS_SHORT_PKT_WRITE_P1, 0x16, 0x40);
HAL_DSI_ShortWrite(&hdsi_eval, 0, DSI_DCS_SHORT_PKT_WRITE_P1, 0x17, 0x07);
HAL_DSI_ShortWrite(&hdsi_eval, 0, DSI_DCS_SHORT_PKT_WRITE_P1, 0x18, 0x01);
HAL_DSI_ShortWrite(&hdsi_eval, 0, DSI_DCS_SHORT_PKT_WRITE_P1, 0x19, 0xA7);
HAL_DSI_ShortWrite(&hdsi_eval, 0, DSI_DCS_SHORT_PKT_WRITE_P1, 0x1A, 0x00);
/* VSR4 timing set */
HAL_DSI_ShortWrite(&hdsi_eval, 0, DSI_DCS_SHORT_PKT_WRITE_P1, 0x1B, 0x82);
HAL_DSI_ShortWrite(&hdsi_eval, 0, DSI_DCS_SHORT_PKT_WRITE_P1, 0x1C, 0x00);
HAL_DSI_ShortWrite(&hdsi_eval, 0, DSI_DCS_SHORT_PKT_WRITE_P1, 0x1D, 0xFF);
HAL_DSI_ShortWrite(&hdsi_eval, 0, DSI_DCS_SHORT_PKT_WRITE_P1, 0x1E, 0x05);
HAL_DSI_ShortWrite(&hdsi_eval, 0, DSI_DCS_SHORT_PKT_WRITE_P1, 0x1F, 0x60);
HAL_DSI_ShortWrite(&hdsi_eval, 0, DSI_DCS_SHORT_PKT_WRITE_P1, 0x20, 0x02);
HAL_DSI_ShortWrite(&hdsi_eval, 0, DSI_DCS_SHORT_PKT_WRITE_P1, 0x21, 0x01);
HAL_DSI_ShortWrite(&hdsi_eval, 0, DSI_DCS_SHORT_PKT_WRITE_P1, 0x22, 0x7C);
HAL_DSI_ShortWrite(&hdsi_eval, 0, DSI_DCS_SHORT_PKT_WRITE_P1, 0x23, 0x00);
/* VSR5 timing set */
HAL_DSI_ShortWrite(&hdsi_eval, 0, DSI_DCS_SHORT_PKT_WRITE_P1, 0x24, 0xC2);
HAL_DSI_ShortWrite(&hdsi_eval, 0, DSI_DCS_SHORT_PKT_WRITE_P1, 0x25, 0x00);
HAL_DSI_ShortWrite(&hdsi_eval, 0, DSI_DCS_SHORT_PKT_WRITE_P1, 0x26, 0x04);
HAL_DSI_ShortWrite(&hdsi_eval, 0, DSI_DCS_SHORT_PKT_WRITE_P1, 0x27, 0x02);
HAL_DSI_ShortWrite(&hdsi_eval, 0, DSI_DCS_SHORT_PKT_WRITE_P1, 0x28, 0x70);
HAL_DSI_ShortWrite(&hdsi_eval, 0, DSI_DCS_SHORT_PKT_WRITE_P1, 0x29, 0x05);
HAL_DSI_ShortWrite(&hdsi_eval, 0, DSI_DCS_SHORT_PKT_WRITE_P1, 0x2A, 0x74);
HAL_DSI_ShortWrite(&hdsi_eval, 0, DSI_DCS_SHORT_PKT_WRITE_P1, 0x2B, 0x8D);
HAL_DSI_ShortWrite(&hdsi_eval, 0, DSI_DCS_SHORT_PKT_WRITE_P1, 0x2D, 0x00);
/* VSR6 timing set */
HAL_DSI_ShortWrite(&hdsi_eval, 0, DSI_DCS_SHORT_PKT_WRITE_P1, 0x2F, 0xC2);
HAL_DSI_ShortWrite(&hdsi_eval, 0, DSI_DCS_SHORT_PKT_WRITE_P1, 0x30, 0x00);
HAL_DSI_ShortWrite(&hdsi_eval, 0, DSI_DCS_SHORT_PKT_WRITE_P1, 0x31, 0x04);
HAL_DSI_ShortWrite(&hdsi_eval, 0, DSI_DCS_SHORT_PKT_WRITE_P1, 0x32, 0x02);
HAL_DSI_ShortWrite(&hdsi_eval, 0, DSI_DCS_SHORT_PKT_WRITE_P1, 0x33, 0x70);
HAL_DSI_ShortWrite(&hdsi_eval, 0, DSI_DCS_SHORT_PKT_WRITE_P1, 0x34, 0x07);
HAL_DSI_ShortWrite(&hdsi_eval, 0, DSI_DCS_SHORT_PKT_WRITE_P1, 0x35, 0x74);
HAL_DSI_ShortWrite(&hdsi_eval, 0, DSI_DCS_SHORT_PKT_WRITE_P1, 0x36, 0x8D);
HAL_DSI_ShortWrite(&hdsi_eval, 0, DSI_DCS_SHORT_PKT_WRITE_P1, 0x37, 0x00);
/* VSR marping command */
HAL_DSI_ShortWrite(&hdsi_eval, 0, DSI_DCS_SHORT_PKT_WRITE_P1, 0x5E, 0x20);
HAL_DSI_ShortWrite(&hdsi_eval, 0, DSI_DCS_SHORT_PKT_WRITE_P1, 0x5F, 0x31);
HAL_DSI_ShortWrite(&hdsi_eval, 0, DSI_DCS_SHORT_PKT_WRITE_P1, 0x60, 0x54);
HAL_DSI_ShortWrite(&hdsi_eval, 0, DSI_DCS_SHORT_PKT_WRITE_P1, 0x61, 0x76);
HAL_DSI_ShortWrite(&hdsi_eval, 0, DSI_DCS_SHORT_PKT_WRITE_P1, 0x62, 0x98);
/* Go to command 6 */
HAL_DSI_ShortWrite(&hdsi_eval, 0, DSI_DCS_SHORT_PKT_WRITE_P1, 0xFE, 0x05);
/* Set the ELVSS voltage */
HAL_DSI_ShortWrite(&hdsi_eval, 0, DSI_DCS_SHORT_PKT_WRITE_P1, 0x05, 0x17);
HAL_DSI_ShortWrite(&hdsi_eval, 0, DSI_DCS_SHORT_PKT_WRITE_P1, 0x2A, 0x04);
HAL_DSI_ShortWrite(&hdsi_eval, 0, DSI_DCS_SHORT_PKT_WRITE_P1, 0x91, 0x00);
/* Go back in standard commands */
HAL_DSI_ShortWrite(&hdsi_eval, 0, DSI_DCS_SHORT_PKT_WRITE_P1, 0xFE, 0x00);
/* Set tear off */
HAL_DSI_ShortWrite(&hdsi_eval, 0, DSI_DCS_SHORT_PKT_WRITE_P1, DSI_SET_TEAR_OFF, 0x0);
/* Set DSI mode to internal timing added vs ORIGINAL for Command mode */
HAL_DSI_ShortWrite(&hdsi_eval, 0, DSI_DCS_SHORT_PKT_WRITE_P1, 0xC2, 0x0);
/* Set memory address MODIFIED vs ORIGINAL */
uint8_t InitParam1[4]= {0x00, 0x04, 0x01, 0x89}; // MODIF OFe: adjusted w/ real image
HAL_DSI_LongWrite(&hdsi_eval, 0, DSI_DCS_LONG_PKT_WRITE, 4, DSI_SET_COLUMN_ADDRESS, InitParam1);
uint8_t InitParam2[4]= {0x00, 0x00, 0x01, 0x85};
HAL_DSI_LongWrite(&hdsi_eval, 0, DSI_DCS_LONG_PKT_WRITE, 4, DSI_SET_PAGE_ADDRESS, InitParam2);
/* Sleep out */
HAL_DSI_ShortWrite(&hdsi_eval, 0, DSI_DCS_SHORT_PKT_WRITE_P0, DSI_EXIT_SLEEP_MODE, 0x0);
HAL_Delay(120);
/* Set display on */
if(HAL_DSI_ShortWrite(&hdsi_eval,
0,
DSI_DCS_SHORT_PKT_WRITE_P0,
DSI_SET_DISPLAY_ON,
0x0) != HAL_OK)
{
return(LCD_ERROR);
}
/* Enable DSI Wrapper */
__HAL_DSI_WRAPPER_ENABLE(&hdsi_eval);
/* Initialize the font */
BSP_DSI_LCD_SetFont(&LCD_DEFAULT_FONT);
bsp_lcd_initialized = 1;
}
return(LCD_OK);
}
/**
* @brief De-initialize the DSI LCD.
* @retval LCD state
*/
uint8_t BSP_DSI_LCD_DeInit(void)
{
if(bsp_lcd_initialized == 1)
{
/* Disable DSI wrapper */
__HAL_DSI_WRAPPER_DISABLE(&hdsi_eval);
/* Set display off */
if(HAL_DSI_ShortWrite(&hdsi_eval,
0,
DSI_DCS_SHORT_PKT_WRITE_P0,
DSI_SET_DISPLAY_OFF,
0x0) != HAL_OK)
{
return(LCD_ERROR);
}
/* Wait before entering in sleep mode */
HAL_Delay(2000);
/* Put LCD in sleep mode */
if(HAL_DSI_ShortWrite(&hdsi_eval,
0,
DSI_DCS_SHORT_PKT_WRITE_P0,
DSI_ENTER_SLEEP_MODE,
0x0) != HAL_OK)
{
return(LCD_ERROR);
}
HAL_Delay(120);
/* De-initialize DSI */
if(HAL_DSI_DeInit(&hdsi_eval) != HAL_OK)
{
return(LCD_ERROR);
}
/* De-initialize LTDC */
if(HAL_LTDC_DeInit(&hltdc_eval) != HAL_OK)
{
return(LCD_ERROR);
}
/* De-initialize GFXMMU */
if(HAL_GFXMMU_DeInit(&hgfxmmu_eval) != HAL_OK)
{
return(LCD_ERROR);
}
/* Call MSP de-initialize function */
BSP_DSI_LCD_MspDeInit();
bsp_lcd_initialized = 0;
}
return(LCD_OK);
}
/**
* @brief Gets the LCD X size.
* @retval Used LCD X size
*/
uint32_t BSP_DSI_LCD_GetXSize(void)
{
return (lcd_x_size);
}
/**
* @brief Gets the LCD Y size.
* @retval Used LCD Y size
*/
uint32_t BSP_DSI_LCD_GetYSize(void)
{
return (lcd_y_size);
}
/**
* @brief Selects the LCD Layer.
* @param LayerIndex: Layer foreground (1) or background (0)
* @note : Only background layer can be used.
* @retval LCD state
*/
uint8_t BSP_DSI_LCD_SelectLayer(uint32_t LayerIndex)
{
uint8_t status = LCD_OK;
if(LayerIndex == LTDC_ACTIVE_LAYER_BACKGROUND)
{
ActiveLayer = LayerIndex;
}
else
{
status = LCD_ERROR;
}
return(status);
}
/**
* @brief Sets an LCD Layer visible
* @param LayerIndex: Visible Layer
* @param State: New state of the specified layer
* This parameter can be one of the following values:
* @arg ENABLE
* @arg DISABLE
* @note : Only background layer can be used.
* @retval LCD state
*/
uint8_t BSP_DSI_LCD_SetLayerVisible(uint32_t LayerIndex, FunctionalState State)
{
uint8_t status = LCD_OK;
if(LayerIndex == LTDC_ACTIVE_LAYER_BACKGROUND)
{
if(State == ENABLE)
{
__HAL_LTDC_LAYER_ENABLE(&(hltdc_eval), LayerIndex);
}
else
{
__HAL_LTDC_LAYER_DISABLE(&(hltdc_eval), LayerIndex);
}
__HAL_LTDC_RELOAD_IMMEDIATE_CONFIG(&(hltdc_eval));
}
else
{
status = LCD_ERROR;
}
return(status);
}
/**
* @brief Configures the transparency.
* @param LayerIndex: Layer foreground or background.
* @param Transparency: Transparency
* This parameter must be a number between Min_Data = 0x00 and Max_Data = 0xFF
* @note : Only background layer can be used.
* @retval LCD state
*/
uint8_t BSP_DSI_LCD_SetTransparency(uint32_t LayerIndex, uint8_t Transparency)
{
uint8_t status = LCD_OK;
if(LayerIndex == LTDC_ACTIVE_LAYER_BACKGROUND)
{
HAL_LTDC_SetAlpha(&(hltdc_eval), Transparency, LayerIndex);
}
else
{
status = LCD_ERROR;
}
return(status);
}
/**
* @brief Configures and sets the color keying.
* @param LayerIndex: Layer foreground (1) or background (0)
* @param RGBValue: Color reference
* @note : Only background layer can be used.
* @retval LCD state
*/
uint8_t BSP_DSI_LCD_SetColorKeying(uint32_t LayerIndex, uint32_t RGBValue)
{
uint8_t status = LCD_OK;
if(LayerIndex == LTDC_ACTIVE_LAYER_BACKGROUND)
{
/* Configure and Enable the color Keying for LCD Layer */
HAL_LTDC_ConfigColorKeying(&(hltdc_eval), RGBValue, LayerIndex);
HAL_LTDC_EnableColorKeying(&(hltdc_eval), LayerIndex);
}
else
{
status = LCD_ERROR;
}
return(status);
}
/**
* @brief Disables the color keying.
* @param LayerIndex: Layer foreground (1) or background (0)
* @note : Only background layer can be used.
* @retval LCD state
*/
uint8_t BSP_DSI_LCD_ResetColorKeying(uint32_t LayerIndex)
{
uint8_t status = LCD_OK;
if(LayerIndex == LTDC_ACTIVE_LAYER_BACKGROUND)
{
/* Disable the color Keying for LCD Layer */
HAL_LTDC_DisableColorKeying(&(hltdc_eval), LayerIndex);
}
else
{
status = LCD_ERROR;
}
return(status);
}
/**
* @brief Sets the LCD text color.
* @param Color: Text color code ARGB8888
*/
void BSP_DSI_LCD_SetTextColor(uint32_t Color)
{
DrawProp[ActiveLayer].TextColor = Color;
}
/**
* @brief Gets the LCD text color.
* @retval Used text color.
*/
uint32_t BSP_DSI_LCD_GetTextColor(void)
{
return DrawProp[ActiveLayer].TextColor;
}
/**
* @brief Sets the LCD background color.
* @param Color: Layer background color code ARGB8888
*/
void BSP_DSI_LCD_SetBackColor(uint32_t Color)
{
DrawProp[ActiveLayer].BackColor = Color;
}
/**
* @brief Gets the LCD background color.
* @retval Used background color
*/
uint32_t BSP_DSI_LCD_GetBackColor(void)
{
return DrawProp[ActiveLayer].BackColor;
}
/**
* @brief Sets the LCD text font.
* @param fonts: Layer font to be used
*/
void BSP_DSI_LCD_SetFont(sFONT *fonts)
{
DrawProp[ActiveLayer].pFont = fonts;
}
/**
* @brief Gets the LCD text font.
* @retval Used layer font
*/
sFONT *BSP_DSI_LCD_GetFont(void)
{
return DrawProp[ActiveLayer].pFont;
}
/**
* @brief Reads an LCD pixel.
* @param Xpos: X position
* @param Ypos: Y position
* @retval ARGB8888 pixel color
*/
uint32_t BSP_DSI_LCD_ReadPixel(uint16_t Xpos, uint16_t Ypos)
{
uint32_t ret = 0;
/* Read value of corresponding pixel */
/* We have 768 pixels per line and 4 bytes per pixel so 3072 bytes per line */
ret = *(__IO uint32_t*) (hltdc_eval.LayerCfg[ActiveLayer].FBStartAdress + (4*(Ypos*768 + Xpos)));
/* Return pixel value */
return ret;
}
/**
* @brief Clears the whole currently active layer of LTDC.
* @param Color: Color of the background (in ARGB8888 format)
*/
void BSP_DSI_LCD_Clear(uint32_t Color)
{
/* Clear the LCD */
/* Offset line is 768 - 390 = 378 */
LL_FillBuffer(ActiveLayer, (uint32_t *)(hltdc_eval.LayerCfg[ActiveLayer].FBStartAdress), 390, 390, 378, Color);
}
/**
* @brief Clears the selected line in currently active layer.
* @param Line: Line to be cleared
*/
void BSP_DSI_LCD_ClearStringLine(uint32_t Line)
{
uint32_t color_backup = DrawProp[ActiveLayer].TextColor;
DrawProp[ActiveLayer].TextColor = DrawProp[ActiveLayer].BackColor;
/* Draw rectangle with background color */
BSP_DSI_LCD_FillRect(0, (Line * DrawProp[ActiveLayer].pFont->Height), 390, DrawProp[ActiveLayer].pFont->Height);
DrawProp[ActiveLayer].TextColor = color_backup;
BSP_DSI_LCD_SetTextColor(DrawProp[ActiveLayer].TextColor);
}
/**
* @brief Displays one character in currently active layer.
* @param Xpos: Start column address
* @param Ypos: Line where to display the character shape.
* @param Ascii: Character ascii code
* This parameter must be a number between Min_Data = 0x20 and Max_Data = 0x7E
*/
void BSP_DSI_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)]);
}
/**
* @brief Displays characters in currently active layer.
* @param Xpos: X position (in pixel)
* @param Ypos: Y position (in pixel)
* @param Text: Pointer to string to display on LCD
* @param Mode: Display mode
* This parameter can be one of the following values:
* @arg CENTER_MODE
* @arg RIGHT_MODE
* @arg LEFT_MODE
*/
void BSP_DSI_LCD_DisplayStringAt(uint16_t Xpos, uint16_t Ypos, uint8_t *Text, Text_AlignModeTypdef Mode)
{
uint16_t refcolumn = 1, i = 0;
uint32_t size = 0, xsize = 0;
uint8_t *ptr = Text;
/* Get the text size */
while (*ptr++) size ++ ;
/* Characters number per line */
xsize = (390/DrawProp[ActiveLayer].pFont->Width);
switch (Mode)
{
case CENTER_MODE:
{
refcolumn = Xpos + ((xsize - size)* DrawProp[ActiveLayer].pFont->Width) / 2;
break;
}
case LEFT_MODE:
{
refcolumn = Xpos;
break;
}
case RIGHT_MODE:
{
refcolumn = - Xpos + ((xsize - size)*DrawProp[ActiveLayer].pFont->Width);
break;
}
default:
{
refcolumn = Xpos;
break;
}
}
/* Check that the Start column is located in the screen */
if ((refcolumn < 1) || (refcolumn >= 0x8000))
{
refcolumn = 1;
}
/* Send the string character by character on LCD */
while ((*Text != 0) & (((390 - (i*DrawProp[ActiveLayer].pFont->Width)) & 0xFFFF) >= DrawProp[ActiveLayer].pFont->Width))
{
/* Display one character on LCD */
BSP_DSI_LCD_DisplayChar(refcolumn, Ypos, *Text);
/* Decrement the column position by 16 */
refcolumn += DrawProp[ActiveLayer].pFont->Width;
/* Point on the next character */
Text++;
i++;
}
}
/**
* @brief Displays string on specified line of the LCD.
* @param Line: Line where to display the character shape
* @param ptr: Pointer to string to display on LCD
*/
void BSP_DSI_LCD_DisplayStringAtLine(uint16_t Line, uint8_t *ptr)
{
BSP_DSI_LCD_DisplayStringAt(0, Line * (((sFONT *)BSP_DSI_LCD_GetFont())->Height), ptr, CENTER_MODE);
}
/**
* @brief Draws an horizontal line in currently active layer.
* @param Xpos: X position
* @param Ypos: Y position
* @param Length: Line length
*/
void BSP_DSI_LCD_DrawHLine(uint16_t Xpos, uint16_t Ypos, uint16_t Length)
{
uint32_t Xaddress = 0;
/* Get the line address */
Xaddress = (hltdc_eval.LayerCfg[ActiveLayer].FBStartAdress) + 4*(768*Ypos + Xpos);
/* Write line */
LL_FillBuffer(ActiveLayer, (uint32_t *)Xaddress, Length, 1, (768 - Length), DrawProp[ActiveLayer].TextColor);
}
/**
* @brief Draws a vertical line in currently active layer.
* @param Xpos: X position
* @param Ypos: Y position
* @param Length: Line length
*/
void BSP_DSI_LCD_DrawVLine(uint16_t Xpos, uint16_t Ypos, uint16_t Length)
{
uint32_t Xaddress = 0;
/* Get the line address */
Xaddress = (hltdc_eval.LayerCfg[ActiveLayer].FBStartAdress) + 4*(768*Ypos + Xpos);
/* Write line */
LL_FillBuffer(ActiveLayer, (uint32_t *)Xaddress, 1, Length, (768 - 1), DrawProp[ActiveLayer].TextColor);
}
/**
* @brief Draws an uni-line (between two points) in currently active layer.
* @param x1: Point 1 X position
* @param y1: Point 1 Y position
* @param x2: Point 2 X position
* @param y2: Point 2 Y position
*/
void BSP_DSI_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); /* The difference between the x's */