STM32469I-Discovery BSP User Manual: stm32469i_discovery_lcd.c Source File

STM32469I-Discovery BSP Drivers

stm32469i_discovery_lcd.c
Go to the documentation of this file.
00001 /**
00002   ******************************************************************************
00003   * @file    stm32469i_discovery_lcd.c
00004   * @author  MCD Application Team
00005   * @version V2.0.0
00006   * @date    31-January-2017
00007   * @brief   This file includes the driver for Liquid Crystal Display (LCD) module
00008   *          mounted on STM32469I-Discovery evaluation board.
00009   ******************************************************************************
00010   * @attention
00011   *
00012   * <h2><center>&copy; COPYRIGHT(c) 2017 STMicroelectronics</center></h2>
00013   *
00014   * Redistribution and use in source and binary forms, with or without modification,
00015   * are permitted provided that the following conditions are met:
00016   *   1. Redistributions of source code must retain the above copyright notice,
00017   *      this list of conditions and the following disclaimer.
00018   *   2. Redistributions in binary form must reproduce the above copyright notice,
00019   *      this list of conditions and the following disclaimer in the documentation
00020   *      and/or other materials provided with the distribution.
00021   *   3. Neither the name of STMicroelectronics nor the names of its contributors
00022   *      may be used to endorse or promote products derived from this software
00023   *      without specific prior written permission.
00024   *
00025   * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
00026   * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00027   * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
00028   * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
00029   * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
00030   * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
00031   * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
00032   * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
00033   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
00034   * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00035   *
00036   ******************************************************************************
00037   */
00038 
00039 /* File Info: ------------------------------------------------------------------
00040                                    User NOTES
00041 1. How To use this driver:
00042 --------------------------
00043    - This driver is used to drive directly in video mode a LCD TFT using the DSI interface.
00044      The following IPs are implied : DSI Host IP block working
00045      in conjunction to the LTDC controller.
00046    - This driver is linked by construction to LCD KoD mounted on board MB1166.
00047 
00048 2. Driver description:
00049 ---------------------
00050   + Initialization steps:
00051      o Initialize the LCD using the BSP_LCD_Init() function.
00052      o Select the LCD layer to be used using the BSP_LCD_SelectLayer() function.
00053      o Enable the LCD display using the BSP_LCD_DisplayOn() function.
00054 
00055   + Options
00056      o Configure and enable the color keying functionality using the
00057        BSP_LCD_SetColorKeying() function.
00058      o Modify in the fly the transparency and/or the frame buffer address
00059        using the following functions:
00060        - BSP_LCD_SetTransparency()
00061        - BSP_LCD_SetLayerAddress()
00062 
00063   + Display on LCD
00064      o Clear the whole LCD using BSP_LCD_Clear() function or only one specified string
00065        line using the BSP_LCD_ClearStringLine() function.
00066      o Display a character on the specified line and column using the BSP_LCD_DisplayChar()
00067        function or a complete string line using the BSP_LCD_DisplayStringAtLine() function.
00068      o Display a string line on the specified position (x,y in pixel) and align mode
00069        using the BSP_LCD_DisplayStringAtLine() function.
00070      o Draw and fill a basic shapes (dot, line, rectangle, circle, ellipse, .. bitmap)
00071        on LCD using the available set of functions.
00072 
00073 ------------------------------------------------------------------------------*/
00074 
00075 /* Includes ------------------------------------------------------------------*/
00076 #include "stm32469i_discovery_lcd.h"
00077 #include "../../../Utilities/Fonts/fonts.h"
00078 #include "../../../Utilities/Fonts/font24.c"
00079 #include "../../../Utilities/Fonts/font20.c"
00080 #include "../../../Utilities/Fonts/font16.c"
00081 #include "../../../Utilities/Fonts/font12.c"
00082 #include "../../../Utilities/Fonts/font8.c"
00083 
00084 /** @addtogroup BSP
00085   * @{
00086   */
00087 
00088 /** @addtogroup STM32469I_Discovery
00089   * @{
00090   */
00091 
00092 /** @defgroup STM32469I-Discovery_LCD STM32469I Discovery LCD
00093   * @{
00094   */
00095 
00096 /** @defgroup STM32469I-Discovery_LCD_Private_TypesDefinitions STM32469I Discovery LCD Private TypesDefinitions
00097   * @{
00098   */
00099 static DSI_VidCfgTypeDef hdsivideo_handle;
00100 
00101 /**
00102   * @}
00103   */
00104 
00105 /** @defgroup STM32469I-Discovery_LCD_Private_Defines STM32469I Discovery LCD Private Defines
00106   * @{
00107   */
00108 /**
00109   * @}
00110   */
00111 
00112 /** @defgroup STM32469I-Discovery_LCD_Private_Macros STM32469I Discovery LCD Private Macros
00113   * @{
00114   */
00115 #define ABS(X)                 ((X) > 0 ? (X) : -(X))
00116 
00117 #define POLY_X(Z)              ((int32_t)((Points + (Z))->X))
00118 #define POLY_Y(Z)              ((int32_t)((Points + (Z))->Y))
00119 /**
00120   * @}
00121   */
00122 
00123 /** @defgroup STM32469I-Discovery_LCD_Exported_Variables STM32469I Discovery LCD Exported Variables
00124   * @{
00125   */
00126 
00127 /**
00128   * @}
00129   */
00130 
00131 
00132 /** @defgroup STM32469I-Discovery_LCD_Private_Variables STM32469I Discovery LCD Private Variables
00133   * @{
00134   */
00135 
00136 DMA2D_HandleTypeDef hdma2d_eval;
00137 LTDC_HandleTypeDef  hltdc_eval;
00138 DSI_HandleTypeDef hdsi_eval;
00139 uint32_t lcd_x_size = OTM8009A_800X480_WIDTH;
00140 uint32_t lcd_y_size = OTM8009A_800X480_HEIGHT;
00141 
00142 /**
00143   * @}
00144   */
00145 
00146 
00147 /** @defgroup STM32469I-Discovery_LCD_Private_Variables STM32469I Discovery LCD Private Variables
00148   * @{
00149   */
00150 
00151 /**
00152   * @brief  Default Active LTDC Layer in which drawing is made is LTDC Layer Background
00153   */
00154 static uint32_t  ActiveLayer = LTDC_ACTIVE_LAYER_BACKGROUND;
00155 
00156 /**
00157   * @brief  Current Drawing Layer properties variable
00158   */
00159 static LCD_DrawPropTypeDef DrawProp[LTDC_MAX_LAYER_NUMBER];
00160 /**
00161   * @}
00162   */
00163 
00164 /** @defgroup STM32469I-Discovery_LCD_Private_FunctionPrototypes STM32469I Discovery LCD Private FunctionPrototypes
00165   * @{
00166   */
00167 static void DrawChar(uint16_t Xpos, uint16_t Ypos, const uint8_t *c);
00168 static void FillTriangle(uint16_t x1, uint16_t x2, uint16_t x3, uint16_t y1, uint16_t y2, uint16_t y3);
00169 static void LL_FillBuffer(uint32_t LayerIndex, void *pDst, uint32_t xSize, uint32_t ySize, uint32_t OffLine, uint32_t ColorIndex);
00170 static void LL_ConvertLineToARGB8888(void * pSrc, void *pDst, uint32_t xSize, uint32_t ColorMode);
00171 /**
00172   * @}
00173   */
00174 
00175 /** @defgroup STM32469I-Discovery_LCD_Exported_Functions STM32469I Discovery LCD Exported Functions
00176   * @{
00177   */
00178 
00179 /**
00180   * @brief  Initializes the DSI LCD.
00181   * @retval LCD state
00182   */
00183 uint8_t BSP_LCD_Init(void)
00184 {
00185   return (BSP_LCD_InitEx(LCD_ORIENTATION_LANDSCAPE));
00186 }
00187 
00188 /**
00189   * @brief  Initializes the DSI LCD. 
00190   * The ititialization is done as below:
00191   *     - DSI PLL ititialization
00192   *     - DSI ititialization
00193   *     - LTDC ititialization
00194   *     - OTM8009A LCD Display IC Driver ititialization
00195   * @retval LCD state
00196   */
00197 uint8_t BSP_LCD_InitEx(LCD_OrientationTypeDef orientation)
00198 {
00199   DSI_PLLInitTypeDef dsiPllInit;
00200   DSI_PHY_TimerTypeDef  PhyTimings;
00201   static RCC_PeriphCLKInitTypeDef  PeriphClkInitStruct;
00202   uint32_t LcdClock  = 27429; /*!< LcdClk = 27429 kHz */
00203   
00204   uint32_t laneByteClk_kHz = 0;
00205   uint32_t                   VSA; /*!< Vertical start active time in units of lines */
00206   uint32_t                   VBP; /*!< Vertical Back Porch time in units of lines */
00207   uint32_t                   VFP; /*!< Vertical Front Porch time in units of lines */
00208   uint32_t                   VACT; /*!< Vertical Active time in units of lines = imageSize Y in pixels to display */
00209   uint32_t                   HSA; /*!< Horizontal start active time in units of lcdClk */
00210   uint32_t                   HBP; /*!< Horizontal Back Porch time in units of lcdClk */
00211   uint32_t                   HFP; /*!< Horizontal Front Porch time in units of lcdClk */
00212   uint32_t                   HACT; /*!< Horizontal Active time in units of lcdClk = imageSize X in pixels to display */
00213   
00214   
00215   /* Toggle Hardware Reset of the DSI LCD using
00216   * its XRES signal (active low) */
00217   BSP_LCD_Reset();
00218   
00219   /* Call first MSP Initialize only in case of first initialization
00220   * This will set IP blocks LTDC, DSI and DMA2D
00221   * - out of reset
00222   * - clocked
00223   * - NVIC IRQ related to IP blocks enabled
00224   */
00225   BSP_LCD_MspInit();
00226   
00227 /*************************DSI Initialization***********************************/  
00228   
00229   /* Base address of DSI Host/Wrapper registers to be set before calling De-Init */
00230   hdsi_eval.Instance = DSI;
00231   
00232   HAL_DSI_DeInit(&(hdsi_eval));
00233   
00234 #if !defined(USE_STM32469I_DISCO_REVA)
00235   dsiPllInit.PLLNDIV  = 125;
00236   dsiPllInit.PLLIDF   = DSI_PLL_IN_DIV2;
00237   dsiPllInit.PLLODF   = DSI_PLL_OUT_DIV1;
00238 #else  
00239   dsiPllInit.PLLNDIV  = 100;
00240   dsiPllInit.PLLIDF   = DSI_PLL_IN_DIV5;
00241   dsiPllInit.PLLODF   = DSI_PLL_OUT_DIV1;
00242 #endif
00243   laneByteClk_kHz = 62500; /* 500 MHz / 8 = 62.5 MHz = 62500 kHz */
00244   
00245   /* Set number of Lanes */
00246   hdsi_eval.Init.NumberOfLanes = DSI_TWO_DATA_LANES;
00247   
00248   /* TXEscapeCkdiv = f(LaneByteClk)/15.62 = 4 */
00249   hdsi_eval.Init.TXEscapeCkdiv = laneByteClk_kHz/15620; 
00250   
00251   HAL_DSI_Init(&(hdsi_eval), &(dsiPllInit));
00252   
00253   /* Timing parameters for all Video modes
00254   * Set Timing parameters of LTDC depending on its chosen orientation
00255   */
00256   if(orientation == LCD_ORIENTATION_PORTRAIT)
00257   {
00258     lcd_x_size = OTM8009A_480X800_WIDTH;  /* 480 */
00259     lcd_y_size = OTM8009A_480X800_HEIGHT; /* 800 */                                
00260   }
00261   else
00262   {
00263     /* lcd_orientation == LCD_ORIENTATION_LANDSCAPE */
00264     lcd_x_size = OTM8009A_800X480_WIDTH;  /* 800 */
00265     lcd_y_size = OTM8009A_800X480_HEIGHT; /* 480 */                                
00266   }
00267   
00268   HACT = lcd_x_size;
00269   VACT = lcd_y_size;
00270   
00271   /* The following values are same for portrait and landscape orientations */
00272   VSA  = OTM8009A_480X800_VSYNC;
00273   VBP  = OTM8009A_480X800_VBP;
00274   VFP  = OTM8009A_480X800_VFP;
00275   HSA  = OTM8009A_480X800_HSYNC;
00276   HBP  = OTM8009A_480X800_HBP;
00277   HFP  = OTM8009A_480X800_HFP;
00278   
00279   
00280   hdsivideo_handle.VirtualChannelID = LCD_OTM8009A_ID;
00281   hdsivideo_handle.ColorCoding = LCD_DSI_PIXEL_DATA_FMT_RBG888;
00282   hdsivideo_handle.VSPolarity = DSI_VSYNC_ACTIVE_HIGH;
00283   hdsivideo_handle.HSPolarity = DSI_HSYNC_ACTIVE_HIGH;
00284   hdsivideo_handle.DEPolarity = DSI_DATA_ENABLE_ACTIVE_HIGH;  
00285   hdsivideo_handle.Mode = DSI_VID_MODE_BURST; /* Mode Video burst ie : one LgP per line */
00286   hdsivideo_handle.NullPacketSize = 0xFFF;
00287   hdsivideo_handle.NumberOfChunks = 0;
00288   hdsivideo_handle.PacketSize                = HACT; /* Value depending on display orientation choice portrait/landscape */ 
00289   hdsivideo_handle.HorizontalSyncActive      = (HSA * laneByteClk_kHz) / LcdClock;
00290   hdsivideo_handle.HorizontalBackPorch       = (HBP * laneByteClk_kHz) / LcdClock;
00291   hdsivideo_handle.HorizontalLine            = ((HACT + HSA + HBP + HFP) * laneByteClk_kHz) / LcdClock; /* Value depending on display orientation choice portrait/landscape */
00292   hdsivideo_handle.VerticalSyncActive        = VSA;
00293   hdsivideo_handle.VerticalBackPorch         = VBP;
00294   hdsivideo_handle.VerticalFrontPorch        = VFP;
00295   hdsivideo_handle.VerticalActive            = VACT; /* Value depending on display orientation choice portrait/landscape */
00296   
00297   /* Enable or disable sending LP command while streaming is active in video mode */
00298   hdsivideo_handle.LPCommandEnable = DSI_LP_COMMAND_ENABLE; /* Enable sending commands in mode LP (Low Power) */
00299   
00300   /* Largest packet size possible to transmit in LP mode in VSA, VBP, VFP regions */
00301   /* Only useful when sending LP packets is allowed while streaming is active in video mode */
00302   hdsivideo_handle.LPLargestPacketSize = 16;
00303   
00304   /* Largest packet size possible to transmit in LP mode in HFP region during VACT period */
00305   /* Only useful when sending LP packets is allowed while streaming is active in video mode */
00306   hdsivideo_handle.LPVACTLargestPacketSize = 0;
00307   
00308   
00309   /* Specify for each region of the video frame, if the transmission of command in LP mode is allowed in this region */
00310   /* while streaming is active in video mode                                                                         */
00311   hdsivideo_handle.LPHorizontalFrontPorchEnable = DSI_LP_HFP_ENABLE;   /* Allow sending LP commands during HFP period */
00312   hdsivideo_handle.LPHorizontalBackPorchEnable  = DSI_LP_HBP_ENABLE;   /* Allow sending LP commands during HBP period */
00313   hdsivideo_handle.LPVerticalActiveEnable = DSI_LP_VACT_ENABLE;  /* Allow sending LP commands during VACT period */
00314   hdsivideo_handle.LPVerticalFrontPorchEnable = DSI_LP_VFP_ENABLE;   /* Allow sending LP commands during VFP period */
00315   hdsivideo_handle.LPVerticalBackPorchEnable = DSI_LP_VBP_ENABLE;   /* Allow sending LP commands during VBP period */
00316   hdsivideo_handle.LPVerticalSyncActiveEnable = DSI_LP_VSYNC_ENABLE; /* Allow sending LP commands during VSync = VSA period */
00317   
00318   /* Configure DSI Video mode timings with settings set above */
00319   HAL_DSI_ConfigVideoMode(&(hdsi_eval), &(hdsivideo_handle));
00320 
00321   /* Configure DSI PHY HS2LP and LP2HS timings */
00322   PhyTimings.ClockLaneHS2LPTime = 35;
00323   PhyTimings.ClockLaneLP2HSTime = 35;
00324   PhyTimings.DataLaneHS2LPTime = 35;
00325   PhyTimings.DataLaneLP2HSTime = 35;
00326   PhyTimings.DataLaneMaxReadTime = 0;
00327   PhyTimings.StopWaitTime = 10;
00328   HAL_DSI_ConfigPhyTimer(&hdsi_eval, &PhyTimings);
00329 
00330 /*************************End DSI Initialization*******************************/ 
00331   
00332   
00333 /************************LTDC Initialization***********************************/  
00334   
00335   /* Timing Configuration */    
00336   hltdc_eval.Init.HorizontalSync = (HSA - 1);
00337   hltdc_eval.Init.AccumulatedHBP = (HSA + HBP - 1);
00338   hltdc_eval.Init.AccumulatedActiveW = (lcd_x_size + HSA + HBP - 1);
00339   hltdc_eval.Init.TotalWidth = (lcd_x_size + HSA + HBP + HFP - 1);
00340   
00341   /* Initialize the LCD pixel width and pixel height */
00342   hltdc_eval.LayerCfg->ImageWidth  = lcd_x_size;
00343   hltdc_eval.LayerCfg->ImageHeight = lcd_y_size;   
00344   
00345   
00346   /* LCD clock configuration */
00347   /* PLLSAI_VCO Input = HSE_VALUE/PLL_M = 1 Mhz */
00348   /* PLLSAI_VCO Output = PLLSAI_VCO Input * PLLSAIN = 384 Mhz */
00349   /* PLLLCDCLK = PLLSAI_VCO Output/PLLSAIR = 384 MHz / 7 = 54.857 MHz */
00350   /* LTDC clock frequency = PLLLCDCLK / LTDC_PLLSAI_DIVR_2 = 54.857 MHz / 2 = 27.429 MHz */
00351   PeriphClkInitStruct.PeriphClockSelection = RCC_PERIPHCLK_LTDC;
00352   PeriphClkInitStruct.PLLSAI.PLLSAIN = 384;
00353   PeriphClkInitStruct.PLLSAI.PLLSAIR = 7;
00354   PeriphClkInitStruct.PLLSAIDivR = RCC_PLLSAIDIVR_2;
00355   HAL_RCCEx_PeriphCLKConfig(&PeriphClkInitStruct); 
00356   
00357   /* Background value */
00358   hltdc_eval.Init.Backcolor.Blue = 0;
00359   hltdc_eval.Init.Backcolor.Green = 0;
00360   hltdc_eval.Init.Backcolor.Red = 0;
00361   hltdc_eval.Init.PCPolarity = LTDC_PCPOLARITY_IPC;
00362   hltdc_eval.Instance = LTDC;
00363   
00364   /* Get LTDC Configuration from DSI Configuration */
00365   HAL_LTDCEx_StructInitFromVideoConfig(&(hltdc_eval), &(hdsivideo_handle));
00366   
00367   /* Initialize the LTDC */  
00368   HAL_LTDC_Init(&hltdc_eval);
00369 
00370   /* Enable the DSI host and wrapper after the LTDC initialization
00371      To avoid any synchronization issue, the DSI shall be started after enabling the LTDC */
00372   HAL_DSI_Start(&(hdsi_eval));
00373   
00374 #if !defined(DATA_IN_ExtSDRAM)
00375   /* Initialize the SDRAM */
00376   BSP_SDRAM_Init();
00377 #endif /* DATA_IN_ExtSDRAM */
00378   
00379   /* Initialize the font */
00380   BSP_LCD_SetFont(&LCD_DEFAULT_FONT);
00381   
00382 /************************End LTDC Initialization*******************************/
00383   
00384   
00385 /***********************OTM8009A Initialization********************************/  
00386   
00387   /* Initialize the OTM8009A LCD Display IC Driver (KoD LCD IC Driver)
00388   *  depending on configuration set in 'hdsivideo_handle'.
00389   */
00390   OTM8009A_Init(OTM8009A_FORMAT_RGB888, orientation);
00391   
00392 /***********************End OTM8009A Initialization****************************/ 
00393   
00394   return LCD_OK;
00395 }
00396 
00397 /**
00398   * @brief  BSP LCD Reset
00399   *         Hw reset the LCD DSI activating its XRES signal (active low for some time)
00400   *         and desactivating it later.
00401   *         This signal is only cabled on Discovery Rev B and beyond.
00402   */
00403 void BSP_LCD_Reset(void)
00404 {
00405 #if !defined(USE_STM32469I_DISCO_REVA)
00406 /* EVAL Rev B and beyond : reset the LCD by activation of XRES (active low) connected to PH7 */
00407   GPIO_InitTypeDef  gpio_init_structure;
00408 
00409   __HAL_RCC_GPIOH_CLK_ENABLE();
00410 
00411     /* Configure the GPIO on PH7 */
00412     gpio_init_structure.Pin   = GPIO_PIN_7;
00413     gpio_init_structure.Mode  = GPIO_MODE_OUTPUT_OD;
00414     gpio_init_structure.Pull  = GPIO_NOPULL;
00415     gpio_init_structure.Speed = GPIO_SPEED_HIGH;
00416 
00417     HAL_GPIO_Init(GPIOH, &gpio_init_structure);
00418 
00419     /* Activate XRES active low */
00420     HAL_GPIO_WritePin(GPIOH, GPIO_PIN_7, GPIO_PIN_RESET);
00421 
00422     HAL_Delay(20); /* wait 20 ms */
00423 
00424     /* Desactivate XRES */
00425     HAL_GPIO_WritePin(GPIOH, GPIO_PIN_7, GPIO_PIN_SET);
00426     
00427     /* Wait for 10ms after releasing XRES before sending commands */
00428     HAL_Delay(10);    
00429 #else
00430   
00431 #endif /* USE_STM32469I_DISCO_REVA == 0 */
00432 }
00433 
00434 /**
00435   * @brief  Gets the LCD X size.
00436   * @retval Used LCD X size
00437   */
00438 uint32_t BSP_LCD_GetXSize(void)
00439 {
00440   return (lcd_x_size);
00441 }
00442 
00443 /**
00444   * @brief  Gets the LCD Y size.
00445   * @retval Used LCD Y size
00446   */
00447 uint32_t BSP_LCD_GetYSize(void)
00448 {
00449   return (lcd_y_size);
00450 }
00451 
00452 /**
00453   * @brief  Set the LCD X size.
00454   * @param  imageWidthPixels : uint32_t image width in pixels unit
00455   */
00456 void BSP_LCD_SetXSize(uint32_t imageWidthPixels)
00457 {
00458   hltdc_eval.LayerCfg[ActiveLayer].ImageWidth = imageWidthPixels;
00459 }
00460 
00461 /**
00462   * @brief  Set the LCD Y size.
00463   * @param  imageHeightPixels : uint32_t image height in lines unit
00464   */
00465 void BSP_LCD_SetYSize(uint32_t imageHeightPixels)
00466 {
00467   hltdc_eval.LayerCfg[ActiveLayer].ImageHeight = imageHeightPixels;
00468 }
00469 
00470 
00471 /**
00472   * @brief  Initializes the LCD layers.
00473   * @param  LayerIndex: Layer foreground or background
00474   * @param  FB_Address: Layer frame buffer
00475   */
00476 void BSP_LCD_LayerDefaultInit(uint16_t LayerIndex, uint32_t FB_Address)
00477 {
00478     LCD_LayerCfgTypeDef  Layercfg;
00479 
00480   /* Layer Init */
00481   Layercfg.WindowX0 = 0;
00482   Layercfg.WindowX1 = BSP_LCD_GetXSize();
00483   Layercfg.WindowY0 = 0;
00484   Layercfg.WindowY1 = BSP_LCD_GetYSize(); 
00485   Layercfg.PixelFormat = LTDC_PIXEL_FORMAT_ARGB8888;
00486   Layercfg.FBStartAdress = FB_Address;
00487   Layercfg.Alpha = 255;
00488   Layercfg.Alpha0 = 0;
00489   Layercfg.Backcolor.Blue = 0;
00490   Layercfg.Backcolor.Green = 0;
00491   Layercfg.Backcolor.Red = 0;
00492   Layercfg.BlendingFactor1 = LTDC_BLENDING_FACTOR1_PAxCA;
00493   Layercfg.BlendingFactor2 = LTDC_BLENDING_FACTOR2_PAxCA;
00494   Layercfg.ImageWidth = BSP_LCD_GetXSize();
00495   Layercfg.ImageHeight = BSP_LCD_GetYSize();
00496   
00497   HAL_LTDC_ConfigLayer(&hltdc_eval, &Layercfg, LayerIndex); 
00498   
00499   DrawProp[LayerIndex].BackColor = LCD_COLOR_WHITE;
00500   DrawProp[LayerIndex].pFont     = &Font24;
00501   DrawProp[LayerIndex].TextColor = LCD_COLOR_BLACK;
00502 }
00503 
00504 
00505 /**
00506   * @brief  Selects the LCD Layer.
00507   * @param  LayerIndex: Layer foreground or background
00508   */
00509 void BSP_LCD_SelectLayer(uint32_t LayerIndex)
00510 {
00511   ActiveLayer = LayerIndex;
00512 }
00513 
00514 /**
00515   * @brief  Sets an LCD Layer visible
00516   * @param  LayerIndex: Visible Layer
00517   * @param  State: New state of the specified layer
00518   *          This parameter can be one of the following values:
00519   *            @arg  ENABLE
00520   *            @arg  DISABLE
00521   */
00522 void BSP_LCD_SetLayerVisible(uint32_t LayerIndex, FunctionalState State)
00523 {
00524   if(State == ENABLE)
00525   {
00526     __HAL_LTDC_LAYER_ENABLE(&(hltdc_eval), LayerIndex);
00527   }
00528   else
00529   {
00530     __HAL_LTDC_LAYER_DISABLE(&(hltdc_eval), LayerIndex);
00531   }
00532   __HAL_LTDC_RELOAD_IMMEDIATE_CONFIG(&(hltdc_eval));
00533   
00534 }
00535 
00536 /**
00537   * @brief  Configures the transparency.
00538   * @param  LayerIndex: Layer foreground or background.
00539   * @param  Transparency: Transparency
00540   *           This parameter must be a number between Min_Data = 0x00 and Max_Data = 0xFF
00541   */
00542 void BSP_LCD_SetTransparency(uint32_t LayerIndex, uint8_t Transparency)
00543 {
00544   
00545   HAL_LTDC_SetAlpha(&(hltdc_eval), Transparency, LayerIndex);
00546   
00547 }
00548 
00549 /**
00550   * @brief  Sets an LCD layer frame buffer address.
00551   * @param  LayerIndex: Layer foreground or background
00552   * @param  Address: New LCD frame buffer value
00553   */
00554 void BSP_LCD_SetLayerAddress(uint32_t LayerIndex, uint32_t Address)
00555 {
00556   
00557   HAL_LTDC_SetAddress(&(hltdc_eval), Address, LayerIndex);
00558   
00559 }
00560 
00561 /**
00562   * @brief  Sets display window.
00563   * @param  LayerIndex: Layer index
00564   * @param  Xpos: LCD X position
00565   * @param  Ypos: LCD Y position
00566   * @param  Width: LCD window width
00567   * @param  Height: LCD window height
00568   */
00569 void BSP_LCD_SetLayerWindow(uint16_t LayerIndex, uint16_t Xpos, uint16_t Ypos, uint16_t Width, uint16_t Height)
00570 {
00571   /* Reconfigure the layer size */
00572   HAL_LTDC_SetWindowSize(&(hltdc_eval), Width, Height, LayerIndex);
00573   
00574   /* Reconfigure the layer position */
00575   HAL_LTDC_SetWindowPosition(&(hltdc_eval), Xpos, Ypos, LayerIndex);
00576   
00577 }
00578 
00579 /**
00580   * @brief  Configures and sets the color keying.
00581   * @param  LayerIndex: Layer foreground or background
00582   * @param  RGBValue: Color reference
00583   */
00584 void BSP_LCD_SetColorKeying(uint32_t LayerIndex, uint32_t RGBValue)
00585 {
00586   /* Configure and Enable the color Keying for LCD Layer */
00587   HAL_LTDC_ConfigColorKeying(&(hltdc_eval), RGBValue, LayerIndex);
00588   HAL_LTDC_EnableColorKeying(&(hltdc_eval), LayerIndex);
00589 }
00590 
00591 /**
00592   * @brief  Disables the color keying.
00593   * @param  LayerIndex: Layer foreground or background
00594   */
00595 void BSP_LCD_ResetColorKeying(uint32_t LayerIndex)
00596 {
00597   /* Disable the color Keying for LCD Layer */
00598   HAL_LTDC_DisableColorKeying(&(hltdc_eval), LayerIndex);
00599 }
00600 
00601 /**
00602   * @brief  Sets the LCD text color.
00603   * @param  Color: Text color code ARGB(8-8-8-8)
00604   */
00605 void BSP_LCD_SetTextColor(uint32_t Color)
00606 {
00607   DrawProp[ActiveLayer].TextColor = Color;
00608 }
00609 
00610 /**
00611   * @brief  Gets the LCD text color.
00612   * @retval Used text color.
00613   */
00614 uint32_t BSP_LCD_GetTextColor(void)
00615 {
00616   return DrawProp[ActiveLayer].TextColor;
00617 }
00618 
00619 /**
00620   * @brief  Sets the LCD background color.
00621   * @param  Color: Layer background color code ARGB(8-8-8-8)
00622   */
00623 void BSP_LCD_SetBackColor(uint32_t Color)
00624 {
00625   DrawProp[ActiveLayer].BackColor = Color;
00626 }
00627 
00628 /**
00629   * @brief  Gets the LCD background color.
00630   * @retval Used background color
00631   */
00632 uint32_t BSP_LCD_GetBackColor(void)
00633 {
00634   return DrawProp[ActiveLayer].BackColor;
00635 }
00636 
00637 /**
00638   * @brief  Sets the LCD text font.
00639   * @param  fonts: Layer font to be used
00640   */
00641 void BSP_LCD_SetFont(sFONT *fonts)
00642 {
00643   DrawProp[ActiveLayer].pFont = fonts;
00644 }
00645 
00646 /**
00647   * @brief  Gets the LCD text font.
00648   * @retval Used layer font
00649   */
00650 sFONT *BSP_LCD_GetFont(void)
00651 {
00652   return DrawProp[ActiveLayer].pFont;
00653 }
00654 
00655 /**
00656   * @brief  Reads an LCD pixel.
00657   * @param  Xpos: X position
00658   * @param  Ypos: Y position
00659   * @retval RGB pixel color
00660   */
00661 uint32_t BSP_LCD_ReadPixel(uint16_t Xpos, uint16_t Ypos)
00662 {
00663   uint32_t ret = 0;
00664 
00665   if(hltdc_eval.LayerCfg[ActiveLayer].PixelFormat == LTDC_PIXEL_FORMAT_ARGB8888)
00666   {
00667     /* Read data value from SDRAM memory */
00668     ret = *(__IO uint32_t*) (hltdc_eval.LayerCfg[ActiveLayer].FBStartAdress + (4*(Ypos*BSP_LCD_GetXSize() + Xpos)));
00669   }
00670   else if(hltdc_eval.LayerCfg[ActiveLayer].PixelFormat == LTDC_PIXEL_FORMAT_RGB888)
00671   {
00672     /* Read data value from SDRAM memory */
00673     ret = (*(__IO uint32_t*) (hltdc_eval.LayerCfg[ActiveLayer].FBStartAdress + (4*(Ypos*BSP_LCD_GetXSize() + Xpos))) & 0x00FFFFFF);
00674   }
00675   else if((hltdc_eval.LayerCfg[ActiveLayer].PixelFormat == LTDC_PIXEL_FORMAT_RGB565) || \
00676           (hltdc_eval.LayerCfg[ActiveLayer].PixelFormat == LTDC_PIXEL_FORMAT_ARGB4444) || \
00677           (hltdc_eval.LayerCfg[ActiveLayer].PixelFormat == LTDC_PIXEL_FORMAT_AL88))
00678   {
00679     /* Read data value from SDRAM memory */
00680     ret = *(__IO uint16_t*) (hltdc_eval.LayerCfg[ActiveLayer].FBStartAdress + (2*(Ypos*BSP_LCD_GetXSize() + Xpos)));
00681   }
00682   else
00683   {
00684     /* Read data value from SDRAM memory */
00685     ret = *(__IO uint8_t*) (hltdc_eval.LayerCfg[ActiveLayer].FBStartAdress + (2*(Ypos*BSP_LCD_GetXSize() + Xpos)));
00686   }
00687 
00688   return ret;
00689 }
00690 
00691 /**
00692   * @brief  Clears the whole currently active layer of LTDC.
00693   * @param  Color: Color of the background
00694   */
00695 void BSP_LCD_Clear(uint32_t Color)
00696 {
00697   /* Clear the LCD */
00698   LL_FillBuffer(ActiveLayer, (uint32_t *)(hltdc_eval.LayerCfg[ActiveLayer].FBStartAdress), BSP_LCD_GetXSize(), BSP_LCD_GetYSize(), 0, Color);
00699 }
00700 
00701 /**
00702   * @brief  Clears the selected line in currently active layer.
00703   * @param  Line: Line to be cleared
00704   */
00705 void BSP_LCD_ClearStringLine(uint32_t Line)
00706 {
00707   uint32_t color_backup = DrawProp[ActiveLayer].TextColor;
00708   DrawProp[ActiveLayer].TextColor = DrawProp[ActiveLayer].BackColor;
00709 
00710   /* Draw rectangle with background color */
00711   BSP_LCD_FillRect(0, (Line * DrawProp[ActiveLayer].pFont->Height), BSP_LCD_GetXSize(), DrawProp[ActiveLayer].pFont->Height);
00712 
00713   DrawProp[ActiveLayer].TextColor = color_backup;
00714   BSP_LCD_SetTextColor(DrawProp[ActiveLayer].TextColor);
00715 }
00716 
00717 /**
00718   * @brief  Displays one character in currently active layer.
00719   * @param  Xpos: Start column address
00720   * @param  Ypos: Line where to display the character shape.
00721   * @param  Ascii: Character ascii code
00722   *           This parameter must be a number between Min_Data = 0x20 and Max_Data = 0x7E
00723   */
00724 void BSP_LCD_DisplayChar(uint16_t Xpos, uint16_t Ypos, uint8_t Ascii)
00725 {
00726   DrawChar(Xpos, Ypos, &DrawProp[ActiveLayer].pFont->table[(Ascii-' ') *\
00727     DrawProp[ActiveLayer].pFont->Height * ((DrawProp[ActiveLayer].pFont->Width + 7) / 8)]);
00728 }
00729 
00730 /**
00731   * @brief  Displays characters in currently active layer.
00732   * @param  Xpos: X position (in pixel)
00733   * @param  Ypos: Y position (in pixel)
00734   * @param  Text: Pointer to string to display on LCD
00735   * @param  Mode: Display mode
00736   *          This parameter can be one of the following values:
00737   *            @arg  CENTER_MODE
00738   *            @arg  RIGHT_MODE
00739   *            @arg  LEFT_MODE
00740   */
00741 void BSP_LCD_DisplayStringAt(uint16_t Xpos, uint16_t Ypos, uint8_t *Text, Text_AlignModeTypdef Mode)
00742 {
00743   uint16_t refcolumn = 1, i = 0;
00744   uint32_t size = 0, xsize = 0;
00745   uint8_t  *ptr = Text;
00746 
00747   /* Get the text size */
00748   while (*ptr++) size ++ ;
00749 
00750   /* Characters number per line */
00751   xsize = (BSP_LCD_GetXSize()/DrawProp[ActiveLayer].pFont->Width);
00752 
00753   switch (Mode)
00754   {
00755   case CENTER_MODE:
00756     {
00757       refcolumn = Xpos + ((xsize - size)* DrawProp[ActiveLayer].pFont->Width) / 2;
00758       break;
00759     }
00760   case LEFT_MODE:
00761     {
00762       refcolumn = Xpos;
00763       break;
00764     }
00765   case RIGHT_MODE:
00766     {
00767       refcolumn = - Xpos + ((xsize - size)*DrawProp[ActiveLayer].pFont->Width);
00768       break;
00769     }
00770   default:
00771     {
00772       refcolumn = Xpos;
00773       break;
00774     }
00775   }
00776 
00777   /* Check that the Start column is located in the screen */
00778   if ((refcolumn < 1) || (refcolumn >= 0x8000))
00779   {
00780     refcolumn = 1;
00781   }
00782 
00783   /* Send the string character by character on LCD */
00784   while ((*Text != 0) & (((BSP_LCD_GetXSize() - (i*DrawProp[ActiveLayer].pFont->Width)) & 0xFFFF) >= DrawProp[ActiveLayer].pFont->Width))
00785   {
00786     /* Display one character on LCD */
00787     BSP_LCD_DisplayChar(refcolumn, Ypos, *Text);
00788     /* Decrement the column position by 16 */
00789     refcolumn += DrawProp[ActiveLayer].pFont->Width;
00790 
00791     /* Point on the next character */
00792     Text++;
00793     i++;
00794   }
00795 
00796 }
00797 
00798 /**
00799   * @brief  Displays a maximum of 60 characters on the LCD.
00800   * @param  Line: Line where to display the character shape
00801   * @param  ptr: Pointer to string to display on LCD
00802   */
00803 void BSP_LCD_DisplayStringAtLine(uint16_t Line, uint8_t *ptr)
00804 {
00805   BSP_LCD_DisplayStringAt(0, LINE(Line), ptr, LEFT_MODE);
00806 }
00807 
00808 /**
00809   * @brief  Draws an horizontal line in currently active layer.
00810   * @param  Xpos: X position
00811   * @param  Ypos: Y position
00812   * @param  Length: Line length
00813   */
00814 void BSP_LCD_DrawHLine(uint16_t Xpos, uint16_t Ypos, uint16_t Length)
00815 {
00816   uint32_t  Xaddress = 0;
00817 
00818   /* Get the line address */
00819   Xaddress = (hltdc_eval.LayerCfg[ActiveLayer].FBStartAdress) + 4*(BSP_LCD_GetXSize()*Ypos + Xpos);
00820 
00821   /* Write line */
00822   LL_FillBuffer(ActiveLayer, (uint32_t *)Xaddress, Length, 1, 0, DrawProp[ActiveLayer].TextColor);
00823 }
00824 
00825 /**
00826   * @brief  Draws a vertical line in currently active layer.
00827   * @param  Xpos: X position
00828   * @param  Ypos: Y position
00829   * @param  Length: Line length
00830   */
00831 void BSP_LCD_DrawVLine(uint16_t Xpos, uint16_t Ypos, uint16_t Length)
00832 {
00833   uint32_t  Xaddress = 0;
00834 
00835   /* Get the line address */
00836   Xaddress = (hltdc_eval.LayerCfg[ActiveLayer].FBStartAdress) + 4*(BSP_LCD_GetXSize()*Ypos + Xpos);
00837 
00838   /* Write line */
00839   LL_FillBuffer(ActiveLayer, (uint32_t *)Xaddress, 1, Length, (BSP_LCD_GetXSize() - 1), DrawProp[ActiveLayer].TextColor);
00840 }
00841 
00842 /**
00843   * @brief  Draws an uni-line (between two points) in currently active layer.
00844   * @param  x1: Point 1 X position
00845   * @param  y1: Point 1 Y position
00846   * @param  x2: Point 2 X position
00847   * @param  y2: Point 2 Y position
00848   */
00849 void BSP_LCD_DrawLine(uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2)
00850 {
00851   int16_t deltax = 0, deltay = 0, x = 0, y = 0, xinc1 = 0, xinc2 = 0,
00852   yinc1 = 0, yinc2 = 0, den = 0, num = 0, numadd = 0, numpixels = 0,
00853   curpixel = 0;
00854 
00855   deltax = ABS(x2 - x1);        /* The difference between the x's */
00856   deltay = ABS(y2 - y1);        /* The difference between the y's */
00857   x = x1;                       /* Start x off at the first pixel */
00858   y = y1;                       /* Start y off at the first pixel */
00859 
00860   if (x2 >= x1)                 /* The x-values are increasing */
00861   {
00862     xinc1 = 1;
00863     xinc2 = 1;
00864   }
00865   else                          /* The x-values are decreasing */
00866   {
00867     xinc1 = -1;
00868     xinc2 = -1;
00869   }
00870 
00871   if (y2 >= y1)                 /* The y-values are increasing */
00872   {
00873     yinc1 = 1;
00874     yinc2 = 1;
00875   }
00876   else                          /* The y-values are decreasing */
00877   {
00878     yinc1 = -1;
00879     yinc2 = -1;
00880   }
00881 
00882   if (deltax >= deltay)         /* There is at least one x-value for every y-value */
00883   {
00884     xinc1 = 0;                  /* Don't change the x when numerator >= denominator */
00885     yinc2 = 0;                  /* Don't change the y for every iteration */
00886     den = deltax;
00887     num = deltax / 2;
00888     numadd = deltay;
00889     numpixels = deltax;         /* There are more x-values than y-values */
00890   }
00891   else                          /* There is at least one y-value for every x-value */
00892   {
00893     xinc2 = 0;                  /* Don't change the x for every iteration */
00894     yinc1 = 0;                  /* Don't change the y when numerator >= denominator */
00895     den = deltay;
00896     num = deltay / 2;
00897     numadd = deltax;
00898     numpixels = deltay;         /* There are more y-values than x-values */
00899   }
00900 
00901   for (curpixel = 0; curpixel <= numpixels; curpixel++)
00902   {
00903     BSP_LCD_DrawPixel(x, y, DrawProp[ActiveLayer].TextColor);   /* Draw the current pixel */
00904     num += numadd;                            /* Increase the numerator by the top of the fraction */
00905     if (num >= den)                           /* Check if numerator >= denominator */
00906     {
00907       num -= den;                             /* Calculate the new numerator value */
00908       x += xinc1;                             /* Change the x as appropriate */
00909       y += yinc1;                             /* Change the y as appropriate */
00910     }
00911     x += xinc2;                               /* Change the x as appropriate */
00912     y += yinc2;                               /* Change the y as appropriate */
00913   }
00914 }
00915 
00916 /**
00917   * @brief  Draws a rectangle in currently active layer.
00918   * @param  Xpos: X position
00919   * @param  Ypos: Y position
00920   * @param  Width: Rectangle width
00921   * @param  Height: Rectangle height
00922   */
00923 void BSP_LCD_DrawRect(uint16_t Xpos, uint16_t Ypos, uint16_t Width, uint16_t Height)
00924 {
00925   /* Draw horizontal lines */
00926   BSP_LCD_DrawHLine(Xpos, Ypos, Width);
00927   BSP_LCD_DrawHLine(Xpos, (Ypos+ Height), Width);
00928 
00929   /* Draw vertical lines */
00930   BSP_LCD_DrawVLine(Xpos, Ypos, Height);
00931   BSP_LCD_DrawVLine((Xpos + Width), Ypos, Height);
00932 }
00933 
00934 /**
00935   * @brief  Draws a circle in currently active layer.
00936   * @param  Xpos: X position
00937   * @param  Ypos: Y position
00938   * @param  Radius: Circle radius
00939   */
00940 void BSP_LCD_DrawCircle(uint16_t Xpos, uint16_t Ypos, uint16_t Radius)
00941 {
00942   int32_t   D;    /* Decision Variable */
00943   uint32_t  CurX; /* Current X Value */
00944   uint32_t  CurY; /* Current Y Value */
00945 
00946   D = 3 - (Radius << 1);
00947   CurX = 0;
00948   CurY = Radius;
00949 
00950   while (CurX <= CurY)
00951   {
00952     BSP_LCD_DrawPixel((Xpos + CurX), (Ypos - CurY), DrawProp[ActiveLayer].TextColor);
00953 
00954     BSP_LCD_DrawPixel((Xpos - CurX), (Ypos - CurY), DrawProp[ActiveLayer].TextColor);
00955 
00956     BSP_LCD_DrawPixel((Xpos + CurY), (Ypos - CurX), DrawProp[ActiveLayer].TextColor);
00957 
00958     BSP_LCD_DrawPixel((Xpos - CurY), (Ypos - CurX), DrawProp[ActiveLayer].TextColor);
00959 
00960     BSP_LCD_DrawPixel((Xpos + CurX), (Ypos + CurY), DrawProp[ActiveLayer].TextColor);
00961 
00962     BSP_LCD_DrawPixel((Xpos - CurX), (Ypos + CurY), DrawProp[ActiveLayer].TextColor);
00963 
00964     BSP_LCD_DrawPixel((Xpos + CurY), (Ypos + CurX), DrawProp[ActiveLayer].TextColor);
00965 
00966     BSP_LCD_DrawPixel((Xpos - CurY), (Ypos + CurX), DrawProp[ActiveLayer].TextColor);
00967 
00968     if (D < 0)
00969     {
00970       D += (CurX << 2) + 6;
00971     }
00972     else
00973     {
00974       D += ((CurX - CurY) << 2) + 10;
00975       CurY--;
00976     }
00977     CurX++;
00978   }
00979 }
00980 
00981 /**
00982   * @brief  Draws an poly-line (between many points) in currently active layer.
00983   * @param  Points: Pointer to the points array
00984   * @param  PointCount: Number of points
00985   */
00986 void BSP_LCD_DrawPolygon(pPoint Points, uint16_t PointCount)
00987 {
00988   int16_t X = 0, Y = 0;
00989 
00990   if(PointCount < 2)
00991   {
00992     return;
00993   }
00994 
00995   BSP_LCD_DrawLine(Points->X, Points->Y, (Points+PointCount-1)->X, (Points+PointCount-1)->Y);
00996 
00997   while(--PointCount)
00998   {
00999     X = Points->X;
01000     Y = Points->Y;
01001     Points++;
01002     BSP_LCD_DrawLine(X, Y, Points->X, Points->Y);
01003   }
01004 }
01005 
01006 /**
01007   * @brief  Draws an ellipse on LCD in currently active layer.
01008   * @param  Xpos: X position
01009   * @param  Ypos: Y position
01010   * @param  XRadius: Ellipse X radius
01011   * @param  YRadius: Ellipse Y radius
01012   */
01013 void BSP_LCD_DrawEllipse(int Xpos, int Ypos, int XRadius, int YRadius)
01014 {
01015   int x = 0, y = -YRadius, err = 2-2*XRadius, e2;
01016   float K = 0, rad1 = 0, rad2 = 0;
01017 
01018   rad1 = XRadius;
01019   rad2 = YRadius;
01020 
01021   K = (float)(rad2/rad1);
01022 
01023   do {
01024     BSP_LCD_DrawPixel((Xpos-(uint16_t)(x/K)), (Ypos+y), DrawProp[ActiveLayer].TextColor);
01025     BSP_LCD_DrawPixel((Xpos+(uint16_t)(x/K)), (Ypos+y), DrawProp[ActiveLayer].TextColor);
01026     BSP_LCD_DrawPixel((Xpos+(uint16_t)(x/K)), (Ypos-y), DrawProp[ActiveLayer].TextColor);
01027     BSP_LCD_DrawPixel((Xpos-(uint16_t)(x/K)), (Ypos-y), DrawProp[ActiveLayer].TextColor);
01028 
01029     e2 = err;
01030     if (e2 <= x) {
01031       err += ++x*2+1;
01032       if (-y == x && e2 <= y) e2 = 0;
01033     }
01034     if (e2 > y) err += ++y*2+1;
01035   }
01036   while (y <= 0);
01037 }
01038 
01039 /**
01040   * @brief  Draws a bitmap picture loaded in the internal Flash (32 bpp) in currently active layer.
01041   * @param  Xpos: Bmp X position in the LCD
01042   * @param  Ypos: Bmp Y position in the LCD
01043   * @param  pbmp: Pointer to Bmp picture address in the internal Flash
01044   */
01045 void BSP_LCD_DrawBitmap(uint32_t Xpos, uint32_t Ypos, uint8_t *pbmp)
01046 {
01047   uint32_t index = 0, width = 0, height = 0, bit_pixel = 0;
01048   uint32_t Address;
01049   uint32_t InputColorMode = 0;
01050 
01051   /* Get bitmap data address offset */
01052   index = *(__IO uint16_t *) (pbmp + 10);
01053   index |= (*(__IO uint16_t *) (pbmp + 12)) << 16;
01054 
01055   /* Read bitmap width */
01056   width = *(uint16_t *) (pbmp + 18);
01057   width |= (*(uint16_t *) (pbmp + 20)) << 16;
01058 
01059   /* Read bitmap height */
01060   height = *(uint16_t *) (pbmp + 22);
01061   height |= (*(uint16_t *) (pbmp + 24)) << 16;
01062 
01063   /* Read bit/pixel */
01064   bit_pixel = *(uint16_t *) (pbmp + 28);
01065 
01066   /* Set the address */
01067   Address = hltdc_eval.LayerCfg[ActiveLayer].FBStartAdress + (((BSP_LCD_GetXSize()*Ypos) + Xpos)*(4));
01068 
01069   /* Get the layer pixel format */
01070   if ((bit_pixel/8) == 4)
01071   {
01072     InputColorMode = CM_ARGB8888;
01073   }
01074   else if ((bit_pixel/8) == 2)
01075   {
01076     InputColorMode = CM_RGB565;
01077   }
01078   else
01079   {
01080     InputColorMode = CM_RGB888;
01081   }
01082 
01083   /* Bypass the bitmap header */
01084   pbmp += (index + (width * (height - 1) * (bit_pixel/8)));
01085 
01086   /* Convert picture to ARGB8888 pixel format */
01087   for(index=0; index < height; index++)
01088   {
01089     /* Pixel format conversion */
01090     LL_ConvertLineToARGB8888((uint32_t *)pbmp, (uint32_t *)Address, width, InputColorMode);
01091 
01092     /* Increment the source and destination buffers */
01093     Address+=  (BSP_LCD_GetXSize()*4);
01094     pbmp -= width*(bit_pixel/8);
01095   }
01096 }
01097 
01098 /**
01099   * @brief  Draws a full rectangle in currently active layer.
01100   * @param  Xpos: X position
01101   * @param  Ypos: Y position
01102   * @param  Width: Rectangle width
01103   * @param  Height: Rectangle height
01104   */
01105 void BSP_LCD_FillRect(uint16_t Xpos, uint16_t Ypos, uint16_t Width, uint16_t Height)
01106 {
01107   uint32_t  Xaddress = 0;
01108 
01109   /* Set the text color */
01110   BSP_LCD_SetTextColor(DrawProp[ActiveLayer].TextColor);
01111 
01112   /* Get the rectangle start address */
01113   Xaddress = (hltdc_eval.LayerCfg[ActiveLayer].FBStartAdress) + 4*(BSP_LCD_GetXSize()*Ypos + Xpos);
01114 
01115   /* Fill the rectangle */
01116   LL_FillBuffer(ActiveLayer, (uint32_t *)Xaddress, Width, Height, (BSP_LCD_GetXSize() - Width), DrawProp[ActiveLayer].TextColor);
01117 }
01118 
01119 /**
01120   * @brief  Draws a full circle in currently active layer.
01121   * @param  Xpos: X position
01122   * @param  Ypos: Y position
01123   * @param  Radius: Circle radius
01124   */
01125 void BSP_LCD_FillCircle(uint16_t Xpos, uint16_t Ypos, uint16_t Radius)
01126 {
01127   int32_t  D;     /* Decision Variable */
01128   uint32_t  CurX; /* Current X Value */
01129   uint32_t  CurY; /* Current Y Value */
01130 
01131   D = 3 - (Radius << 1);
01132 
01133   CurX = 0;
01134   CurY = Radius;
01135 
01136   BSP_LCD_SetTextColor(DrawProp[ActiveLayer].TextColor);
01137 
01138   while (CurX <= CurY)
01139   {
01140     if(CurY > 0)
01141     {
01142       BSP_LCD_DrawHLine(Xpos - CurY, Ypos + CurX, 2*CurY);
01143       BSP_LCD_DrawHLine(Xpos - CurY, Ypos - CurX, 2*CurY);
01144     }
01145 
01146     if(CurX > 0)
01147     {
01148       BSP_LCD_DrawHLine(Xpos - CurX, Ypos - CurY, 2*CurX);
01149       BSP_LCD_DrawHLine(Xpos - CurX, Ypos + CurY, 2*CurX);
01150     }
01151     if (D < 0)
01152     {
01153       D += (CurX << 2) + 6;
01154     }
01155     else
01156     {
01157       D += ((CurX - CurY) << 2) + 10;
01158       CurY--;
01159     }
01160     CurX++;
01161   }
01162 
01163   BSP_LCD_SetTextColor(DrawProp[ActiveLayer].TextColor);
01164   BSP_LCD_DrawCircle(Xpos, Ypos, Radius);
01165 }
01166 
01167 /**
01168   * @brief  Draws a full poly-line (between many points) in currently active layer.
01169   * @param  Points: Pointer to the points array
01170   * @param  PointCount: Number of points
01171   */
01172 void BSP_LCD_FillPolygon(pPoint Points, uint16_t PointCount)
01173 {
01174   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;
01175   uint16_t  IMAGE_LEFT = 0, IMAGE_RIGHT = 0, IMAGE_TOP = 0, IMAGE_BOTTOM = 0;
01176 
01177   IMAGE_LEFT = IMAGE_RIGHT = Points->X;
01178   IMAGE_TOP= IMAGE_BOTTOM = Points->Y;
01179 
01180   for(counter = 1; counter < PointCount; counter++)
01181   {
01182     pixelX = POLY_X(counter);
01183     if(pixelX < IMAGE_LEFT)
01184     {
01185       IMAGE_LEFT = pixelX;
01186     }
01187     if(pixelX > IMAGE_RIGHT)
01188     {
01189       IMAGE_RIGHT = pixelX;
01190     }
01191 
01192     pixelY = POLY_Y(counter);
01193     if(pixelY < IMAGE_TOP)
01194     {
01195       IMAGE_TOP = pixelY;
01196     }
01197     if(pixelY > IMAGE_BOTTOM)
01198     {
01199       IMAGE_BOTTOM = pixelY;
01200     }
01201   }
01202 
01203   if(PointCount < 2)
01204   {
01205     return;
01206   }
01207 
01208   X_center = (IMAGE_LEFT + IMAGE_RIGHT)/2;
01209   Y_center = (IMAGE_BOTTOM + IMAGE_TOP)/2;
01210 
01211   X_first = Points->X;
01212   Y_first = Points->Y;
01213 
01214   while(--PointCount)
01215   {
01216     X = Points->X;
01217     Y = Points->Y;
01218     Points++;
01219     X2 = Points->X;
01220     Y2 = Points->Y;
01221 
01222     FillTriangle(X, X2, X_center, Y, Y2, Y_center);
01223     FillTriangle(X, X_center, X2, Y, Y_center, Y2);
01224     FillTriangle(X_center, X2, X, Y_center, Y2, Y);
01225   }
01226 
01227   FillTriangle(X_first, X2, X_center, Y_first, Y2, Y_center);
01228   FillTriangle(X_first, X_center, X2, Y_first, Y_center, Y2);
01229   FillTriangle(X_center, X2, X_first, Y_center, Y2, Y_first);
01230 }
01231 
01232 /**
01233   * @brief  Draws a full ellipse in currently active layer.
01234   * @param  Xpos: X position
01235   * @param  Ypos: Y position
01236   * @param  XRadius: Ellipse X radius
01237   * @param  YRadius: Ellipse Y radius
01238   */
01239 void BSP_LCD_FillEllipse(int Xpos, int Ypos, int XRadius, int YRadius)
01240 {
01241   int x = 0, y = -YRadius, err = 2-2*XRadius, e2;
01242   float K = 0, rad1 = 0, rad2 = 0;
01243 
01244   rad1 = XRadius;
01245   rad2 = YRadius;
01246 
01247   K = (float)(rad2/rad1);
01248 
01249   do
01250   {
01251     BSP_LCD_DrawHLine((Xpos-(uint16_t)(x/K)), (Ypos+y), (2*(uint16_t)(x/K) + 1));
01252     BSP_LCD_DrawHLine((Xpos-(uint16_t)(x/K)), (Ypos-y), (2*(uint16_t)(x/K) + 1));
01253 
01254     e2 = err;
01255     if (e2 <= x)
01256     {
01257       err += ++x*2+1;
01258       if (-y == x && e2 <= y) e2 = 0;
01259     }
01260     if (e2 > y) err += ++y*2+1;
01261   }
01262   while (y <= 0);
01263 }
01264 
01265 /**
01266   * @brief  Switch back on the display if was switched off by previous call of BSP_LCD_DisplayOff().
01267   *         Exit DSI ULPM mode if was allowed and configured in Dsi Configuration.
01268   */
01269 void BSP_LCD_DisplayOn(void)
01270 {
01271   /* Send Display on DCS command to display */
01272   HAL_DSI_ShortWrite(&(hdsi_eval),
01273                      hdsivideo_handle.VirtualChannelID,
01274                      DSI_DCS_SHORT_PKT_WRITE_P1,
01275                      OTM8009A_CMD_DISPON,
01276                      0x00);
01277   
01278 }
01279 
01280 /**
01281   * @brief  Switch Off the display.
01282   *         Enter DSI ULPM mode if was allowed and configured in Dsi Configuration.
01283   */
01284 void BSP_LCD_DisplayOff(void)
01285 {
01286   /* Send Display off DCS Command to display */
01287   HAL_DSI_ShortWrite(&(hdsi_eval),
01288                      hdsivideo_handle.VirtualChannelID,
01289                      DSI_DCS_SHORT_PKT_WRITE_P1,
01290                      OTM8009A_CMD_DISPOFF,
01291                      0x00);
01292   
01293 }
01294 
01295 /**
01296   * @brief  DCS or Generic short/long write command
01297   * @param  NbrParams: Number of parameters. It indicates the write command mode:
01298   *                 If inferior to 2, a long write command is performed else short.
01299   * @param  pParams: Pointer to parameter values table.
01300   * @retval HAL status
01301   */
01302 void DSI_IO_WriteCmd(uint32_t NbrParams, uint8_t *pParams)
01303 {
01304   if(NbrParams <= 1)
01305   {
01306    HAL_DSI_ShortWrite(&hdsi_eval, LCD_OTM8009A_ID, DSI_DCS_SHORT_PKT_WRITE_P1, pParams[0], pParams[1]); 
01307   }
01308   else
01309   {
01310    HAL_DSI_LongWrite(&hdsi_eval,  LCD_OTM8009A_ID, DSI_DCS_LONG_PKT_WRITE, NbrParams, pParams[NbrParams], pParams); 
01311   }
01312 }
01313 
01314 /*******************************************************************************
01315                        LTDC, DMA2D and DSI BSP Routines
01316 *******************************************************************************/
01317 /**
01318   * @brief  Handles DMA2D interrupt request.
01319   * @note : Can be surcharged by application code implementation of the function.
01320   */
01321 __weak void BSP_LCD_DMA2D_IRQHandler(void)
01322 {
01323   HAL_DMA2D_IRQHandler(&hdma2d_eval);
01324 }
01325 
01326 /**
01327   * @brief  Handles DSI interrupt request.
01328   * @note : Can be surcharged by application code implementation of the function.
01329   */
01330 __weak void BSP_LCD_DSI_IRQHandler(void)
01331 {
01332   HAL_DSI_IRQHandler(&(hdsi_eval));
01333 }
01334 
01335 
01336 /**
01337   * @brief  Handles LTDC interrupt request.
01338   * @note : Can be surcharged by application code implementation of the function.
01339   */
01340 __weak void BSP_LCD_LTDC_IRQHandler(void)
01341 {
01342   HAL_LTDC_IRQHandler(&(hltdc_eval));
01343 }
01344 
01345 /**
01346   * @brief  De-Initializes the BSP LCD Msp
01347   * Application can surcharge if needed this function implementation.
01348   */
01349 __weak void BSP_LCD_MspDeInit(void)
01350 {
01351   /** @brief Disable IRQ of LTDC IP */
01352   HAL_NVIC_DisableIRQ(LTDC_IRQn);
01353 
01354   /** @brief Disable IRQ of DMA2D IP */
01355   HAL_NVIC_DisableIRQ(DMA2D_IRQn);
01356 
01357   /** @brief Disable IRQ of DSI IP */
01358   HAL_NVIC_DisableIRQ(DSI_IRQn);
01359 
01360   /** @brief Force and let in reset state LTDC, DMA2D and DSI Host + Wrapper IPs */
01361   __HAL_RCC_LTDC_FORCE_RESET();
01362   __HAL_RCC_DMA2D_FORCE_RESET();
01363   __HAL_RCC_DSI_FORCE_RESET();
01364 
01365   /** @brief Disable the LTDC, DMA2D and DSI Host and Wrapper clocks */
01366   __HAL_RCC_LTDC_CLK_DISABLE();
01367   __HAL_RCC_DMA2D_CLK_DISABLE();
01368   __HAL_RCC_DSI_CLK_DISABLE();
01369 }
01370 
01371 /**
01372   * @brief  Initialize the BSP LCD Msp.
01373   * Application can surcharge if needed this function implementation
01374   */
01375 __weak void BSP_LCD_MspInit(void)
01376 {
01377   /** @brief Enable the LTDC clock */
01378   __HAL_RCC_LTDC_CLK_ENABLE();
01379 
01380   /** @brief Toggle Sw reset of LTDC IP */
01381   __HAL_RCC_LTDC_FORCE_RESET();
01382   __HAL_RCC_LTDC_RELEASE_RESET();
01383 
01384   /** @brief Enable the DMA2D clock */
01385   __HAL_RCC_DMA2D_CLK_ENABLE();
01386 
01387   /** @brief Toggle Sw reset of DMA2D IP */
01388   __HAL_RCC_DMA2D_FORCE_RESET();
01389   __HAL_RCC_DMA2D_RELEASE_RESET();
01390 
01391   /** @brief Enable DSI Host and wrapper clocks */
01392   __HAL_RCC_DSI_CLK_ENABLE();
01393 
01394   /** @brief Soft Reset the DSI Host and wrapper */
01395   __HAL_RCC_DSI_FORCE_RESET();
01396   __HAL_RCC_DSI_RELEASE_RESET();
01397 
01398   /** @brief NVIC configuration for LTDC interrupt that is now enabled */
01399   HAL_NVIC_SetPriority(LTDC_IRQn, 3, 0);
01400   HAL_NVIC_EnableIRQ(LTDC_IRQn);
01401 
01402   /** @brief NVIC configuration for DMA2D interrupt that is now enabled */
01403   HAL_NVIC_SetPriority(DMA2D_IRQn, 3, 0);
01404   HAL_NVIC_EnableIRQ(DMA2D_IRQn);
01405 
01406   /** @brief NVIC configuration for DSI interrupt that is now enabled */
01407   HAL_NVIC_SetPriority(DSI_IRQn, 3, 0);
01408   HAL_NVIC_EnableIRQ(DSI_IRQn);
01409 }
01410 
01411 /**
01412   * @brief  This function handles LTDC Error interrupt Handler.
01413   * @note : Can be surcharged by application code implementation of the function.
01414   */
01415 
01416 __weak void BSP_LCD_LTDC_ER_IRQHandler(void)
01417 {
01418   HAL_LTDC_IRQHandler(&(hltdc_eval));
01419 }
01420 
01421 
01422 /**
01423   * @brief  Draws a pixel on LCD.
01424   * @param  Xpos: X position
01425   * @param  Ypos: Y position
01426   * @param  RGB_Code: Pixel color in ARGB mode (8-8-8-8)
01427   */
01428 void BSP_LCD_DrawPixel(uint16_t Xpos, uint16_t Ypos, uint32_t RGB_Code)
01429 {
01430   /* Write data value to all SDRAM memory */
01431   *(__IO uint32_t*) (hltdc_eval.LayerCfg[ActiveLayer].FBStartAdress + (4*(Ypos*BSP_LCD_GetXSize() + Xpos))) = RGB_Code;
01432 }
01433 
01434 
01435 /**
01436   * @brief  Draws a character on LCD.
01437   * @param  Xpos: Line where to display the character shape
01438   * @param  Ypos: Start column address
01439   * @param  c: Pointer to the character data
01440   */
01441 static void DrawChar(uint16_t Xpos, uint16_t Ypos, const uint8_t *c)
01442 {
01443   uint32_t i = 0, j = 0;
01444   uint16_t height, width;
01445   uint8_t  offset;
01446   uint8_t  *pchar;
01447   uint32_t line;
01448 
01449   height = DrawProp[ActiveLayer].pFont->Height;
01450   width  = DrawProp[ActiveLayer].pFont->Width;
01451 
01452   offset =  8 *((width + 7)/8) -  width ;
01453 
01454   for(i = 0; i < height; i++)
01455   {
01456     pchar = ((uint8_t *)c + (width + 7)/8 * i);
01457 
01458     switch(((width + 7)/8))
01459     {
01460 
01461     case 1:
01462       line =  pchar[0];
01463       break;
01464 
01465     case 2:
01466       line =  (pchar[0]<< 8) | pchar[1];
01467       break;
01468 
01469     case 3:
01470     default:
01471       line =  (pchar[0]<< 16) | (pchar[1]<< 8) | pchar[2];
01472       break;
01473     }
01474 
01475     for (j = 0; j < width; j++)
01476     {
01477       if(line & (1 << (width- j + offset- 1)))
01478       {
01479         BSP_LCD_DrawPixel((Xpos + j), Ypos, DrawProp[ActiveLayer].TextColor);
01480       }
01481       else
01482       {
01483         BSP_LCD_DrawPixel((Xpos + j), Ypos, DrawProp[ActiveLayer].BackColor);
01484       }
01485     }
01486     Ypos++;
01487   }
01488 }
01489 
01490 /**
01491   * @brief  Fills a triangle (between 3 points).
01492   * @param  x1: Point 1 X position
01493   * @param  y1: Point 1 Y position
01494   * @param  x2: Point 2 X position
01495   * @param  y2: Point 2 Y position
01496   * @param  x3: Point 3 X position
01497   * @param  y3: Point 3 Y position
01498   */
01499 static void FillTriangle(uint16_t x1, uint16_t x2, uint16_t x3, uint16_t y1, uint16_t y2, uint16_t y3)
01500 {
01501   int16_t deltax = 0, deltay = 0, x = 0, y = 0, xinc1 = 0, xinc2 = 0,
01502   yinc1 = 0, yinc2 = 0, den = 0, num = 0, numadd = 0, numpixels = 0,
01503   curpixel = 0;
01504 
01505   deltax = ABS(x2 - x1);        /* The difference between the x's */
01506   deltay = ABS(y2 - y1);        /* The difference between the y's */
01507   x = x1;                       /* Start x off at the first pixel */
01508   y = y1;                       /* Start y off at the first pixel */
01509 
01510   if (x2 >= x1)                 /* The x-values are increasing */
01511   {
01512     xinc1 = 1;
01513     xinc2 = 1;
01514   }
01515   else                          /* The x-values are decreasing */
01516   {
01517     xinc1 = -1;
01518     xinc2 = -1;
01519   }
01520 
01521   if (y2 >= y1)                 /* The y-values are increasing */
01522   {
01523     yinc1 = 1;
01524     yinc2 = 1;
01525   }
01526   else                          /* The y-values are decreasing */
01527   {
01528     yinc1 = -1;
01529     yinc2 = -1;
01530   }
01531 
01532   if (deltax >= deltay)         /* There is at least one x-value for every y-value */
01533   {
01534     xinc1 = 0;                  /* Don't change the x when numerator >= denominator */
01535     yinc2 = 0;                  /* Don't change the y for every iteration */
01536     den = deltax;
01537     num = deltax / 2;
01538     numadd = deltay;
01539     numpixels = deltax;         /* There are more x-values than y-values */
01540   }
01541   else                          /* There is at least one y-value for every x-value */
01542   {
01543     xinc2 = 0;                  /* Don't change the x for every iteration */
01544     yinc1 = 0;                  /* Don't change the y when numerator >= denominator */
01545     den = deltay;
01546     num = deltay / 2;
01547     numadd = deltax;
01548     numpixels = deltay;         /* There are more y-values than x-values */
01549   }
01550 
01551   for (curpixel = 0; curpixel <= numpixels; curpixel++)
01552   {
01553     BSP_LCD_DrawLine(x, y, x3, y3);
01554 
01555     num += numadd;              /* Increase the numerator by the top of the fraction */
01556     if (num >= den)             /* Check if numerator >= denominator */
01557     {
01558       num -= den;               /* Calculate the new numerator value */
01559       x += xinc1;               /* Change the x as appropriate */
01560       y += yinc1;               /* Change the y as appropriate */
01561     }
01562     x += xinc2;                 /* Change the x as appropriate */
01563     y += yinc2;                 /* Change the y as appropriate */
01564   }
01565 }
01566 
01567 /**
01568   * @brief  Fills a buffer.
01569   * @param  LayerIndex: Layer index
01570   * @param  pDst: Pointer to destination buffer
01571   * @param  xSize: Buffer width
01572   * @param  ySize: Buffer height
01573   * @param  OffLine: Offset
01574   * @param  ColorIndex: Color index
01575   */
01576 static void LL_FillBuffer(uint32_t LayerIndex, void *pDst, uint32_t xSize, uint32_t ySize, uint32_t OffLine, uint32_t ColorIndex)
01577 {
01578   /* Register to memory mode with ARGB8888 as color Mode */
01579   hdma2d_eval.Init.Mode         = DMA2D_R2M;
01580   hdma2d_eval.Init.ColorMode    = DMA2D_ARGB8888;
01581   hdma2d_eval.Init.OutputOffset = OffLine;
01582 
01583   hdma2d_eval.Instance = DMA2D;
01584 
01585   /* DMA2D Initialization */
01586   if(HAL_DMA2D_Init(&hdma2d_eval) == HAL_OK)
01587   {
01588     if(HAL_DMA2D_ConfigLayer(&hdma2d_eval, LayerIndex) == HAL_OK)
01589     {
01590       if (HAL_DMA2D_Start(&hdma2d_eval, ColorIndex, (uint32_t)pDst, xSize, ySize) == HAL_OK)
01591       {
01592         /* Polling For DMA transfer */
01593         HAL_DMA2D_PollForTransfer(&hdma2d_eval, 10);
01594       }
01595     }
01596   }
01597 }
01598 
01599 /**
01600   * @brief  Converts a line to an ARGB8888 pixel format.
01601   * @param  pSrc: Pointer to source buffer
01602   * @param  pDst: Output color
01603   * @param  xSize: Buffer width
01604   * @param  ColorMode: Input color mode
01605   */
01606 static void LL_ConvertLineToARGB8888(void *pSrc, void *pDst, uint32_t xSize, uint32_t ColorMode)
01607 {
01608   /* Configure the DMA2D Mode, Color Mode and output offset */
01609   hdma2d_eval.Init.Mode         = DMA2D_M2M_PFC;
01610   hdma2d_eval.Init.ColorMode    = DMA2D_ARGB8888;
01611   hdma2d_eval.Init.OutputOffset = 0;
01612 
01613   /* Foreground Configuration */
01614   hdma2d_eval.LayerCfg[1].AlphaMode = DMA2D_NO_MODIF_ALPHA;
01615   hdma2d_eval.LayerCfg[1].InputAlpha = 0xFF;
01616   hdma2d_eval.LayerCfg[1].InputColorMode = ColorMode;
01617   hdma2d_eval.LayerCfg[1].InputOffset = 0;
01618 
01619   hdma2d_eval.Instance = DMA2D;
01620 
01621   /* DMA2D Initialization */
01622   if(HAL_DMA2D_Init(&hdma2d_eval) == HAL_OK)
01623   {
01624     if(HAL_DMA2D_ConfigLayer(&hdma2d_eval, 1) == HAL_OK)
01625     {
01626       if (HAL_DMA2D_Start(&hdma2d_eval, (uint32_t)pSrc, (uint32_t)pDst, xSize, 1) == HAL_OK)
01627       {
01628         /* Polling For DMA transfer */
01629         HAL_DMA2D_PollForTransfer(&hdma2d_eval, 10);
01630       }
01631     }
01632   }
01633 }
01634 
01635 /**
01636   * @}
01637   */
01638 
01639 /**
01640   * @}
01641   */
01642 
01643 /**
01644   * @}
01645   */
01646 
01647 /**
01648   * @}
01649   */
01650 
01651 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
Generated on Fri Jan 13 2017 11:00:15 for STM32469I-Discovery BSP User Manual by   doxygen 1.7.6.1