Select one of the symbols to view example projects that use it.
 
Outline
#include <common/TouchGFXInit.hpp>
#include <touchgfx/hal/BoardConfiguration.hpp>
#include <touchgfx/hal/GPIO.hpp>
#include <platform/driver/lcd/LCD16bpp.hpp>
#include <platform/driver/lcd/LCD24bpp.hpp>
#include <STM32F4DMA.hpp>
#include <STM32F4HAL_DSI.hpp>
#include <STM32F4Instrumentation.hpp>
#include <OTM8009TouchController.hpp>
#include "../Components/otm8009a/otm8009a.h"
#include "stm32f4xx_hal.h"
#include "stm32f4xx_hal_dsi.h"
#include "stm32469i_eval.h"
#include "stm32469i_eval_sdram.h"
#include "stm32469i_eval_qspi.h"
os_inited
hltdc
hdsi
hdma2d
CmdCfg
LPCmd
dsiPllInit
PeriphClkInitStruct
LCD_GetXSize()
LCD_GetYSize()
#define VSYNC
#define VBP
#define VFP
#define VACT
#define HSYNC
#define HBP
#define HFP
#define LAYER0_ADDRESS
#define HACT
#define HACT
pCols
pColLeft
pColRight
pPage
pScanCol
frameBuf0
touchgfx
LCD_ReqTear()
LCD_SetUpdateRegion(int)
LCD_SetUpdateRegionLeft()
LCD_SetUpdateRegionRight()
SystemClock_Config()
LCD_Reset()
LCD_MspInit()
LCD_LayerInit(uint16_t, uint32_t)
LTDC_Init()
DSI_IO_WriteCmd(uint32_t, uint8_t *)
LCD_Init()
Files
loading...
CodeScopeSTM32 Libraries and SamplesTouchGFXGui/target/BoardConfiguration.cpp
 
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
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
/** ****************************************************************************** * This file is part of the TouchGFX 4.10.0 distribution. * * @attention * * Copyright (c) 2018 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. * ****************************************************************************** *//* ... */ #include <common/TouchGFXInit.hpp> #include <touchgfx/hal/BoardConfiguration.hpp> #include <touchgfx/hal/GPIO.hpp> #include <platform/driver/lcd/LCD16bpp.hpp> #include <platform/driver/lcd/LCD24bpp.hpp> #include <STM32F4DMA.hpp> #include <STM32F4HAL_DSI.hpp> #include <STM32F4Instrumentation.hpp> #include <OTM8009TouchController.hpp> #include "../Components/otm8009a/otm8009a.h" 10 includes /** * In order to use double buffering, simply enable the USE_DOUBLE_BUFFERING #define below * Enabling double buffering will yield a performance increase (potentionally higher frame rate), * at the expense of consuming an additional frame buffer's worth of external RAM - e.g. 800 * 480 * 2 bytes (16 bpp) *//* ... */ //#define USE_DOUBLE_BUFFERING 1 /*********************************************************** ****** 24 Bits Per Pixel Support ******* *********************************************************** * * The default bit depth of the framebuffer is 16bpp. If you want 24bpp support, define the symbol "USE_BPP" with a value * of "24", e.g. "USE_BPP=24". This symbol affects the following: * * 1. Type of TouchGFX LCD (16bpp vs 24bpp) * 2. Bit depth of the framebuffer(s) * 3. TFT controller configuration. * * WARNING: Remember to modify your image formats accordingly in app/config/. Please see the following knowledgebase article * for further details on how to choose and configure the appropriate image formats for your application: * * https://touchgfx.zendesk.com/hc/en-us/articles/206725849 *//* ... */ extern "C" { #include "stm32f4xx_hal.h" #include "stm32f4xx_hal_dsi.h" #include "stm32469i_eval.h" #include "stm32469i_eval_sdram.h" #include "stm32469i_eval_qspi.h" 5 includes bool os_inited = false; LTDC_HandleTypeDef hltdc; DSI_HandleTypeDef hdsi; DMA2D_HandleTypeDef hdma2d; extern "C" { static DSI_CmdCfgTypeDef CmdCfg; static DSI_LPCmdTypeDef LPCmd; static DSI_PLLInitTypeDef dsiPllInit; static RCC_PeriphCLKInitTypeDef PeriphClkInitStruct; uint32_t LCD_GetXSize() { return OTM8009A_800X480_WIDTH; }{ ... } uint32_t LCD_GetYSize() { return OTM8009A_800X480_HEIGHT; }{ ... } }extern "C" { ... } #define VSYNC 1 #define VBP 1 #define VFP 1 #define VACT 480 #define HSYNC 1 #define HBP 1 #define HFP 1 #define LAYER0_ADDRESS (0xC0000000) 8 defines #if !defined(USE_BPP) || USE_BPP==16 #define HACT 200 /* Note: 16bpp: Screen divided in 4 areas of 200 pixels to avoid DSI tearing */ #elif USE_BPP==24 #define HACT 400 /* Note: 24bpp: Screen divided in 2 areas of 400 pixels to avoid DSI tearing */ #else #error Unknown USE_BPP #endif }extern "C" { ... } uint8_t pCols[4][4] = { {0x00, 0x00, 0x00, 0xC7}, /* 0 -> 199 */ {0x00, 0xC8, 0x01, 0x8F}, /* 200 -> 399 */ {0x01, 0x90, 0x02, 0x57}, /* 400 -> 599 */ {0x02, 0x58, 0x03, 0x1F}, /* 600 -> 799 */ ...}; uint8_t pColLeft[] = {0x00, 0x00, 0x01, 0x8F}; /* 0 -> 399 */ uint8_t pColRight[] = {0x01, 0x90, 0x03, 0x1F}; /* 400 -> 799 */ uint8_t pPage[] = {0x00, 0x00, 0x01, 0xDF}; /* 0 -> 479 */ uint8_t pScanCol[] = {0x02, 0x15}; /* Scan @ 533 */ static uint32_t frameBuf0 = (uint32_t)(LAYER0_ADDRESS); static void SystemClock_Config(); static void LTDC_Init(); static uint8_t LCD_Init(void); static void LCD_LayerInit(uint16_t LayerIndex, uint32_t Address); namespace touchgfx { void hw_init() { HAL_Init(); __HAL_RCC_CRC_CLK_ENABLE(); /* Configure the system clock to 180 MHz */ SystemClock_Config(); /* Initialize QSPI */ BSP_QSPI_Init(); BSP_QSPI_EnableMemoryMappedMode(); HAL_NVIC_DisableIRQ(QUADSPI_IRQn); /* Initialize the SDRAM */ BSP_SDRAM_Init(); /* Initialize the display */ LCD_Init(); GPIO::init(); }{ ... } STM32F4DMA dma; OTM8009TouchController tc; STM32F4Instrumentation mcuInstr; #if !defined(USE_BPP) || USE_BPP==16 static LCD16bpp display; static uint16_t bitDepth = 16;/* ... */ #elif USE_BPP==24 static LCD24bpp display; static uint16_t bitDepth = 24;/* ... */ #else #error Unknown USE_BPP #endif void touchgfx_init() { uint16_t dispWidth = 800; uint16_t dispHeight = 480; #if !defined(USE_BPP) || USE_BPP==16 HAL& hal = touchgfx_generic_init<STM32F4HAL_DSI>(dma, display, tc, dispWidth, dispHeight, (uint16_t*)(frameBuf0 + (dispWidth * dispHeight * 2) * 2), 2 * 1024 * 1024, 16);/* ... */ #else HAL& hal = touchgfx_generic_init<STM32F4HAL_DSI>(dma, display, tc, dispWidth, dispHeight, (uint16_t*)(frameBuf0 + (dispWidth * dispHeight * 3) * 2), 2 * 1024 * 1024, 16);/* ... */ #endif os_inited = true; hal.setFrameBufferStartAddress((uint16_t*)frameBuf0, bitDepth, false, true); // By default frame rate compensation is off. // Enable frame rate compensation to smooth out animations in case there is periodic slow frame rates. hal.setFrameRateCompensation(false); hal.setTouchSampleRate(1); hal.setFingerSize(10); // This platform can handle simultaneous DMA and TFT accesses to SDRAM, so disable lock to increase performance. hal.lockDMAToFrontPorch(false); mcuInstr.init(); //Set MCU instrumentation and Load calculation hal.setMCUInstrumentation(&mcuInstr); hal.enableMCULoadCalculation(true); }{ ... } }... extern "C" { /** * Request TE at scanline. *//* ... */ void LCD_ReqTear(void) { uint8_t ScanLineParams[2]; uint16_t scanline = 533; ScanLineParams[0] = scanline >> 8; ScanLineParams[1] = scanline & 0x00FF; HAL_DSI_LongWrite(&hdsi, 0, DSI_DCS_LONG_PKT_WRITE, 2, 0x44, ScanLineParams); HAL_DSI_ShortWrite(&hdsi, 0, DSI_DCS_SHORT_PKT_WRITE_P1, 0x35, 0x00); }{ ... } void LCD_SetUpdateRegion(int idx) { HAL_DSI_LongWrite(&hdsi, 0, DSI_DCS_LONG_PKT_WRITE, 4, OTM8009A_CMD_CASET, pCols[idx]); }{ ... } void LCD_SetUpdateRegionLeft() { HAL_DSI_LongWrite(&hdsi, 0, DSI_DCS_LONG_PKT_WRITE, 4, OTM8009A_CMD_CASET, pColLeft); }{ ... } void LCD_SetUpdateRegionRight() { HAL_DSI_LongWrite(&hdsi, 0, DSI_DCS_LONG_PKT_WRITE, 4, OTM8009A_CMD_CASET, pColRight); }{ ... } }extern "C" { ... } /** * @brief System Clock Configuration * The system Clock is configured as follow : * System Clock source = PLL (HSE) * SYSCLK(Hz) = 180000000 * HCLK(Hz) = 180000000 * AHB Prescaler = 1 * APB1 Prescaler = 4 * APB2 Prescaler = 2 * HSE Frequency(Hz) = 25000000 * PLL_M = 25 * PLL_N = 360 * PLL_P = 2 * PLL_Q = 7 * PLL_R = 6 * VDD(V) = 3.3 * Main regulator output voltage = Scale1 mode * Flash Latency(WS) = 5 * @param None * @retval None *//* ... */ static void SystemClock_Config(void) { RCC_ClkInitTypeDef RCC_ClkInitStruct; RCC_OscInitTypeDef RCC_OscInitStruct; HAL_StatusTypeDef ret = HAL_OK; /* Enable Power Control clock */ __HAL_RCC_PWR_CLK_ENABLE(); /* The voltage scaling allows optimizing the power consumption when the device is clocked below the maximum system frequency, to update the voltage scaling value regarding system frequency refer to product datasheet. *//* ... */ __HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE1); /* Enable HSE Oscillator and activate PLL with HSE as source */ RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE; RCC_OscInitStruct.HSEState = RCC_HSE_ON; RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON; RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE; RCC_OscInitStruct.PLL.PLLM = 25; RCC_OscInitStruct.PLL.PLLN = 360; RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV2; RCC_OscInitStruct.PLL.PLLQ = 7; RCC_OscInitStruct.PLL.PLLR = 6; ret = HAL_RCC_OscConfig(&RCC_OscInitStruct); if(ret != HAL_OK) { while(1) { ; } }if (ret != HAL_OK) { ... } /* Activate the OverDrive to reach the 180 MHz Frequency */ ret = HAL_PWREx_EnableOverDrive(); if(ret != HAL_OK) { while(1) { ; } }if (ret != HAL_OK) { ... } /* Select PLL as system clock source and configure the HCLK, PCLK1 and PCLK2 clocks dividers */ RCC_ClkInitStruct.ClockType = (RCC_CLOCKTYPE_SYSCLK | RCC_CLOCKTYPE_HCLK | RCC_CLOCKTYPE_PCLK1 | RCC_CLOCKTYPE_PCLK2); RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK; RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1; RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV4; RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV2; ret = HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_5); if(ret != HAL_OK) { while(1) { ; } }if (ret != HAL_OK) { ... } }{ ... } /** * @brief BSP LCD Reset * Hw reset the LCD DSI activating its XRES signal (active low for some time) * and desactivating it later. * This signal is only cabled on Discovery Rev B and beyond. *//* ... */ static void LCD_Reset(void) { #if !defined(USE_STM32469I_EVAL_REVA) /* EVAL Rev B and beyond : reset the LCD by activation of XRES (active low) connected to PK7 */ GPIO_InitTypeDef gpio_init_structure; __HAL_RCC_GPIOK_CLK_ENABLE(); /* Configure the GPIO on PK7 */ gpio_init_structure.Pin = GPIO_PIN_7; gpio_init_structure.Mode = GPIO_MODE_OUTPUT_PP; gpio_init_structure.Pull = GPIO_PULLUP; gpio_init_structure.Speed = GPIO_SPEED_HIGH; HAL_GPIO_Init(GPIOK, &gpio_init_structure); /* Activate XRES active low */ HAL_GPIO_WritePin(GPIOK, GPIO_PIN_7, GPIO_PIN_RESET); HAL_Delay(20); /* wait 20 ms */ /* Deactivate XRES */ HAL_GPIO_WritePin(GPIOK, GPIO_PIN_7, GPIO_PIN_SET); /* Wait for 10ms after releasing XRES before sending commands */ HAL_Delay(10); /* ... */ #else #endif /* USE_STM32469I_EVAL_REVA == 0 */ }{ ... } static void LCD_MspInit(void) { /** @brief Enable the LTDC clock */ __HAL_RCC_LTDC_CLK_ENABLE(); /** @brief Toggle Sw reset of LTDC IP */ __HAL_RCC_LTDC_FORCE_RESET(); __HAL_RCC_LTDC_RELEASE_RESET(); /** @brief Enable the DMA2D clock */ __HAL_RCC_DMA2D_CLK_ENABLE(); /** @brief Toggle Sw reset of DMA2D IP */ __HAL_RCC_DMA2D_FORCE_RESET(); __HAL_RCC_DMA2D_RELEASE_RESET(); /** @brief Enable DSI Host and wrapper clocks */ __HAL_RCC_DSI_CLK_ENABLE(); /** @brief Soft Reset the DSI Host and wrapper */ __HAL_RCC_DSI_FORCE_RESET(); __HAL_RCC_DSI_RELEASE_RESET(); /** @brief NVIC configuration for LTDC interrupt that is now enabled */ HAL_NVIC_SetPriority(LTDC_IRQn, 3, 0); HAL_NVIC_EnableIRQ(LTDC_IRQn); /** @brief NVIC configuration for DMA2D interrupt that is now enabled */ HAL_NVIC_SetPriority(DMA2D_IRQn, 3, 0); HAL_NVIC_EnableIRQ(DMA2D_IRQn); /** @brief NVIC configuration for DSI interrupt that is now enabled */ HAL_NVIC_SetPriority(DSI_IRQn, 3, 0); HAL_NVIC_EnableIRQ(DSI_IRQn); }{ ... } /** * @brief Initializes the LCD layers. * @param LayerIndex: Layer foreground or background * @param FB_Address: Layer frame buffer * @retval None *//* ... */ static void LCD_LayerInit(uint16_t LayerIndex, uint32_t Address) { LTDC_LayerCfgTypeDef Layercfg; /* Layer Init */ Layercfg.WindowX0 = 0; Layercfg.WindowY0 = 0; Layercfg.WindowY1 = LCD_GetYSize(); Layercfg.FBStartAdress = Address; Layercfg.Alpha = 255; Layercfg.Alpha0 = 0; Layercfg.Backcolor.Blue = 0; Layercfg.Backcolor.Green = 0; Layercfg.Backcolor.Red = 0; Layercfg.ImageHeight = LCD_GetYSize(); #if !defined(USE_BPP) || USE_BPP==16 Layercfg.WindowX1 = LCD_GetXSize() / 4; //Note: Div4 due to screen being divided into 4 areas. Layercfg.PixelFormat = LTDC_PIXEL_FORMAT_RGB565; Layercfg.BlendingFactor1 = LTDC_BLENDING_FACTOR1_CA; Layercfg.BlendingFactor2 = LTDC_BLENDING_FACTOR2_CA; Layercfg.ImageWidth = LCD_GetXSize() / 4; //Note: Div4 due to screen being divided into 4 areas./* ... */ #elif USE_BPP==24 Layercfg.WindowX1 = LCD_GetXSize() / 2; //Note: Div2 due to screen being divided into 2 areas. Layercfg.PixelFormat = LTDC_PIXEL_FORMAT_RGB888; Layercfg.BlendingFactor1 = LTDC_BLENDING_FACTOR1_PAxCA; Layercfg.BlendingFactor2 = LTDC_BLENDING_FACTOR2_PAxCA; Layercfg.ImageWidth = LCD_GetXSize() / 2; //Note: Div2 due to screen being divided into 2 areas./* ... */ #else #error Unknown USE_BPP #endif HAL_LTDC_ConfigLayer(&hltdc, &Layercfg, LayerIndex); }{ ... } /** * @brief Initialize the LTDC * @param None * @retval None *//* ... */ static void LTDC_Init(void) { /* DeInit */ HAL_LTDC_DeInit(&hltdc); /* LTDC Config */ /* Timing and polarity */ hltdc.Init.HorizontalSync = HSYNC; hltdc.Init.VerticalSync = VSYNC; hltdc.Init.AccumulatedHBP = HSYNC + HBP; hltdc.Init.AccumulatedVBP = VSYNC + VBP; hltdc.Init.AccumulatedActiveH = VSYNC + VBP + VACT; hltdc.Init.AccumulatedActiveW = HSYNC + HBP + HACT; hltdc.Init.TotalHeigh = VSYNC + VBP + VACT + VFP; hltdc.Init.TotalWidth = HSYNC + HBP + HACT + HFP; /* 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); }{ ... } /** * @brief DCS or Generic short/long write command * @param NbParams: Number of parameters. It indicates the write command mode: * If inferior to 2, a long write command is performed else short. * @param pParams: Pointer to parameter values table. * @retval HAL status *//* ... */ extern "C" void DSI_IO_WriteCmd(uint32_t NbrParams, uint8_t *pParams) { if (NbrParams <= 1) HAL_DSI_ShortWrite(&hdsi, 0, DSI_DCS_SHORT_PKT_WRITE_P1, pParams[0], pParams[1]); else HAL_DSI_LongWrite(&hdsi, 0, DSI_DCS_LONG_PKT_WRITE, NbrParams, pParams[NbrParams], pParams); }{ ... } /** * @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 None * @retval LCD state *//* ... */ static uint8_t LCD_Init(void) { GPIO_InitTypeDef GPIO_Init_Structure; DSI_PHY_TimerTypeDef PhyTimings; LCD_Reset(); LCD_MspInit(); /* Configure DSI TE pin on GPIOJ2 */ __HAL_RCC_GPIOJ_CLK_ENABLE(); GPIO_Init_Structure.Pin = GPIO_PIN_2; GPIO_Init_Structure.Mode = GPIO_MODE_AF_PP; GPIO_Init_Structure.Pull = GPIO_NOPULL; GPIO_Init_Structure.Speed = GPIO_SPEED_HIGH; GPIO_Init_Structure.Alternate = GPIO_AF13_DSI; HAL_GPIO_Init(GPIOJ, &GPIO_Init_Structure); /* LCD clock configuration, 417/5/2 = 41.7MHz */ PeriphClkInitStruct.PeriphClockSelection = RCC_PERIPHCLK_LTDC; PeriphClkInitStruct.PLLSAI.PLLSAIN = 250; PeriphClkInitStruct.PLLSAI.PLLSAIR = 5; PeriphClkInitStruct.PLLSAIDivR = RCC_PLLSAIDIVR_2; HAL_RCCEx_PeriphCLKConfig(&PeriphClkInitStruct); /* Base address of DSI Host/Wrapper registers to be set before calling De-Init */ hdsi.Instance = DSI; HAL_DSI_DeInit(&hdsi); dsiPllInit.PLLNDIV = 100; dsiPllInit.PLLIDF = DSI_PLL_IN_DIV5; dsiPllInit.PLLODF = DSI_PLL_OUT_DIV1; hdsi.Init.NumberOfLanes = DSI_TWO_DATA_LANES; hdsi.Init.TXEscapeCkdiv = 0x4; HAL_DSI_Init(&hdsi, &dsiPllInit); /* Configure the DSI for Command mode */ CmdCfg.VirtualChannelID = 0; CmdCfg.HSPolarity = DSI_HSYNC_ACTIVE_HIGH; CmdCfg.VSPolarity = DSI_VSYNC_ACTIVE_HIGH; CmdCfg.DEPolarity = DSI_DATA_ENABLE_ACTIVE_HIGH; CmdCfg.CommandSize = HACT; CmdCfg.TearingEffectSource = DSI_TE_EXTERNAL; CmdCfg.TearingEffectPolarity = DSI_TE_RISING_EDGE; CmdCfg.VSyncPol = DSI_VSYNC_FALLING; CmdCfg.AutomaticRefresh = DSI_AR_DISABLE; CmdCfg.TEAcknowledgeRequest = DSI_TE_ACKNOWLEDGE_ENABLE; #if !defined(USE_BPP) || USE_BPP==16 CmdCfg.ColorCoding = DSI_RGB565; #elif USE_BPP==24 CmdCfg.ColorCoding = DSI_RGB888; #else #error Unknown USE_BPP #endif HAL_DSI_ConfigAdaptedCommandMode(&hdsi, &CmdCfg); LPCmd.LPGenShortWriteNoP = DSI_LP_GSW0P_ENABLE; LPCmd.LPGenShortWriteOneP = DSI_LP_GSW1P_ENABLE; LPCmd.LPGenShortWriteTwoP = DSI_LP_GSW2P_ENABLE; LPCmd.LPGenShortReadNoP = DSI_LP_GSR0P_ENABLE; LPCmd.LPGenShortReadOneP = DSI_LP_GSR1P_ENABLE; LPCmd.LPGenShortReadTwoP = DSI_LP_GSR2P_ENABLE; LPCmd.LPGenLongWrite = DSI_LP_GLW_ENABLE; LPCmd.LPDcsShortWriteNoP = DSI_LP_DSW0P_ENABLE; LPCmd.LPDcsShortWriteOneP = DSI_LP_DSW1P_ENABLE; LPCmd.LPDcsShortReadNoP = DSI_LP_DSR0P_ENABLE; LPCmd.LPDcsLongWrite = DSI_LP_DLW_ENABLE; HAL_DSI_ConfigCommand(&hdsi, &LPCmd); /* Configure DSI PHY HS2LP and LP2HS timings */ PhyTimings.ClockLaneHS2LPTime = 35; PhyTimings.ClockLaneLP2HSTime = 35; PhyTimings.DataLaneHS2LPTime = 35; PhyTimings.DataLaneLP2HSTime = 35; PhyTimings.DataLaneMaxReadTime = 0; PhyTimings.StopWaitTime = 10; HAL_DSI_ConfigPhyTimer(&hdsi, &PhyTimings); /* Initialize LTDC */ LTDC_Init(); __HAL_LTDC_DISABLE(&hltdc); /* Start DSI */ HAL_DSI_Start(&hdsi); #if !defined(USE_BPP) || USE_BPP==16 OTM8009A_Init(OTM8009A_FORMAT_RBG565, 1); #elif USE_BPP==24 OTM8009A_Init(OTM8009A_FORMAT_RGB888, 1); #else #error Unknown USE_BPP #endif LPCmd.LPGenShortWriteNoP = DSI_LP_GSW0P_DISABLE; LPCmd.LPGenShortWriteOneP = DSI_LP_GSW1P_DISABLE; LPCmd.LPGenShortWriteTwoP = DSI_LP_GSW2P_DISABLE; LPCmd.LPGenShortReadNoP = DSI_LP_GSR0P_DISABLE; LPCmd.LPGenShortReadOneP = DSI_LP_GSR1P_DISABLE; LPCmd.LPGenShortReadTwoP = DSI_LP_GSR2P_DISABLE; LPCmd.LPGenLongWrite = DSI_LP_GLW_DISABLE; LPCmd.LPDcsShortWriteNoP = DSI_LP_DSW0P_DISABLE; LPCmd.LPDcsShortWriteOneP = DSI_LP_DSW1P_DISABLE; LPCmd.LPDcsShortReadNoP = DSI_LP_DSR0P_DISABLE; LPCmd.LPDcsLongWrite = DSI_LP_DLW_DISABLE; HAL_DSI_ConfigCommand(&hdsi, &LPCmd); /* Initialize LTDC layer 0 iused for Hint */ LCD_LayerInit(0, LAYER0_ADDRESS); /* Update pitch: drawing is done on the whole physical X Size */ HAL_LTDC_SetPitch(&hltdc, LCD_GetXSize(), 0); /* Finally enable the LTDC IP */ __HAL_LTDC_ENABLE(&hltdc); return 0; }{ ... }