Select one of the symbols to view example projects that use it.
 
Outline
#include "LCDConf.h"
#include "GUI_Private.h"
#define LCD_SWAP_XY
#define LCD_MIRROR_Y
#define XSIZE_PHYS
#define YSIZE_PHYS
#define NUM_BUFFERS
#define NUM_VSCREENS
#define BK_COLOR
#define GUI_NUM_LAYERS
#define COLOR_CONVERSION_0
#define DISPLAY_DRIVER_0
#define COLOR_CONVERSION_1
#define DISPLAY_DRIVER_1
#define NUM_VSCREENS
#define LCD_LAYER0_FRAME_BUFFER
#define LCD_LAYER1_FRAME_BUFFER
hltdc
hdma2d
layer_prop
apColorConvAPI
LCD_LL_GetPixelformat(unsigned long)
HAL_DMA2D_MspInit(DMA2D_HandleTypeDef *)
HAL_DMA2D_MspDeInit(DMA2D_HandleTypeDef *)
HAL_LTDC_MspInit(LTDC_HandleTypeDef *)
HAL_LTDC_MspDeInit(LTDC_HandleTypeDef *)
HAL_LTDC_LineEventCallback(LTDC_HandleTypeDef *)
LCD_X_Config()
LCD_X_DisplayDriver(unsigned int, unsigned int, void *)
LCD_LL_LayerInit(unsigned long)
LCD_LL_Init()
DMA2D_CopyBuffer(unsigned long, void *, void *, unsigned long, unsigned long, unsigned long, unsigned long)
DMA2D_FillBuffer(unsigned long, void *, unsigned long, unsigned long, unsigned long, unsigned long)
GetBufferSize(unsigned long)
CUSTOM_CopyBuffer(int, int, int)
CUSTOM_CopyRect(int, int, int, int, int, int, int)
CUSTOM_FillRect(int, int, int, int, int, unsigned long)
CUSTOM_DrawBitmap32bpp(int, int, int, const unsigned char *, int, int, int)
Files
loading...
CodeScopeSTM32 Libraries and SamplesSTemWinGui/Target/LCDConf_stm32f429i_disco_MB1075.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
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
/** ****************************************************************************** * @file lcdconf.c * @author MCD Application Team * @brief This file implements the configuration for the GUI library ****************************************************************************** * @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. * ****************************************************************************** *//* ... */ /* Includes ------------------------------------------------------------------*/ #include "LCDConf.h" #include "GUI_Private.h" /** @addtogroup LCD CONFIGURATION * @{ *//* ... */ /** @defgroup LCD CONFIGURATION * @brief This file contains the LCD Configuration * @{ *//* ... */ /** @defgroup LCD CONFIGURATION_Private_TypesDefinitions * @{ *//* ... */ /** * @} *//* ... */ /** @defgroup LCD CONFIGURATION_Private_Defines * @{ *//* ... */ #undef LCD_SWAP_XY #undef LCD_MIRROR_Y #define LCD_SWAP_XY 1 #define LCD_MIRROR_Y 1 #define XSIZE_PHYS 240 #define YSIZE_PHYS 320 #define NUM_BUFFERS 3 /* Number of multiple buffers to be used */ #define NUM_VSCREENS 1 /* Number of virtual screens to be used */ #define BK_COLOR GUI_DARKBLUE 7 defines #undef GUI_NUM_LAYERS #define GUI_NUM_LAYERS 1 #define COLOR_CONVERSION_0 GUICC_M8888I #define DISPLAY_DRIVER_0 GUIDRV_LIN_32 #if (GUI_NUM_LAYERS > 1) #define COLOR_CONVERSION_1 GUICC_M8888I #define DISPLAY_DRIVER_1 GUIDRV_LIN_32 /* ... */#endif #ifndef XSIZE_PHYS #error Physical X size of display is not defined! #endif #ifndef YSIZE_PHYS #error Physical Y size of display is not defined! #endif #ifndef NUM_VSCREENS #define NUM_VSCREENS 1 #else #if (NUM_VSCREENS <= 0) #error At least one screeen needs to be defined! #endif/* ... */ #endif #if (NUM_VSCREENS > 1) && (NUM_BUFFERS > 1) #error Virtual screens and multiple buffers are not allowed! #endif #define LCD_LAYER0_FRAME_BUFFER ((uint32_t)0xD0200000) #define LCD_LAYER1_FRAME_BUFFER ((uint32_t)0xD0400000) /** * @} *//* ... */ /** @defgroup LCD CONFIGURATION_Private_Macros * @{ *//* ... */ /** * @} *//* ... */ /** @defgroup LCD CONFIGURATION_Private_Variables * @{ *//* ... */ LTDC_HandleTypeDef hltdc; static DMA2D_HandleTypeDef hdma2d; static LCD_LayerPropTypedef layer_prop[GUI_NUM_LAYERS]; static const LCD_API_COLOR_CONV * apColorConvAPI[] = { COLOR_CONVERSION_0, #if GUI_NUM_LAYERS > 1 COLOR_CONVERSION_1, #endif ...}; /** * @} *//* ... */ /** @defgroup LCD CONFIGURATION_Private_FunctionPrototypes * @{ *//* ... */ static void DMA2D_CopyBuffer (U32 LayerIndex, void * pSrc, void * pDst, U32 xSize, U32 ySize, U32 OffLineSrc, U32 OffLineDst); static void DMA2D_FillBuffer(U32 LayerIndex, void * pDst, U32 xSize, U32 ySize, U32 OffLine, U32 ColorIndex); static void LCD_LL_Init(void); static void LCD_LL_LayerInit(U32 LayerIndex); static void CUSTOM_CopyBuffer(int LayerIndex, int IndexSrc, int IndexDst); static void CUSTOM_CopyRect(int LayerIndex, int x0, int y0, int x1, int y1, int xSize, int ySize); static void CUSTOM_FillRect(int LayerIndex, int x0, int y0, int x1, int y1, U32 PixelIndex); static void CUSTOM_DrawBitmap32bpp(int LayerIndex, int x, int y, U8 const * p, int xSize, int ySize, int BytesPerLine); static U32 GetBufferSize(U32 LayerIndex); /** * @} *//* ... */ /** @defgroup LCD CONFIGURATION_Private_Functions * @{ *//* ... */ /** * @brief Return Pixel format for a given layer * @param LayerIndex : Layer Index * @retval Status ( 0 : 0k , 1: error) *//* ... */ static inline U32 LCD_LL_GetPixelformat(U32 LayerIndex) { return LTDC_PIXEL_FORMAT_ARGB8888; }{ ... } /******************************************************************************* LTDC and DMA2D BSP Routines *******************************************************************************//* ... */ /** * @brief DMA2D MSP Initialization * This function configures the hardware resources used in this demonstration: * - Peripheral's clock enable * - Peripheral's GPIO Configuration * @param hdma2d: DMA2D handle pointer * @retval None *//* ... */ void HAL_DMA2D_MspInit(DMA2D_HandleTypeDef *hdma2d) { /* Enable peripheral */ __HAL_RCC_DMA2D_CLK_ENABLE(); }{ ... } /** * @brief DMA2D MSP De-Initialization * This function frees the hardware resources used in this demonstration: * - Disable the Peripheral's clock * @param hdma2d: DMA2D handle pointer * @retval None *//* ... */ void HAL_DMA2D_MspDeInit(DMA2D_HandleTypeDef *hdma2d) { /* Enable DMA2D reset state */ __HAL_RCC_DMA2D_FORCE_RESET(); /* Release DMA2D from reset state */ __HAL_RCC_DMA2D_RELEASE_RESET(); }{ ... } /** * @brief LTDC MSP Initialization * This function configures the hardware resources used in this demonstration: * - Peripheral's clock enable * - Peripheral's GPIO Configuration * @param hltdc: LTDC handle pointer * @retval None *//* ... */ void HAL_LTDC_MspInit(LTDC_HandleTypeDef *hltdc) { GPIO_InitTypeDef GPIO_Init_Structure; /* Enable peripherals and GPIO Clocks */ /* Enable the LTDC Clock */ __HAL_RCC_LTDC_CLK_ENABLE(); /* Enable GPIO Clock */ __HAL_RCC_GPIOA_CLK_ENABLE(); __HAL_RCC_GPIOB_CLK_ENABLE(); __HAL_RCC_GPIOC_CLK_ENABLE(); __HAL_RCC_GPIOD_CLK_ENABLE(); __HAL_RCC_GPIOF_CLK_ENABLE(); __HAL_RCC_GPIOG_CLK_ENABLE(); /* Configure peripheral GPIO */ /* GPIOs Configuration */ /* +------------------------+-----------------------+----------------------------+ + LCD pins assignment + +------------------------+-----------------------+----------------------------+ | LCD_TFT R2 <-> PC.10 | LCD_TFT G2 <-> PA.06 | LCD_TFT B2 <-> PD.06 | | LCD_TFT R3 <-> PB.00 | LCD_TFT G3 <-> PG.10 | LCD_TFT B3 <-> PG.11 | | LCD_TFT R4 <-> PA.11 | LCD_TFT G4 <-> PB.10 | LCD_TFT B4 <-> PG.12 | | LCD_TFT R5 <-> PA.12 | LCD_TFT G5 <-> PB.11 | LCD_TFT B5 <-> PA.03 | | LCD_TFT R6 <-> PB.01 | LCD_TFT G6 <-> PC.07 | LCD_TFT B6 <-> PB.08 | | LCD_TFT R7 <-> PG.06 | LCD_TFT G7 <-> PD.03 | LCD_TFT B7 <-> PB.09 | ------------------------------------------------------------------------------- | LCD_TFT HSYNC <-> PC.06 | LCDTFT VSYNC <-> PA.04 | | LCD_TFT CLK <-> PG.07 | LCD_TFT DE <-> PF.10 | ----------------------------------------------------- *//* ... */ /* GPIOA configuration */ GPIO_Init_Structure.Pin = GPIO_PIN_3 | GPIO_PIN_4 | GPIO_PIN_6 | GPIO_PIN_11 | GPIO_PIN_12; GPIO_Init_Structure.Mode = GPIO_MODE_AF_PP; GPIO_Init_Structure.Pull = GPIO_NOPULL; GPIO_Init_Structure.Speed = GPIO_SPEED_FAST; GPIO_Init_Structure.Alternate= GPIO_AF14_LTDC; HAL_GPIO_Init(GPIOA, &GPIO_Init_Structure); /* GPIOB configuration */ GPIO_Init_Structure.Pin = GPIO_PIN_8 | \ GPIO_PIN_9 | GPIO_PIN_10 | GPIO_PIN_11; HAL_GPIO_Init(GPIOB, &GPIO_Init_Structure); /* GPIOC configuration */ GPIO_Init_Structure.Pin = GPIO_PIN_6 | GPIO_PIN_7 | GPIO_PIN_10; HAL_GPIO_Init(GPIOC, &GPIO_Init_Structure); /* GPIOD configuration */ GPIO_Init_Structure.Pin = GPIO_PIN_3 | GPIO_PIN_6; HAL_GPIO_Init(GPIOD, &GPIO_Init_Structure); /* GPIOF configuration */ GPIO_Init_Structure.Pin = GPIO_PIN_10; HAL_GPIO_Init(GPIOF, &GPIO_Init_Structure); /* GPIOG configuration */ GPIO_Init_Structure.Pin = GPIO_PIN_6 | GPIO_PIN_7 | \ GPIO_PIN_11; HAL_GPIO_Init(GPIOG, &GPIO_Init_Structure); /* GPIOB configuration */ GPIO_Init_Structure.Pin = GPIO_PIN_0 | GPIO_PIN_1; GPIO_Init_Structure.Alternate= GPIO_AF9_LTDC; HAL_GPIO_Init(GPIOB, &GPIO_Init_Structure); /* GPIOG configuration */ GPIO_Init_Structure.Pin = GPIO_PIN_10 | GPIO_PIN_12; HAL_GPIO_Init(GPIOG, &GPIO_Init_Structure); /* Set LTDC Interrupt to the lowest priority */ HAL_NVIC_SetPriority(LTDC_IRQn, 0xE, 0); /* Enable LTDC Interrupt */ HAL_NVIC_EnableIRQ(LTDC_IRQn); }{ ... } /** * @brief LTDC MSP De-Initialization * This function frees the hardware resources used in this demonstration: * - Disable the Peripheral's clock * @param hltdc: LTDC handle pointer * @retval None *//* ... */ void HAL_LTDC_MspDeInit(LTDC_HandleTypeDef *hltdc) { /* Reset peripherals */ /* Enable LTDC reset state */ __HAL_RCC_LTDC_FORCE_RESET(); /* Release LTDC from reset state */ __HAL_RCC_LTDC_RELEASE_RESET(); }{ ... } /** * @brief Line Event callback. * @param hltdc: pointer to a LTDC_HandleTypeDef structure that contains * the configuration information for the specified LTDC. * @retval None *//* ... */ void HAL_LTDC_LineEvenCallback(LTDC_HandleTypeDef *hltdc) { U32 Addr; U32 layer; for (layer = 0; layer < GUI_NUM_LAYERS; layer++) { if (layer_prop[layer].pending_buffer >= 0) { /* Calculate address of buffer to be used as visible frame buffer */ Addr = layer_prop[layer].address + \ layer_prop[layer].xSize * layer_prop[layer].ySize * layer_prop[layer].pending_buffer * layer_prop[layer].BytesPerPixel; __HAL_LTDC_LAYER(hltdc, layer)->CFBAR = Addr; __HAL_LTDC_RELOAD_CONFIG(hltdc); /* Notify STemWin that buffer is used */ GUI_MULTIBUF_ConfirmEx(layer, layer_prop[layer].pending_buffer); /* Clear pending buffer flag of layer */ layer_prop[layer].pending_buffer = -1; }if (layer_prop[layer].pending_buffer >= 0) { ... } }for (layer = 0; layer < GUI_NUM_LAYERS; layer++) { ... } HAL_LTDC_ProgramLineEvent(hltdc, 0); }{ ... } /******************************************************************************* Display configuration *******************************************************************************//* ... */ /** * @brief Called during the initialization process in order to set up the * display driver configuration * @param None * @retval None *//* ... */ void LCD_X_Config(void) { U32 i; LCD_LL_Init (); /* At first initialize use of multiple buffers on demand */ #if (NUM_BUFFERS > 1) for (i = 0; i < GUI_NUM_LAYERS; i++) { GUI_MULTIBUF_ConfigEx(i, NUM_BUFFERS); }for (i = 0; i < GUI_NUM_LAYERS; i++) { ... } /* ... */#endif /* Set display driver and color conversion for 1st layer */ GUI_DEVICE_CreateAndLink(DISPLAY_DRIVER_0, COLOR_CONVERSION_0, 0, 0); /* Set size of 1st layer */ if (LCD_GetSwapXYEx(0)) { LCD_SetSizeEx (0, YSIZE_PHYS, XSIZE_PHYS); LCD_SetVSizeEx(0, YSIZE_PHYS * NUM_VSCREENS, XSIZE_PHYS); }if (LCD_GetSwapXYEx(0)) { ... } else { LCD_SetSizeEx (0, XSIZE_PHYS, YSIZE_PHYS); LCD_SetVSizeEx(0, XSIZE_PHYS, YSIZE_PHYS * NUM_VSCREENS); }else { ... } #if (GUI_NUM_LAYERS > 1) /* Set display driver and color conversion for 2nd layer */ GUI_DEVICE_CreateAndLink(DISPLAY_DRIVER_1, COLOR_CONVERSION_1, 0, 1); /* Set size of 2nd layer */ if (LCD_GetSwapXYEx(1)) { LCD_SetSizeEx (1, YSIZE_PHYS, XSIZE_PHYS); LCD_SetVSizeEx(1, YSIZE_PHYS * NUM_VSCREENS, XSIZE_PHYS); }if (LCD_GetSwapXYEx(1)) { ... } else { LCD_SetSizeEx (1, XSIZE_PHYS, YSIZE_PHYS); LCD_SetVSizeEx(1, XSIZE_PHYS, YSIZE_PHYS * NUM_VSCREENS); }else { ... } /* ... */ #endif /*Initialize GUI Layer structure */ layer_prop[0].address = LCD_LAYER0_FRAME_BUFFER; #if (GUI_NUM_LAYERS > 1) layer_prop[1].address = LCD_LAYER1_FRAME_BUFFER; #endif /* Setting up VRam address and custom functions for CopyBuffer-, CopyRect- and FillRect operations */ for (i = 0; i < GUI_NUM_LAYERS; i++) { layer_prop[i].pColorConvAPI = (LCD_API_COLOR_CONV *)apColorConvAPI[i]; layer_prop[i].pending_buffer = -1; /* Set VRAM address */ LCD_SetVRAMAddrEx(i, (void *)(layer_prop[i].address)); /* Remember color depth for further operations */ layer_prop[i].BytesPerPixel = LCD_GetBitsPerPixelEx(i) >> 3; /* Set custom functions for several operations */ LCD_SetDevFunc(i, LCD_DEVFUNC_COPYBUFFER, (void(*)(void))CUSTOM_CopyBuffer); LCD_SetDevFunc(i, LCD_DEVFUNC_COPYRECT, (void(*)(void))CUSTOM_CopyRect); LCD_SetDevFunc(i, LCD_DEVFUNC_FILLRECT, (void(*)(void))CUSTOM_FillRect); /* Set up drawing routine for 32bpp bitmap using DMA2D */ if (LCD_LL_GetPixelformat(i) == LTDC_PIXEL_FORMAT_ARGB8888) { LCD_SetDevFunc(i, LCD_DEVFUNC_DRAWBMP_32BPP, (void(*)(void))CUSTOM_DrawBitmap32bpp); /* Set up drawing routine for 32bpp bitmap using DMA2D. Makes only sense with ARGB8888 */ }if (LCD_LL_GetPixelformat(i) == LTDC_PIXEL_FORMAT_ARGB8888) { ... } }for (i = 0; i < GUI_NUM_LAYERS; i++) { ... } }{ ... } /** * @brief This function is called by the display driver for several purposes. * To support the according task the routine needs to be adapted to * the display controller. Please note that the commands marked with * 'optional' are not cogently required and should only be adapted if * the display controller supports these features * @param LayerIndex: Index of layer to be configured * @param Cmd :Please refer to the details in the switch statement below * @param pData :Pointer to a LCD_X_DATA structure * @retval Status (-1 : Error, 0 : Ok) *//* ... */ int LCD_X_DisplayDriver(unsigned LayerIndex, unsigned Cmd, void * pData) { int r = 0; U32 addr; int xPos, yPos; U32 Color; switch (Cmd) { case LCD_X_INITCONTROLLER: LCD_LL_LayerInit(LayerIndex); break; case LCD_X_INITCONTROLLER: case LCD_X_SETORG: addr = layer_prop[LayerIndex].address + ((LCD_X_SETORG_INFO *)pData)->yPos * layer_prop[LayerIndex].xSize * layer_prop[LayerIndex].BytesPerPixel; HAL_LTDC_SetAddress(&hltdc, addr, LayerIndex); break; case LCD_X_SETORG: case LCD_X_SHOWBUFFER: layer_prop[LayerIndex].pending_buffer = ((LCD_X_SHOWBUFFER_INFO *)pData)->Index; break; case LCD_X_SHOWBUFFER: case LCD_X_SETLUTENTRY: HAL_LTDC_ConfigCLUT(&hltdc, (uint32_t *)&(((LCD_X_SETLUTENTRY_INFO *)pData)->Color), 1, LayerIndex); break; case LCD_X_SETLUTENTRY: case LCD_X_ON: __HAL_LTDC_ENABLE(&hltdc); break; case LCD_X_ON: case LCD_X_OFF: __HAL_LTDC_DISABLE(&hltdc); break; case LCD_X_OFF: case LCD_X_SETVIS: if(((LCD_X_SETVIS_INFO *)pData)->OnOff == ENABLE ) { __HAL_LTDC_LAYER_ENABLE(&hltdc, LayerIndex); }if (((LCD_X_SETVIS_INFO *)pData)->OnOff == ENABLE) { ... } else { __HAL_LTDC_LAYER_DISABLE(&hltdc, LayerIndex); }else { ... } __HAL_LTDC_RELOAD_CONFIG(&hltdc); break; case LCD_X_SETVIS: case LCD_X_SETPOS: HAL_LTDC_SetWindowPosition(&hltdc, ((LCD_X_SETPOS_INFO *)pData)->xPos, ((LCD_X_SETPOS_INFO *)pData)->yPos, LayerIndex); break; case LCD_X_SETPOS: case LCD_X_SETSIZE: GUI_GetLayerPosEx(LayerIndex, &xPos, &yPos); layer_prop[LayerIndex].xSize = ((LCD_X_SETSIZE_INFO *)pData)->xSize; layer_prop[LayerIndex].ySize = ((LCD_X_SETSIZE_INFO *)pData)->ySize; HAL_LTDC_SetWindowPosition(&hltdc, xPos, yPos, LayerIndex); break; case LCD_X_SETSIZE: case LCD_X_SETALPHA: HAL_LTDC_SetAlpha(&hltdc, ((LCD_X_SETALPHA_INFO *)pData)->Alpha, LayerIndex); break; case LCD_X_SETALPHA: case LCD_X_SETCHROMAMODE: if(((LCD_X_SETCHROMAMODE_INFO *)pData)->ChromaMode != 0) { HAL_LTDC_EnableColorKeying(&hltdc, LayerIndex); }if (((LCD_X_SETCHROMAMODE_INFO *)pData)->ChromaMode != 0) { ... } else { HAL_LTDC_DisableColorKeying(&hltdc, LayerIndex); }else { ... } break; case LCD_X_SETCHROMAMODE: case LCD_X_SETCHROMA: Color = ((((LCD_X_SETCHROMA_INFO *)pData)->ChromaMin & 0xFF0000) >> 16) |\ (((LCD_X_SETCHROMA_INFO *)pData)->ChromaMin & 0x00FF00) |\ ((((LCD_X_SETCHROMA_INFO *)pData)->ChromaMin & 0x0000FF) << 16); HAL_LTDC_ConfigColorKeying(&hltdc, Color, LayerIndex); break; case LCD_X_SETCHROMA: default: r = -1;default }switch (Cmd) { ... } return r; }{ ... } /** * @brief Initialize the LCD Controller. * @param LayerIndex : layer Index. * @retval None *//* ... */ static void LCD_LL_LayerInit(U32 LayerIndex) { LTDC_LayerCfgTypeDef layer_cfg; if (LayerIndex < GUI_NUM_LAYERS) { /* Layer configuration */ layer_cfg.WindowX0 = 0; layer_cfg.WindowX1 = XSIZE_PHYS; layer_cfg.WindowY0 = 0; layer_cfg.WindowY1 = YSIZE_PHYS; layer_cfg.PixelFormat = LCD_LL_GetPixelformat(LayerIndex); layer_cfg.FBStartAdress = layer_prop[LayerIndex].address; layer_cfg.Alpha = 255; layer_cfg.Alpha0 = 0; layer_cfg.Backcolor.Blue = 0; layer_cfg.Backcolor.Green = 0; layer_cfg.Backcolor.Red = 0; layer_cfg.BlendingFactor1 = LTDC_BLENDING_FACTOR1_PAxCA; layer_cfg.BlendingFactor2 = LTDC_BLENDING_FACTOR2_PAxCA; layer_cfg.ImageWidth = XSIZE_PHYS; layer_cfg.ImageHeight = YSIZE_PHYS; HAL_LTDC_ConfigLayer(&hltdc, &layer_cfg, LayerIndex); /* Enable LUT on demand */ if (LCD_GetBitsPerPixelEx(LayerIndex) <= 8) { /* Enable usage of LUT for all modes with <= 8bpp*/ HAL_LTDC_EnableCLUT(&hltdc, LayerIndex); }if (LCD_GetBitsPerPixelEx(LayerIndex) <= 8) { ... } }if (LayerIndex < GUI_NUM_LAYERS) { ... } }{ ... } /** * @brief Initialize the LCD Controller. * @param None * @retval None *//* ... */ static void LCD_LL_Init(void) { static RCC_PeriphCLKInitTypeDef PeriphClkInitStruct; /* DeInit */ hltdc.Instance = LTDC; HAL_LTDC_DeInit(&hltdc); /* Initialization of ILI9341 component*/ ili9341_Init(); /* Set LCD Timings */ hltdc.Init.HorizontalSync = 9; hltdc.Init.VerticalSync = 1; hltdc.Init.AccumulatedHBP = 29; hltdc.Init.AccumulatedVBP = 3; hltdc.Init.AccumulatedActiveH = 323; hltdc.Init.AccumulatedActiveW = 269; hltdc.Init.TotalHeigh = 327; hltdc.Init.TotalWidth = 279; /* background value */ hltdc.Init.Backcolor.Blue = 0; hltdc.Init.Backcolor.Green = 0; hltdc.Init.Backcolor.Red = 0; /* LCD clock configuration */ /* PLLSAI_VCO Input = HSE_VALUE/PLL_M = 1 MHz */ /* PLLSAI_VCO Output = PLLSAI_VCO Input * PLLSAIN = 192 MHz */ /* PLLLCDCLK = PLLSAI_VCO Output/PLLSAIR = 192/4 = 48 MHz */ /* LTDC clock frequency = PLLLCDCLK / LTDC_PLLSAI_DIVR_8 = 48/8 = 6 MHz */ PeriphClkInitStruct.PeriphClockSelection = RCC_PERIPHCLK_LTDC; PeriphClkInitStruct.PLLSAI.PLLSAIN = 192; PeriphClkInitStruct.PLLSAI.PLLSAIR = 4; PeriphClkInitStruct.PLLSAIDivR = RCC_PLLSAIDIVR_8; HAL_RCCEx_PeriphCLKConfig(&PeriphClkInitStruct); /* Polarity */ 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.Instance = LTDC; HAL_LTDC_Init(&hltdc); HAL_LTDC_ProgramLineEvent(&hltdc, 0); /* Configure the DMA2D default mode */ hdma2d.Init.Mode = DMA2D_R2M; hdma2d.Init.ColorMode = DMA2D_ARGB8888; hdma2d.Init.OutputOffset = 0x0; hdma2d.Instance = DMA2D; if(HAL_DMA2D_Init(&hdma2d) != HAL_OK) { while (1); }if (HAL_DMA2D_Init(&hdma2d) != HAL_OK) { ... } }{ ... } /** * @brief Return Pixel format for a given layer * @param LayerIndex : Layer Index * @retval Status ( 0 : 0k , 1: error) *//* ... */ static void DMA2D_CopyBuffer(U32 LayerIndex, void * pSrc, void * pDst, U32 xSize, U32 ySize, U32 OffLineSrc, U32 OffLineDst) { U32 PixelFormat; PixelFormat = LCD_LL_GetPixelformat(LayerIndex); DMA2D->CR = 0x00000000UL | (1 << 9); /* Set up pointers */ DMA2D->FGMAR = (U32)pSrc; DMA2D->OMAR = (U32)pDst; DMA2D->FGOR = OffLineSrc; DMA2D->OOR = OffLineDst; /* Set up pixel format */ DMA2D->FGPFCCR = PixelFormat; /* Set up size */ DMA2D->NLR = (U32)(xSize << 16) | (U16)ySize; DMA2D->CR |= DMA2D_CR_START; /* Wait until transfer is done */ while (DMA2D->CR & DMA2D_CR_START) { }while (DMA2D->CR & DMA2D_CR_START) { ... } }{ ... } /** * @brief Fill Buffer * @param LayerIndex : Layer Index * @param pDst: pointer to destination * @param xSize: X size * @param ySize: Y size * @param OffLine: offset after each line * @param ColorIndex: color to be used. * @retval None *//* ... */ static void DMA2D_FillBuffer(U32 LayerIndex, void * pDst, U32 xSize, U32 ySize, U32 OffLine, U32 ColorIndex) { U32 PixelFormat; PixelFormat = LCD_LL_GetPixelformat(LayerIndex); /* Set up mode */ DMA2D->CR = 0x00030000UL | (1 << 9); DMA2D->OCOLR = ColorIndex; /* Set up pointers */ DMA2D->OMAR = (U32)pDst; /* Set up offsets */ DMA2D->OOR = OffLine; /* Set up pixel format */ DMA2D->OPFCCR = PixelFormat; /* Set up size */ DMA2D->NLR = (U32)(xSize << 16) | (U16)ySize; DMA2D->CR |= DMA2D_CR_START; /* Wait until transfer is done */ while (DMA2D->CR & DMA2D_CR_START) { }while (DMA2D->CR & DMA2D_CR_START) { ... } }{ ... } /** * @brief Get buffer size * @param LayerIndex : Layer Index * @retval None *//* ... */ static U32 GetBufferSize(U32 LayerIndex) { U32 BufferSize; BufferSize = layer_prop[LayerIndex].xSize * layer_prop[LayerIndex].ySize * layer_prop[LayerIndex].BytesPerPixel; return BufferSize; }{ ... } /** * @brief Customized copy buffer * @param LayerIndex : Layer Index * @param IndexSrc: index source * @param IndexDst: index destination * @retval None *//* ... */ static void CUSTOM_CopyBuffer(int LayerIndex, int IndexSrc, int IndexDst) { U32 BufferSize, AddrSrc, AddrDst; BufferSize = GetBufferSize(LayerIndex); AddrSrc = layer_prop[LayerIndex].address + BufferSize * IndexSrc; AddrDst = layer_prop[LayerIndex].address + BufferSize * IndexDst; DMA2D_CopyBuffer(LayerIndex, (void *)AddrSrc, (void *)AddrDst, layer_prop[LayerIndex].xSize, layer_prop[LayerIndex].ySize, 0, 0); layer_prop[LayerIndex].buffer_index = IndexDst; }{ ... } /** * @brief Copy rectangle * @param LayerIndex : Layer Index * @param x0: X0 position * @param y0: Y0 position * @param x1: X1 position * @param y1: Y1 position * @param xSize: X size. * @param ySize: Y size. * @retval None *//* ... */ static void CUSTOM_CopyRect(int LayerIndex, int x0, int y0, int x1, int y1, int xSize, int ySize) { U32 AddrSrc, AddrDst; AddrSrc = layer_prop[LayerIndex].address + (y0 * layer_prop[LayerIndex].xSize + x0) * layer_prop[LayerIndex].BytesPerPixel; AddrDst = layer_prop[LayerIndex].address + (y1 * layer_prop[LayerIndex].xSize + x1) * layer_prop[LayerIndex].BytesPerPixel; DMA2D_CopyBuffer(LayerIndex, (void *)AddrSrc, (void *)AddrDst, xSize, ySize, layer_prop[LayerIndex].xSize - xSize, layer_prop[LayerIndex].xSize - xSize); }{ ... } /** * @brief Fill rectangle * @param LayerIndex : Layer Index * @param x0: X0 position * @param y0: Y0 position * @param x1: X1 position * @param y1: Y1 position * @param PixelIndex: Pixel index. * @retval None *//* ... */ static void CUSTOM_FillRect(int LayerIndex, int x0, int y0, int x1, int y1, U32 PixelIndex) { U32 BufferSize, AddrDst; int xSize, ySize; if (GUI_GetDrawMode() == GUI_DM_XOR) { LCD_SetDevFunc(LayerIndex, LCD_DEVFUNC_FILLRECT, NULL); LCD_FillRect(x0, y0, x1, y1); LCD_SetDevFunc(LayerIndex, LCD_DEVFUNC_FILLRECT, (void(*)(void))CUSTOM_FillRect); }if (GUI_GetDrawMode() == GUI_DM_XOR) { ... } else { xSize = x1 - x0 + 1; ySize = y1 - y0 + 1; BufferSize = GetBufferSize(LayerIndex); AddrDst = layer_prop[LayerIndex].address + BufferSize * layer_prop[LayerIndex].buffer_index + (y0 * layer_prop[LayerIndex].xSize + x0) * layer_prop[LayerIndex].BytesPerPixel; DMA2D_FillBuffer(LayerIndex, (void *)AddrDst, xSize, ySize, layer_prop[LayerIndex].xSize - xSize, PixelIndex); }else { ... } }{ ... } /** * @brief Draw indirect color bitmap * @param pSrc: pointer to the source * @param pDst: pointer to the destination * @param OffSrc: offset source * @param OffDst: offset destination * @param PixelFormatDst: pixel format for destination * @param xSize: X size * @param ySize: Y size * @retval None *//* ... */ static void CUSTOM_DrawBitmap32bpp(int LayerIndex, int x, int y, U8 const * p, int xSize, int ySize, int BytesPerLine) { U32 BufferSize, AddrDst; int OffLineSrc, OffLineDst; BufferSize = GetBufferSize(LayerIndex); AddrDst = layer_prop[LayerIndex].address + BufferSize * layer_prop[LayerIndex].buffer_index + (y * layer_prop[LayerIndex].xSize + x) * layer_prop[LayerIndex].BytesPerPixel; OffLineSrc = (BytesPerLine / 4) - xSize; OffLineDst = layer_prop[LayerIndex].xSize - xSize; DMA2D_CopyBuffer(LayerIndex, (void *)p, (void *)AddrDst, xSize, ySize, OffLineSrc, OffLineDst); }{ ... }