STM32F769IDiscovery  1.00
uDANTE Audio Networking with STM32F7 DISCO board
LCDConf.c
Go to the documentation of this file.
1 
48 /* Includes ------------------------------------------------------------------*/
49 #include "LCDConf.h"
50 #include "GUI_Private.h"
51 
67 LTDC_HandleTypeDef hltdc_eval;
68 DSI_HandleTypeDef hdsi_eval;
69  DSI_VidCfgTypeDef hdsivideo_handle;
70 
74 #undef LCD_SWAP_XY
75 #undef LCD_MIRROR_Y
76 
77 #define LCD_SWAP_XY 1
78 #define LCD_MIRROR_Y 1
79 
80 #define XSIZE_PHYS 800
81 #define YSIZE_PHYS 480
82 
83 #define NUM_BUFFERS 3 /* Number of multiple buffers to be used */
84 #define NUM_VSCREENS 1 /* Number of virtual screens to be used */
85 
86 #define BK_COLOR GUI_DARKBLUE
87 
88 #undef GUI_NUM_LAYERS
89 #define GUI_NUM_LAYERS 2
90 
91 #define COLOR_CONVERSION_0 GUICC_M565
92 #define DISPLAY_DRIVER_0 GUIDRV_LIN_16
93 
94 
95 #if (GUI_NUM_LAYERS > 1)
96  #define COLOR_CONVERSION_1 GUICC_M1555I
97  #define DISPLAY_DRIVER_1 GUIDRV_LIN_16
98 
99 #endif
100 
101 #ifndef XSIZE_PHYS
102  #error Physical X size of display is not defined!
103 #endif
104 #ifndef YSIZE_PHYS
105  #error Physical Y size of display is not defined!
106 #endif
107 #ifndef NUM_VSCREENS
108  #define NUM_VSCREENS 1
109 #else
110  #if (NUM_VSCREENS <= 0)
111  #error At least one screeen needs to be defined!
112  #endif
113 #endif
114 #if (NUM_VSCREENS > 1) && (NUM_BUFFERS > 1)
115  #error Virtual screens and multiple buffers are not allowed!
116 #endif
117 
118 /************************************************************* To Be Verified */
119 /* From SDRAM */
120 #define LCD_LAYER0_FRAME_BUFFER ((int)0xC0400000)
121 #define LCD_LAYER1_FRAME_BUFFER ((int)0xC0800000)
122 
136 
137 static const LCD_API_COLOR_CONV * apColorConvAPI[] =
138 {
140 #if GUI_NUM_LAYERS > 1
142 #endif
143 };
144 
152 static U32 GetPixelformat(U32 LayerIndex);
153 static U32 GetBufferSize(U32 LayerIndex);
154 
155 static void DMA2D_CopyBufferWithAlpha(U32 LayerIndex, void * pSrc, void * pDst, U32 xSize, U32 ySize, U32 OffLineSrc, U32 OffLineDst);
156 static void DMA2D_CopyBuffer (U32 LayerIndex, void * pSrc, void * pDst, U32 xSize, U32 ySize, U32 OffLineSrc, U32 OffLineDst);
157 static void DMA2D_FillBuffer(U32 LayerIndex, void * pDst, U32 xSize, U32 ySize, U32 OffLine, U32 ColorIndex);
158 
159 static void LCD_LL_Init(void);
160 static void LCD_LL_Reset(void);
161 static void LCD_LL_CopyBuffer(int LayerIndex, int IndexSrc, int IndexDst);
162 static void LCD_LL_CopyRect(int LayerIndex, int x0, int y0, int x1, int y1, int xSize, int ySize);
163 static void LCD_LL_FillRect(int LayerIndex, int x0, int y0, int x1, int y1, U32 PixelIndex);
164 static void LCD_LL_DrawBitmap8bpp(int LayerIndex, int x, int y, U8 const * p, int xSize, int ySize, int BytesPerLine);
165 void LCD_LL_DrawBitmap16bpp(int LayerIndex, int x, int y, U16 const * p, int xSize, int ySize, int BytesPerLine);
166 void LCD_LL_DrawBitmap32bpp(int LayerIndex, int x, int y, U8 const * p, int xSize, int ySize, int BytesPerLine);
167 
168 
176 void DSI_IO_WriteCmd(uint32_t NbrParams, uint8_t *pParams)
177 {
178  if(NbrParams <= 1)
179  {
180  HAL_DSI_ShortWrite(&hdsi_eval, 0, DSI_DCS_SHORT_PKT_WRITE_P1, pParams[0], pParams[1]);
181  }
182  else
183  {
184  HAL_DSI_LongWrite(&hdsi_eval, 0, DSI_DCS_LONG_PKT_WRITE, NbrParams, pParams[NbrParams], pParams);
185  }
186 }
187 
194 static void LCD_LL_Reset(void)
195 {
196  GPIO_InitTypeDef gpio_init_structure;
197 
199 
200  /* Configure the GPIO on PK7 */
201  gpio_init_structure.Pin = GPIO_PIN_15;
202  gpio_init_structure.Mode = GPIO_MODE_OUTPUT_PP;
203  gpio_init_structure.Pull = GPIO_PULLUP;
204  gpio_init_structure.Speed = GPIO_SPEED_HIGH;
205 
206  HAL_GPIO_Init(GPIOJ, &gpio_init_structure);
207 
208  /* Activate XRES active low */
210 
211  HAL_Delay(20); /* wait 20 ms */
212 
213  /* Desactivate XRES */
215 
216  /* Wait after releasing RESX before sending commands */
217  HAL_Delay(10); /* wait 10 ms */
218 
219 }
220 
226 static void LCD_LL_Init(void)
227 {
228  DSI_PLLInitTypeDef dsiPllInit;
229 
231 
232  uint32_t LcdClock = 27429;
233  uint32_t Clockratio = 0;
234  uint32_t lcd_x_size = 0;
235  uint32_t lcd_y_size = 0;
236  uint32_t laneByteClk_kHz = 0;
237  uint32_t VSA;
238  uint32_t VBP;
239  uint32_t VFP;
240  uint32_t VACT;
241  uint32_t HSA;
242  uint32_t HBP;
243  uint32_t HFP;
244  uint32_t HACT;
245 
246 
247  /* Toggle Hardware Reset of the DSI LCD using
248  * its XRES signal (active low) */
249  LCD_LL_Reset();
250 
252  __HAL_RCC_LTDC_CLK_ENABLE();
253 
255  __HAL_RCC_LTDC_FORCE_RESET();
256  __HAL_RCC_LTDC_RELEASE_RESET();
257 
260 
264 
266  __HAL_RCC_DSI_CLK_ENABLE();
267 
269  __HAL_RCC_DSI_FORCE_RESET();
270  __HAL_RCC_DSI_RELEASE_RESET();
271 
275 
276  /* Base address of DSI Host/Wrapper registers to be set before calling De-Init */
277  hdsi_eval.Instance = DSI;
278 
279  HAL_DSI_DeInit(&(hdsi_eval));
280 
281  dsiPllInit.PLLNDIV = 100;
282  dsiPllInit.PLLIDF = DSI_PLL_IN_DIV5;
283  dsiPllInit.PLLODF = DSI_PLL_OUT_DIV1;
284  laneByteClk_kHz = 62500; /* 500 MHz / 8 = 62.5 MHz = 62500 kHz */
285 
286  /* Set number of Lanes */
287  hdsi_eval.Init.NumberOfLanes = DSI_TWO_DATA_LANES;
288 
289  /* TXEscapeCkdiv = f(LaneByteClk)/15.62 = 4 */
290  hdsi_eval.Init.TXEscapeCkdiv = laneByteClk_kHz/15620;
291 
292  HAL_DSI_Init(&(hdsi_eval), &(dsiPllInit));
293  Clockratio = laneByteClk_kHz/LcdClock;
294  /* Timing parameters for all Video modes
295  * Set Timing parameters of LTDC depending on its chosen orientation
296  */
297  /* lcd_orientation == LCD_ORIENTATION_LANDSCAPE */
298  VSA = OTM8009A_800X480_VSYNC; /* 12 */
299  VBP = OTM8009A_800X480_VBP; /* 12 */
300  VFP = OTM8009A_800X480_VFP; /* 12 */
301  HSA = OTM8009A_800X480_HSYNC; /* 120 */
302  HBP = OTM8009A_800X480_HBP; /* 120 */
303  HFP = OTM8009A_800X480_HFP; /* 120 */
304  lcd_x_size = OTM8009A_800X480_WIDTH; /* 800 */
305  lcd_y_size = OTM8009A_800X480_HEIGHT; /* 480 */
306 
307  HACT = lcd_x_size;
308  VACT = lcd_y_size;
309 
310 
311  hdsivideo_handle.VirtualChannelID = 0;
313  hdsivideo_handle.VSPolarity = DSI_VSYNC_ACTIVE_HIGH;
314  hdsivideo_handle.HSPolarity = DSI_HSYNC_ACTIVE_HIGH;
315  hdsivideo_handle.DEPolarity = DSI_DATA_ENABLE_ACTIVE_HIGH;
316  hdsivideo_handle.Mode = DSI_VID_MODE_BURST; /* Mode Video burst ie : one LgP per line */
317  hdsivideo_handle.NullPacketSize = 0xFFF;
318  hdsivideo_handle.NumberOfChunks = 0;
319  hdsivideo_handle.PacketSize = HACT; /* Value depending on display orientation choice portrait/landscape */
320  hdsivideo_handle.HorizontalSyncActive = HSA*Clockratio;
321  hdsivideo_handle.HorizontalBackPorch = HBP*Clockratio;
322  hdsivideo_handle.HorizontalLine = (HACT + HSA + HBP + HFP)*Clockratio; /* Value depending on display orientation choice portrait/landscape */
323  hdsivideo_handle.VerticalSyncActive = VSA;
324  hdsivideo_handle.VerticalBackPorch = VBP;
325  hdsivideo_handle.VerticalFrontPorch = VFP;
326  hdsivideo_handle.VerticalActive = VACT; /* Value depending on display orientation choice portrait/landscape */
327 
328  /* Enable or disable sending LP command while streaming is active in video mode */
329  hdsivideo_handle.LPCommandEnable = DSI_LP_COMMAND_ENABLE; /* Enable sending commands in mode LP (Low Power) */
330 
331  /* Largest packet size possible to transmit in LP mode in VSA, VBP, VFP regions */
332  /* Only useful when sending LP packets is allowed while streaming is active in video mode */
333  hdsivideo_handle.LPLargestPacketSize = 64;
334 
335  /* Largest packet size possible to transmit in LP mode in HFP region during VACT period */
336  /* Only useful when sending LP packets is allowed while streaming is active in video mode */
337  hdsivideo_handle.LPVACTLargestPacketSize = 64;
338 
339 
340  /* Specify for each region of the video frame, if the transmission of command in LP mode is allowed in this region */
341  /* while streaming is active in video mode */
342  hdsivideo_handle.LPHorizontalFrontPorchEnable = DSI_LP_HFP_ENABLE; /* Allow sending LP commands during HFP period */
343  hdsivideo_handle.LPHorizontalBackPorchEnable = DSI_LP_HBP_ENABLE; /* Allow sending LP commands during HBP period */
344  hdsivideo_handle.LPVerticalActiveEnable = DSI_LP_VACT_ENABLE; /* Allow sending LP commands during VACT period */
345  hdsivideo_handle.LPVerticalFrontPorchEnable = DSI_LP_VFP_ENABLE; /* Allow sending LP commands during VFP period */
346  hdsivideo_handle.LPVerticalBackPorchEnable = DSI_LP_VBP_ENABLE; /* Allow sending LP commands during VBP period */
347  hdsivideo_handle.LPVerticalSyncActiveEnable = DSI_LP_VSYNC_ENABLE; /* Allow sending LP commands during VSync = VSA period */
348 
349  /* Configure DSI Video mode timings with settings set above */
350  HAL_DSI_ConfigVideoMode(&(hdsi_eval), &(hdsivideo_handle));
351 
352  /* Enable the DSI host and wrapper : but LTDC is not started yet at this stage */
353  HAL_DSI_Start(&(hdsi_eval));
354 
355  /* Timing Configuration */
356  hltdc_eval.Init.HorizontalSync = (HSA - 1);
357  hltdc_eval.Init.AccumulatedHBP = (HSA + HBP - 1);
358  hltdc_eval.Init.AccumulatedActiveW = (lcd_x_size + HSA + HBP - 1);
359  hltdc_eval.Init.TotalWidth = (lcd_x_size + HSA + HBP + HFP - 1);
360 
361  /* Initialize the LCD pixel width and pixel height */
362  hltdc_eval.LayerCfg->ImageWidth = lcd_x_size;
363  hltdc_eval.LayerCfg->ImageHeight = lcd_y_size;
364 
365 
366  /* LCD clock configuration */
367  /* PLLSAI_VCO Input = HSE_VALUE/PLL_M = 1 Mhz */
368  /* PLLSAI_VCO Output = PLLSAI_VCO Input * PLLSAIN = 384 Mhz */
369  /* PLLLCDCLK = PLLSAI_VCO Output/PLLSAIR = 384 MHz / 7 = 54.857 MHz */
370  /* LTDC clock frequency = PLLLCDCLK / LTDC_PLLSAI_DIVR_2 = 54.857 MHz / 2 = 27.429 MHz */
371  PeriphClkInitStruct.PeriphClockSelection = RCC_PERIPHCLK_LTDC;
372  PeriphClkInitStruct.PLLSAI.PLLSAIN = 384;
373  PeriphClkInitStruct.PLLSAI.PLLSAIR = 7;
374  PeriphClkInitStruct.PLLSAIDivR = RCC_PLLSAIDIVR_2;
375  HAL_RCCEx_PeriphCLKConfig(&PeriphClkInitStruct);
376 
377  /* Background value */
378  hltdc_eval.Init.Backcolor.Blue = 0;
379  hltdc_eval.Init.Backcolor.Green = 0;
380  hltdc_eval.Init.Backcolor.Red = 0;
381  hltdc_eval.Init.PCPolarity = LTDC_PCPOLARITY_IPC;
382  hltdc_eval.Instance = LTDC;
383 
384  /* Get LTDC Configuration from DSI Configuration */
385  HAL_LTDC_StructInitFromVideoConfig(&(hltdc_eval), &(hdsivideo_handle));
386 
387  /* Initialize the LTDC */
388  HAL_LTDC_Init(&hltdc_eval);
389 
391 
392  HAL_LTDC_ProgramLineEvent(&hltdc_eval, 0);
393 }
394 
395 
401 static void LCD_LL_LayerInit(U32 LayerIndex, U32 address)
402 {
403  LTDC_LayerCfgTypeDef Layercfg;
404 
405  /* Layer Init */
406  Layercfg.WindowX0 = 0;
407  Layercfg.WindowX1 = XSIZE_PHYS;
408  Layercfg.WindowY0 = 0;
409  Layercfg.WindowY1 = YSIZE_PHYS;
410  Layercfg.PixelFormat = GetPixelformat(LayerIndex);
411  Layercfg.FBStartAdress = address;
412  Layercfg.Alpha = 255;
413  Layercfg.Alpha0 = 0;
414  Layercfg.Backcolor.Blue = 0;
415  Layercfg.Backcolor.Green = 0;
416  Layercfg.Backcolor.Red = 0;
417  Layercfg.BlendingFactor1 = LTDC_BLENDING_FACTOR1_PAxCA;
418  Layercfg.BlendingFactor2 = LTDC_BLENDING_FACTOR2_PAxCA;
419  Layercfg.ImageWidth = XSIZE_PHYS;
420  Layercfg.ImageHeight = YSIZE_PHYS;
421 
422  HAL_LTDC_ConfigLayer(&hltdc_eval, &Layercfg, LayerIndex);
423 }
424 
425 
426 
432 static U32 GetPixelformat(U32 LayerIndex)
433 {
434  if (LayerIndex == 0)
435  {
436  return LTDC_PIXEL_FORMAT_RGB565;
437  }
438  else
439  {
440  return LTDC_PIXEL_FORMAT_ARGB1555;
441  }
442 }
443 
449 static void DMA2D_CopyBuffer(U32 LayerIndex, void * pSrc, void * pDst, U32 xSize, U32 ySize, U32 OffLineSrc, U32 OffLineDst)
450 {
451  U32 PixelFormat;
452 
453  PixelFormat = GetPixelformat(LayerIndex);
454  DMA2D->CR = 0x00000000UL | (1 << 9);
455 
456  /* Set up pointers */
457  DMA2D->FGMAR = (U32)pSrc;
458  DMA2D->OMAR = (U32)pDst;
459  DMA2D->FGOR = OffLineSrc;
460  DMA2D->OOR = OffLineDst;
461 
462  /* Set up pixel format */
463  DMA2D->FGPFCCR = PixelFormat;
464 
465  /* Set up size */
466  DMA2D->NLR = (U32)(xSize << 16) | (U16)ySize;
467 
468  DMA2D->CR |= DMA2D_CR_START;
469 
470  /* Wait until transfer is done */
471  while (DMA2D->CR & DMA2D_CR_START)
472  {
473  }
474 }
475 
476 /*********************************************************************
477 *
478 * CopyBuffer
479 */
480 static void DMA2D_CopyBufferWithAlpha(U32 LayerIndex, void * pSrc, void * pDst, U32 xSize, U32 ySize, U32 OffLineSrc, U32 OffLineDst)
481 {
482  uint32_t PixelFormat;
483 
484  PixelFormat = GetPixelformat(LayerIndex);
485  DMA2D->CR = 0x00000000UL | (1 << 9) | (0x2 << 16);
486 
487  /* Set up pointers */
488  DMA2D->FGMAR = (U32)pSrc;
489  DMA2D->OMAR = (U32)pDst;
490  DMA2D->BGMAR = (U32)pDst;
491  DMA2D->FGOR = OffLineSrc;
492  DMA2D->OOR = OffLineDst;
493  DMA2D->BGOR = OffLineDst;
494 
495  /* Set up pixel format */
496  DMA2D->FGPFCCR = LTDC_PIXEL_FORMAT_ARGB8888;
497  DMA2D->BGPFCCR = PixelFormat;
498  DMA2D->OPFCCR = PixelFormat;
499 
500  /* Set up size */
501  DMA2D->NLR = (U32)(xSize << 16) | (U16)ySize;
502 
503  DMA2D->CR |= DMA2D_CR_START;
504 
505  /* Wait until transfer is done */
506  while (DMA2D->CR & DMA2D_CR_START)
507  {
508  }
509 }
510 
521 static void DMA2D_FillBuffer(U32 LayerIndex, void * pDst, U32 xSize, U32 ySize, U32 OffLine, U32 ColorIndex)
522 {
523 
524  U32 PixelFormat;
525 
526  PixelFormat = GetPixelformat(LayerIndex);
527 
528  /* Set up mode */
529  DMA2D->CR = 0x00030000UL | (1 << 9);
530  DMA2D->OCOLR = ColorIndex;
531 
532  /* Set up pointers */
533  DMA2D->OMAR = (U32)pDst;
534 
535  /* Set up offsets */
536  DMA2D->OOR = OffLine;
537 
538  /* Set up pixel format */
539  DMA2D->OPFCCR = PixelFormat;
540 
541  /* Set up size */
542  DMA2D->NLR = (U32)(xSize << 16) | (U16)ySize;
543 
544  DMA2D->CR |= DMA2D_CR_START;
545 
546  /* Wait until transfer is done */
547  while (DMA2D->CR & DMA2D_CR_START)
548  {
549  }
550 }
551 
552 
558 static U32 GetBufferSize(U32 LayerIndex)
559 {
560  return (layer_prop[LayerIndex].xSize * layer_prop[LayerIndex].ySize * layer_prop[LayerIndex].BytesPerPixel);
561 }
562 
570 static void LCD_LL_CopyBuffer(int LayerIndex, int IndexSrc, int IndexDst) {
571  U32 BufferSize, AddrSrc, AddrDst;
572 
573  BufferSize = GetBufferSize(LayerIndex);
574  AddrSrc = layer_prop[LayerIndex].address + BufferSize * IndexSrc;
575  AddrDst = layer_prop[LayerIndex].address + BufferSize * IndexDst;
576  DMA2D_CopyBuffer(LayerIndex, (void *)AddrSrc, (void *)AddrDst, layer_prop[LayerIndex].xSize, layer_prop[LayerIndex].ySize, 0, 0);
577  layer_prop[LayerIndex].buffer_index = IndexDst;
578 }
579 
591 static void LCD_LL_CopyRect(int LayerIndex, int x0, int y0, int x1, int y1, int xSize, int ySize)
592 {
593  U32 AddrSrc, AddrDst;
594 
595  AddrSrc = layer_prop[LayerIndex].address + (y0 * layer_prop[LayerIndex].xSize + x0) * layer_prop[LayerIndex].BytesPerPixel;
596  AddrDst = layer_prop[LayerIndex].address + (y1 * layer_prop[LayerIndex].xSize + x1) * layer_prop[LayerIndex].BytesPerPixel;
597  DMA2D_CopyBuffer(LayerIndex, (void *)AddrSrc, (void *)AddrDst, xSize, ySize, layer_prop[LayerIndex].xSize - xSize, layer_prop[LayerIndex].xSize - xSize);
598 }
599 
610 static void LCD_LL_FillRect(int LayerIndex, int x0, int y0, int x1, int y1, U32 PixelIndex)
611 {
612  U32 BufferSize, AddrDst;
613  int xSize, ySize;
614 
615  if (GUI_GetDrawMode() == GUI_DM_XOR)
616  {
618  LCD_FillRect(x0, y0, x1, y1);
619  LCD_SetDevFunc(LayerIndex, LCD_DEVFUNC_FILLRECT, (void(*)(void))LCD_LL_FillRect);
620  }
621  else
622  {
623  xSize = x1 - x0 + 1;
624  ySize = y1 - y0 + 1;
625  BufferSize = GetBufferSize(LayerIndex);
626  AddrDst = layer_prop[LayerIndex].address + BufferSize * layer_prop[LayerIndex].buffer_index + (y0 * layer_prop[LayerIndex].xSize + x0) * layer_prop[LayerIndex].BytesPerPixel;
627  DMA2D_FillBuffer(LayerIndex, (void *)AddrDst, xSize, ySize, layer_prop[LayerIndex].xSize - xSize, PixelIndex);
628  }
629 }
630 
642 static void DMA2D_DrawBitmapL8(void * pSrc, void * pDst, U32 OffSrc, U32 OffDst, U32 PixelFormatDst, U32 xSize, U32 ySize)
643 {
644  /* Set up mode */
645  DMA2D->CR = 0x00010000UL | (1 << 9); /* Control Register (Memory to memory with pixel format conversion and TCIE) */
646 
647  /* Set up pointers */
648  DMA2D->FGMAR = (U32)pSrc; /* Foreground Memory Address Register (Source address) */
649  DMA2D->OMAR = (U32)pDst; /* Output Memory Address Register (Destination address) */
650 
651  /* Set up offsets */
652  DMA2D->FGOR = OffSrc; /* Foreground Offset Register (Source line offset) */
653  DMA2D->OOR = OffDst; /* Output Offset Register (Destination line offset) */
654 
655  /* Set up pixel format */
656  DMA2D->FGPFCCR = LTDC_PIXEL_FORMAT_L8; /* Foreground PFC Control Register (Defines the input pixel format) */
657  DMA2D->OPFCCR = PixelFormatDst; /* Output PFC Control Register (Defines the output pixel format) */
658 
659  /* Set up size */
660  DMA2D->NLR = (U32)(xSize << 16) | ySize; /* Number of Line Register (Size configuration of area to be transfered) */
661 
662  /* Execute operation */
663  DMA2D->CR |= DMA2D_CR_START; /* Start operation */
664 
665  /* Wait until transfer is done */
666  while (DMA2D->CR & DMA2D_CR_START)
667  {
668  }
669  __DSB();
670 }
671 
683 void LCD_LL_DrawBitmap16bpp(int LayerIndex, int x, int y, U16 const * p, int xSize, int ySize, int BytesPerLine)
684 {
685  U32 BufferSize, AddrDst;
686  int OffLineSrc, OffLineDst;
687 
688  BufferSize = GetBufferSize(LayerIndex);
689  AddrDst = layer_prop[LayerIndex].address + BufferSize * layer_prop[LayerIndex].buffer_index + (y * layer_prop[LayerIndex].xSize + x) * layer_prop[LayerIndex].BytesPerPixel;
690  OffLineSrc = (BytesPerLine / 2) - xSize;
691  OffLineDst = layer_prop[LayerIndex].xSize - xSize;
692  DMA2D_CopyBuffer(LayerIndex, (void *)p, (void *)AddrDst, xSize, ySize, OffLineSrc, OffLineDst);
693 }
694 
695 void LCD_LL_DrawBitmap32bpp(int LayerIndex, int x, int y, U8 const * p, int xSize, int ySize, int BytesPerLine)
696 {
697  U32 BufferSize, AddrDst;
698  int OffLineSrc, OffLineDst;
699 
700  BufferSize = GetBufferSize(LayerIndex);
701  AddrDst = layer_prop[LayerIndex].address + BufferSize * layer_prop[LayerIndex].buffer_index + (y * layer_prop[LayerIndex].xSize + x) * layer_prop[LayerIndex].BytesPerPixel;
702  OffLineSrc = (BytesPerLine / 4) - xSize;
703  OffLineDst = layer_prop[LayerIndex].xSize - xSize;
704  DMA2D_CopyBufferWithAlpha(LayerIndex, (void *)p, (void *)AddrDst, xSize, ySize, OffLineSrc, OffLineDst);
705 }
706 
718 static void LCD_LL_DrawBitmap8bpp(int LayerIndex, int x, int y, U8 const * p, int xSize, int ySize, int BytesPerLine)
719 {
720  U32 BufferSize, AddrDst;
721  int OffLineSrc, OffLineDst;
722  U32 PixelFormat;
723 
724  BufferSize = GetBufferSize(LayerIndex);
725  AddrDst = layer_prop[LayerIndex].address + BufferSize * layer_prop[LayerIndex].buffer_index + (y * layer_prop[LayerIndex].xSize + x) * layer_prop[LayerIndex].BytesPerPixel;
726  OffLineSrc = BytesPerLine - xSize;
727  OffLineDst = layer_prop[LayerIndex].xSize - xSize;
728  PixelFormat = GetPixelformat(LayerIndex);
729  DMA2D_DrawBitmapL8((void *)p, (void *)AddrDst, OffLineSrc, OffLineDst, PixelFormat, xSize, ySize);
730 }
731 
738 void HAL_LTDC_LineEvenCallback(LTDC_HandleTypeDef *hltdc_eval) {
739 
740  U32 Addr;
741  U32 layer;
742 
743  for (layer = 0; layer < GUI_NUM_LAYERS; layer++)
744  {
745  if (layer_prop[layer].pending_buffer >= 0)
746  {
747  /* Calculate address of buffer to be used as visible frame buffer */
748  Addr = layer_prop[layer].address + \
749  layer_prop[layer].xSize * layer_prop[layer].ySize * layer_prop[layer].pending_buffer * layer_prop[layer].BytesPerPixel;
750 
751  __HAL_LTDC_LAYER(hltdc_eval, layer)->CFBAR = Addr;
752 
753  __HAL_LTDC_RELOAD_CONFIG(hltdc_eval);
754 
755  /* Notify STemWin that buffer is used */
756  GUI_MULTIBUF_ConfirmEx(layer, layer_prop[layer].pending_buffer);
757 
758  /* Clear pending buffer flag of layer */
759  layer_prop[layer].pending_buffer = -1;
760  }
761  }
762 
763  HAL_LTDC_ProgramLineEvent(hltdc_eval, 0);
764 
765 }
772 void LCD_X_Config(void)
773 {
774  U32 i;
775 
776  LCD_LL_Init ();
777 
778  /* At first initialize use of multiple buffers on demand */
779 #if (NUM_BUFFERS > 1)
780  for (i = 0; i < GUI_NUM_LAYERS; i++)
781  {
783  }
784 #endif
785 
786  /* Set display driver and color conversion for 1st layer */
788 
789  /* Set size of 1st layer */
790  if (LCD_GetSwapXYEx(0)) {
793  } else {
796  }
797 #if (GUI_NUM_LAYERS > 1)
798 
799  /* Set display driver and color conversion for 2nd layer */
801 
802  /* Set size of 2nd layer */
803  if (LCD_GetSwapXYEx(1)) {
806  } else {
809  }
810 #endif
811 
812 
813  /*Initialize GUI Layer structure */
814  layer_prop[0].address = LCD_LAYER0_FRAME_BUFFER;
815 
816 #if (GUI_NUM_LAYERS > 1)
817  layer_prop[1].address = LCD_LAYER1_FRAME_BUFFER;
818 #endif
819 
820  /* Setting up VRam address and custom functions for CopyBuffer-, CopyRect- and FillRect operations */
821  for (i = 0; i < GUI_NUM_LAYERS; i++)
822  {
823 
824  layer_prop[i].pColorConvAPI = (LCD_API_COLOR_CONV *)apColorConvAPI[i];
825 
826  layer_prop[i].pending_buffer = -1;
827 
828  /* Set VRAM address */
829  LCD_SetVRAMAddrEx(i, (void *)(layer_prop[i].address));
830 
831  /* Remember color depth for further operations */
832  layer_prop[i].BytesPerPixel = LCD_GetBitsPerPixelEx(i) >> 3;
833 
834  /* Set custom functions for several operations */
835  LCD_SetDevFunc(i, LCD_DEVFUNC_COPYBUFFER, (void(*)(void))LCD_LL_CopyBuffer);
836  LCD_SetDevFunc(i, LCD_DEVFUNC_COPYRECT, (void(*)(void))LCD_LL_CopyRect);
837 
838  /* Filling via DMA2D does only work with 16bpp or more */
839  LCD_SetDevFunc(i, LCD_DEVFUNC_FILLRECT, (void(*)(void))LCD_LL_FillRect);
840  LCD_SetDevFunc(i, LCD_DEVFUNC_DRAWBMP_8BPP, (void(*)(void))LCD_LL_DrawBitmap8bpp);
843  }
844 }
845 
857 int LCD_X_DisplayDriver(unsigned LayerIndex, unsigned Cmd, void * pData)
858 {
859  int r = 0;
860  U32 addr;
861  int xPos, yPos;
862  U32 Color;
863 
864  switch (Cmd)
865  {
866  case LCD_X_INITCONTROLLER:
867  LCD_LL_LayerInit(LayerIndex, layer_prop[LayerIndex].address);
868  break;
869 
870  case LCD_X_SETORG:
871  addr = layer_prop[LayerIndex].address + ((LCD_X_SETORG_INFO *)pData)->yPos * layer_prop[LayerIndex].xSize * layer_prop[LayerIndex].BytesPerPixel;
872  HAL_LTDC_SetAddress(&hltdc_eval, addr, LayerIndex);
873  break;
874 
875  case LCD_X_SHOWBUFFER:
876  layer_prop[LayerIndex].pending_buffer = ((LCD_X_SHOWBUFFER_INFO *)pData)->Index;
877  break;
878 
879  case LCD_X_ON:
880  __HAL_LTDC_ENABLE(&hltdc_eval);
881  break;
882 
883  case LCD_X_OFF:
884  __HAL_LTDC_DISABLE(&hltdc_eval);
885  break;
886 
887  case LCD_X_SETVIS:
888  if(((LCD_X_SETVIS_INFO *)pData)->OnOff == ENABLE )
889  {
890  __HAL_LTDC_LAYER_ENABLE(&hltdc_eval, LayerIndex);
891  }
892  else
893  {
894  __HAL_LTDC_LAYER_DISABLE(&hltdc_eval, LayerIndex);
895  }
896  __HAL_LTDC_RELOAD_CONFIG(&hltdc_eval);
897 
898  break;
899 
900  case LCD_X_SETPOS:
901  HAL_LTDC_SetWindowPosition(&hltdc_eval,
902  ((LCD_X_SETPOS_INFO *)pData)->xPos,
903  ((LCD_X_SETPOS_INFO *)pData)->yPos,
904  LayerIndex);
905  break;
906 
907  case LCD_X_SETSIZE:
908  GUI_GetLayerPosEx(LayerIndex, &xPos, &yPos);
909  layer_prop[LayerIndex].xSize = ((LCD_X_SETSIZE_INFO *)pData)->xSize;
910  layer_prop[LayerIndex].ySize = ((LCD_X_SETSIZE_INFO *)pData)->ySize;
911  HAL_LTDC_SetWindowPosition(&hltdc_eval, xPos, yPos, LayerIndex);
912  break;
913 
914  case LCD_X_SETALPHA:
915  HAL_LTDC_SetAlpha(&hltdc_eval, ((LCD_X_SETALPHA_INFO *)pData)->Alpha, LayerIndex);
916  break;
917 
918  case LCD_X_SETCHROMAMODE:
919  if(((LCD_X_SETCHROMAMODE_INFO *)pData)->ChromaMode != 0)
920  {
921  HAL_LTDC_EnableColorKeying(&hltdc_eval, LayerIndex);
922  }
923  else
924  {
925  HAL_LTDC_DisableColorKeying(&hltdc_eval, LayerIndex);
926  }
927  break;
928 
929  case LCD_X_SETCHROMA:
930 
931  Color = ((((LCD_X_SETCHROMA_INFO *)pData)->ChromaMin & 0xFF0000) >> 16) |\
932  (((LCD_X_SETCHROMA_INFO *)pData)->ChromaMin & 0x00FF00) |\
933  ((((LCD_X_SETCHROMA_INFO *)pData)->ChromaMin & 0x0000FF) << 16);
934 
935  HAL_LTDC_ConfigColorKeying(&hltdc_eval, Color, LayerIndex);
936  break;
937 
938  default:
939  r = -1;
940  }
941  return r;
942 }
943 
944 
945 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
946 
#define LCD_X_SETSIZE
Definition: LCD.h:520
GUI_DRAWMODE GUI_GetDrawMode(void)
DSI_HandleTypeDef hdsi_eval
Definition: LCDConf.c:68
#define VACT
Definition: main.c:82
LCD_API_COLOR_CONV * pColorConvAPI
Definition: LCDConf.h:64
#define LTDC
Definition: stm32f746xx.h:1365
#define COLOR_CONVERSION_1
Definition: LCDConf.c:96
#define YSIZE_PHYS
Definition: LCDConf.c:81
int LCD_GetSwapXYEx(int LayerIndex)
#define LCD_DEVFUNC_DRAWBMP_32BPP
Definition: LCD.h:443
#define LCD_LAYER1_FRAME_BUFFER
Definition: LCDConf.c:121
#define HBP
Definition: main.c:84
void HAL_Delay(__IO uint32_t Delay)
This function provides accurate delay (in milliseconds) based on variable incremented.
int32_t buffer_index
Definition: LCDConf.h:60
uint32_t lcd_y_size
#define U32
Definition: Global.h:50
HAL_StatusTypeDef HAL_RCCEx_PeriphCLKConfig(RCC_PeriphCLKInitTypeDef *PeriphClkInit)
GUI_DEVICE * GUI_DEVICE_CreateAndLink(const GUI_DEVICE_API *pDeviceAPI, const LCD_API_COLOR_CONV *pColorConvAPI, U16 Flags, int LayerIndex)
void DSI_IO_WriteCmd(uint32_t NbrParams, uint8_t *pParams)
DCS or Generic short/long write command.
Definition: LCDConf.c:176
#define OTM8009A_800X480_WIDTH
Definition: otm8009a.h:95
#define LCD_X_SETPOS
Definition: LCD.h:521
void GUI_MULTIBUF_ConfigEx(int LayerIndex, int NumBuffers)
#define GPIOJ
Definition: stm32f745xx.h:1322
void GUI_MULTIBUF_ConfirmEx(int LayerIndex, int BufferIndex)
int LCD_SetSizeEx(int LayerIndex, int xSize, int ySize)
#define DISPLAY_DRIVER_1
Definition: LCDConf.c:97
#define LCD_X_ON
Definition: LCD.h:518
LTDC_HandleTypeDef hltdc_eval
Definition: LCDConf.c:67
#define LCD_X_SETVIS
Definition: LCD.h:522
#define OTM8009A_800X480_HFP
Definition: otm8009a.h:114
#define HFP
Definition: main.c:85
#define LCD_X_SHOWBUFFER
Definition: LCD.h:527
int LCD_SetVSizeEx(int LayerIndex, int xSize, int ySize)
#define LCD_DEVFUNC_DRAWBMP_16BPP
Definition: LCD.h:439
#define LCD_X_INITCONTROLLER
Definition: LCD.h:514
#define LCD_X_SETCHROMA
Definition: LCD.h:526
#define GPIO_PULLUP
#define __HAL_RCC_DMA2D_FORCE_RESET()
void LCD_LL_DrawBitmap16bpp(int LayerIndex, int x, int y, U16 const *p, int xSize, int ySize, int BytesPerLine)
Draw 16bpp bitmap file.
Definition: LCDConf.c:683
#define LCD_X_SETALPHA
Definition: LCD.h:523
#define HACT
Definition: main.c:86
#define DISPLAY_DRIVER_0
Definition: LCDConf.c:92
#define LCD_X_OFF
Definition: LCD.h:519
#define NUM_VSCREENS
Definition: LCDConf.c:84
#define OTM8009A_800X480_HEIGHT
Definition: otm8009a.h:96
#define __DSB()
Data Synchronization Barrier.
Definition: cmsis_armcc.h:355
void LCD_X_Config(void)
Called during the initialization process in order to set up the display driver configuration.
Definition: LCDConf.c:772
#define NULL
Definition: usbd_def.h:53
#define LCD_DEVFUNC_FILLRECT
Definition: LCD.h:434
#define __HAL_RCC_GPIOJ_CLK_ENABLE()
#define OTM8009A_800X480_HSYNC
OTM8009A_800X480 Timing parameters for Landscape orientation mode Same values as for Portrait mode in...
Definition: otm8009a.h:112
RCC extended clocks structure definition.
__IO int32_t pending_buffer
Definition: LCDConf.h:59
void HAL_NVIC_SetPriority(IRQn_Type IRQn, uint32_t PreemptPriority, uint32_t SubPriority)
#define DMA2D_CR_START
Definition: stm32f745xx.h:3450
void HAL_GPIO_WritePin(GPIO_TypeDef *GPIOx, uint16_t GPIO_Pin, GPIO_PinState PinState)
void GUI_GetLayerPosEx(unsigned Index, int *pxPos, int *pyPos)
#define __HAL_RCC_DMA2D_CLK_ENABLE()
#define OTM8009A_800X480_VSYNC
Definition: otm8009a.h:115
#define XSIZE_PHYS
Definition: LCDConf.c:80
#define __HAL_RCC_DMA2D_RELEASE_RESET()
#define LCD_X_SETCHROMAMODE
Definition: LCD.h:525
LCD_LayerPropTypedef layer_prop[GUI_NUM_LAYERS]
Definition: LCDConf.c:135
void HAL_NVIC_EnableIRQ(IRQn_Type IRQn)
#define VFP
Definition: main.c:81
void HAL_LTDC_LineEvenCallback(LTDC_HandleTypeDef *hltdc_eval)
Line Event callback.
Definition: LCDConf.c:738
uint32_t lcd_x_size
#define LCD_DEVFUNC_COPYRECT
Definition: LCD.h:438
GPIO Init structure definition.
void LCD_LL_DrawBitmap32bpp(int LayerIndex, int x, int y, U8 const *p, int xSize, int ySize, int BytesPerLine)
Definition: LCDConf.c:695
#define GUI_NUM_LAYERS
Definition: LCDConf.c:89
#define GPIO_PIN_15
#define OTM8009A_ORIENTATION_LANDSCAPE
Definition: otm8009a.h:77
int LCD_SetDevFunc(int LayerIndex, int IdFunc, void(*pDriverFunc)(void))
DSI_PLLInitTypeDef dsiPllInit
Definition: main.c:70
void HAL_GPIO_Init(GPIO_TypeDef *GPIOx, GPIO_InitTypeDef *GPIO_Init)
#define LCD_DEVFUNC_DRAWBMP_8BPP
Definition: LCD.h:440
#define LCD_DEVFUNC_COPYBUFFER
Definition: LCD.h:436
int LCD_SetVRAMAddrEx(int LayerIndex, void *pVRAM)
#define LCD_X_SETORG
Definition: LCD.h:516
int LCD_GetBitsPerPixelEx(int LayerIndex)
int32_t BytesPerPixel
Definition: LCDConf.h:63
#define COLOR_CONVERSION_0
Definition: LCDConf.c:91
#define LCD_LAYER0_FRAME_BUFFER
Definition: LCDConf.c:120
#define OTM8009A_800X480_HBP
Definition: otm8009a.h:113
#define DSI
Definition: stm32f769xx.h:1690
#define RCC_PLLSAIDIVR_2
DSI_VidCfgTypeDef hdsivideo_handle
Definition: LCDConf.c:69
Header for LCDConf file.
#define OTM8009A_800X480_VBP
Definition: otm8009a.h:116
#define U16
Definition: Global.h:47
#define DMA2D
Definition: stm32f745xx.h:1346
void LCD_FillRect(int x0, int y0, int x1, int y1)
#define GUI_DM_XOR
Definition: GUI.h:1940
#define NUM_BUFFERS
Definition: LCDConf.c:83
#define VBP
Definition: main.c:80
uint8_t OTM8009A_Init(uint32_t ColorCoding, uint32_t orientation)
Initializes the LCD KoD display part by communication in DSI mode in Video Mode with IC Display Drive...
Definition: otm8009a.c:194
#define GPIO_MODE_OUTPUT_PP
int LCD_X_DisplayDriver(unsigned LayerIndex, unsigned Cmd, void *pData)
This function is called by the display driver for several purposes. To support the according task the...
Definition: LCDConf.c:857
#define OTM8009A_800X480_VFP
Definition: otm8009a.h:117
RCC_PeriphCLKInitTypeDef PeriphClkInitStruct
#define __HAL_LTDC_LAYER
#define U8
Definition: Global.h:44
RCC_PLLSAIInitTypeDef PLLSAI