-
Notifications
You must be signed in to change notification settings - Fork 0
/
stm32h735g_discovery_lcd.c
1472 lines (1284 loc) · 41.5 KB
/
stm32h735g_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 stm32h735g_discovery_lcd.c
* @author MCD Application Team
* @brief This file includes the driver for Liquid Crystal Display (LCD) module
* mounted on STM32H735G_DISCO board.
******************************************************************************
@verbatim
How To use this driver:
--------------------------
- This driver is used to drive directly a LCD TFT using the LTDC controller.
- This driver uses the adequate timing and setting for the RK043FN48H LCD component
Driver description:
---------------------
+ Initialization steps:
o Initialize the LCD in default mode using the BSP_LCD_Init() function with the
following settings:
- Pixelformat : LCD_PIXEL_FORMAT_RGB888
- Orientation : LCD_ORIENTATION_LANDSCAPE.
- Width : LCD_DEFAULT_WIDTH (480)
- Height : LCD_DEFAULT_HEIGHT(272)
The default LTDC layer configured is layer 0.
BSP_LCD_Init() includes LTDC, LTDC Layer and clock configurations by calling:
- MX_LTDC_ClockConfig()
- MX_LTDC_Init()
- MX_LTDC_ConfigLayer()
o Initialize the LCD with required parameters using the BSP_LCD_InitEx() function.
o Select the LCD layer to be activated using the BSP_LCD_SetActiveLayer() function.
o Enable the LCD display using the BSP_LCD_DisplayOn() function.
o Disable the LCD display using the BSP_LCD_DisplayOff() function.
o Set the display brightness using the BSP_LCD_SetBrightness() function.
o Get the display brightness using the BSP_LCD_GetBrightness() function.
o Write a pixel to the LCD memory using the BSP_LCD_WritePixel() function.
o Read a pixel from the LCD memory using the BSP_LCD_ReadPixel() function.
o Draw an horizontal line using the BSP_LCD_DrawHLine() function.
o Draw a vertical line using the BSP_LCD_DrawVLine() function.
o Draw a bitmap image using the BSP_LCD_DrawBitmap() function.
+ Options
o Configure the LTDC reload mode by calling BSP_LCD_Relaod(). By default, the
reload mode is set to BSP_LCD_RELOAD_IMMEDIATE then LTDC is reloaded immediately.
To control the reload mode:
- Call BSP_LCD_Relaod() with ReloadType parameter set to BSP_LCD_RELOAD_NONE
- Configure LTDC (color keying, transparency ..)
- Call BSP_LCD_Relaod() with ReloadType parameter set to BSP_LCD_RELOAD_IMMEDIATE
for immediate reload or BSP_LCD_RELOAD_VERTICAL_BLANKING for LTDC reload
in the next vertical blanking
o Configure LTDC layers using BSP_LCD_ConfigLayer()
o Control layer visibility using BSP_LCD_SetLayerVisible()
o Configure and enable the color keying functionality using the
BSP_LCD_SetColorKeying() function.
o Disable the color keying functionality using the BSP_LCD_ResetColorKeying() function.
o Modify on the fly the transparency and/or the frame buffer address
using the following functions:
- BSP_LCD_SetTransparency()
- BSP_LCD_SetLayerAddress()
+ Display on LCD
o To draw and fill a basic shapes (dot, line, rectangle, circle, ellipse, .. bitmap)
on LCD and display text, utility basic_gui.c/.h must be called. Once the LCD is initialized,
user should call GUI_SetFuncDriver() API to link board LCD drivers to BASIC GUI LCD drivers.
The basic gui services, defined in basic_gui utility, are ready for use.
Note:
--------
Regarding the "Instance" parameter, needed for all functions, it is used to select
an LCD instance. On the STM32F769I_EVAL board, there's one instance. Then, this
parameter should be 0.
@endverbatim
******************************************************************************
* @attention
*
* Copyright (c) 2019 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.
*
******************************************************************************
*/
/* Includes ------------------------------------------------------------------*/
#include "stm32h735g_discovery_lcd.h"
#include "stm32h735g_discovery_bus.h"
#include "stm32h735g_discovery_ts.h"
#include "stm32h735g_discovery_ospi.h"
/** @addtogroup BSP
* @{
*/
/** @addtogroup STM32H735G_DISCO
* @{
*/
/** @defgroup STM32H735G_DISCO_LCD STM32H735G_DISCO LCD
* @{
*/
/** @defgroup STM32H735G_DISCO_LCD_Private_Variables LCD Private Variables
* @{
*/
static uint32_t PixelFormatFactor;
/**
* @}
*/
/** @defgroup STM32H735G_DISCO_LCD_Private_TypesDefinitions LCD Private TypesDefinitions
* @{
*/
const LCD_UTILS_Drv_t LCD_Driver =
{
BSP_LCD_DrawBitmap,
BSP_LCD_FillRGBRect,
BSP_LCD_DrawHLine,
BSP_LCD_DrawVLine,
BSP_LCD_FillRect,
BSP_LCD_ReadPixel,
BSP_LCD_WritePixel,
BSP_LCD_GetXSize,
BSP_LCD_GetYSize,
BSP_LCD_SetActiveLayer,
BSP_LCD_GetPixelFormat
};
/**
* @}
*/
/** @defgroup STM32H735G_DISCO_LCD_Exported_Variables Exported Variables
* @{
*/
DMA2D_HandleTypeDef hlcd_dma2d;
LTDC_HandleTypeDef hlcd_ltdc;
BSP_LCD_Ctx_t Lcd_Ctx[LCD_INSTANCES_NBR];
/**
* @}
*/
/** @defgroup STM32H735G_DISCO_LCD_Private_FunctionPrototypes LCD Private FunctionPrototypes
* @{
*/
static void LTDC_MspInit(LTDC_HandleTypeDef *hltdc);
static void LTDC_MspDeInit(LTDC_HandleTypeDef *hltdc);
static void DMA2D_MspInit(DMA2D_HandleTypeDef *hdma2d);
static void DMA2D_MspDeInit(DMA2D_HandleTypeDef *hdma2d);
static void LL_FillBuffer(uint32_t Instance, uint32_t LayerIndex, uint32_t *pDst, uint32_t xSize, uint32_t ySize,
uint32_t OffLine, uint32_t Color);
static void LL_ConvertLineToRGB(uint32_t Instance, uint32_t *pSrc, uint32_t *pDst, uint32_t xSize, uint32_t ColorMode);
/**
* @}
*/
/** @defgroup STM32H735G_EVAL_LCD_Private_Macros Private Macros
* @{
*/
#define CONVERTRGB5652ARGB8888(Color)(((((((Color >> 11) & 0x1FU) * 527) + 23) >> 6) << 16) |\
((((((Color >> 5) & 0x3FU) * 259) + 33) >> 6) << 8) |\
((((Color & 0x1FU) * 527) + 23) >> 6) | 0xFF000000)
/**
* @}
*/
/** @defgroup STM32H735G_DISCO_LCD_Exported_Functions LCD Exported Functions
* @{
*/
/**
* @brief Initializes the LCD in default mode.
* @param Instance LCD Instance
* @param Orientation LCD_ORIENTATION_LANDSCAPE
* @retval BSP status
*/
int32_t BSP_LCD_Init(uint32_t Instance, uint32_t Orientation)
{
return BSP_LCD_InitEx(Instance, Orientation, LCD_PIXEL_FORMAT_RGB888, LCD_DEFAULT_WIDTH, LCD_DEFAULT_HEIGHT);
}
/**
* @brief Initializes the LCD.
* @param Instance LCD Instance
* @param Orientation LCD_ORIENTATION_LANDSCAPE
* @param PixelFormat LCD_PIXEL_FORMAT_RGB565 or LCD_PIXEL_FORMAT_RGB888
* @param Width Display width
* @param Height Display height
* @retval BSP status
*/
int32_t BSP_LCD_InitEx(uint32_t Instance, uint32_t Orientation, uint32_t PixelFormat, uint32_t Width, uint32_t Height)
{
int32_t ret = BSP_ERROR_NONE;
uint32_t ltdc_pixel_format;
MX_LTDC_LayerConfig_t config;
BSP_OSPI_RAM_Init_t ospi_init;
if ((Orientation > LCD_ORIENTATION_LANDSCAPE) || (Instance >= LCD_INSTANCES_NBR))
{
ret = BSP_ERROR_WRONG_PARAM;
}
else
{
switch (PixelFormat)
{
case LCD_PIXEL_FORMAT_RGB565:
ltdc_pixel_format = LTDC_PIXEL_FORMAT_RGB565;
PixelFormatFactor = 2U;
break;
case LCD_PIXEL_FORMAT_RGB888:
default:
ltdc_pixel_format = LTDC_PIXEL_FORMAT_ARGB8888;
PixelFormatFactor = 4U;
break;
}
/* Store pixel format, xsize and ysize information */
Lcd_Ctx[Instance].PixelFormat = PixelFormat;
Lcd_Ctx[Instance].XSize = Width;
Lcd_Ctx[Instance].YSize = Height;
/* Initializes peripherals instance value */
hlcd_ltdc.Instance = LTDC;
hlcd_dma2d.Instance = DMA2D;
/* MSP initialization */
#if (USE_HAL_LTDC_REGISTER_CALLBACKS == 1)
/* Register the LTDC MSP Callbacks */
if (Lcd_Ctx[Instance].IsMspCallbacksValid == 0U)
{
if (BSP_LCD_RegisterDefaultMspCallbacks(0) != BSP_ERROR_NONE)
{
return BSP_ERROR_PERIPH_FAILURE;
}
}
#else
LTDC_MspInit(&hlcd_ltdc);
#endif
/* De-assert display enable LCD_DISP_EN pin */
HAL_GPIO_WritePin(LCD_DISP_EN_GPIO_PORT, LCD_DISP_EN_PIN, GPIO_PIN_RESET);
/* Assert display enable LCD_DISP_CTRL pin */
HAL_GPIO_WritePin(LCD_DISP_CTRL_GPIO_PORT, LCD_DISP_CTRL_PIN, GPIO_PIN_SET);
/* Assert backlight LCD_BL_CTRL pin */
HAL_GPIO_WritePin(LCD_BL_CTRL_GPIO_PORT, LCD_BL_CTRL_PIN, GPIO_PIN_SET);
DMA2D_MspInit(&hlcd_dma2d);
if(MX_LTDC_ClockConfig(&hlcd_ltdc) != HAL_OK)
{
ret = BSP_ERROR_PERIPH_FAILURE;
}
else
{
if (MX_LTDC_Init(&hlcd_ltdc, Width, Height) != HAL_OK)
{
ret = BSP_ERROR_PERIPH_FAILURE;
}
}
if (ret == BSP_ERROR_NONE)
{
/* Before configuring LTDC layer, ensure OSPI is initialized */
ospi_init.LatencyType = BSP_OSPI_RAM_FIXED_LATENCY;
ospi_init.BurstType = BSP_OSPI_RAM_LINEAR_BURST;
ospi_init.BurstLength = BSP_OSPI_RAM_BURST_32_BYTES;
if (BSP_OSPI_RAM_Init(0, &ospi_init) != BSP_ERROR_NONE)
{
ret = BSP_ERROR_NO_INIT;
}
else if (BSP_OSPI_RAM_EnableMemoryMappedMode(0) != BSP_ERROR_NONE)
{
ret = BSP_ERROR_PERIPH_FAILURE;
}
else
{
/* Configure default LTDC Layer 0. This configuration can be override by calling
BSP_LCD_ConfigLayer() at application level */
config.X0 = 0;
config.X1 = Width;
config.Y0 = 0;
config.Y1 = Height;
config.PixelFormat = ltdc_pixel_format;
config.Address = LCD_LAYER_0_ADDRESS;
if (MX_LTDC_ConfigLayer(&hlcd_ltdc, 0, &config) != HAL_OK)
{
ret = BSP_ERROR_PERIPH_FAILURE;
}
/* By default the reload is activated and executed immediately */
Lcd_Ctx[Instance].ReloadEnable = 1U;
}
}
}
return ret;
}
/**
* @brief De-Initializes the LCD resources.
* @param Instance LCD Instance
* @retval BSP status
*/
int32_t BSP_LCD_DeInit(uint32_t Instance)
{
int32_t ret = BSP_ERROR_NONE;
if (Instance >= LCD_INSTANCES_NBR)
{
ret = BSP_ERROR_WRONG_PARAM;
}
else
{
/* Assert display enable LCD_DISP pin */
HAL_GPIO_WritePin(LCD_DISP_CTRL_GPIO_PORT, LCD_DISP_CTRL_PIN, GPIO_PIN_RESET);
/* Assert backlight LCD_BL_CTRL pin */
HAL_GPIO_WritePin(LCD_BL_CTRL_GPIO_PORT, LCD_BL_CTRL_PIN, GPIO_PIN_RESET);
#if (USE_HAL_LTDC_REGISTER_CALLBACKS == 0)
LTDC_MspDeInit(&hlcd_ltdc);
#endif /* (USE_HAL_LTDC_REGISTER_CALLBACKS == 0) */
DMA2D_MspDeInit(&hlcd_dma2d);
(void)HAL_LTDC_DeInit(&hlcd_ltdc);
if (HAL_DMA2D_DeInit(&hlcd_dma2d) != HAL_OK)
{
ret = BSP_ERROR_PERIPH_FAILURE;
}
else
{
Lcd_Ctx[Instance].IsMspCallbacksValid = 0;
}
}
return ret;
}
/**
* @brief Initializes the LTDC.
* @param hltdc LTDC handle
* @param Width LTDC width
* @param Height LTDC height
* @retval HAL status
*/
__weak HAL_StatusTypeDef MX_LTDC_Init(LTDC_HandleTypeDef *hltdc, uint32_t Width, uint32_t Height)
{
hltdc->Instance = LTDC;
hltdc->Init.HSPolarity = LTDC_HSPOLARITY_AL;
hltdc->Init.VSPolarity = LTDC_VSPOLARITY_AL;
hltdc->Init.DEPolarity = LTDC_DEPOLARITY_AL;
hltdc->Init.PCPolarity = LTDC_PCPOLARITY_IPC;
hltdc->Init.HorizontalSync = RK043FN48H_HSYNC - 1;
hltdc->Init.AccumulatedHBP = (RK043FN48H_HSYNC + (RK043FN48H_HBP - 11) - 1);
hltdc->Init.AccumulatedActiveW = RK043FN48H_HSYNC + Width + RK043FN48H_HBP - 1;
hltdc->Init.TotalWidth = RK043FN48H_HSYNC + Width + (RK043FN48H_HBP - 11) + RK043FN48H_HFP - 1;
hltdc->Init.VerticalSync = RK043FN48H_VSYNC - 1;
hltdc->Init.AccumulatedVBP = RK043FN48H_VSYNC + RK043FN48H_VBP - 1;
hltdc->Init.AccumulatedActiveH = RK043FN48H_VSYNC + Height + RK043FN48H_VBP - 1;
hltdc->Init.TotalHeigh = RK043FN48H_VSYNC + Height + RK043FN48H_VBP + RK043FN48H_VFP - 1;
hltdc->Init.Backcolor.Blue = 0xFF;
hltdc->Init.Backcolor.Green = 0xFF;
hltdc->Init.Backcolor.Red = 0xFF;
return HAL_LTDC_Init(hltdc);
}
/**
* @brief MX LTDC layer configuration.
* @param hltdc LTDC handle
* @param LayerIndex Layer 0 or 1
* @param Config Layer configuration
* @retval HAL status
*/
__weak HAL_StatusTypeDef MX_LTDC_ConfigLayer(LTDC_HandleTypeDef *hltdc, uint32_t LayerIndex,
MX_LTDC_LayerConfig_t *Config)
{
LTDC_LayerCfgTypeDef pLayerCfg;
pLayerCfg.WindowX0 = Config->X0;
pLayerCfg.WindowX1 = Config->X1;
pLayerCfg.WindowY0 = Config->Y0;
pLayerCfg.WindowY1 = Config->Y1;
pLayerCfg.PixelFormat = Config->PixelFormat;
pLayerCfg.Alpha = 255;
pLayerCfg.Alpha0 = 0;
pLayerCfg.BlendingFactor1 = LTDC_BLENDING_FACTOR1_PAxCA;
pLayerCfg.BlendingFactor2 = LTDC_BLENDING_FACTOR2_PAxCA;
pLayerCfg.FBStartAdress = Config->Address;
pLayerCfg.ImageWidth = (Config->X1 - Config->X0);
pLayerCfg.ImageHeight = (Config->Y1 - Config->Y0);
pLayerCfg.Backcolor.Blue = 0;
pLayerCfg.Backcolor.Green = 0;
pLayerCfg.Backcolor.Red = 0;
return HAL_LTDC_ConfigLayer(hltdc, &pLayerCfg, LayerIndex);
}
/**
* @brief LTDC Clock Config for LCD DPI display.
* @param hltdc LTDC Handle
* Being __weak it can be overwritten by the application
* @retval HAL_status
*/
__weak HAL_StatusTypeDef MX_LTDC_ClockConfig(LTDC_HandleTypeDef *hltdc)
{
RCC_PeriphCLKInitTypeDef PeriphClkInitStruct;
/* RK043FN48H LCD clock configuration */
/* LCD clock configuration */
/* PLL3_VCO Input = HSE_VALUE/PLL3M = 5 Mhz */
/* PLL3_VCO Output = PLL3_VCO Input * PLL3N = 800 Mhz */
/* PLLLCDCLK = PLL3_VCO Output/PLL3R = 800/83 = 9.63 Mhz */
/* LTDC clock frequency = PLLLCDCLK = 9.63 Mhz */
PeriphClkInitStruct.PeriphClockSelection = RCC_PERIPHCLK_LTDC;
PeriphClkInitStruct.PLL3.PLL3M = 5;
PeriphClkInitStruct.PLL3.PLL3N = 160;
PeriphClkInitStruct.PLL3.PLL3P = 2;
PeriphClkInitStruct.PLL3.PLL3Q = 2;
PeriphClkInitStruct.PLL3.PLL3R = 83;
PeriphClkInitStruct.PLL3.PLL3FRACN = 0;
PeriphClkInitStruct.PLL3.PLL3VCOSEL = RCC_PLL1VCOWIDE;
PeriphClkInitStruct.PLL3.PLL3RGE = RCC_PLL1VCIRANGE_0;
return HAL_RCCEx_PeriphCLKConfig(&PeriphClkInitStruct);
}
#if (USE_HAL_LTDC_REGISTER_CALLBACKS == 1)
/**
* @brief Default BSP LCD Msp Callbacks
* @param Instance BSP LCD Instance
* @retval BSP status
*/
int32_t BSP_LCD_RegisterDefaultMspCallbacks(uint32_t Instance)
{
int32_t ret = BSP_ERROR_NONE;
if (Instance >= LCD_INSTANCES_NBR)
{
ret = BSP_ERROR_WRONG_PARAM;
}
else
{
if (HAL_LTDC_RegisterCallback(&hlcd_ltdc, HAL_LTDC_MSPINIT_CB_ID, LTDC_MspInit) != HAL_OK)
{
ret = BSP_ERROR_PERIPH_FAILURE;
}
else
{
if (HAL_LTDC_RegisterCallback(&hlcd_ltdc, HAL_LTDC_MSPDEINIT_CB_ID, LTDC_MspDeInit) != HAL_OK)
{
ret = BSP_ERROR_PERIPH_FAILURE;
}
}
Lcd_Ctx[Instance].IsMspCallbacksValid = 1;
}
return ret;
}
/**
* @brief BSP LCD Msp Callback registering
* @param Instance LCD Instance
* @param CallBacks pointer to LCD MspInit/MspDeInit functions
* @retval BSP status
*/
int32_t BSP_LCD_RegisterMspCallbacks(uint32_t Instance, BSP_LCD_Cb_t *CallBacks)
{
int32_t ret = BSP_ERROR_NONE;
if (Instance >= LCD_INSTANCES_NBR)
{
ret = BSP_ERROR_WRONG_PARAM;
}
else
{
if (HAL_LTDC_RegisterCallback(&hlcd_ltdc, HAL_LTDC_MSPINIT_CB_ID, CallBacks->pMspLtdcInitCb) != HAL_OK)
{
ret = BSP_ERROR_PERIPH_FAILURE;
}
else
{
if (HAL_LTDC_RegisterCallback(&hlcd_ltdc, HAL_LTDC_MSPDEINIT_CB_ID, CallBacks->pMspLtdcDeInitCb) != HAL_OK)
{
ret = BSP_ERROR_PERIPH_FAILURE;
}
}
Lcd_Ctx[Instance].IsMspCallbacksValid = 1;
}
return ret;
}
#endif /*(USE_HAL_LTDC_REGISTER_CALLBACKS == 1) */
/**
* @brief LTDC layer configuration.
* @param Instance LCD instance
* @param LayerIndex Layer 0 or 1
* @param Config Layer configuration
* @retval HAL status
*/
int32_t BSP_LCD_ConfigLayer(uint32_t Instance, uint32_t LayerIndex, BSP_LCD_LayerConfig_t *Config)
{
int32_t ret = BSP_ERROR_NONE;
if (Instance >= LCD_INSTANCES_NBR)
{
ret = BSP_ERROR_WRONG_PARAM;
}
else
{
if (MX_LTDC_ConfigLayer(&hlcd_ltdc, LayerIndex, Config) != HAL_OK)
{
ret = BSP_ERROR_PERIPH_FAILURE;
}
}
return ret;
}
/**
* @brief Gets the LCD Active LCD Pixel Format.
* @param Instance LCD Instance
* @param PixelFormat Active LCD Pixel Format
* @retval BSP status
*/
int32_t BSP_LCD_GetPixelFormat(uint32_t Instance, uint32_t *PixelFormat)
{
int32_t ret = BSP_ERROR_NONE;
if (Instance >= LCD_INSTANCES_NBR)
{
ret = BSP_ERROR_WRONG_PARAM;
}
else
{
/* Only RGB565 format is supported */
*PixelFormat = Lcd_Ctx[Instance].PixelFormat;
}
return ret;
}
/**
* @brief Set the LCD Active Layer.
* @param Instance LCD Instance
* @param LayerIndex LCD layer index
* @retval BSP status
*/
int32_t BSP_LCD_SetActiveLayer(uint32_t Instance, uint32_t LayerIndex)
{
int32_t ret = BSP_ERROR_NONE;
if (Instance >= LCD_INSTANCES_NBR)
{
ret = BSP_ERROR_WRONG_PARAM;
}
else
{
Lcd_Ctx[Instance].ActiveLayer = LayerIndex;
}
return ret;
}
/**
* @brief Control the LTDC reload
* @param Instance LCD Instance
* @param ReloadType can be one of the following values
* - BSP_LCD_RELOAD_NONE
* - BSP_LCD_RELOAD_IMMEDIATE
* - BSP_LCD_RELOAD_VERTICAL_BLANKING
* @retval BSP status
*/
int32_t BSP_LCD_Relaod(uint32_t Instance, uint32_t ReloadType)
{
int32_t ret = BSP_ERROR_NONE;
if (Instance >= LCD_INSTANCES_NBR)
{
ret = BSP_ERROR_WRONG_PARAM;
}
else if (ReloadType == BSP_LCD_RELOAD_NONE)
{
Lcd_Ctx[Instance].ReloadEnable = 0U;
}
else if (HAL_LTDC_Reload(&hlcd_ltdc, ReloadType) != HAL_OK)
{
ret = BSP_ERROR_PERIPH_FAILURE;
}
else
{
Lcd_Ctx[Instance].ReloadEnable = 1U;
}
return ret;
}
/**
* @brief Sets an LCD Layer visible
* @param Instance LCD Instance
* @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
* @retval BSP status
*/
int32_t BSP_LCD_SetLayerVisible(uint32_t Instance, uint32_t LayerIndex, FunctionalState State)
{
int32_t ret = BSP_ERROR_NONE;
if (Instance >= LCD_INSTANCES_NBR)
{
ret = BSP_ERROR_WRONG_PARAM;
}
else
{
if (State == ENABLE)
{
__HAL_LTDC_LAYER_ENABLE(&hlcd_ltdc, LayerIndex);
}
else
{
__HAL_LTDC_LAYER_DISABLE(&hlcd_ltdc, LayerIndex);
}
if (Lcd_Ctx[Instance].ReloadEnable == 1U)
{
__HAL_LTDC_RELOAD_IMMEDIATE_CONFIG(&hlcd_ltdc);
}
}
return ret;
}
/**
* @brief Configures the transparency.
* @param Instance LCD Instance
* @param LayerIndex Layer foreground or background.
* @param Transparency Transparency
* This parameter must be a number between Min_Data = 0x00 and Max_Data = 0xFF
* @retval BSP status
*/
int32_t BSP_LCD_SetTransparency(uint32_t Instance, uint32_t LayerIndex, uint8_t Transparency)
{
int32_t ret = BSP_ERROR_NONE;
if (Instance >= LCD_INSTANCES_NBR)
{
ret = BSP_ERROR_WRONG_PARAM;
}
else
{
if (Lcd_Ctx[Instance].ReloadEnable == 1U)
{
(void)HAL_LTDC_SetAlpha(&hlcd_ltdc, Transparency, LayerIndex);
}
else
{
(void)HAL_LTDC_SetAlpha_NoReload(&hlcd_ltdc, Transparency, LayerIndex);
}
}
return ret;
}
/**
* @brief Sets an LCD layer frame buffer address.
* @param Instance LCD Instance
* @param LayerIndex Layer foreground or background
* @param Address New LCD frame buffer value
* @retval BSP status
*/
int32_t BSP_LCD_SetLayerAddress(uint32_t Instance, uint32_t LayerIndex, uint32_t Address)
{
int32_t ret = BSP_ERROR_NONE;
if (Instance >= LCD_INSTANCES_NBR)
{
ret = BSP_ERROR_WRONG_PARAM;
}
else
{
if (Lcd_Ctx[Instance].ReloadEnable == 1U)
{
(void)HAL_LTDC_SetAddress(&hlcd_ltdc, Address, LayerIndex);
}
else
{
(void)HAL_LTDC_SetAddress_NoReload(&hlcd_ltdc, Address, LayerIndex);
}
}
return ret;
}
/**
* @brief Sets display window.
* @param Instance LCD Instance
* @param LayerIndex Layer index
* @param Xpos LCD X position
* @param Ypos LCD Y position
* @param Width LCD window width
* @param Height LCD window height
* @retval BSP status
*/
int32_t BSP_LCD_SetLayerWindow(uint32_t Instance, uint16_t LayerIndex, uint16_t Xpos, uint16_t Ypos, uint16_t Width,
uint16_t Height)
{
int32_t ret = BSP_ERROR_NONE;
if (Instance >= LCD_INSTANCES_NBR)
{
ret = BSP_ERROR_WRONG_PARAM;
}
else
{
if (Lcd_Ctx[Instance].ReloadEnable == 1U)
{
/* Reconfigure the layer size and position */
(void)HAL_LTDC_SetWindowSize(&hlcd_ltdc, Width, Height, LayerIndex);
(void)HAL_LTDC_SetWindowPosition(&hlcd_ltdc, Xpos, Ypos, LayerIndex);
}
else
{
/* Reconfigure the layer size and position */
(void)HAL_LTDC_SetWindowSize_NoReload(&hlcd_ltdc, Width, Height, LayerIndex);
(void)HAL_LTDC_SetWindowPosition_NoReload(&hlcd_ltdc, Xpos, Ypos, LayerIndex);
}
Lcd_Ctx[Instance].XSize = Width;
Lcd_Ctx[Instance].YSize = Height;
}
return ret;
}
/**
* @brief Configures and sets the color keying.
* @param Instance LCD Instance
* @param LayerIndex Layer foreground or background
* @param Color Color reference
* @retval BSP status
*/
int32_t BSP_LCD_SetColorKeying(uint32_t Instance, uint32_t LayerIndex, uint32_t Color)
{
int32_t ret = BSP_ERROR_NONE;
if (Instance >= LCD_INSTANCES_NBR)
{
ret = BSP_ERROR_WRONG_PARAM;
}
else
{
if (Lcd_Ctx[Instance].ReloadEnable == 1U)
{
/* Configure and Enable the color Keying for LCD Layer */
(void)HAL_LTDC_ConfigColorKeying(&hlcd_ltdc, Color, LayerIndex);
(void)HAL_LTDC_EnableColorKeying(&hlcd_ltdc, LayerIndex);
}
else
{
/* Configure and Enable the color Keying for LCD Layer */
(void)HAL_LTDC_ConfigColorKeying_NoReload(&hlcd_ltdc, Color, LayerIndex);
(void)HAL_LTDC_EnableColorKeying_NoReload(&hlcd_ltdc, LayerIndex);
}
}
return ret;
}
/**
* @brief Disables the color keying.
* @param Instance LCD Instance
* @param LayerIndex Layer foreground or background
* @retval BSP status
*/
int32_t BSP_LCD_ResetColorKeying(uint32_t Instance, uint32_t LayerIndex)
{
int32_t ret = BSP_ERROR_NONE;
if (Instance >= LCD_INSTANCES_NBR)
{
ret = BSP_ERROR_WRONG_PARAM;
}
else
{
if (Lcd_Ctx[Instance].ReloadEnable == 1U)
{
/* Disable the color Keying for LCD Layer */
(void)HAL_LTDC_DisableColorKeying(&hlcd_ltdc, LayerIndex);
}
else
{
/* Disable the color Keying for LCD Layer */
(void)HAL_LTDC_DisableColorKeying_NoReload(&hlcd_ltdc, LayerIndex);
}
}
return ret;
}
/**
* @brief Gets the LCD X size.
* @param Instance LCD Instance
* @param XSize LCD width
* @retval BSP status
*/
int32_t BSP_LCD_GetXSize(uint32_t Instance, uint32_t *XSize)
{
int32_t ret = BSP_ERROR_NONE;
if (Instance >= LCD_INSTANCES_NBR)
{
ret = BSP_ERROR_WRONG_PARAM;
}
else
{
*XSize = Lcd_Ctx[Instance].XSize;
}
return ret;
}
/**
* @brief Gets the LCD Y size.
* @param Instance LCD Instance
* @param YSize LCD Height
* @retval BSP status
*/
int32_t BSP_LCD_GetYSize(uint32_t Instance, uint32_t *YSize)
{
int32_t ret = BSP_ERROR_NONE;
if (Instance >= LCD_INSTANCES_NBR)
{
ret = BSP_ERROR_WRONG_PARAM;
}
else
{
*YSize = Lcd_Ctx[Instance].YSize;
}
return ret;
}
/**
* @brief Switch On the display.
* @param Instance LCD Instance
* @retval BSP status
*/
int32_t BSP_LCD_DisplayOn(uint32_t Instance)
{
int32_t ret;
if (Instance >= LCD_INSTANCES_NBR)
{
ret = BSP_ERROR_WRONG_PARAM;
}
else
{
__HAL_LTDC_ENABLE(&hlcd_ltdc);
/* Assert LCD_DISP_CTRL_EN pin */
HAL_GPIO_WritePin(LCD_DISP_CTRL_GPIO_PORT, LCD_DISP_CTRL_PIN, GPIO_PIN_SET);
/* Assert LCD_BL_CTRL pin */
HAL_GPIO_WritePin(LCD_BL_CTRL_GPIO_PORT, LCD_BL_CTRL_PIN, GPIO_PIN_SET);
ret = BSP_ERROR_NONE;
}
return ret;
}
/**
* @brief Switch Off the display.
* @param Instance LCD Instance
* @retval BSP status
*/
int32_t BSP_LCD_DisplayOff(uint32_t Instance)
{
int32_t ret;
if (Instance >= LCD_INSTANCES_NBR)
{
ret = BSP_ERROR_WRONG_PARAM;
}
else
{
__HAL_LTDC_DISABLE(&hlcd_ltdc);
/* Assert LCD_DISP_CTRL_EN pin */
HAL_GPIO_WritePin(LCD_DISP_CTRL_GPIO_PORT, LCD_DISP_CTRL_PIN, GPIO_PIN_RESET);
/* Assert LCD_BL_CTRL pin */
HAL_GPIO_WritePin(LCD_BL_CTRL_GPIO_PORT, LCD_BL_CTRL_PIN, GPIO_PIN_RESET);
ret = BSP_ERROR_NONE;
}
return ret;
}
/**
* @brief Set the brightness value
* @param Instance LCD Instance
* @param Brightness [00: Min (black), 100 Max]
* @retval BSP status
*/
int32_t BSP_LCD_SetBrightness(uint32_t Instance, uint32_t Brightness)
{
int32_t ret = BSP_ERROR_NONE;
if (Instance >= LCD_INSTANCES_NBR)
{
ret = BSP_ERROR_WRONG_PARAM;
}
else
{
ret = BSP_ERROR_FEATURE_NOT_SUPPORTED;
}
return ret;
}
/**
* @brief Set the brightness value
* @param Instance LCD Instance
* @param Brightness [00: Min (black), 100 Max]
* @retval BSP status
*/
int32_t BSP_LCD_GetBrightness(uint32_t Instance, uint32_t *Brightness)
{
int32_t ret = BSP_ERROR_NONE;
if (Instance >= LCD_INSTANCES_NBR)
{
ret = BSP_ERROR_WRONG_PARAM;
}
else
{
ret = BSP_ERROR_FEATURE_NOT_SUPPORTED;
}
return ret;
}
/**
* @brief Draws a bitmap picture loaded in the internal Flash in currently active layer.
* @param Instance LCD Instance
* @param Xpos Bmp X position in the LCD
* @param Ypos Bmp Y position in the LCD
* @param pbmp Pointer to Bmp picture address in the internal Flash.
* @retval BSP status
*/
int32_t BSP_LCD_DrawBitmap(uint32_t Instance, uint32_t Xpos, uint32_t Ypos, uint8_t *pBmp)
{
int32_t ret = BSP_ERROR_NONE;
uint32_t index, width, height, bit_pixel;
uint32_t Address;
uint32_t input_color_mode;
uint8_t *pbmp;
/* Get bitmap data address offset */
index = (uint32_t)pBmp[10] + ((uint32_t)pBmp[11] << 8) + ((uint32_t)pBmp[12] << 16) + ((uint32_t)pBmp[13] << 24);
/* Read bitmap width */
width = (uint32_t)pBmp[18] + ((uint32_t)pBmp[19] << 8) + ((uint32_t)pBmp[20] << 16) + ((uint32_t)pBmp[21] << 24);
/* Read bitmap height */
height = (uint32_t)pBmp[22] + ((uint32_t)pBmp[23] << 8) + ((uint32_t)pBmp[24] << 16) + ((uint32_t)pBmp[25] << 24);
/* Read bit/pixel */
bit_pixel = (uint32_t)pBmp[28] + ((uint32_t)pBmp[29] << 8);
/* Set the address */
Address = hlcd_ltdc.LayerCfg[Lcd_Ctx[Instance].ActiveLayer].FBStartAdress + (((Lcd_Ctx[Instance].XSize * Ypos) + Xpos) * PixelFormatFactor);
/* Get the layer pixel format */
if ((bit_pixel / 8U) == 4U)
{
input_color_mode = DMA2D_INPUT_ARGB8888;
}
else if ((bit_pixel / 8U) == 2U)
{
input_color_mode = DMA2D_INPUT_RGB565;
}
else
{
input_color_mode = DMA2D_INPUT_RGB888;
}
/* Bypass the bitmap header */
pbmp = pBmp + (index + (width * (height - 1U) * (bit_pixel / 8U)));
/* Convert picture to ARGB8888 pixel format */