-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathSTemwin_wrapper.c
929 lines (794 loc) · 27.1 KB
/
STemwin_wrapper.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
/**
******************************************************************************
* @file lcdconf.c
* @author MCD Application Team
* @version V1.2.0
* @date 30-December-2016
* @brief This file implements the configuration for the GUI library
******************************************************************************
* @attention
*
* <h2><center>© Copyright (c) 2016 STMicroelectronics International N.V.
* All rights reserved.</center></h2>
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted, provided that the following conditions are met:
*
* 1. Redistribution of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
* 3. Neither the name of STMicroelectronics nor the names of other
* contributors to this software may be used to endorse or promote products
* derived from this software without specific written permission.
* 4. This software, including modifications and/or derivative works of this
* software, must execute solely and exclusively on microcontroller or
* microprocessor devices manufactured by or for STMicroelectronics.
* 5. Redistribution and use of this software other than as permitted under
* this license is void and will automatically terminate your rights under
* this license.
*
* THIS SOFTWARE IS PROVIDED BY STMICROELECTRONICS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS, IMPLIED OR STATUTORY WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
* PARTICULAR PURPOSE AND NON-INFRINGEMENT OF THIRD PARTY INTELLECTUAL PROPERTY
* RIGHTS ARE DISCLAIMED TO THE FULLEST EXTENT PERMITTED BY LAW. IN NO EVENT
* SHALL STMICROELECTRONICS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
******************************************************************************
*/
/* Includes ------------------------------------------------------------------*/
#include <STemwin_wrapper.h>
#include "GUI_Private.h"
#include "WM.h"
#include "stm32746g_discovery.h"
#include "stm32746g_discovery_lcd.h"
#include "stm32746g_discovery_sdram.h"
#include "stm32746g_discovery_ts.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
#undef LCD_SWAP_RB
#define LCD_SWAP_XY 1
#define LCD_MIRROR_Y 1
#define LCD_SWAP_RB 1
#define XSIZE_PHYS 480
#define YSIZE_PHYS 272
#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
#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_M1555I
#define DISPLAY_DRIVER_1 GUIDRV_LIN_16
#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
/* From SDRAM */
#define LCD_LAYER0_FRAME_BUFFER ((int)0xC0000000)
TS_StateTypeDef TS_State;
/**
* @}
*/
/** @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
};
extern volatile GUI_TIMER_TIME OS_TimeMS;
volatile char TransferInProgress = 0;
/**
* @}
*/
/** @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) {
if (LayerIndex == 0) {
return LTDC_PIXEL_FORMAT_ARGB8888;
} else {
return LTDC_PIXEL_FORMAT_ARGB1555;
}
}
/*******************************************************************************
LTDC and DMA2D BSP Routines
*******************************************************************************/
/**
* @brief DMA2D MSP Initialization
* This function configures the hardware resources used in this example:
* - 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 example:
* - 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 example:
* - 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;
static RCC_PeriphCLKInitTypeDef PeriphClkInitStruct;
/* Enable the LTDC clocks */
__HAL_RCC_LTDC_CLK_ENABLE()
;
/* LCD clock configuration */
/* PLLSAI_VCO Input = HSE_VALUE/PLL_M = 1 Mhz */
/* PLLSAI_VCO Output = PLLSAI_VCO Input * PLLSAIN = 429 Mhz */
/* PLLLCDCLK = PLLSAI_VCO Output/PLLSAIR = 429/5 = 85 Mhz */
/* LTDC clock frequency = PLLLCDCLK / LTDC_PLLSAI_DIVR_2 = 85/4 = 21 Mhz */
PeriphClkInitStruct.PeriphClockSelection = RCC_PERIPHCLK_LTDC;
PeriphClkInitStruct.PLLSAI.PLLSAIN = 192;
PeriphClkInitStruct.PLLSAI.PLLSAIR = 5;
PeriphClkInitStruct.PLLSAIDivR = RCC_PLLSAIDIVR_4;
HAL_RCCEx_PeriphCLKConfig(&PeriphClkInitStruct);
/* Enable GPIOs clock */
__HAL_RCC_GPIOE_CLK_ENABLE()
;
__HAL_RCC_GPIOG_CLK_ENABLE()
;
__HAL_RCC_GPIOI_CLK_ENABLE()
;
__HAL_RCC_GPIOJ_CLK_ENABLE()
;
__HAL_RCC_GPIOK_CLK_ENABLE()
;
/*** LTDC Pins configuration ***/
/* GPIOE configuration */
gpio_init_structure.Pin = GPIO_PIN_4;
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(GPIOE, &gpio_init_structure);
/* GPIOG configuration */
gpio_init_structure.Pin = GPIO_PIN_12;
gpio_init_structure.Mode = GPIO_MODE_AF_PP;
gpio_init_structure.Alternate = GPIO_AF9_LTDC;
HAL_GPIO_Init(GPIOG, &gpio_init_structure);
/* GPIOI LTDC alternate configuration */
gpio_init_structure.Pin = GPIO_PIN_9 | GPIO_PIN_10 |
GPIO_PIN_13 | GPIO_PIN_14 | GPIO_PIN_15;
gpio_init_structure.Mode = GPIO_MODE_AF_PP;
gpio_init_structure.Alternate = GPIO_AF14_LTDC;
HAL_GPIO_Init(GPIOI, &gpio_init_structure);
/* GPIOJ configuration */
gpio_init_structure.Pin = GPIO_PIN_0 | GPIO_PIN_1 | GPIO_PIN_2 | GPIO_PIN_3
|
GPIO_PIN_4 | GPIO_PIN_5 | GPIO_PIN_6 | GPIO_PIN_7 |
GPIO_PIN_8 | GPIO_PIN_9 | GPIO_PIN_10 | GPIO_PIN_11 |
GPIO_PIN_13 | GPIO_PIN_14 | GPIO_PIN_15;
gpio_init_structure.Mode = GPIO_MODE_AF_PP;
gpio_init_structure.Alternate = GPIO_AF14_LTDC;
HAL_GPIO_Init(GPIOJ, &gpio_init_structure);
/* GPIOK configuration */
gpio_init_structure.Pin = GPIO_PIN_0 | GPIO_PIN_1 | GPIO_PIN_2 | GPIO_PIN_4
|
GPIO_PIN_5 | GPIO_PIN_6 | GPIO_PIN_7;
gpio_init_structure.Mode = GPIO_MODE_AF_PP;
gpio_init_structure.Alternate = GPIO_AF14_LTDC;
HAL_GPIO_Init(GPIOK, &gpio_init_structure);
/* LCD_DISP GPIO configuration */
gpio_init_structure.Pin = GPIO_PIN_12; /* LCD_DISP pin has to be manually controlled */
gpio_init_structure.Mode = GPIO_MODE_OUTPUT_PP;
HAL_GPIO_Init(GPIOI, &gpio_init_structure);
/* LCD_BL_CTRL GPIO configuration */
gpio_init_structure.Pin = GPIO_PIN_3; /* LCD_BL_CTRL pin has to be manually controlled */
gpio_init_structure.Mode = GPIO_MODE_OUTPUT_PP;
HAL_GPIO_Init(GPIOK, &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 example:
* - 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;
}
}
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);
}
#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);
} else {
LCD_SetSizeEx(0, XSIZE_PHYS, YSIZE_PHYS);
LCD_SetVSizeEx(0, XSIZE_PHYS, YSIZE_PHYS * NUM_VSCREENS);
}
#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);
} else {
LCD_SetSizeEx (1, XSIZE_PHYS, YSIZE_PHYS);
LCD_SetVSizeEx(1, XSIZE_PHYS, YSIZE_PHYS * NUM_VSCREENS);
}
#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 */
}
}
}
/**
* @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_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_SHOWBUFFER:
layer_prop[LayerIndex].pending_buffer =
((LCD_X_SHOWBUFFER_INFO *) pData)->Index;
break;
case LCD_X_SETLUTENTRY:
HAL_LTDC_ConfigCLUT(&hltdc,
(uint32_t *) &(((LCD_X_SETLUTENTRY_INFO *) pData)->Color), 1,
LayerIndex);
break;
case LCD_X_ON:
__HAL_LTDC_ENABLE(&hltdc);
break;
case LCD_X_OFF:
__HAL_LTDC_DISABLE(&hltdc);
break;
case LCD_X_SETVIS:
if (((LCD_X_SETVIS_INFO *) pData)->OnOff == ENABLE) {
__HAL_LTDC_LAYER_ENABLE(&hltdc, LayerIndex);
} else {
__HAL_LTDC_LAYER_DISABLE(&hltdc, LayerIndex);
}
__HAL_LTDC_RELOAD_CONFIG(&hltdc);
break;
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_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_SETALPHA:
HAL_LTDC_SetAlpha(&hltdc, ((LCD_X_SETALPHA_INFO *) pData)->Alpha,
LayerIndex);
break;
case LCD_X_SETCHROMAMODE:
if (((LCD_X_SETCHROMAMODE_INFO *) pData)->ChromaMode != 0) {
HAL_LTDC_EnableColorKeying(&hltdc, LayerIndex);
} else {
HAL_LTDC_DisableColorKeying(&hltdc, LayerIndex);
}
break;
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;
default:
r = -1;
}
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 = ((uint32_t) 0xC0000000);
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);
}
}
}
/**
* @brief Initialize the LCD Controller.
* @param LayerIndex : layer Index.
* @retval None
*/
static void LCD_LL_Init(void) {
/* DeInit */
HAL_LTDC_DeInit(&hltdc);
/* Set LCD Timings */
hltdc.Init.HorizontalSync = 40;
hltdc.Init.VerticalSync = 9;
hltdc.Init.AccumulatedHBP = 53;
hltdc.Init.AccumulatedVBP = 11;
hltdc.Init.AccumulatedActiveH = 283;
hltdc.Init.AccumulatedActiveW = 533;
hltdc.Init.TotalHeigh = 285;
hltdc.Init.TotalWidth = 565;
/* background value */
hltdc.Init.Backcolor.Blue = 0;
hltdc.Init.Backcolor.Green = 0;
hltdc.Init.Backcolor.Red = 0;
/* 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);
/* Enable dithering */
HAL_LTDC_EnableDither(&hltdc);
/* Configure the DMA2D default mode */
hdma2d.Init.Mode = DMA2D_R2M;
hdma2d.Init.ColorMode = DMA2D_OUTPUT_ARGB8888;//DMA2D_RGB565;
hdma2d.Init.OutputOffset = 0x0;
hdma2d.Instance = DMA2D;
if (HAL_DMA2D_Init(&hdma2d) != HAL_OK) {
while (1)
;
}
/* Assert display enable LCD_DISP pin */
HAL_GPIO_WritePin(GPIOI, GPIO_PIN_12, GPIO_PIN_SET);
/* Assert backlight LCD_BL_CTRL pin */
HAL_GPIO_WritePin(GPIOK, GPIO_PIN_3, GPIO_PIN_SET);
}
/**
* @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) {
}
}
/**
* @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) {
}
}
/**
* @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);
} 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);
}
}
/**
* @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);
}
static void TransferComplete(DMA2D_HandleTypeDef *hdma2d) {
TransferInProgress = 0;
}
void DMA2D_Init(void) {
/* Configure the DMA2D transfer complete callback mode */
hdma2d.XferCpltCallback = TransferComplete;
if (HAL_DMA2D_Init(&hdma2d) != HAL_OK) {
Error_Handler();
}
if (HAL_DMA2D_ConfigLayer(&hdma2d, 1) != HAL_OK) {
Error_Handler();
}
}
void GRAPHICS_Init(void) {
MX_FMC_Init();
BSP_SDRAM_Init();
#if GUI_SUPPORT_TOUCH
if (BSP_TS_Init(BSP_LCD_GetXSize(), BSP_LCD_GetYSize()) != TS_OK) {
while (1);
}
#endif
GUI_Init();/* Initialize the GUI */
WM_MULTIBUF_Enable(1);/* Enable the multi-buffering functionality */
WM_SetCreateFlags(WM_CF_MEMDEV); /* USER CODE BEGIN WM_SetCreateFlags */
}
void TouchUpdate(void) {
static GUI_PID_STATE GUI_TS_State = { 0, 0, 0, 0 };
//TS_StateTypeDef TS_State;
uint16_t xDiff, yDiff;
BSP_TS_GetState(&TS_State);
if ((TS_State.touchX[0] >= LCD_GetXSize()) || (TS_State.touchY[0] >= LCD_GetYSize())) {
TS_State.touchX[0] = 0;
TS_State.touchY[0] = 0;
TS_State.touchDetected = 0;
}
xDiff = (GUI_TS_State.x > TS_State.touchX[0]) ?
(GUI_TS_State.x - TS_State.touchX[0]) : (TS_State.touchX[0] - GUI_TS_State.x);
yDiff = (GUI_TS_State.y > TS_State.touchY[0]) ?
(GUI_TS_State.y - TS_State.touchY[0]) : (TS_State.touchY[0] - GUI_TS_State.y);
if ((GUI_TS_State.Pressed != TS_State.touchDetected) || (xDiff > 10)
|| (yDiff > 10)) {
GUI_TS_State.Pressed = TS_State.touchDetected;
//GUI_TS_State.Layer = SelLayer;
if (TS_State.touchDetected) {
GUI_TS_State.x = TS_State.touchX[0];
GUI_TS_State.y = TS_State.touchY[0];
GUI_TOUCH_StoreStateEx(&GUI_TS_State);
} else {
GUI_TOUCH_StoreStateEx(&GUI_TS_State);
GUI_TS_State.x = 0;
GUI_TS_State.y = 0;
}
}
}
void TouchUpdate2(void)
{
static GUI_PID_STATE TS_State = {0, 0, 0, 0};
__IO TS_StateTypeDef ts;
uint16_t xDiff, yDiff;
BSP_TS_GetState((TS_StateTypeDef *)&ts);
if((ts.touchX[0] >= LCD_GetXSize()) ||(ts.touchY[0] >= LCD_GetYSize()) )
{
ts.touchX[0] = 0;
ts.touchY[0] = 0;
ts.touchDetected =0;
}
xDiff = (TS_State.x > ts.touchX[0]) ? (TS_State.x - ts.touchX[0]) : (ts.touchX[0] - TS_State.x);
yDiff = (TS_State.y > ts.touchY[0]) ? (TS_State.y - ts.touchY[0]) : (ts.touchY[0] - TS_State.y);
if((TS_State.Pressed != ts.touchDetected ) ||
(xDiff > 30 )||
(yDiff > 30))
{
TS_State.Pressed = ts.touchDetected;
TS_State.Layer = 0;
if(ts.touchDetected)
{
TS_State.x = ts.touchX[0];
TS_State.y = ts.touchY[0];
GUI_TOUCH_StoreStateEx(&TS_State);
}
else
{
GUI_TOUCH_StoreStateEx(&TS_State);
TS_State.x = 0;
TS_State.y = 0;
}
}
}
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/