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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
65
66
67
68
69
70
71
72
73
74
75
76
77
81
82
86
87
88
97
98
99
100
101
102
103
104
105
106
107
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
159
160
162
163
164
165
166
167
168
169
170
171
174
175
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
206
207
208
209
210
211
212
213
214
215
216
217
218
222
223
227
228
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
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
285
286
287
288
292
293
294
295
296
297
298
299
300
301
305
306
307
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
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
407
408
413
414
415
416
417
418
419
420
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
463
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
/* ... */
#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
/* ... */
/* ... */
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
#elif USE_BPP==24
#define HACT 400
#else
#error Unknown USE_BPP
#endif
}extern "C" { ... }
uint8_t pCols[4][4] =
{
{0x00, 0x00, 0x00, 0xC7},
{0x00, 0xC8, 0x01, 0x8F},
{0x01, 0x90, 0x02, 0x57},
{0x02, 0x58, 0x03, 0x1F},
...};
uint8_t pColLeft[] = {0x00, 0x00, 0x01, 0x8F};
uint8_t pColRight[] = {0x01, 0x90, 0x03, 0x1F};
uint8_t pPage[] = {0x00, 0x00, 0x01, 0xDF};
uint8_t pScanCol[] = {0x02, 0x15};
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();
SystemClock_Config();
BSP_QSPI_Init();
BSP_QSPI_EnableMemoryMappedMode();
HAL_NVIC_DisableIRQ(QUADSPI_IRQn);
BSP_SDRAM_Init();
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);
hal.setFrameRateCompensation(false);
hal.setTouchSampleRate(1);
hal.setFingerSize(10);
hal.lockDMAToFrontPorch(false);
mcuInstr.init();
hal.setMCUInstrumentation(&mcuInstr);
hal.enableMCULoadCalculation(true);
}{ ... }
}...
extern "C"
{
/* ... */
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" { ... }
/* ... */
static void SystemClock_Config(void)
{
RCC_ClkInitTypeDef RCC_ClkInitStruct;
RCC_OscInitTypeDef RCC_OscInitStruct;
HAL_StatusTypeDef ret = HAL_OK;
__HAL_RCC_PWR_CLK_ENABLE();
/* ... */
__HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE1);
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) { ... }
ret = HAL_PWREx_EnableOverDrive();
if(ret != HAL_OK)
{
while(1) { ; }
}if (ret != HAL_OK) { ... }
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) { ... }
}{ ... }
/* ... */
static void LCD_Reset(void)
{
#if !defined(USE_STM32469I_EVAL_REVA)
GPIO_InitTypeDef gpio_init_structure;
__HAL_RCC_GPIOK_CLK_ENABLE();
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);
HAL_GPIO_WritePin(GPIOK, GPIO_PIN_7, GPIO_PIN_RESET);
HAL_Delay(20);
HAL_GPIO_WritePin(GPIOK, GPIO_PIN_7, GPIO_PIN_SET);
HAL_Delay(10); /* ... */
#else
#endif
}{ ... }
static void LCD_MspInit(void)
{
__HAL_RCC_LTDC_CLK_ENABLE();
__HAL_RCC_LTDC_FORCE_RESET();
__HAL_RCC_LTDC_RELEASE_RESET();
__HAL_RCC_DMA2D_CLK_ENABLE();
__HAL_RCC_DMA2D_FORCE_RESET();
__HAL_RCC_DMA2D_RELEASE_RESET();
__HAL_RCC_DSI_CLK_ENABLE();
__HAL_RCC_DSI_FORCE_RESET();
__HAL_RCC_DSI_RELEASE_RESET();
HAL_NVIC_SetPriority(LTDC_IRQn, 3, 0);
HAL_NVIC_EnableIRQ(LTDC_IRQn);
HAL_NVIC_SetPriority(DMA2D_IRQn, 3, 0);
HAL_NVIC_EnableIRQ(DMA2D_IRQn);
HAL_NVIC_SetPriority(DSI_IRQn, 3, 0);
HAL_NVIC_EnableIRQ(DSI_IRQn);
}{ ... }
/* ... */
static void LCD_LayerInit(uint16_t LayerIndex, uint32_t Address)
{
LTDC_LayerCfgTypeDef Layercfg;
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;
Layercfg.PixelFormat = LTDC_PIXEL_FORMAT_RGB565;
Layercfg.BlendingFactor1 = LTDC_BLENDING_FACTOR1_CA;
Layercfg.BlendingFactor2 = LTDC_BLENDING_FACTOR2_CA;
Layercfg.ImageWidth = LCD_GetXSize() / 4; /* ... */
#elif USE_BPP==24
Layercfg.WindowX1 = LCD_GetXSize() / 2;
Layercfg.PixelFormat = LTDC_PIXEL_FORMAT_RGB888;
Layercfg.BlendingFactor1 = LTDC_BLENDING_FACTOR1_PAxCA;
Layercfg.BlendingFactor2 = LTDC_BLENDING_FACTOR2_PAxCA;
Layercfg.ImageWidth = LCD_GetXSize() / 2; /* ... */
#else
#error Unknown USE_BPP
#endif
HAL_LTDC_ConfigLayer(&hltdc, &Layercfg, LayerIndex);
}{ ... }
/* ... */
static void LTDC_Init(void)
{
HAL_LTDC_DeInit(&hltdc);
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;
hltdc.Init.Backcolor.Blue = 0;
hltdc.Init.Backcolor.Green = 0;
hltdc.Init.Backcolor.Red = 0;
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);
}{ ... }
/* ... */
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);
}{ ... }
/* ... */
static uint8_t LCD_Init(void)
{
GPIO_InitTypeDef GPIO_Init_Structure;
DSI_PHY_TimerTypeDef PhyTimings;
LCD_Reset();
LCD_MspInit();
__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);
PeriphClkInitStruct.PeriphClockSelection = RCC_PERIPHCLK_LTDC;
PeriphClkInitStruct.PLLSAI.PLLSAIN = 250;
PeriphClkInitStruct.PLLSAI.PLLSAIR = 5;
PeriphClkInitStruct.PLLSAIDivR = RCC_PLLSAIDIVR_2;
HAL_RCCEx_PeriphCLKConfig(&PeriphClkInitStruct);
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);
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);
PhyTimings.ClockLaneHS2LPTime = 35;
PhyTimings.ClockLaneLP2HSTime = 35;
PhyTimings.DataLaneHS2LPTime = 35;
PhyTimings.DataLaneLP2HSTime = 35;
PhyTimings.DataLaneMaxReadTime = 0;
PhyTimings.StopWaitTime = 10;
HAL_DSI_ConfigPhyTimer(&hdsi, &PhyTimings);
LTDC_Init();
__HAL_LTDC_DISABLE(&hltdc);
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);
LCD_LayerInit(0, LAYER0_ADDRESS);
HAL_LTDC_SetPitch(&hltdc, LCD_GetXSize(), 0);
__HAL_LTDC_ENABLE(&hltdc);
return 0;
}{ ... }