STM32F769IDiscovery  1.00
uDANTE Audio Networking with STM32F7 DISCO board
stm32f769i_discovery_lcd.c
Go to the documentation of this file.
1 
39 /* File Info: ------------------------------------------------------------------
40  User NOTES
41 1. How To use this driver:
42 --------------------------
43  - This driver is used to drive directly in video mode a LCD TFT using the DSI interface.
44  The following IPs are implied : DSI Host IP block working
45  in conjunction to the LTDC controller.
46  - This driver is linked by construction to LCD KoD mounted on board MB1166.
47 
48 2. Driver description:
49 ---------------------
50  + Initialization steps:
51  o Initialize the LCD using the BSP_LCD_Init() function.
52  o Select the LCD layer to be used using the BSP_LCD_SelectLayer() function.
53  o Enable the LCD display using the BSP_LCD_DisplayOn() function.
54 
55  + Options
56  o Configure and enable the color keying functionality using the
57  BSP_LCD_SetColorKeying() function.
58  o Modify in the fly the transparency and/or the frame buffer address
59  using the following functions:
60  - BSP_LCD_SetTransparency()
61  - BSP_LCD_SetLayerAddress()
62 
63  + Display on LCD
64  o Clear the whole LCD using BSP_LCD_Clear() function or only one specified string
65  line using the BSP_LCD_ClearStringLine() function.
66  o Display a character on the specified line and column using the BSP_LCD_DisplayChar()
67  function or a complete string line using the BSP_LCD_DisplayStringAtLine() function.
68  o Display a string line on the specified position (x,y in pixel) and align mode
69  using the BSP_LCD_DisplayStringAtLine() function.
70  o Draw and fill a basic shapes (dot, line, rectangle, circle, ellipse, .. bitmap)
71  on LCD using the available set of functions.
72 
73 ------------------------------------------------------------------------------*/
74 
75 /* Includes ------------------------------------------------------------------*/
77 #include "../Fonts/fonts.h"
78 #include "../Fonts/font24.c"
79 #include "../Fonts/font20.c"
80 #include "../Fonts/font16.c"
81 #include "../Fonts/font12.c"
82 #include "../Fonts/font8.c"
83 
106 static DSI_VidCfgTypeDef hdsivideo_handle;
114 #define ABS(X) ((X) > 0 ? (X) : -(X))
115 
116 #define POLY_X(Z) ((int32_t)((Points + (Z))->X))
117 #define POLY_Y(Z) ((int32_t)((Points + (Z))->Y))
118 
126 LTDC_HandleTypeDef hltdc_discovery;
127 DSI_HandleTypeDef hdsi_discovery;
142 static uint32_t ActiveLayer = LTDC_ACTIVE_LAYER_BACKGROUND;
143 
155 static void DrawChar(uint16_t Xpos, uint16_t Ypos, const uint8_t *c);
156 static void FillTriangle(uint16_t x1, uint16_t x2, uint16_t x3, uint16_t y1, uint16_t y2, uint16_t y3);
157 static void LL_FillBuffer(uint32_t LayerIndex, void *pDst, uint32_t xSize, uint32_t ySize, uint32_t OffLine, uint32_t ColorIndex);
158 static void LL_ConvertLineToARGB8888(void * pSrc, void *pDst, uint32_t xSize, uint32_t ColorMode);
172 uint8_t BSP_LCD_Init(void)
173 {
175 }
176 
188 {
189  DSI_PLLInitTypeDef dsiPllInit;
191  uint32_t LcdClock = 27429;
193  uint32_t laneByteClk_kHz = 0;
194  uint32_t VSA;
195  uint32_t VBP;
196  uint32_t VFP;
197  uint32_t VACT;
198  uint32_t HSA;
199  uint32_t HBP;
200  uint32_t HFP;
201  uint32_t HACT;
203  /* Toggle Hardware Reset of the DSI LCD using
204  * its XRES signal (active low) */
205  BSP_LCD_Reset();
206 
207  /* Call first MSP Initialize only in case of first initialization
208  * This will set IP blocks LTDC, DSI and DMA2D
209  * - out of reset
210  * - clocked
211  * - NVIC IRQ related to IP blocks enabled
212  */
213  BSP_LCD_MspInit();
214 
215 /*************************DSI Initialization***********************************/
216 
217  /* Base address of DSI Host/Wrapper registers to be set before calling De-Init */
218  hdsi_discovery.Instance = DSI;
219 
220  HAL_DSI_DeInit(&(hdsi_discovery));
221 
222  dsiPllInit.PLLNDIV = 100;
223  dsiPllInit.PLLIDF = DSI_PLL_IN_DIV5;
224  dsiPllInit.PLLODF = DSI_PLL_OUT_DIV1;
225  laneByteClk_kHz = 62500; /* 500 MHz / 8 = 62.5 MHz = 62500 kHz */
226 
227  /* Set number of Lanes */
228  hdsi_discovery.Init.NumberOfLanes = DSI_TWO_DATA_LANES;
229 
230  /* TXEscapeCkdiv = f(LaneByteClk)/15.62 = 4 */
231  hdsi_discovery.Init.TXEscapeCkdiv = laneByteClk_kHz/15620;
232 
233  HAL_DSI_Init(&(hdsi_discovery), &(dsiPllInit));
234 
235  /* Timing parameters for all Video modes
236  * Set Timing parameters of LTDC depending on its chosen orientation
237  */
238  if(orientation == LCD_ORIENTATION_PORTRAIT)
239  {
240  VSA = OTM8009A_480X800_VSYNC; /* 12 */
241  VBP = OTM8009A_480X800_VBP; /* 12 */
242  VFP = OTM8009A_480X800_VFP; /* 12 */
243  HSA = OTM8009A_480X800_HSYNC; /* 120 */
244  HBP = OTM8009A_480X800_HBP; /* 120 */
245  HFP = OTM8009A_480X800_HFP; /* 120 */
247  lcd_y_size = OTM8009A_480X800_HEIGHT; /* 800 */
248  }
249  else
250  {
251  /* lcd_orientation == LCD_ORIENTATION_LANDSCAPE */
252  VSA = OTM8009A_800X480_VSYNC; /* 12 */
253  VBP = OTM8009A_800X480_VBP; /* 12 */
254  VFP = OTM8009A_800X480_VFP; /* 12 */
255  HSA = OTM8009A_800X480_HSYNC; /* 120 */
256  HBP = OTM8009A_800X480_HBP; /* 120 */
257  HFP = OTM8009A_800X480_HFP; /* 120 */
259  lcd_y_size = OTM8009A_800X480_HEIGHT; /* 480 */
260  }
261 
262  HACT = lcd_x_size;
263  VACT = lcd_y_size;
264 
265  hdsivideo_handle.VirtualChannelID = LCD_OTM8009A_ID;
267  hdsivideo_handle.VSPolarity = DSI_VSYNC_ACTIVE_HIGH;
268  hdsivideo_handle.HSPolarity = DSI_HSYNC_ACTIVE_HIGH;
269  hdsivideo_handle.DEPolarity = DSI_DATA_ENABLE_ACTIVE_HIGH;
270  hdsivideo_handle.Mode = DSI_VID_MODE_BURST; /* Mode Video burst ie : one LgP per line */
271  hdsivideo_handle.NullPacketSize = 0xFFF;
272  hdsivideo_handle.NumberOfChunks = 0;
273  hdsivideo_handle.PacketSize = HACT; /* Value depending on display orientation choice portrait/landscape */
274  hdsivideo_handle.HorizontalSyncActive = (HSA * laneByteClk_kHz)/LcdClock;
275  hdsivideo_handle.HorizontalBackPorch = (HBP * laneByteClk_kHz)/LcdClock;
276  hdsivideo_handle.HorizontalLine = ((HACT + HSA + HBP + HFP) * laneByteClk_kHz)/LcdClock; /* Value depending on display orientation choice portrait/landscape */
277  hdsivideo_handle.VerticalSyncActive = VSA;
278  hdsivideo_handle.VerticalBackPorch = VBP;
279  hdsivideo_handle.VerticalFrontPorch = VFP;
280  hdsivideo_handle.VerticalActive = VACT; /* Value depending on display orientation choice portrait/landscape */
281 
282  /* Enable or disable sending LP command while streaming is active in video mode */
283  hdsivideo_handle.LPCommandEnable = DSI_LP_COMMAND_ENABLE; /* Enable sending commands in mode LP (Low Power) */
284 
285  /* Largest packet size possible to transmit in LP mode in VSA, VBP, VFP regions */
286  /* Only useful when sending LP packets is allowed while streaming is active in video mode */
287  hdsivideo_handle.LPLargestPacketSize = 64;
288 
289  /* Largest packet size possible to transmit in LP mode in HFP region during VACT period */
290  /* Only useful when sending LP packets is allowed while streaming is active in video mode */
291  hdsivideo_handle.LPVACTLargestPacketSize = 64;
292 
293 
294  /* Specify for each region of the video frame, if the transmission of command in LP mode is allowed in this region */
295  /* while streaming is active in video mode */
296  hdsivideo_handle.LPHorizontalFrontPorchEnable = DSI_LP_HFP_ENABLE; /* Allow sending LP commands during HFP period */
297  hdsivideo_handle.LPHorizontalBackPorchEnable = DSI_LP_HBP_ENABLE; /* Allow sending LP commands during HBP period */
298  hdsivideo_handle.LPVerticalActiveEnable = DSI_LP_VACT_ENABLE; /* Allow sending LP commands during VACT period */
299  hdsivideo_handle.LPVerticalFrontPorchEnable = DSI_LP_VFP_ENABLE; /* Allow sending LP commands during VFP period */
300  hdsivideo_handle.LPVerticalBackPorchEnable = DSI_LP_VBP_ENABLE; /* Allow sending LP commands during VBP period */
301  hdsivideo_handle.LPVerticalSyncActiveEnable = DSI_LP_VSYNC_ENABLE; /* Allow sending LP commands during VSync = VSA period */
302 
303  /* Configure DSI Video mode timings with settings set above */
304  HAL_DSI_ConfigVideoMode(&(hdsi_discovery), &(hdsivideo_handle));
305 
306  /* Enable the DSI host and wrapper : but LTDC is not started yet at this stage */
307  HAL_DSI_Start(&(hdsi_discovery));
308 /*************************End DSI Initialization*******************************/
309 
310 /************************LTDC Initialization***********************************/
311 
312  /* Timing Configuration */
313  hltdc_discovery.Init.HorizontalSync = (HSA - 1);
314  hltdc_discovery.Init.AccumulatedHBP = (HSA + HBP - 1);
315  hltdc_discovery.Init.AccumulatedActiveW = (lcd_x_size + HSA + HBP - 1);
316  hltdc_discovery.Init.TotalWidth = (lcd_x_size + HSA + HBP + HFP - 1);
317 
318  /* Initialize the LCD pixel width and pixel height */
319  hltdc_discovery.LayerCfg->ImageWidth = lcd_x_size;
320  hltdc_discovery.LayerCfg->ImageHeight = lcd_y_size;
321 
322  /* LCD clock configuration */
323  /* PLLSAI_VCO Input = HSE_VALUE/PLL_M = 1 Mhz */
324  /* PLLSAI_VCO Output = PLLSAI_VCO Input * PLLSAIN = 384 Mhz */
325  /* PLLLCDCLK = PLLSAI_VCO Output/PLLSAIR = 384 MHz / 7 = 54.857 MHz */
326  /* LTDC clock frequency = PLLLCDCLK / LTDC_PLLSAI_DIVR_2 = 54.857 MHz / 2 = 27.429 MHz */
327  PeriphClkInitStruct.PeriphClockSelection = RCC_PERIPHCLK_LTDC;
328  PeriphClkInitStruct.PLLSAI.PLLSAIN = 384; //384
329  PeriphClkInitStruct.PLLSAI.PLLSAIR = 7;
330  PeriphClkInitStruct.PLLSAIDivR = RCC_PLLSAIDIVR_2;
331  HAL_RCCEx_PeriphCLKConfig(&PeriphClkInitStruct);
332 
333  /* Background value */
334  hltdc_discovery.Init.Backcolor.Blue = 0;
335  hltdc_discovery.Init.Backcolor.Green = 0;
336  hltdc_discovery.Init.Backcolor.Red = 0;
337  hltdc_discovery.Init.PCPolarity = LTDC_PCPOLARITY_IPC;
338  hltdc_discovery.Instance = LTDC;
339 
340  /* Get LTDC Configuration from DSI Configuration */
341  HAL_LTDC_StructInitFromVideoConfig(&(hltdc_discovery), &(hdsivideo_handle));
342 
343  /* Initialize the LTDC */
344  HAL_LTDC_Init(&hltdc_discovery);
345 
346 #if !defined(DATA_IN_ExtSDRAM)
347  /* Initialize the SDRAM */
348  BSP_SDRAM_Init();
349 #endif /* DATA_IN_ExtSDRAM */
350 
351  /* Initialize the font */
353 
354 /************************End LTDC Initialization*******************************/
355 
356 
357 /***********************OTM8009A Initialization********************************/
358 
359  /* Initialize the OTM8009A LCD Display IC Driver (KoD LCD IC Driver)
360  * depending on configuration set in 'hdsivideo_handle'.
361  */
362  OTM8009A_Init(hdsivideo_handle.ColorCoding, orientation);
363 
364 /***********************End OTM8009A Initialization****************************/
365 
366  return LCD_OK;
367 }
368 
374 void BSP_LCD_Reset(void)
375 {
376  GPIO_InitTypeDef gpio_init_structure;
377 
379 
380  /* Configure the GPIO on PJ15 */
381  gpio_init_structure.Pin = GPIO_PIN_15;
382  gpio_init_structure.Mode = GPIO_MODE_OUTPUT_PP;
383  gpio_init_structure.Pull = GPIO_PULLUP;
384  gpio_init_structure.Speed = GPIO_SPEED_HIGH;
385 
386  HAL_GPIO_Init(GPIOJ, &gpio_init_structure);
387 
388  /* Activate XRES active low */
390 
391  HAL_Delay(20); /* wait 20 ms */
392 
393  /* Desactivate XRES */
395 
396  /* Wait for 10ms after releasing XRES before sending commands */
397  HAL_Delay(10);
398 }
399 
404 uint32_t BSP_LCD_GetXSize(void)
405 {
406  return (lcd_x_size);
407 }
408 
413 uint32_t BSP_LCD_GetYSize(void)
414 {
415  return (lcd_y_size);
416 }
417 
423 void BSP_LCD_SetXSize(uint32_t imageWidthPixels)
424 {
425  hltdc_discovery.LayerCfg[ActiveLayer].ImageWidth = imageWidthPixels;
426 }
427 
432 void BSP_LCD_SetYSize(uint32_t imageHeightPixels)
433 {
434  hltdc_discovery.LayerCfg[ActiveLayer].ImageHeight = imageHeightPixels;
435 }
436 
437 
444 void BSP_LCD_LayerDefaultInit(uint16_t LayerIndex, uint32_t FB_Address)
445 {
446  LCD_LayerCfgTypeDef Layercfg;
447 
448  /* Layer Init */
449  Layercfg.WindowX0 = 0;
450  Layercfg.WindowX1 = BSP_LCD_GetXSize();
451  Layercfg.WindowY0 = 0;
452  Layercfg.WindowY1 = BSP_LCD_GetYSize();
453  Layercfg.PixelFormat = LTDC_PIXEL_FORMAT_ARGB8888;
454  Layercfg.FBStartAdress = FB_Address;
455  Layercfg.Alpha = 255;
456  Layercfg.Alpha0 = 0;
457  Layercfg.Backcolor.Blue = 0;
458  Layercfg.Backcolor.Green = 0;
459  Layercfg.Backcolor.Red = 0;
460  Layercfg.BlendingFactor1 = LTDC_BLENDING_FACTOR1_PAxCA;
461  Layercfg.BlendingFactor2 = LTDC_BLENDING_FACTOR2_PAxCA;
462  Layercfg.ImageWidth = BSP_LCD_GetXSize();
463  Layercfg.ImageHeight = BSP_LCD_GetYSize();
464 
465  HAL_LTDC_ConfigLayer(&hltdc_discovery, &Layercfg, LayerIndex);
466 
467  DrawProp[LayerIndex].BackColor = LCD_COLOR_WHITE;
468  DrawProp[LayerIndex].pFont = &Font24;
469  DrawProp[LayerIndex].TextColor = LCD_COLOR_BLACK;
470 }
471 
472 
477 void BSP_LCD_SelectLayer(uint32_t LayerIndex)
478 {
479  ActiveLayer = LayerIndex;
480 }
481 
490 void BSP_LCD_SetLayerVisible(uint32_t LayerIndex, FunctionalState State)
491 {
492  if(State == ENABLE)
493  {
494  __HAL_LTDC_LAYER_ENABLE(&(hltdc_discovery), LayerIndex);
495  }
496  else
497  {
498  __HAL_LTDC_LAYER_DISABLE(&(hltdc_discovery), LayerIndex);
499  }
500  __HAL_LTDC_RELOAD_CONFIG(&(hltdc_discovery));
501 
502 }
503 
510 void BSP_LCD_SetTransparency(uint32_t LayerIndex, uint8_t Transparency)
511 {
512 
513  HAL_LTDC_SetAlpha(&(hltdc_discovery), Transparency, LayerIndex);
514 
515 }
516 
522 void BSP_LCD_SetLayerAddress(uint32_t LayerIndex, uint32_t Address)
523 {
524 
525  HAL_LTDC_SetAddress(&(hltdc_discovery), Address, LayerIndex);
526 
527 }
528 
537 void BSP_LCD_SetLayerWindow(uint16_t LayerIndex, uint16_t Xpos, uint16_t Ypos, uint16_t Width, uint16_t Height)
538 {
539  /* Reconfigure the layer size */
540  HAL_LTDC_SetWindowSize(&(hltdc_discovery), Width, Height, LayerIndex);
541 
542  /* Reconfigure the layer position */
543  HAL_LTDC_SetWindowPosition(&(hltdc_discovery), Xpos, Ypos, LayerIndex);
544 
545 }
546 
552 void BSP_LCD_SetColorKeying(uint32_t LayerIndex, uint32_t RGBValue)
553 {
554  /* Configure and Enable the color Keying for LCD Layer */
555  HAL_LTDC_ConfigColorKeying(&(hltdc_discovery), RGBValue, LayerIndex);
556  HAL_LTDC_EnableColorKeying(&(hltdc_discovery), LayerIndex);
557 }
558 
563 void BSP_LCD_ResetColorKeying(uint32_t LayerIndex)
564 {
565  /* Disable the color Keying for LCD Layer */
566  HAL_LTDC_DisableColorKeying(&(hltdc_discovery), LayerIndex);
567 }
568 
573 void BSP_LCD_SetTextColor(uint32_t Color)
574 {
575  DrawProp[ActiveLayer].TextColor = Color;
576 }
577 
582 uint32_t BSP_LCD_GetTextColor(void)
583 {
584  return DrawProp[ActiveLayer].TextColor;
585 }
586 
591 void BSP_LCD_SetBackColor(uint32_t Color)
592 {
593  DrawProp[ActiveLayer].BackColor = Color;
594 }
595 
600 uint32_t BSP_LCD_GetBackColor(void)
601 {
602  return DrawProp[ActiveLayer].BackColor;
603 }
604 
609 void BSP_LCD_SetFont(sFONT *fonts)
610 {
611  DrawProp[ActiveLayer].pFont = fonts;
612 }
613 
619 {
620  return DrawProp[ActiveLayer].pFont;
621 }
622 
629 uint32_t BSP_LCD_ReadPixel(uint16_t Xpos, uint16_t Ypos)
630 {
631  uint32_t ret = 0;
632 
633  if(hltdc_discovery.LayerCfg[ActiveLayer].PixelFormat == LTDC_PIXEL_FORMAT_ARGB8888)
634  {
635  /* Read data value from SDRAM memory */
636  ret = *(__IO uint32_t*) (hltdc_discovery.LayerCfg[ActiveLayer].FBStartAdress + (2*(Ypos*BSP_LCD_GetXSize() + Xpos)));
637  }
638  else if(hltdc_discovery.LayerCfg[ActiveLayer].PixelFormat == LTDC_PIXEL_FORMAT_RGB888)
639  {
640  /* Read data value from SDRAM memory */
641  ret = (*(__IO uint32_t*) (hltdc_discovery.LayerCfg[ActiveLayer].FBStartAdress + (2*(Ypos*BSP_LCD_GetXSize() + Xpos))) & 0x00FFFFFF);
642  }
643  else if((hltdc_discovery.LayerCfg[ActiveLayer].PixelFormat == LTDC_PIXEL_FORMAT_RGB565) || \
644  (hltdc_discovery.LayerCfg[ActiveLayer].PixelFormat == LTDC_PIXEL_FORMAT_ARGB4444) || \
645  (hltdc_discovery.LayerCfg[ActiveLayer].PixelFormat == LTDC_PIXEL_FORMAT_AL88))
646  {
647  /* Read data value from SDRAM memory */
648  ret = *(__IO uint16_t*) (hltdc_discovery.LayerCfg[ActiveLayer].FBStartAdress + (2*(Ypos*BSP_LCD_GetXSize() + Xpos)));
649  }
650  else
651  {
652  /* Read data value from SDRAM memory */
653  ret = *(__IO uint8_t*) (hltdc_discovery.LayerCfg[ActiveLayer].FBStartAdress + (2*(Ypos*BSP_LCD_GetXSize() + Xpos)));
654  }
655 
656  return ret;
657 }
658 
663 void BSP_LCD_Clear(uint32_t Color)
664 {
665  /* Clear the LCD */
666  LL_FillBuffer(ActiveLayer, (uint32_t *)(hltdc_discovery.LayerCfg[ActiveLayer].FBStartAdress), BSP_LCD_GetXSize(), BSP_LCD_GetYSize(), 0, Color);
667 }
668 
673 void BSP_LCD_ClearStringLine(uint32_t Line)
674 {
675  uint32_t color_backup = DrawProp[ActiveLayer].TextColor;
676  DrawProp[ActiveLayer].TextColor = DrawProp[ActiveLayer].BackColor;
677 
678  /* Draw rectangle with background color */
679  BSP_LCD_FillRect(0, (Line * DrawProp[ActiveLayer].pFont->Height), BSP_LCD_GetXSize(), DrawProp[ActiveLayer].pFont->Height);
680 
681  DrawProp[ActiveLayer].TextColor = color_backup;
682  BSP_LCD_SetTextColor(DrawProp[ActiveLayer].TextColor);
683 }
684 
692 void BSP_LCD_DisplayChar(uint16_t Xpos, uint16_t Ypos, uint8_t Ascii)
693 {
694  DrawChar(Xpos, Ypos, &DrawProp[ActiveLayer].pFont->table[(Ascii-' ') *\
695  DrawProp[ActiveLayer].pFont->Height * ((DrawProp[ActiveLayer].pFont->Width + 7) / 8)]);
696 }
697 
709 void BSP_LCD_DisplayStringAt(uint16_t Xpos, uint16_t Ypos, uint8_t *Text, Text_AlignModeTypdef Mode)
710 {
711  uint16_t refcolumn = 1, i = 0;
712  uint32_t size = 0, xsize = 0;
713  uint8_t *ptr = Text;
714 
715  /* Get the text size */
716  while (*ptr++) size ++ ;
717 
718  /* Characters number per line */
719  xsize = (BSP_LCD_GetXSize()/DrawProp[ActiveLayer].pFont->Width);
720 
721  switch (Mode)
722  {
723  case CENTER_MODE:
724  {
725  refcolumn = Xpos + ((xsize - size)* DrawProp[ActiveLayer].pFont->Width) / 2;
726  break;
727  }
728  case LEFT_MODE:
729  {
730  refcolumn = Xpos;
731  break;
732  }
733  case RIGHT_MODE:
734  {
735  refcolumn = - Xpos + ((xsize - size)*DrawProp[ActiveLayer].pFont->Width);
736  break;
737  }
738  default:
739  {
740  refcolumn = Xpos;
741  break;
742  }
743  }
744 
745  /* Check that the Start column is located in the screen */
746  if ((refcolumn < 1) || (refcolumn >= 0x8000))
747  {
748  refcolumn = 1;
749  }
750 
751  /* Send the string character by character on LCD */
752  while ((*Text != 0) & (((BSP_LCD_GetXSize() - (i*DrawProp[ActiveLayer].pFont->Width)) & 0xFFFF) >= DrawProp[ActiveLayer].pFont->Width))
753  {
754  /* Display one character on LCD */
755  BSP_LCD_DisplayChar(refcolumn, Ypos, *Text);
756  /* Decrement the column position by 16 */
757  refcolumn += DrawProp[ActiveLayer].pFont->Width;
758 
759  /* Point on the next character */
760  Text++;
761  i++;
762  }
763 
764 }
765 
771 void BSP_LCD_DisplayStringAtLine(uint16_t Line, uint8_t *ptr)
772 {
773  BSP_LCD_DisplayStringAt(0, LINE(Line), ptr, LEFT_MODE);
774 }
775 
782 void BSP_LCD_DrawHLine(uint16_t Xpos, uint16_t Ypos, uint16_t Length)
783 {
784  uint32_t Xaddress = 0;
785 
786  /* Get the line address */
787  Xaddress = (hltdc_discovery.LayerCfg[ActiveLayer].FBStartAdress) + 4*(BSP_LCD_GetXSize()*Ypos + Xpos);
788 
789  /* Write line */
790  LL_FillBuffer(ActiveLayer, (uint32_t *)Xaddress, Length, 1, 0, DrawProp[ActiveLayer].TextColor);
791 }
792 
799 void BSP_LCD_DrawVLine(uint16_t Xpos, uint16_t Ypos, uint16_t Length)
800 {
801  uint32_t Xaddress = 0;
802 
803  /* Get the line address */
804  Xaddress = (hltdc_discovery.LayerCfg[ActiveLayer].FBStartAdress) + 4*(BSP_LCD_GetXSize()*Ypos + Xpos);
805 
806  /* Write line */
807  LL_FillBuffer(ActiveLayer, (uint32_t *)Xaddress, 1, Length, (BSP_LCD_GetXSize() - 1), DrawProp[ActiveLayer].TextColor);
808 }
809 
817 void BSP_LCD_DrawLine(uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2)
818 {
819  int16_t deltax = 0, deltay = 0, x = 0, y = 0, xinc1 = 0, xinc2 = 0,
820  yinc1 = 0, yinc2 = 0, den = 0, num = 0, numadd = 0, numpixels = 0,
821  curpixel = 0;
822 
823  deltax = ABS(x2 - x1); /* The difference between the x's */
824  deltay = ABS(y2 - y1); /* The difference between the y's */
825  x = x1; /* Start x off at the first pixel */
826  y = y1; /* Start y off at the first pixel */
827 
828  if (x2 >= x1) /* The x-values are increasing */
829  {
830  xinc1 = 1;
831  xinc2 = 1;
832  }
833  else /* The x-values are decreasing */
834  {
835  xinc1 = -1;
836  xinc2 = -1;
837  }
838 
839  if (y2 >= y1) /* The y-values are increasing */
840  {
841  yinc1 = 1;
842  yinc2 = 1;
843  }
844  else /* The y-values are decreasing */
845  {
846  yinc1 = -1;
847  yinc2 = -1;
848  }
849 
850  if (deltax >= deltay) /* There is at least one x-value for every y-value */
851  {
852  xinc1 = 0; /* Don't change the x when numerator >= denominator */
853  yinc2 = 0; /* Don't change the y for every iteration */
854  den = deltax;
855  num = deltax / 2;
856  numadd = deltay;
857  numpixels = deltax; /* There are more x-values than y-values */
858  }
859  else /* There is at least one y-value for every x-value */
860  {
861  xinc2 = 0; /* Don't change the x for every iteration */
862  yinc1 = 0; /* Don't change the y when numerator >= denominator */
863  den = deltay;
864  num = deltay / 2;
865  numadd = deltax;
866  numpixels = deltay; /* There are more y-values than x-values */
867  }
868 
869  for (curpixel = 0; curpixel <= numpixels; curpixel++)
870  {
871  BSP_LCD_DrawPixel(x, y, DrawProp[ActiveLayer].TextColor); /* Draw the current pixel */
872  num += numadd; /* Increase the numerator by the top of the fraction */
873  if (num >= den) /* Check if numerator >= denominator */
874  {
875  num -= den; /* Calculate the new numerator value */
876  x += xinc1; /* Change the x as appropriate */
877  y += yinc1; /* Change the y as appropriate */
878  }
879  x += xinc2; /* Change the x as appropriate */
880  y += yinc2; /* Change the y as appropriate */
881  }
882 }
883 
891 void BSP_LCD_DrawRect(uint16_t Xpos, uint16_t Ypos, uint16_t Width, uint16_t Height)
892 {
893  /* Draw horizontal lines */
894  BSP_LCD_DrawHLine(Xpos, Ypos, Width);
895  BSP_LCD_DrawHLine(Xpos, (Ypos+ Height), Width);
896 
897  /* Draw vertical lines */
898  BSP_LCD_DrawVLine(Xpos, Ypos, Height);
899  BSP_LCD_DrawVLine((Xpos + Width), Ypos, Height);
900 }
901 
908 void BSP_LCD_DrawCircle(uint16_t Xpos, uint16_t Ypos, uint16_t Radius)
909 {
910  int32_t D; /* Decision Variable */
911  uint32_t CurX; /* Current X Value */
912  uint32_t CurY; /* Current Y Value */
913 
914  D = 3 - (Radius << 1);
915  CurX = 0;
916  CurY = Radius;
917 
918  while (CurX <= CurY)
919  {
920  BSP_LCD_DrawPixel((Xpos + CurX), (Ypos - CurY), DrawProp[ActiveLayer].TextColor);
921 
922  BSP_LCD_DrawPixel((Xpos - CurX), (Ypos - CurY), DrawProp[ActiveLayer].TextColor);
923 
924  BSP_LCD_DrawPixel((Xpos + CurY), (Ypos - CurX), DrawProp[ActiveLayer].TextColor);
925 
926  BSP_LCD_DrawPixel((Xpos - CurY), (Ypos - CurX), DrawProp[ActiveLayer].TextColor);
927 
928  BSP_LCD_DrawPixel((Xpos + CurX), (Ypos + CurY), DrawProp[ActiveLayer].TextColor);
929 
930  BSP_LCD_DrawPixel((Xpos - CurX), (Ypos + CurY), DrawProp[ActiveLayer].TextColor);
931 
932  BSP_LCD_DrawPixel((Xpos + CurY), (Ypos + CurX), DrawProp[ActiveLayer].TextColor);
933 
934  BSP_LCD_DrawPixel((Xpos - CurY), (Ypos + CurX), DrawProp[ActiveLayer].TextColor);
935 
936  if (D < 0)
937  {
938  D += (CurX << 2) + 6;
939  }
940  else
941  {
942  D += ((CurX - CurY) << 2) + 10;
943  CurY--;
944  }
945  CurX++;
946  }
947 }
948 
954 void BSP_LCD_DrawPolygon(pPoint Points, uint16_t PointCount)
955 {
956  int16_t X = 0, Y = 0;
957 
958  if(PointCount < 2)
959  {
960  return;
961  }
962 
963  BSP_LCD_DrawLine(Points->X, Points->Y, (Points+PointCount-1)->X, (Points+PointCount-1)->Y);
964 
965  while(--PointCount)
966  {
967  X = Points->X;
968  Y = Points->Y;
969  Points++;
970  BSP_LCD_DrawLine(X, Y, Points->X, Points->Y);
971  }
972 }
973 
981 void BSP_LCD_DrawEllipse(int Xpos, int Ypos, int XRadius, int YRadius)
982 {
983  int x = 0, y = -YRadius, err = 2-2*XRadius, e2;
984  float K = 0, rad1 = 0, rad2 = 0;
985 
986  rad1 = XRadius;
987  rad2 = YRadius;
988 
989  K = (float)(rad2/rad1);
990 
991  do {
992  BSP_LCD_DrawPixel((Xpos-(uint16_t)(x/K)), (Ypos+y), DrawProp[ActiveLayer].TextColor);
993  BSP_LCD_DrawPixel((Xpos+(uint16_t)(x/K)), (Ypos+y), DrawProp[ActiveLayer].TextColor);
994  BSP_LCD_DrawPixel((Xpos+(uint16_t)(x/K)), (Ypos-y), DrawProp[ActiveLayer].TextColor);
995  BSP_LCD_DrawPixel((Xpos-(uint16_t)(x/K)), (Ypos-y), DrawProp[ActiveLayer].TextColor);
996 
997  e2 = err;
998  if (e2 <= x) {
999  err += ++x*2+1;
1000  if (-y == x && e2 <= y) e2 = 0;
1001  }
1002  if (e2 > y) err += ++y*2+1;
1003  }
1004  while (y <= 0);
1005 }
1006 
1013 void BSP_LCD_DrawBitmap(uint32_t Xpos, uint32_t Ypos, uint8_t *pbmp)
1014 {
1015  uint32_t index = 0, width = 0, height = 0, bit_pixel = 0;
1016  uint32_t Address;
1017  uint32_t InputColorMode = 0;
1018 
1019  /* Get bitmap data address offset */
1020  index = *(__IO uint16_t *) (pbmp + 10);
1021  index |= (*(__IO uint16_t *) (pbmp + 12)) << 16;
1022 
1023  /* Read bitmap width */
1024  width = *(uint16_t *) (pbmp + 18);
1025  width |= (*(uint16_t *) (pbmp + 20)) << 16;
1026 
1027  /* Read bitmap height */
1028  height = *(uint16_t *) (pbmp + 22);
1029  height |= (*(uint16_t *) (pbmp + 24)) << 16;
1030 
1031  /* Read bit/pixel */
1032  bit_pixel = *(uint16_t *) (pbmp + 28);
1033 
1034  /* Set the address */
1035  Address = hltdc_discovery.LayerCfg[ActiveLayer].FBStartAdress + (((BSP_LCD_GetXSize()*Ypos) + Xpos)*(4));
1036 
1037  /* Get the layer pixel format */
1038  if ((bit_pixel/8) == 4)
1039  {
1040  InputColorMode = DMA2D_INPUT_ARGB8888;
1041  }
1042  else if ((bit_pixel/8) == 2)
1043  {
1044  InputColorMode = DMA2D_INPUT_RGB565;
1045  }
1046  else
1047  {
1048  InputColorMode = DMA2D_INPUT_RGB888;
1049  }
1050 
1051  /* Bypass the bitmap header */
1052  pbmp += (index + (width * (height - 1) * (bit_pixel/8)));
1053 
1054  /* Convert picture to ARGB8888 pixel format */
1055  for(index=0; index < height; index++)
1056  {
1057  /* Pixel format conversion */
1058  LL_ConvertLineToARGB8888((uint32_t *)pbmp, (uint32_t *)Address, width, InputColorMode);
1059 
1060  /* Increment the source and destination buffers */
1061  Address+= (BSP_LCD_GetXSize()*4);
1062  pbmp -= width*(bit_pixel/8);
1063  }
1064 }
1065 
1073 void BSP_LCD_FillRect(uint16_t Xpos, uint16_t Ypos, uint16_t Width, uint16_t Height)
1074 {
1075  uint32_t Xaddress = 0;
1076 
1077  /* Set the text color */
1078  BSP_LCD_SetTextColor(DrawProp[ActiveLayer].TextColor);
1079 
1080  /* Get the rectangle start address */
1081  Xaddress = (hltdc_discovery.LayerCfg[ActiveLayer].FBStartAdress) + 4*(BSP_LCD_GetXSize()*Ypos + Xpos);
1082 
1083  /* Fill the rectangle */
1084  LL_FillBuffer(ActiveLayer, (uint32_t *)Xaddress, Width, Height, (BSP_LCD_GetXSize() - Width), DrawProp[ActiveLayer].TextColor);
1085 }
1086 
1093 void BSP_LCD_FillCircle(uint16_t Xpos, uint16_t Ypos, uint16_t Radius)
1094 {
1095  int32_t D; /* Decision Variable */
1096  uint32_t CurX; /* Current X Value */
1097  uint32_t CurY; /* Current Y Value */
1098 
1099  D = 3 - (Radius << 1);
1100 
1101  CurX = 0;
1102  CurY = Radius;
1103 
1104  BSP_LCD_SetTextColor(DrawProp[ActiveLayer].TextColor);
1105 
1106  while (CurX <= CurY)
1107  {
1108  if(CurY > 0)
1109  {
1110  BSP_LCD_DrawHLine(Xpos - CurY, Ypos + CurX, 2*CurY);
1111  BSP_LCD_DrawHLine(Xpos - CurY, Ypos - CurX, 2*CurY);
1112  }
1113 
1114  if(CurX > 0)
1115  {
1116  BSP_LCD_DrawHLine(Xpos - CurX, Ypos - CurY, 2*CurX);
1117  BSP_LCD_DrawHLine(Xpos - CurX, Ypos + CurY, 2*CurX);
1118  }
1119  if (D < 0)
1120  {
1121  D += (CurX << 2) + 6;
1122  }
1123  else
1124  {
1125  D += ((CurX - CurY) << 2) + 10;
1126  CurY--;
1127  }
1128  CurX++;
1129  }
1130 
1131  BSP_LCD_SetTextColor(DrawProp[ActiveLayer].TextColor);
1132  BSP_LCD_DrawCircle(Xpos, Ypos, Radius);
1133 }
1134 
1140 void BSP_LCD_FillPolygon(pPoint Points, uint16_t PointCount)
1141 {
1142  int16_t X = 0, Y = 0, X2 = 0, Y2 = 0, X_center = 0, Y_center = 0, X_first = 0, Y_first = 0, pixelX = 0, pixelY = 0, counter = 0;
1143  uint16_t IMAGE_LEFT = 0, IMAGE_RIGHT = 0, IMAGE_TOP = 0, IMAGE_BOTTOM = 0;
1144 
1145  IMAGE_LEFT = IMAGE_RIGHT = Points->X;
1146  IMAGE_TOP= IMAGE_BOTTOM = Points->Y;
1147 
1148  for(counter = 1; counter < PointCount; counter++)
1149  {
1150  pixelX = POLY_X(counter);
1151  if(pixelX < IMAGE_LEFT)
1152  {
1153  IMAGE_LEFT = pixelX;
1154  }
1155  if(pixelX > IMAGE_RIGHT)
1156  {
1157  IMAGE_RIGHT = pixelX;
1158  }
1159 
1160  pixelY = POLY_Y(counter);
1161  if(pixelY < IMAGE_TOP)
1162  {
1163  IMAGE_TOP = pixelY;
1164  }
1165  if(pixelY > IMAGE_BOTTOM)
1166  {
1167  IMAGE_BOTTOM = pixelY;
1168  }
1169  }
1170 
1171  if(PointCount < 2)
1172  {
1173  return;
1174  }
1175 
1176  X_center = (IMAGE_LEFT + IMAGE_RIGHT)/2;
1177  Y_center = (IMAGE_BOTTOM + IMAGE_TOP)/2;
1178 
1179  X_first = Points->X;
1180  Y_first = Points->Y;
1181 
1182  while(--PointCount)
1183  {
1184  X = Points->X;
1185  Y = Points->Y;
1186  Points++;
1187  X2 = Points->X;
1188  Y2 = Points->Y;
1189 
1190  FillTriangle(X, X2, X_center, Y, Y2, Y_center);
1191  FillTriangle(X, X_center, X2, Y, Y_center, Y2);
1192  FillTriangle(X_center, X2, X, Y_center, Y2, Y);
1193  }
1194 
1195  FillTriangle(X_first, X2, X_center, Y_first, Y2, Y_center);
1196  FillTriangle(X_first, X_center, X2, Y_first, Y_center, Y2);
1197  FillTriangle(X_center, X2, X_first, Y_center, Y2, Y_first);
1198 }
1199 
1207 void BSP_LCD_FillEllipse(int Xpos, int Ypos, int XRadius, int YRadius)
1208 {
1209  int x = 0, y = -YRadius, err = 2-2*XRadius, e2;
1210  float K = 0, rad1 = 0, rad2 = 0;
1211 
1212  rad1 = XRadius;
1213  rad2 = YRadius;
1214 
1215  K = (float)(rad2/rad1);
1216 
1217  do
1218  {
1219  BSP_LCD_DrawHLine((Xpos-(uint16_t)(x/K)), (Ypos+y), (2*(uint16_t)(x/K) + 1));
1220  BSP_LCD_DrawHLine((Xpos-(uint16_t)(x/K)), (Ypos-y), (2*(uint16_t)(x/K) + 1));
1221 
1222  e2 = err;
1223  if (e2 <= x)
1224  {
1225  err += ++x*2+1;
1226  if (-y == x && e2 <= y) e2 = 0;
1227  }
1228  if (e2 > y) err += ++y*2+1;
1229  }
1230  while (y <= 0);
1231 }
1232 
1238 {
1239  /* Send Display on DCS command to display */
1240  HAL_DSI_ShortWrite(&(hdsi_discovery),
1241  hdsivideo_handle.VirtualChannelID,
1242  DSI_DCS_SHORT_PKT_WRITE_P1,
1244  0x00);
1245 
1246 }
1247 
1253 {
1254  /* Send Display off DCS Command to display */
1255  HAL_DSI_ShortWrite(&(hdsi_discovery),
1256  hdsivideo_handle.VirtualChannelID,
1257  DSI_DCS_SHORT_PKT_WRITE_P1,
1259  0x00);
1260 
1261 }
1262 
1267 void BSP_LCD_SetBrightness(uint8_t BrightnessValue)
1268 {
1269  /* Send Display on DCS command to display */
1270  HAL_DSI_ShortWrite(&hdsi_discovery,
1271  LCD_OTM8009A_ID,
1272  DSI_DCS_SHORT_PKT_WRITE_P1,
1273  OTM8009A_CMD_WRDISBV, (uint16_t)(BrightnessValue * 255)/100);
1274 
1275 }
1276 
1284 void DSI_IO_WriteCmd(uint32_t NbrParams, uint8_t *pParams)
1285 {
1286  if(NbrParams <= 1)
1287  {
1288  HAL_DSI_ShortWrite(&hdsi_discovery, LCD_OTM8009A_ID, DSI_DCS_SHORT_PKT_WRITE_P1, pParams[0], pParams[1]);
1289  }
1290  else
1291  {
1292  HAL_DSI_LongWrite(&hdsi_discovery, LCD_OTM8009A_ID, DSI_DCS_LONG_PKT_WRITE, NbrParams, pParams[NbrParams], pParams);
1293  }
1294 }
1295 
1296 /*******************************************************************************
1297  LTDC, DMA2D and DSI BSP Routines
1298 *******************************************************************************/
1303 __weak void BSP_LCD_MspDeInit(void)
1304 {
1307 
1310 
1313 
1315  __HAL_RCC_LTDC_FORCE_RESET();
1317  __HAL_RCC_DSI_FORCE_RESET();
1318 
1320  __HAL_RCC_LTDC_CLK_DISABLE();
1322  __HAL_RCC_DSI_CLK_DISABLE();
1323 }
1324 
1329 __weak void BSP_LCD_MspInit(void)
1330 {
1332  __HAL_RCC_LTDC_CLK_ENABLE();
1333 
1335  __HAL_RCC_LTDC_FORCE_RESET();
1336  __HAL_RCC_LTDC_RELEASE_RESET();
1337 
1340 
1344 
1346  __HAL_RCC_DSI_CLK_ENABLE();
1347 
1349  __HAL_RCC_DSI_FORCE_RESET();
1350  __HAL_RCC_DSI_RELEASE_RESET();
1351 
1355 
1359 
1363 }
1364 
1371 void BSP_LCD_DrawPixel(uint16_t Xpos, uint16_t Ypos, uint32_t RGB_Code)
1372 {
1373  /* Write data value to all SDRAM memory */
1374  *(__IO uint32_t*) (hltdc_discovery.LayerCfg[ActiveLayer].FBStartAdress + (4*(Ypos*BSP_LCD_GetXSize() + Xpos))) = RGB_Code;
1375 }
1376 
1377 
1384 static void DrawChar(uint16_t Xpos, uint16_t Ypos, const uint8_t *c)
1385 {
1386  uint32_t i = 0, j = 0;
1387  uint16_t height, width;
1388  uint8_t offset;
1389  uint8_t *pchar;
1390  uint32_t line;
1391 
1392  height = DrawProp[ActiveLayer].pFont->Height;
1393  width = DrawProp[ActiveLayer].pFont->Width;
1394 
1395  offset = 8 *((width + 7)/8) - width ;
1396 
1397  for(i = 0; i < height; i++)
1398  {
1399  pchar = ((uint8_t *)c + (width + 7)/8 * i);
1400 
1401  switch(((width + 7)/8))
1402  {
1403 
1404  case 1:
1405  line = pchar[0];
1406  break;
1407 
1408  case 2:
1409  line = (pchar[0]<< 8) | pchar[1];
1410  break;
1411 
1412  case 3:
1413  default:
1414  line = (pchar[0]<< 16) | (pchar[1]<< 8) | pchar[2];
1415  break;
1416  }
1417 
1418  for (j = 0; j < width; j++)
1419  {
1420  if(line & (1 << (width- j + offset- 1)))
1421  {
1422  BSP_LCD_DrawPixel((Xpos + j), Ypos, DrawProp[ActiveLayer].TextColor);
1423  }
1424  else
1425  {
1426  BSP_LCD_DrawPixel((Xpos + j), Ypos, DrawProp[ActiveLayer].BackColor);
1427  }
1428  }
1429  Ypos++;
1430  }
1431 }
1432 
1442 static void FillTriangle(uint16_t x1, uint16_t x2, uint16_t x3, uint16_t y1, uint16_t y2, uint16_t y3)
1443 {
1444  int16_t deltax = 0, deltay = 0, x = 0, y = 0, xinc1 = 0, xinc2 = 0,
1445  yinc1 = 0, yinc2 = 0, den = 0, num = 0, numadd = 0, numpixels = 0,
1446  curpixel = 0;
1447 
1448  deltax = ABS(x2 - x1); /* The difference between the x's */
1449  deltay = ABS(y2 - y1); /* The difference between the y's */
1450  x = x1; /* Start x off at the first pixel */
1451  y = y1; /* Start y off at the first pixel */
1452 
1453  if (x2 >= x1) /* The x-values are increasing */
1454  {
1455  xinc1 = 1;
1456  xinc2 = 1;
1457  }
1458  else /* The x-values are decreasing */
1459  {
1460  xinc1 = -1;
1461  xinc2 = -1;
1462  }
1463 
1464  if (y2 >= y1) /* The y-values are increasing */
1465  {
1466  yinc1 = 1;
1467  yinc2 = 1;
1468  }
1469  else /* The y-values are decreasing */
1470  {
1471  yinc1 = -1;
1472  yinc2 = -1;
1473  }
1474 
1475  if (deltax >= deltay) /* There is at least one x-value for every y-value */
1476  {
1477  xinc1 = 0; /* Don't change the x when numerator >= denominator */
1478  yinc2 = 0; /* Don't change the y for every iteration */
1479  den = deltax;
1480  num = deltax / 2;
1481  numadd = deltay;
1482  numpixels = deltax; /* There are more x-values than y-values */
1483  }
1484  else /* There is at least one y-value for every x-value */
1485  {
1486  xinc2 = 0; /* Don't change the x for every iteration */
1487  yinc1 = 0; /* Don't change the y when numerator >= denominator */
1488  den = deltay;
1489  num = deltay / 2;
1490  numadd = deltax;
1491  numpixels = deltay; /* There are more y-values than x-values */
1492  }
1493 
1494  for (curpixel = 0; curpixel <= numpixels; curpixel++)
1495  {
1496  BSP_LCD_DrawLine(x, y, x3, y3);
1497 
1498  num += numadd; /* Increase the numerator by the top of the fraction */
1499  if (num >= den) /* Check if numerator >= denominator */
1500  {
1501  num -= den; /* Calculate the new numerator value */
1502  x += xinc1; /* Change the x as appropriate */
1503  y += yinc1; /* Change the y as appropriate */
1504  }
1505  x += xinc2; /* Change the x as appropriate */
1506  y += yinc2; /* Change the y as appropriate */
1507  }
1508 }
1509 
1519 static void LL_FillBuffer(uint32_t LayerIndex, void *pDst, uint32_t xSize, uint32_t ySize, uint32_t OffLine, uint32_t ColorIndex)
1520 {
1521  /* Register to memory mode with ARGB8888 as color Mode */
1522  hdma2d_discovery.Init.Mode = DMA2D_R2M;
1523  hdma2d_discovery.Init.ColorMode = DMA2D_OUTPUT_ARGB8888;
1524  hdma2d_discovery.Init.OutputOffset = OffLine;
1525 
1526  hdma2d_discovery.Instance = DMA2D;
1527 
1528  /* DMA2D Initialization */
1529  if(HAL_DMA2D_Init(&hdma2d_discovery) == HAL_OK)
1530  {
1531  if(HAL_DMA2D_ConfigLayer(&hdma2d_discovery, LayerIndex) == HAL_OK)
1532  {
1533  if (HAL_DMA2D_Start(&hdma2d_discovery, ColorIndex, (uint32_t)pDst, xSize, ySize) == HAL_OK)
1534  {
1535  /* Polling For DMA transfer */
1536  HAL_DMA2D_PollForTransfer(&hdma2d_discovery, 10);
1537  }
1538  }
1539  }
1540 }
1541 
1549 static void LL_ConvertLineToARGB8888(void *pSrc, void *pDst, uint32_t xSize, uint32_t ColorMode)
1550 {
1551  /* Configure the DMA2D Mode, Color Mode and output offset */
1552  hdma2d_discovery.Init.Mode = DMA2D_M2M_PFC;
1553  hdma2d_discovery.Init.ColorMode = DMA2D_OUTPUT_ARGB8888;
1554  hdma2d_discovery.Init.OutputOffset = 0;
1555 
1556  /* Foreground Configuration */
1557  hdma2d_discovery.LayerCfg[1].AlphaMode = DMA2D_NO_MODIF_ALPHA;
1558  hdma2d_discovery.LayerCfg[1].InputAlpha = 0xFF;
1559  hdma2d_discovery.LayerCfg[1].InputColorMode = ColorMode;
1560  hdma2d_discovery.LayerCfg[1].InputOffset = 0;
1561 
1562  hdma2d_discovery.Instance = DMA2D;
1563 
1564  /* DMA2D Initialization */
1565  if(HAL_DMA2D_Init(&hdma2d_discovery) == HAL_OK)
1566  {
1567  if(HAL_DMA2D_ConfigLayer(&hdma2d_discovery, 1) == HAL_OK)
1568  {
1569  if (HAL_DMA2D_Start(&hdma2d_discovery, (uint32_t)pSrc, (uint32_t)pDst, xSize, 1) == HAL_OK)
1570  {
1571  /* Polling For DMA transfer */
1572  HAL_DMA2D_PollForTransfer(&hdma2d_discovery, 10);
1573  }
1574  }
1575  }
1576 }
1577 
1594 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
#define LCD_OTM8009A_ID
LCD Display OTM8009A ID.
#define VACT
Definition: main.c:82
#define OTM8009A_CMD_DISPOFF
Definition: otm8009a.h:131
LCD_OrientationTypeDef
LCD_OrientationTypeDef Possible values of Display Orientation.
#define OTM8009A_CMD_DISPON
Definition: otm8009a.h:132
#define LTDC
Definition: stm32f746xx.h:1365
void BSP_LCD_LayerDefaultInit(uint16_t LayerIndex, uint32_t FB_Address)
Initializes the LCD layers.
void BSP_LCD_SelectLayer(uint32_t LayerIndex)
Selects the LCD Layer.
void BSP_LCD_DrawPolygon(pPoint Points, uint16_t PointCount)
Draws an poly-line (between many points) in currently active layer.
void BSP_LCD_SetFont(sFONT *fonts)
Sets the LCD text font.
HAL_StatusTypeDef HAL_DMA2D_Start(DMA2D_HandleTypeDef *hdma2d, uint32_t pdata, uint32_t DstAddress, uint32_t Width, uint32_t Height)
#define HBP
Definition: main.c:84
void HAL_Delay(__IO uint32_t Delay)
This function provides accurate delay (in milliseconds) based on variable incremented.
#define OTM8009A_480X800_VSYNC
Definition: otm8009a.h:104
void BSP_LCD_DrawVLine(uint16_t Xpos, uint16_t Ypos, uint16_t Length)
Draws a vertical line in currently active layer.
void BSP_LCD_Reset(void)
BSP LCD Reset Hw reset the LCD DSI activating its XRES signal (active low for some time) and desactiv...
#define LTDC_MAX_LAYER_NUMBER
Maximum number of LTDC layers.
uint8_t BSP_LCD_InitEx(LCD_OrientationTypeDef orientation)
Initializes the DSI LCD. The initialization is done as below:
uint32_t lcd_y_size
HAL_StatusTypeDef HAL_RCCEx_PeriphCLKConfig(RCC_PeriphCLKInitTypeDef *PeriphClkInit)
#define LCD_OK
LCD status structure definition.
void BSP_LCD_SetYSize(uint32_t imageHeightPixels)
Set the LCD Y size.
DSI_HandleTypeDef hdsi_discovery
void BSP_LCD_SetLayerWindow(uint16_t LayerIndex, uint16_t Xpos, uint16_t Ypos, uint16_t Width, uint16_t Height)
Sets display window.
uint8_t BSP_LCD_Init(void)
Initializes the DSI LCD.
#define LCD_COLOR_WHITE
White value in ARGB8888 format.
void BSP_LCD_DrawCircle(uint16_t Xpos, uint16_t Ypos, uint16_t Radius)
Draws a circle in currently active layer.
#define OTM8009A_800X480_WIDTH
Definition: otm8009a.h:95
__weak void BSP_LCD_MspDeInit(void)
De-Initializes the BSP LCD Msp Application can surcharge if needed this function implementation.
#define GPIOJ
Definition: stm32f745xx.h:1322
#define DMA2D_R2M
void BSP_LCD_FillCircle(uint16_t Xpos, uint16_t Ypos, uint16_t Radius)
Draws a full circle in currently active layer.
void BSP_LCD_FillRect(uint16_t Xpos, uint16_t Ypos, uint16_t Width, uint16_t Height)
Draws a full rectangle in currently active layer.
LCD Drawing point (pixel) geometric definition.
void BSP_LCD_DisplayStringAtLine(uint16_t Line, uint8_t *ptr)
Displays a maximum of 60 characters on the LCD.
sFONT * BSP_LCD_GetFont(void)
Gets the LCD text font.
void BSP_LCD_SetColorKeying(uint32_t LayerIndex, uint32_t RGBValue)
Configures and sets the color keying.
#define LCD_DEFAULT_FONT
LCD default font.
#define OTM8009A_800X480_HFP
Definition: otm8009a.h:114
Text_AlignModeTypdef
LCD drawing Line alignment mode definitions.
#define HFP
Definition: main.c:85
uint32_t BSP_LCD_GetXSize(void)
Gets the LCD X size.
#define OTM8009A_480X800_HSYNC
OTM8009A_480X800 Timing parameters for Portrait orientation mode.
Definition: otm8009a.h:101
void BSP_LCD_ResetColorKeying(uint32_t LayerIndex)
Disables the color keying.
#define LINE(x)
Definition: fonts.h:88
LCD Drawing main properties.
void BSP_LCD_SetBackColor(uint32_t Color)
Sets the LCD background color.
uint16_t Width
Definition: fonts.h:71
void BSP_LCD_FillPolygon(pPoint Points, uint16_t PointCount)
Draws a full poly-line (between many points) in currently active layer.
#define GPIO_PULLUP
#define __HAL_RCC_DMA2D_FORCE_RESET()
void BSP_LCD_DisplayStringAt(uint16_t Xpos, uint16_t Ypos, uint8_t *Text, Text_AlignModeTypdef Mode)
Displays characters in currently active layer.
#define __HAL_RCC_DMA2D_CLK_DISABLE()
HAL_StatusTypeDef HAL_DMA2D_ConfigLayer(DMA2D_HandleTypeDef *hdma2d, uint32_t LayerIdx)
FunctionalState
Definition: stm32f7xx.h:158
Definition: fonts.h:68
#define DMA2D_INPUT_RGB888
#define DMA2D_INPUT_RGB565
#define OTM8009A_480X800_HEIGHT
Definition: otm8009a.h:92
#define HACT
Definition: main.c:86
#define OTM8009A_480X800_WIDTH
otm8009a_480x800 Size
Definition: otm8009a.h:91
#define OTM8009A_480X800_VFP
Definition: otm8009a.h:106
#define OTM8009A_800X480_HEIGHT
Definition: otm8009a.h:96
This file contains the common defines and functions prototypes for the stm32469i_discovery_lcd.c driver.
HAL_StatusTypeDef HAL_DMA2D_Init(DMA2D_HandleTypeDef *hdma2d)
#define POLY_Y(Z)
#define __HAL_RCC_GPIOJ_CLK_ENABLE()
void BSP_LCD_FillEllipse(int Xpos, int Ypos, int XRadius, int YRadius)
Draws a full ellipse in currently active layer.
#define LCD_LayerCfgTypeDef
void BSP_LCD_Clear(uint32_t Color)
Clears the whole currently active layer of LTDC.
#define OTM8009A_800X480_HSYNC
OTM8009A_800X480 Timing parameters for Landscape orientation mode Same values as for Portrait mode in...
Definition: otm8009a.h:112
#define __IO
Definition: core_cm0.h:213
DMA2D_HandleTypeDef hdma2d_discovery
void BSP_LCD_DrawLine(uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2)
Draws an uni-line (between two points) in currently active layer.
RCC extended clocks structure definition.
#define DMA2D_OUTPUT_ARGB8888
void BSP_LCD_DisplayOff(void)
Switch Off the display. Enter DSI ULPM mode if was allowed and configured in Dsi Configuration.
void BSP_LCD_SetLayerVisible(uint32_t LayerIndex, FunctionalState State)
Sets an LCD Layer visible.
void HAL_NVIC_SetPriority(IRQn_Type IRQn, uint32_t PreemptPriority, uint32_t SubPriority)
uint32_t BSP_LCD_GetTextColor(void)
Gets the LCD text color.
void HAL_GPIO_WritePin(GPIO_TypeDef *GPIOx, uint16_t GPIO_Pin, GPIO_PinState PinState)
void BSP_LCD_DrawEllipse(int Xpos, int Ypos, int XRadius, int YRadius)
Draws an ellipse on LCD in currently active layer.
#define __HAL_RCC_DMA2D_CLK_ENABLE()
#define OTM8009A_800X480_VSYNC
Definition: otm8009a.h:115
void BSP_LCD_DisplayOn(void)
Switch back on the display if was switched off by previous call of BSP_LCD_DisplayOff(). Exit DSI ULPM mode if was allowed and configured in Dsi Configuration.
#define LCD_COLOR_BLACK
Black value in ARGB8888 format.
void BSP_LCD_DisplayChar(uint16_t Xpos, uint16_t Ypos, uint8_t Ascii)
Displays one character in currently active layer.
void BSP_LCD_DrawRect(uint16_t Xpos, uint16_t Ypos, uint16_t Width, uint16_t Height)
Draws a rectangle in currently active layer.
#define __HAL_RCC_DMA2D_RELEASE_RESET()
void HAL_NVIC_EnableIRQ(IRQn_Type IRQn)
#define VFP
Definition: main.c:81
#define POLY_X(Z)
void BSP_LCD_ClearStringLine(uint32_t Line)
Clears the selected line in currently active layer.
void BSP_LCD_SetLayerAddress(uint32_t LayerIndex, uint32_t Address)
Sets an LCD layer frame buffer address.
uint32_t lcd_x_size
LTDC_HandleTypeDef hltdc_discovery
void BSP_LCD_SetTextColor(uint32_t Color)
Sets the LCD text color.
GPIO Init structure definition.
#define GPIO_PIN_15
#define OTM8009A_480X800_VBP
Definition: otm8009a.h:105
DSI_PLLInitTypeDef dsiPllInit
Definition: main.c:70
void HAL_GPIO_Init(GPIO_TypeDef *GPIOx, GPIO_InitTypeDef *GPIO_Init)
sFONT Font24
Definition: font24.c:2558
void BSP_LCD_SetBrightness(uint8_t BrightnessValue)
Set the brightness value.
uint32_t BSP_LCD_GetBackColor(void)
Gets the LCD background color.
void BSP_LCD_DrawHLine(uint16_t Xpos, uint16_t Ypos, uint16_t Length)
Draws an horizontal line in currently active layer.
uint8_t BSP_SDRAM_Init(void)
Initializes the SDRAM device.
__weak void BSP_LCD_MspInit(void)
Initialize the BSP LCD Msp. Application can surcharge if needed this function implementation.
void BSP_LCD_SetTransparency(uint32_t LayerIndex, uint8_t Transparency)
Configures the transparency.
#define DMA2D_INPUT_ARGB8888
uint32_t BSP_LCD_GetYSize(void)
Gets the LCD Y size.
#define OTM8009A_800X480_HBP
Definition: otm8009a.h:113
#define DSI
Definition: stm32f769xx.h:1690
#define RCC_PLLSAIDIVR_2
HAL_StatusTypeDef HAL_DMA2D_PollForTransfer(DMA2D_HandleTypeDef *hdma2d, uint32_t Timeout)
DSI_VidCfgTypeDef hdsivideo_handle
Definition: LCDConf.c:69
#define DMA2D_M2M_PFC
#define OTM8009A_480X800_HFP
Definition: otm8009a.h:103
#define OTM8009A_800X480_VBP
Definition: otm8009a.h:116
void DSI_IO_WriteCmd(uint32_t NbrParams, uint8_t *pParams)
DCS or Generic short/long write command.
void BSP_LCD_DrawPixel(uint16_t Xpos, uint16_t Ypos, uint32_t RGB_Code)
Draws a pixel on LCD.
#define ABS(X)
#define LTDC_ACTIVE_LAYER_BACKGROUND
LTDC Background layer index.
uint32_t BSP_LCD_ReadPixel(uint16_t Xpos, uint16_t Ypos)
Reads an LCD pixel.
void HAL_NVIC_DisableIRQ(IRQn_Type IRQn)
#define DMA2D
Definition: stm32f745xx.h:1346
void BSP_LCD_SetXSize(uint32_t imageWidthPixels)
Set the LCD X size.
#define VBP
Definition: main.c:80
void BSP_LCD_DrawBitmap(uint32_t Xpos, uint32_t Ypos, uint8_t *pbmp)
Draws a bitmap picture loaded in the internal Flash (32 bpp) in currently active layer.
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
#define OTM8009A_800X480_VFP
Definition: otm8009a.h:117
#define OTM8009A_480X800_HBP
Definition: otm8009a.h:102
RCC_PeriphCLKInitTypeDef PeriphClkInitStruct
DMA2D_LayerCfgTypeDef LayerCfg[MAX_DMA2D_LAYER]
DMA2D handle Structure definition.
#define DMA2D_NO_MODIF_ALPHA
uint16_t Height
Definition: fonts.h:72
#define OTM8009A_CMD_WRDISBV
Definition: otm8009a.h:172
RCC_PLLSAIInitTypeDef PLLSAI