-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathstm32f769i_discovery_lcd.c
2036 lines (1744 loc) · 62.2 KB
/
stm32f769i_discovery_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 stm32f769i_discovery_lcd.c
* @author MCD Application Team
* @brief This file includes the driver for Liquid Crystal Display (LCD) module
* mounted on STM32F769I-DISCOVERY board.
******************************************************************************
* @attention
*
* Copyright (c) 2016 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 video 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 KoD mounted on board MB1166.
2. Driver description:
---------------------
+ Initialization steps:
o Initialize the LCD using the BSP_LCD_Init() function.
o Select the LCD layer to be used using the BSP_LCD_SelectLayer() function.
o Enable the LCD display using the BSP_LCD_DisplayOn() function.
+ Options
o Configure and enable the color keying functionality using the
BSP_LCD_SetColorKeying() function.
o Modify in the fly the transparency and/or the frame buffer address
using the following functions:
- BSP_LCD_SetTransparency()
- BSP_LCD_SetLayerAddress()
+ Display on LCD
o Clear the whole LCD using BSP_LCD_Clear() function or only one specified string
line using the BSP_LCD_ClearStringLine() function.
o Display a character on the specified line and column using the BSP_LCD_DisplayChar()
function or a complete string line using the BSP_LCD_DisplayStringAtLine() function.
o Display a string line on the specified position (x,y in pixel) and align mode
using the BSP_LCD_DisplayStringAtLine() function.
o Draw and fill a basic shapes (dot, line, rectangle, circle, ellipse, .. bitmap)
on LCD using the available set of functions.
------------------------------------------------------------------------------*/
/* Dependencies
- stm32f769i_discovery.c
- stm32f769i_discovery_sdram.c
- stm32f7xx_hal_dsi.c
- stm32f7xx_hal_ltdc.c
- stm32f7xx_hal_ltdc_ex.c
- stm32f7xx_hal_dma2d.c
- stm32f7xx_hal_rcc_ex.c
- stm32f7xx_hal_gpio.c
- stm32f7xx_hal_cortex.c
- otm8009a.c
- adv7533.c
- fonts.h
- font24.c
- font20.c
- font16.c
- font12.c
- font8.c"
EndDependencies */
/* Includes ------------------------------------------------------------------*/
#include "stm32f769i_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"
/** @addtogroup BSP
* @{
*/
/** @addtogroup STM32F769I_DISCOVERY
* @{
*/
/** @defgroup STM32F769I_DISCOVERY_LCD STM32F769I_DISCOVERY LCD
* @{
*/
/** @defgroup STM32F769I_DISCOVERY_LCD_Private_Defines LCD Private Defines
* @{
*/
#if defined(USE_LCD_HDMI)
#define HDMI_ASPECT_RATIO_16_9 ADV7533_ASPECT_RATIO_16_9
#define HDMI_ASPECT_RATIO_4_3 ADV7533_ASPECT_RATIO_4_3
#endif /* USE_LCD_HDMI */
#define LCD_DSI_ID 0x11
#define LCD_DSI_ID_REG 0xA8
static DSI_VidCfgTypeDef hdsivideo_handle;
/**
* @}
*/
/** @defgroup STM32F769I_DISCOVERY_LCD_Private_TypesDefinitions LCD Private TypesDefinitions
* @{
*/
#if defined(USE_LCD_HDMI)
/**
* @brief DSI timming params used for different HDMI adpater
*/
typedef struct
{
uint16_t HACT;
uint16_t HSYNC;
uint16_t HBP;
uint16_t HFP;
uint16_t VACT;
uint16_t VSYNC;
uint16_t VBP;
uint16_t VFP;
uint8_t ASPECT_RATIO;
uint8_t RGB_CODING;
} HDMI_FormatTypeDef;
/**
* @brief DSI packet params used for different HDMI adpater
*/
typedef struct
{
uint16_t NullPacketSize;
uint16_t NumberOfChunks;
uint16_t PacketSize;
} HDMI_DSIPacketTypeDef;
/**
* @brief LTDC PLL params used for different HDMI adpater
*/
typedef struct
{
uint16_t PLLSAIN;
uint16_t PLLSAIR;
uint32_t PCLK;
uint16_t IDF;
uint16_t NDIV;
uint16_t ODF;
uint16_t LaneByteClock;
uint16_t TXEscapeCkdiv;
} HDMI_PLLConfigTypeDef;
#endif /* USE_LCD_HDMI */
/**
* @}
*/
/** @defgroup STM32F769I_DISCOVERY_LCD_Private_Macros LCD 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 STM32F769I_DISCOVERY_LCD_Private_Types_Definitions Private Types Definitions
* @{
*/
typedef enum
{
LCD_CTRL_NT35510,
LCD_CTRL_OTM8009A,
LCD_CTRL_NONE
} LCD_Driver_t;
/** @defgroup STM32F769I_DISCOVERY_LCD_Exported_Variables STM32F769I DISCOVERY LCD Exported Variables
* @{
*/
DMA2D_HandleTypeDef hdma2d_discovery;
LTDC_HandleTypeDef hltdc_discovery;
DSI_HandleTypeDef hdsi_discovery;
uint32_t lcd_x_size = OTM8009A_800X480_WIDTH;
uint32_t lcd_y_size = OTM8009A_800X480_HEIGHT;
LCD_Driver_t Lcd_Driver_Type = LCD_CTRL_NT35510;
/**
* @}
*/
/** @defgroup STM32F769I_DISCOVERY_LCD_Private_Variables LCD Private Variables
* @{
*/
#if defined(USE_LCD_HDMI)
/**
* @brief DSI timming used for different HDMI resolution (720x480 and 720x576)
*/
HDMI_FormatTypeDef HDMI_Format[2] =
{
/* HA HS HB HF VA VS VB VF ASPECT BPP */
{720, 62, 60, 30, 480, 6, 19, 9, HDMI_ASPECT_RATIO_4_3, LCD_DSI_PIXEL_DATA_FMT_RBG888},
{720, 64, 68, 12, 576, 5, 39, 5, HDMI_ASPECT_RATIO_16_9, LCD_DSI_PIXEL_DATA_FMT_RBG888}
};
/**
* @brief DSI packet size used for different HDMI resolution (720x480 and 720x576)
*/
HDMI_DSIPacketTypeDef HDMI_DSIPacket[2] =
{
/* NP NC VP */
{0, 1, 720},
{0, 1, 720}
};
/**
* @brief LTDC PLL settings used for different HDMI resolution (720x480 and 720x576)
*/
HDMI_PLLConfigTypeDef HDMI_PLLConfig[4] =
{
/* N DIV Pclk IDF NDIV ODF LBClk TXEscapeCkdiv*/
{325, 6, 27083, DSI_PLL_IN_DIV5, 65, DSI_PLL_OUT_DIV1, 40625, 3},
{325, 6, 27083, DSI_PLL_IN_DIV5, 65, DSI_PLL_OUT_DIV1, 40625, 3}
};
#endif /* USE_LCD_HDMI */
/**
* @brief Default Active LTDC Layer in which drawing is made is LTDC Layer Background
*/
static uint32_t ActiveLayer = LTDC_ACTIVE_LAYER_BACKGROUND;
/**
* @brief Current Drawing Layer properties variable
*/
static LCD_DrawPropTypeDef DrawProp[LTDC_MAX_LAYER_NUMBER];
/**
* @}
*/
/** @defgroup STM32F769I_DISCOVERY_LCD_Private_FunctionPrototypes LCD Private FunctionPrototypes
* @{
*/
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);
static uint16_t LCD_IO_GetID(void);
static LCD_Driver_t Driver_Type(LCD_Driver_t Lcd_type);
/**
* @}
*/
/** @defgroup STM32F769I_DISCOVERY_LCD_Exported_Functions LCD Exported Functions
* @{
*/
/**
* @brief Initializes the DSI LCD.
* @retval LCD state
*/
uint8_t BSP_LCD_Init(void)
{
return (BSP_LCD_InitEx(LCD_ORIENTATION_LANDSCAPE));
}
/**
* @brief Initializes the DSI LCD.
* The ititialization is done as below:
* - DSI PLL ititialization
* - DSI ititialization
* - LTDC ititialization
* - OTM8009A LCD Display IC Driver ititialization
* @param orientation: LCD orientation, can be LCD_ORIENTATION_PORTRAIT or LCD_ORIENTATION_LANDSCAPE
* @retval LCD state
*/
uint8_t BSP_LCD_InitEx(LCD_OrientationTypeDef orientation)
{
DSI_PLLInitTypeDef dsiPllInit;
static RCC_PeriphCLKInitTypeDef PeriphClkInitStruct;
uint32_t LcdClock = 27429; /*!< LcdClk = 27429 kHz */
uint16_t read_id = 0;
uint32_t laneByteClk_kHz = 0;
uint32_t VSA; /*!< Vertical start active time in units of lines */
uint32_t VBP; /*!< Vertical Back Porch time in units of lines */
uint32_t VFP; /*!< Vertical Front Porch time in units of lines */
uint32_t VACT; /*!< Vertical Active time in units of lines = imageSize Y in pixels to display */
uint32_t HSA; /*!< Horizontal start active time in units of lcdClk */
uint32_t HBP; /*!< Horizontal Back Porch time in units of lcdClk */
uint32_t HFP; /*!< Horizontal Front Porch time in units of lcdClk */
uint32_t HACT; /*!< Horizontal Active time in units of lcdClk = imageSize X in pixels to display */
/* Toggle Hardware Reset of the DSI LCD using
* its XRES signal (active low) */
BSP_LCD_Reset();
/* Check the connected monitor */
read_id = LCD_IO_GetID();
#if defined(USE_LCD_HDMI)
if(read_id == ADV7533_ID)
{
return BSP_LCD_HDMIInitEx(HDMI_FORMAT_720_576);
}
else if(read_id != LCD_DSI_ID)
{
return LCD_ERROR;
}
#else
if(read_id != LCD_DSI_ID)
{
return LCD_ERROR;
}
#endif /* USE_LCD_HDMI */
/* Call first MSP Initialize only in case of first initialization
* This will set IP blocks LTDC, DSI and DMA2D
* - out of reset
* - clocked
* - NVIC IRQ related to IP blocks enabled
*/
BSP_LCD_MspInit();
/*************************DSI Initialization***********************************/
/* Base address of DSI Host/Wrapper registers to be set before calling De-Init */
hdsi_discovery.Instance = DSI;
HAL_DSI_DeInit(&(hdsi_discovery));
dsiPllInit.PLLNDIV = 100;
dsiPllInit.PLLIDF = DSI_PLL_IN_DIV5;
dsiPllInit.PLLODF = DSI_PLL_OUT_DIV1;
laneByteClk_kHz = 62500; /* 500 MHz / 8 = 62.5 MHz = 62500 kHz */
/* Set number of Lanes */
hdsi_discovery.Init.NumberOfLanes = DSI_TWO_DATA_LANES;
/* TXEscapeCkdiv = f(LaneByteClk)/15.62 = 4 */
hdsi_discovery.Init.TXEscapeCkdiv = laneByteClk_kHz/15620;
HAL_DSI_Init(&(hdsi_discovery), &(dsiPllInit));
/* Enable the DSI module */
HAL_DSI_Start(&(hdsi_discovery));
/* Enable the DSI BTW for read operations */
HAL_DSI_ConfigFlowControl(&(hdsi_discovery), DSI_FLOW_CONTROL_BTA);
/* Initialize the font */
BSP_LCD_SetFont(&LCD_DEFAULT_FONT);
Lcd_Driver_Type = Driver_Type(Lcd_Driver_Type);
/* Stop the DSI module */
HAL_DSI_Stop(&(hdsi_discovery));
/* Timing parameters for all Video modes
* Set Timing parameters of LTDC depending on its chosen orientation
*/
if(orientation == LCD_ORIENTATION_PORTRAIT)
{
lcd_x_size = OTM8009A_480X800_WIDTH; /* 480 */
lcd_y_size = OTM8009A_480X800_HEIGHT; /* 800 */
}
else
{
/* lcd_orientation == LCD_ORIENTATION_LANDSCAPE */
lcd_x_size = OTM8009A_800X480_WIDTH; /* 800 */
lcd_y_size = OTM8009A_800X480_HEIGHT; /* 480 */
}
HACT = lcd_x_size;
VACT = lcd_y_size;
/* The following values are same for portrait and landscape orientations */
if(Lcd_Driver_Type == LCD_CTRL_OTM8009A)
{
VSA = OTM8009A_480X800_VSYNC;
VBP = OTM8009A_480X800_VBP;
VFP = OTM8009A_480X800_VFP;
HSA = OTM8009A_480X800_HSYNC;
HBP = OTM8009A_480X800_HBP;
HFP = OTM8009A_480X800_HFP;
}
else
{
VSA = NT35510_480X800_VSYNC;
VBP = NT35510_480X800_VBP;
VFP = NT35510_480X800_VFP;
HSA = NT35510_480X800_HSYNC;
HBP = NT35510_480X800_HBP;
HFP = NT35510_480X800_HFP;
}
hdsivideo_handle.VirtualChannelID = LCD_Driver_ID;
hdsivideo_handle.ColorCoding = LCD_DSI_PIXEL_DATA_FMT_RBG888;
hdsivideo_handle.VSPolarity = DSI_VSYNC_ACTIVE_HIGH;
hdsivideo_handle.HSPolarity = DSI_HSYNC_ACTIVE_HIGH;
hdsivideo_handle.DEPolarity = DSI_DATA_ENABLE_ACTIVE_HIGH;
hdsivideo_handle.Mode = DSI_VID_MODE_BURST; /* Mode Video burst ie : one LgP per line */
hdsivideo_handle.NullPacketSize = 0xFFF;
hdsivideo_handle.NumberOfChunks = 0;
hdsivideo_handle.PacketSize = HACT; /* Value depending on display orientation choice portrait/landscape */
hdsivideo_handle.HorizontalSyncActive = (HSA * laneByteClk_kHz)/LcdClock;
hdsivideo_handle.HorizontalBackPorch = (HBP * laneByteClk_kHz)/LcdClock;
hdsivideo_handle.HorizontalLine = ((HACT + HSA + HBP + HFP) * laneByteClk_kHz)/LcdClock; /* Value depending on display orientation choice portrait/landscape */
hdsivideo_handle.VerticalSyncActive = VSA;
hdsivideo_handle.VerticalBackPorch = VBP;
hdsivideo_handle.VerticalFrontPorch = VFP;
hdsivideo_handle.VerticalActive = VACT; /* Value depending on display orientation choice portrait/landscape */
/* Enable or disable sending LP command while streaming is active in video mode */
hdsivideo_handle.LPCommandEnable = DSI_LP_COMMAND_ENABLE; /* Enable sending commands in mode LP (Low Power) */
/* Largest packet size possible to transmit in LP mode in VSA, VBP, VFP regions */
/* Only useful when sending LP packets is allowed while streaming is active in video mode */
hdsivideo_handle.LPLargestPacketSize = 16;
/* Largest packet size possible to transmit in LP mode in HFP region during VACT period */
/* Only useful when sending LP packets is allowed while streaming is active in video mode */
hdsivideo_handle.LPVACTLargestPacketSize = 0;
/* Specify for each region of the video frame, if the transmission of command in LP mode is allowed in this region */
/* while streaming is active in video mode */
hdsivideo_handle.LPHorizontalFrontPorchEnable = DSI_LP_HFP_ENABLE; /* Allow sending LP commands during HFP period */
hdsivideo_handle.LPHorizontalBackPorchEnable = DSI_LP_HBP_ENABLE; /* Allow sending LP commands during HBP period */
hdsivideo_handle.LPVerticalActiveEnable = DSI_LP_VACT_ENABLE; /* Allow sending LP commands during VACT period */
hdsivideo_handle.LPVerticalFrontPorchEnable = DSI_LP_VFP_ENABLE; /* Allow sending LP commands during VFP period */
hdsivideo_handle.LPVerticalBackPorchEnable = DSI_LP_VBP_ENABLE; /* Allow sending LP commands during VBP period */
hdsivideo_handle.LPVerticalSyncActiveEnable = DSI_LP_VSYNC_ENABLE; /* Allow sending LP commands during VSync = VSA period */
/* Configure DSI Video mode timings with settings set above */
HAL_DSI_ConfigVideoMode(&(hdsi_discovery), &(hdsivideo_handle));
/*************************End DSI Initialization*******************************/
/************************LTDC Initialization***********************************/
/* Timing Configuration */
hltdc_discovery.Init.HorizontalSync = (HSA - 1);
hltdc_discovery.Init.AccumulatedHBP = (HSA + HBP - 1);
hltdc_discovery.Init.AccumulatedActiveW = (lcd_x_size + HSA + HBP - 1);
hltdc_discovery.Init.TotalWidth = (lcd_x_size + HSA + HBP + HFP - 1);
/* Initialize the LCD pixel width and pixel height */
hltdc_discovery.LayerCfg->ImageWidth = lcd_x_size;
hltdc_discovery.LayerCfg->ImageHeight = lcd_y_size;
/** LCD clock configuration
* Note: The following values should not be changed as the PLLSAI is also used
* to clock the USB FS
* PLLSAI_VCO Input = HSE_VALUE/PLL_M = 1 Mhz
* PLLSAI_VCO Output = PLLSAI_VCO Input * PLLSAIN = 384 Mhz
* PLLLCDCLK = PLLSAI_VCO Output/PLLSAIR = 384 MHz / 7 = 54.85 MHz
* LTDC clock frequency = PLLLCDCLK / LTDC_PLLSAI_DIVR_2 = 54.85 MHz / 2 = 27.429 MHz
*/
PeriphClkInitStruct.PeriphClockSelection = RCC_PERIPHCLK_LTDC;
PeriphClkInitStruct.PLLSAI.PLLSAIN = 384;
PeriphClkInitStruct.PLLSAI.PLLSAIR = 7;
PeriphClkInitStruct.PLLSAIDivR = RCC_PLLSAIDIVR_2;
HAL_RCCEx_PeriphCLKConfig(&PeriphClkInitStruct);
/* Background value */
hltdc_discovery.Init.Backcolor.Blue = 0;
hltdc_discovery.Init.Backcolor.Green = 0;
hltdc_discovery.Init.Backcolor.Red = 0;
hltdc_discovery.Init.PCPolarity = LTDC_PCPOLARITY_IPC;
hltdc_discovery.Instance = LTDC;
/* Get LTDC Configuration from DSI Configuration */
HAL_LTDC_StructInitFromVideoConfig(&(hltdc_discovery), &(hdsivideo_handle));
/* Initialize the LTDC */
HAL_LTDC_Init(&hltdc_discovery);
/* Enable the DSI host and wrapper after the LTDC initialization
To avoid any synchronization issue, the DSI shall be started after enabling the LTDC */
HAL_DSI_Start(&hdsi_discovery);
#if !defined(DATA_IN_ExtSDRAM)
/* Initialize the SDRAM */
BSP_SDRAM_Init();
#endif /* DATA_IN_ExtSDRAM */
/* Initialize the font */
BSP_LCD_SetFont(&LCD_DEFAULT_FONT);
/************************End LTDC Initialization*******************************/
if(Lcd_Driver_Type==LCD_CTRL_NT35510 )
{
/***********************NT35510 Initialization********************************/
/* Initialize the NT35510 LCD Display IC Driver (TechShine LCD IC Driver)
* depending on configuration set in 'hdsivideo_handle'.
*/
NT35510_Init(NT35510_FORMAT_RGB888, orientation);
}
/***********************End NT35510 Initialization****************************/
else
{
/***********************OTM8009A Initialization********************************/
/* Initialize the OTM8009A LCD Display IC Driver (KoD LCD IC Driver)
* depending on configuration set in 'hdsivideo_handle'.
*/
OTM8009A_Init(OTM8009A_FORMAT_RGB888, orientation);
/***********************End OTM8009A Initialization****************************/
}
return LCD_OK;
}
#if defined(USE_LCD_HDMI)
/**
* @brief Initializes the DSI for HDMI monitor.
* The ititialization is done as below:
* - DSI PLL ititialization
* - DSI ititialization
* - LTDC ititialization
* - DSI-HDMI ADV7533 adapter device ititialization
* @param format : HDMI format could be HDMI_FORMAT_720_480 or HDMI_FORMAT_720_576
* @retval LCD state
*/
uint8_t BSP_LCD_HDMIInitEx(uint8_t format)
{
/************************ADV7533 Initialization********************************/
/* Initialize the ADV7533 HDMI Bridge
* depending on configuration set in 'hdsivideo_handle'.
*/
adv7533ConfigTypeDef adv7533_config;
adv7533_config.DSI_LANES = 2;
adv7533_config.HACT = HDMI_Format[format].HACT;
adv7533_config.HSYNC = HDMI_Format[format].HSYNC;
adv7533_config.HBP = HDMI_Format[format].HBP;
adv7533_config.HFP = HDMI_Format[format].HFP;
adv7533_config.VACT = HDMI_Format[format].VACT;
adv7533_config.VSYNC = HDMI_Format[format].VSYNC;
adv7533_config.VBP = HDMI_Format[format].VBP;
adv7533_config.VFP = HDMI_Format[format].VFP;
ADV7533_Init();
ADV7533_Configure(&adv7533_config);
ADV7533_PowerOn();
/************************ Update hdmi_x_size and hdmi_y_size *****************/
lcd_x_size = HDMI_Format[format].HACT;
lcd_y_size = HDMI_Format[format].VACT;
/***********************End ADV7533 Initialization****************************/
DSI_PLLInitTypeDef dsiPllInit;
DSI_PHY_TimerTypeDef dsiPhyInit;
static RCC_PeriphCLKInitTypeDef PeriphClkInitStruct;
/* Call first MSP Initialize only in case of first initialization
* This will set IP blocks LTDC and DSI
* - out of reset
* - clocked
* - NVIC IRQ related to IP blocks enabled
*/
BSP_LCD_MspInit();
/*************************DSI Initialization***********************************/
/* Base address of DSI Host/Wrapper registers to be set before calling De-Init */
hdsi_discovery.Instance = DSI;
HAL_DSI_DeInit(&(hdsi_discovery));
/* Configure the DSI PLL */
dsiPllInit.PLLNDIV = HDMI_PLLConfig[format].NDIV;
dsiPllInit.PLLIDF = HDMI_PLLConfig[format].IDF;
dsiPllInit.PLLODF = HDMI_PLLConfig[format].ODF;
/* Set number of Lanes */
hdsi_discovery.Init.NumberOfLanes = DSI_TWO_DATA_LANES;
/* Set the TX escape clock division ratio */
hdsi_discovery.Init.TXEscapeCkdiv = HDMI_PLLConfig[format].TXEscapeCkdiv;
/* Disable the automatic clock lane control (the ADV7533 must be clocked) */
hdsi_discovery.Init.AutomaticClockLaneControl = DSI_AUTO_CLK_LANE_CTRL_DISABLE;
/* Init the DSI */
HAL_DSI_Init(&hdsi_discovery, &dsiPllInit);
/* Configure the D-PHY Timings */
dsiPhyInit.ClockLaneHS2LPTime = 0x14;
dsiPhyInit.ClockLaneLP2HSTime = 0x14;
dsiPhyInit.DataLaneHS2LPTime = 0x0A;
dsiPhyInit.DataLaneLP2HSTime = 0x0A;
dsiPhyInit.DataLaneMaxReadTime = 0x00;
dsiPhyInit.StopWaitTime = 0x0;
HAL_DSI_ConfigPhyTimer(&hdsi_discovery, &dsiPhyInit);
/* Virutal channel used by the ADV7533 */
hdsivideo_handle.VirtualChannelID = HDMI_ADV7533_ID;
/* Timing parameters for Video modes
Set Timing parameters of DSI depending on its chosen format */
hdsivideo_handle.ColorCoding = HDMI_Format[format].RGB_CODING;
hdsivideo_handle.LooselyPacked = DSI_LOOSELY_PACKED_DISABLE;
hdsivideo_handle.VSPolarity = DSI_VSYNC_ACTIVE_LOW;
hdsivideo_handle.HSPolarity = DSI_HSYNC_ACTIVE_LOW;
hdsivideo_handle.DEPolarity = DSI_DATA_ENABLE_ACTIVE_HIGH;
hdsivideo_handle.Mode = DSI_VID_MODE_NB_PULSES;
hdsivideo_handle.NullPacketSize = HDMI_DSIPacket[format].NullPacketSize;
hdsivideo_handle.NumberOfChunks = HDMI_DSIPacket[format].NumberOfChunks;
hdsivideo_handle.PacketSize = HDMI_DSIPacket[format].PacketSize;
hdsivideo_handle.HorizontalSyncActive = HDMI_Format[format].HSYNC*HDMI_PLLConfig[format].LaneByteClock/HDMI_PLLConfig[format].PCLK;
hdsivideo_handle.HorizontalBackPorch = HDMI_Format[format].HBP*HDMI_PLLConfig[format].LaneByteClock/HDMI_PLLConfig[format].PCLK;
hdsivideo_handle.HorizontalLine = (HDMI_Format[format].HACT + HDMI_Format[format].HSYNC + HDMI_Format[format].HBP + HDMI_Format[format].HFP)*HDMI_PLLConfig[format].LaneByteClock/HDMI_PLLConfig[format].PCLK;
hdsivideo_handle.VerticalSyncActive = HDMI_Format[format].VSYNC;
hdsivideo_handle.VerticalBackPorch = HDMI_Format[format].VBP;
hdsivideo_handle.VerticalFrontPorch = HDMI_Format[format].VFP;
hdsivideo_handle.VerticalActive = HDMI_Format[format].VACT;
/* Enable or disable sending LP command while streaming is active in video mode */
hdsivideo_handle.LPCommandEnable = DSI_LP_COMMAND_DISABLE; /* Enable sending commands in mode LP (Low Power) */
/* Largest packet size possible to transmit in LP mode in VSA, VBP, VFP regions */
/* Only useful when sending LP packets is allowed while streaming is active in video mode */
hdsivideo_handle.LPLargestPacketSize = 4;
/* Largest packet size possible to transmit in LP mode in HFP region during VACT period */
/* Only useful when sending LP packets is allowed while streaming is active in video mode */
hdsivideo_handle.LPVACTLargestPacketSize = 4;
/* Specify for each region, if the going in LP mode is allowed */
/* while streaming is active in video mode */
hdsivideo_handle.LPHorizontalFrontPorchEnable = DSI_LP_HFP_DISABLE;
hdsivideo_handle.LPHorizontalBackPorchEnable = DSI_LP_HBP_DISABLE;
hdsivideo_handle.LPVerticalActiveEnable = DSI_LP_VACT_DISABLE;
hdsivideo_handle.LPVerticalFrontPorchEnable = DSI_LP_VFP_DISABLE;
hdsivideo_handle.LPVerticalBackPorchEnable = DSI_LP_VBP_DISABLE;
hdsivideo_handle.LPVerticalSyncActiveEnable = DSI_LP_VSYNC_DISABLE;
/* No acknoledge at the end of a frame */
hdsivideo_handle.FrameBTAAcknowledgeEnable = DSI_FBTAA_DISABLE;
/* Configure DSI Video mode timings with settings set above */
HAL_DSI_ConfigVideoMode(&hdsi_discovery, &hdsivideo_handle);
/* Enable the DSI host and wrapper : but LTDC is not started yet at this stage */
HAL_DSI_Start(&hdsi_discovery);
/*************************End DSI Initialization*******************************/
/************************LTDC Initialization***********************************/
/* LTDC clock configuration */
PeriphClkInitStruct.PeriphClockSelection = RCC_PERIPHCLK_LTDC;
PeriphClkInitStruct.PLLSAI.PLLSAIN = HDMI_PLLConfig[format].PLLSAIN;
PeriphClkInitStruct.PLLSAI.PLLSAIR = HDMI_PLLConfig[format].PLLSAIR;
PeriphClkInitStruct.PLLSAIDivR = RCC_PLLSAIDIVR_2;
HAL_RCCEx_PeriphCLKConfig(&PeriphClkInitStruct);
/* Base address of LTDC registers to be set before calling De-Init */
hltdc_discovery.Instance = LTDC;
HAL_LTDC_DeInit(&(hltdc_discovery));
/* Timing Configuration */
hltdc_discovery.Init.HorizontalSync = (HDMI_Format[format].HSYNC - 1);
hltdc_discovery.Init.AccumulatedHBP = (HDMI_Format[format].HSYNC + HDMI_Format[format].HBP - 1);
hltdc_discovery.Init.AccumulatedActiveW = (HDMI_Format[format].HACT + HDMI_Format[format].HSYNC + HDMI_Format[format].HBP - 1);
hltdc_discovery.Init.TotalWidth = (HDMI_Format[format].HACT + HDMI_Format[format].HSYNC + HDMI_Format[format].HBP + HDMI_Format[format].HFP - 1);
hltdc_discovery.Init.VerticalSync = (HDMI_Format[format].VSYNC - 1);
hltdc_discovery.Init.AccumulatedVBP = (HDMI_Format[format].VSYNC + HDMI_Format[format].VBP - 1);
hltdc_discovery.Init.AccumulatedActiveH = (HDMI_Format[format].VACT + HDMI_Format[format].VSYNC + HDMI_Format[format].VBP - 1);
hltdc_discovery.Init.TotalHeigh = (HDMI_Format[format].VACT + HDMI_Format[format].VSYNC + HDMI_Format[format].VBP + HDMI_Format[format].VFP - 1);
/* background value */
hltdc_discovery.Init.Backcolor.Blue = 0x00;
hltdc_discovery.Init.Backcolor.Green = 0xFF;
hltdc_discovery.Init.Backcolor.Red = 0xFF;
/* Polarity */
hltdc_discovery.Init.HSPolarity = LTDC_HSPOLARITY_AL;
hltdc_discovery.Init.VSPolarity = LTDC_VSPOLARITY_AL;
hltdc_discovery.Init.DEPolarity = LTDC_DEPOLARITY_AL;
hltdc_discovery.Init.PCPolarity = LTDC_PCPOLARITY_IPC;
/* Initialize & Start the LTDC */
HAL_LTDC_Init(&hltdc_discovery);
#if !defined(DATA_IN_ExtSDRAM)
/* Initialize the SDRAM */
BSP_SDRAM_Init();
#endif /* DATA_IN_ExtSDRAM */
/* Initialize the font */
BSP_LCD_SetFont(&LCD_DEFAULT_FONT);
/************************End LTDC Initialization*******************************/
return LCD_OK;
}
#endif /* USE_LCD_HDMI */
/**
* @brief BSP LCD Reset
* Hw reset the LCD DSI activating its XRES signal (active low for some time)
* and desactivating it later.
*/
void BSP_LCD_Reset(void)
{
GPIO_InitTypeDef gpio_init_structure;
__HAL_RCC_GPIOJ_CLK_ENABLE();
/* Configure the GPIO on PJ15 */
gpio_init_structure.Pin = GPIO_PIN_15;
gpio_init_structure.Mode = GPIO_MODE_OUTPUT_PP;
gpio_init_structure.Pull = GPIO_PULLUP;
gpio_init_structure.Speed = GPIO_SPEED_HIGH;
HAL_GPIO_Init(GPIOJ, &gpio_init_structure);
/* Activate XRES active low */
HAL_GPIO_WritePin(GPIOJ, GPIO_PIN_15, GPIO_PIN_RESET);
HAL_Delay(20); /* wait 20 ms */
/* Desactivate XRES */
HAL_GPIO_WritePin(GPIOJ, GPIO_PIN_15, GPIO_PIN_SET);
/* Wait for 10ms after releasing XRES before sending commands */
HAL_Delay(10);
}
/**
* @brief Gets the LCD X size.
* @retval Used LCD X size
*/
uint32_t BSP_LCD_GetXSize(void)
{
return (lcd_x_size);
}
/**
* @brief Gets the LCD Y size.
* @retval Used LCD Y size
*/
uint32_t BSP_LCD_GetYSize(void)
{
return (lcd_y_size);
}
/**
* @brief Set the LCD X size.
* @param imageWidthPixels : uint32_t image width in pixels unit
* @retval None
*/
void BSP_LCD_SetXSize(uint32_t imageWidthPixels)
{
hltdc_discovery.LayerCfg[ActiveLayer].ImageWidth = imageWidthPixels;
}
/**
* @brief Set the LCD Y size.
* @param imageHeightPixels : uint32_t image height in lines unit
*/
void BSP_LCD_SetYSize(uint32_t imageHeightPixels)
{
hltdc_discovery.LayerCfg[ActiveLayer].ImageHeight = imageHeightPixels;
}
/**
* @brief Initializes the LCD layers.
* @param LayerIndex: Layer foreground or background
* @param FB_Address: Layer frame buffer
* @retval None
*/
void BSP_LCD_LayerDefaultInit(uint16_t LayerIndex, uint32_t FB_Address)
{
LCD_LayerCfgTypeDef Layercfg;
/* Layer Init */
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(&hltdc_discovery, &Layercfg, LayerIndex);
DrawProp[LayerIndex].BackColor = LCD_COLOR_WHITE;
DrawProp[LayerIndex].pFont = &Font24;
DrawProp[LayerIndex].TextColor = LCD_COLOR_BLACK;
}
/**
* @brief Selects the LCD Layer.
* @param LayerIndex: Layer foreground or background
*/
void BSP_LCD_SelectLayer(uint32_t LayerIndex)
{
ActiveLayer = LayerIndex;
}
/**
* @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
*/
void BSP_LCD_SetLayerVisible(uint32_t LayerIndex, FunctionalState State)
{
if(State == ENABLE)
{
__HAL_LTDC_LAYER_ENABLE(&(hltdc_discovery), LayerIndex);
}
else
{
__HAL_LTDC_LAYER_DISABLE(&(hltdc_discovery), LayerIndex);
}
__HAL_LTDC_RELOAD_CONFIG(&(hltdc_discovery));
}
/**
* @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
*/
void BSP_LCD_SetTransparency(uint32_t LayerIndex, uint8_t Transparency)
{
HAL_LTDC_SetAlpha(&(hltdc_discovery), Transparency, LayerIndex);
}
/**
* @brief Sets an LCD layer frame buffer address.
* @param LayerIndex: Layer foreground or background
* @param Address: New LCD frame buffer value
*/
void BSP_LCD_SetLayerAddress(uint32_t LayerIndex, uint32_t Address)
{
HAL_LTDC_SetAddress(&(hltdc_discovery), Address, LayerIndex);
}
/**
* @brief Sets display window.
* @param LayerIndex: Layer index
* @param Xpos: LCD X position
* @param Ypos: LCD Y position
* @param Width: LCD window width
* @param Height: LCD window height
*/
void BSP_LCD_SetLayerWindow(uint16_t LayerIndex, uint16_t Xpos, uint16_t Ypos, uint16_t Width, uint16_t Height)
{
/* Reconfigure the layer size */
HAL_LTDC_SetWindowSize(&(hltdc_discovery), Width, Height, LayerIndex);
/* Reconfigure the layer position */
HAL_LTDC_SetWindowPosition(&(hltdc_discovery), Xpos, Ypos, LayerIndex);
}
/**
* @brief Configures and sets the color keying.
* @param LayerIndex: Layer foreground or background
* @param RGBValue: Color reference
*/
void BSP_LCD_SetColorKeying(uint32_t LayerIndex, uint32_t RGBValue)
{
/* Configure and Enable the color Keying for LCD Layer */
HAL_LTDC_ConfigColorKeying(&(hltdc_discovery), RGBValue, LayerIndex);
HAL_LTDC_EnableColorKeying(&(hltdc_discovery), LayerIndex);
}
/**
* @brief Disables the color keying.
* @param LayerIndex: Layer foreground or background
*/
void BSP_LCD_ResetColorKeying(uint32_t LayerIndex)
{
/* Disable the color Keying for LCD Layer */
HAL_LTDC_DisableColorKeying(&(hltdc_discovery), LayerIndex);
}
/**
* @brief Sets the LCD text color.
* @param Color: Text color code ARGB(8-8-8-8)
*/
void BSP_LCD_SetTextColor(uint32_t Color)
{
DrawProp[ActiveLayer].TextColor = Color;
}
/**
* @brief Gets the LCD text color.
* @retval Used text color.
*/
uint32_t BSP_LCD_GetTextColor(void)
{
return DrawProp[ActiveLayer].TextColor;
}
/**
* @brief Sets the LCD background color.
* @param Color: Layer background color code ARGB(8-8-8-8)
*/
void BSP_LCD_SetBackColor(uint32_t Color)
{
DrawProp[ActiveLayer].BackColor = Color;
}
/**
* @brief Gets the LCD background color.
* @retval Used background color
*/
uint32_t BSP_LCD_GetBackColor(void)
{
return DrawProp[ActiveLayer].BackColor;
}
/**
* @brief Sets the LCD text font.
* @param fonts: Layer font to be used
*/
void BSP_LCD_SetFont(sFONT *fonts)
{
DrawProp[ActiveLayer].pFont = fonts;
}
/**
* @brief Gets the LCD text font.
* @retval Used layer font
*/
sFONT *BSP_LCD_GetFont(void)
{
return DrawProp[ActiveLayer].pFont;
}
/**
* @brief Reads an LCD pixel.
* @param Xpos: X position
* @param Ypos: Y position
* @retval RGB pixel color
*/
uint32_t BSP_LCD_ReadPixel(uint16_t Xpos, uint16_t Ypos)
{
uint32_t ret = 0;
if(hltdc_discovery.LayerCfg[ActiveLayer].PixelFormat == LTDC_PIXEL_FORMAT_ARGB8888)
{
/* Read data value from SDRAM memory */
ret = *(__IO uint32_t*) (hltdc_discovery.LayerCfg[ActiveLayer].FBStartAdress + (4*(Ypos*BSP_LCD_GetXSize() + Xpos)));
}
else if(hltdc_discovery.LayerCfg[ActiveLayer].PixelFormat == LTDC_PIXEL_FORMAT_RGB888)
{
/* Read data value from SDRAM memory */
ret = (*(__IO uint32_t*) (hltdc_discovery.LayerCfg[ActiveLayer].FBStartAdress + (4*(Ypos*BSP_LCD_GetXSize() + Xpos))) & 0x00FFFFFF);
}
else if((hltdc_discovery.LayerCfg[ActiveLayer].PixelFormat == LTDC_PIXEL_FORMAT_RGB565) || \
(hltdc_discovery.LayerCfg[ActiveLayer].PixelFormat == LTDC_PIXEL_FORMAT_ARGB4444) || \
(hltdc_discovery.LayerCfg[ActiveLayer].PixelFormat == LTDC_PIXEL_FORMAT_AL88))
{
/* Read data value from SDRAM memory */
ret = *(__IO uint16_t*) (hltdc_discovery.LayerCfg[ActiveLayer].FBStartAdress + (2*(Ypos*BSP_LCD_GetXSize() + Xpos)));
}
else
{
/* Read data value from SDRAM memory */
ret = *(__IO uint8_t*) (hltdc_discovery.LayerCfg[ActiveLayer].FBStartAdress + (2*(Ypos*BSP_LCD_GetXSize() + Xpos)));
}
return ret;
}