STM32F429ZI Discovery board drivers

Dependents:   2a 2b 2c 2d1 ... more

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers stm32f429i_discovery_lcd.c Source File

stm32f429i_discovery_lcd.c

Go to the documentation of this file.
00001 /**
00002   ******************************************************************************
00003   * @file    stm32f429i_discovery_lcd.c
00004   * @author  MCD Application Team
00005   * @brief   This file includes the LCD driver for ILI9341 Liquid Crystal 
00006   *          Display Modules of STM32F429I-Discovery kit (MB1075).
00007   ******************************************************************************
00008   * @attention
00009   *
00010   * <h2><center>&copy; COPYRIGHT(c) 2017 STMicroelectronics</center></h2>
00011   *
00012   * Redistribution and use in source and binary forms, with or without modification,
00013   * are permitted provided that the following conditions are met:
00014   *   1. Redistributions of source code must retain the above copyright notice,
00015   *      this list of conditions and the following disclaimer.
00016   *   2. Redistributions in binary form must reproduce the above copyright notice,
00017   *      this list of conditions and the following disclaimer in the documentation
00018   *      and/or other materials provided with the distribution.
00019   *   3. Neither the name of STMicroelectronics nor the names of its contributors
00020   *      may be used to endorse or promote products derived from this software
00021   *      without specific prior written permission.
00022   *
00023   * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
00024   * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00025   * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
00026   * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
00027   * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
00028   * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
00029   * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
00030   * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
00031   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
00032   * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00033   *
00034   ******************************************************************************
00035   */
00036 
00037 /* File Info : -----------------------------------------------------------------
00038                                    User NOTES
00039 1. How To use this driver:
00040 --------------------------
00041    - This driver is used to drive directly an LCD TFT using LTDC controller.
00042    - This driver select dynamically the mounted LCD, ILI9341 240x320 LCD mounted 
00043      on MB1075B discovery board, and use the adequate timing and setting for 
00044      the specified LCD using device ID of the ILI9341 mounted on MB1075B discovery board           
00045 
00046 2. Driver description:
00047 ---------------------
00048   + Initialization steps :
00049      o Initialize the LCD using the LCD_Init() function.
00050      o Apply the Layer configuration using LCD_LayerDefaultInit() function    
00051      o Select the LCD layer to be used using LCD_SelectLayer() function.
00052      o Enable the LCD display using LCD_DisplayOn() function.
00053 
00054   + Options
00055      o Configure and enable the color keying functionality using LCD_SetColorKeying()
00056        function.
00057      o Modify in the fly the transparency and/or the frame buffer address
00058        using the following functions :
00059        - LCD_SetTransparency()
00060        - LCD_SetLayerAddress() 
00061   
00062   + Display on LCD
00063       o Clear the hole LCD using LCD_Clear() function or only one specified string
00064         line using LCD_ClearStringLine() function.
00065       o Display a character on the specified line and column using LCD_DisplayChar()
00066         function or a complete string line using LCD_DisplayStringAtLine() function.
00067       o Display a string line on the specified position (x,y in pixel) and align mode
00068         using LCD_DisplayStringAtLine() function.          
00069       o Draw and fill a basic shapes (dot, line, rectangle, circle, ellipse, .. bitmap) 
00070         on LCD using the available set of functions     
00071  
00072 ------------------------------------------------------------------------------*/
00073 
00074 /* Includes ------------------------------------------------------------------*/
00075 #include "stm32f429i_discovery_lcd.h"
00076 #include "../Fonts/fonts.h"
00077 //#include "../Fonts/font24.c"
00078 //#include "../Fonts/font20.c"
00079 //#include "../Fonts/font16.c"
00080 //#include "../Fonts/font12.c"
00081 //#include "../Fonts/font8.c"
00082 
00083 /** @addtogroup BSP
00084   * @{
00085   */ 
00086 
00087 /** @addtogroup STM32F429I_DISCOVERY
00088   * @{
00089   */
00090     
00091 /** @defgroup STM32F429I_DISCOVERY_LCD STM32F429I DISCOVERY LCD
00092   * @brief This file includes the LCD driver for (ILI9341) 
00093   * @{
00094   */ 
00095 
00096 /** @defgroup STM32F429I_DISCOVERY_LCD_Private_TypesDefinitions STM32F429I DISCOVERY LCD Private TypesDefinitions
00097   * @{
00098   */ 
00099 /**
00100   * @}
00101   */ 
00102 
00103 /** @defgroup STM32F429I_DISCOVERY_LCD_Private_Defines STM32F429I DISCOVERY LCD Private Defines
00104   * @{
00105   */
00106 #define POLY_X(Z)              ((int32_t)((Points + Z)->X))
00107 #define POLY_Y(Z)              ((int32_t)((Points + Z)->Y))
00108 /**
00109   * @}
00110   */ 
00111 
00112 /** @defgroup STM32F429I_DISCOVERY_LCD_Private_Macros STM32F429I DISCOVERY LCD Private Macros
00113   * @{
00114   */
00115 #define ABS(X)  ((X) > 0 ? (X) : -(X))
00116 /**
00117   * @}
00118   */ 
00119   
00120 /** @defgroup STM32F429I_DISCOVERY_LCD_Private_Variables STM32F429I DISCOVERY LCD Private Variables
00121   * @{
00122   */ 
00123 LTDC_HandleTypeDef  LtdcHandler;
00124 static DMA2D_HandleTypeDef Dma2dHandler;
00125 static RCC_PeriphCLKInitTypeDef  PeriphClkInitStruct;
00126 
00127 /* Default LCD configuration with LCD Layer 1 */
00128 static uint32_t ActiveLayer = 0;
00129 static LCD_DrawPropTypeDef DrawProp[MAX_LAYER_NUMBER];
00130 LCD_DrvTypeDef  *LcdDrv;
00131 /**
00132   * @}
00133   */ 
00134 
00135 /** @defgroup STM32F429I_DISCOVERY_LCD_Private_FunctionPrototypes STM32F429I DISCOVERY LCD Private FunctionPrototypes
00136   * @{
00137   */ 
00138 static void DrawChar(uint16_t Xpos, uint16_t Ypos, const uint8_t *c);
00139 static void FillBuffer(uint32_t LayerIndex, void *pDst, uint32_t xSize, uint32_t ySize, uint32_t OffLine, uint32_t ColorIndex);
00140 static void ConvertLineToARGB8888(void *pSrc, void *pDst, uint32_t xSize, uint32_t ColorMode);
00141 /**
00142   * @}
00143   */ 
00144 
00145 /** @defgroup STM32F429I_DISCOVERY_LCD_Private_Functions STM32F429I DISCOVERY LCD Private Functions
00146   * @{
00147   */ 
00148 
00149 /**
00150   * @brief  Initializes the LCD.
00151   * @retval LCD state
00152   */
00153 uint8_t BSP_LCD_Init(void)
00154 { 
00155   /* On STM32F429I-DISCO, it is not possible to read ILI9341 ID because */
00156   /* PIN EXTC is not connected to VDD and then LCD_READ_ID4 is not accessible. */
00157   /* In this case, ReadID function is bypassed.*/  
00158   /*if(ili9341_drv.ReadID() == ILI9341_ID)*/
00159 
00160     /* LTDC Configuration ----------------------------------------------------*/
00161     LtdcHandler.Instance = LTDC;
00162     
00163     /* Timing configuration  (Typical configuration from ILI9341 datasheet)
00164           HSYNC=10 (9+1)
00165           HBP=20 (29-10+1)
00166           ActiveW=240 (269-20-10+1)
00167           HFP=10 (279-240-20-10+1)
00168     
00169           VSYNC=2 (1+1)
00170           VBP=2 (3-2+1)
00171           ActiveH=320 (323-2-2+1)
00172           VFP=4 (327-320-2-2+1)
00173       */
00174     
00175     /* Configure horizontal synchronization width */
00176     LtdcHandler.Init.HorizontalSync = ILI9341_HSYNC;
00177     /* Configure vertical synchronization height */
00178     LtdcHandler.Init.VerticalSync = ILI9341_VSYNC;
00179     /* Configure accumulated horizontal back porch */
00180     LtdcHandler.Init.AccumulatedHBP = ILI9341_HBP;
00181     /* Configure accumulated vertical back porch */
00182     LtdcHandler.Init.AccumulatedVBP = ILI9341_VBP;
00183     /* Configure accumulated active width */
00184     LtdcHandler.Init.AccumulatedActiveW = 269;
00185     /* Configure accumulated active height */
00186     LtdcHandler.Init.AccumulatedActiveH = 323;
00187     /* Configure total width */
00188     LtdcHandler.Init.TotalWidth = 279;
00189     /* Configure total height */
00190     LtdcHandler.Init.TotalHeigh = 327;
00191     
00192     /* Configure R,G,B component values for LCD background color */
00193     LtdcHandler.Init.Backcolor.Red= 0;
00194     LtdcHandler.Init.Backcolor.Blue= 0;
00195     LtdcHandler.Init.Backcolor.Green= 0;
00196     
00197     /* LCD clock configuration */
00198     /* PLLSAI_VCO Input = HSE_VALUE/PLL_M = 1 Mhz */
00199     /* PLLSAI_VCO Output = PLLSAI_VCO Input * PLLSAIN = 192 Mhz */
00200     /* PLLLCDCLK = PLLSAI_VCO Output/PLLSAIR = 192/4 = 48 Mhz */
00201     /* LTDC clock frequency = PLLLCDCLK / LTDC_PLLSAI_DIVR_8 = 48/4 = 6Mhz */
00202     PeriphClkInitStruct.PeriphClockSelection = RCC_PERIPHCLK_LTDC;
00203     PeriphClkInitStruct.PLLSAI.PLLSAIN = 192;
00204     PeriphClkInitStruct.PLLSAI.PLLSAIR = 4;
00205     PeriphClkInitStruct.PLLSAIDivR = RCC_PLLSAIDIVR_8;
00206     HAL_RCCEx_PeriphCLKConfig(&PeriphClkInitStruct); 
00207     
00208     /* Polarity */
00209     LtdcHandler.Init.HSPolarity = LTDC_HSPOLARITY_AL;
00210     LtdcHandler.Init.VSPolarity = LTDC_VSPOLARITY_AL;
00211     LtdcHandler.Init.DEPolarity = LTDC_DEPOLARITY_AL;
00212     LtdcHandler.Init.PCPolarity = LTDC_PCPOLARITY_IPC;
00213     
00214     BSP_LCD_MspInit();
00215     HAL_LTDC_Init(&LtdcHandler); 
00216     
00217     /* Select the device */
00218     LcdDrv = &ili9341_drv;
00219 
00220     /* LCD Init */   
00221     LcdDrv->Init();
00222 
00223     /* Initialize the SDRAM */
00224     BSP_SDRAM_Init();
00225 
00226     /* Initialize the font */
00227     BSP_LCD_SetFont(&LCD_DEFAULT_FONT);
00228 
00229   return LCD_OK;
00230 }  
00231 
00232 /**
00233   * @brief  Gets the LCD X size.  
00234   * @retval The used LCD X size
00235   */
00236 uint32_t BSP_LCD_GetXSize(void)
00237 {
00238   return LcdDrv->GetLcdPixelWidth();
00239 }
00240 
00241 /**
00242   * @brief  Gets the LCD Y size.  
00243   * @retval The used LCD Y size
00244   */
00245 uint32_t BSP_LCD_GetYSize(void)
00246 {
00247   return LcdDrv->GetLcdPixelHeight();
00248 }
00249 
00250 /**
00251   * @brief  Initializes the LCD layers.
00252   * @param  LayerIndex: the layer foreground or background. 
00253   * @param  FB_Address: the layer frame buffer.
00254   */
00255 void BSP_LCD_LayerDefaultInit(uint16_t LayerIndex, uint32_t FB_Address)
00256 {     
00257   LCD_LayerCfgTypeDef   Layercfg;
00258 
00259  /* Layer Init */
00260   Layercfg.WindowX0 = 0;
00261   Layercfg.WindowX1 = BSP_LCD_GetXSize();
00262   Layercfg.WindowY0 = 0;
00263   Layercfg.WindowY1 = BSP_LCD_GetYSize(); 
00264   Layercfg.PixelFormat = LTDC_PIXEL_FORMAT_ARGB8888;
00265   Layercfg.FBStartAdress = FB_Address;
00266   Layercfg.Alpha = 255;
00267   Layercfg.Alpha0 = 0;
00268   Layercfg.Backcolor.Blue = 0;
00269   Layercfg.Backcolor.Green = 0;
00270   Layercfg.Backcolor.Red = 0;
00271   Layercfg.BlendingFactor1 = LTDC_BLENDING_FACTOR1_PAxCA;
00272   Layercfg.BlendingFactor2 = LTDC_BLENDING_FACTOR2_PAxCA;
00273   Layercfg.ImageWidth = BSP_LCD_GetXSize();
00274   Layercfg.ImageHeight = BSP_LCD_GetYSize();
00275   
00276   HAL_LTDC_ConfigLayer(&LtdcHandler, &Layercfg, LayerIndex); 
00277 
00278   DrawProp[LayerIndex].BackColor = LCD_COLOR_WHITE;
00279   DrawProp[LayerIndex].pFont     = &Font24;
00280   DrawProp[LayerIndex].TextColor = LCD_COLOR_BLACK; 
00281 
00282   /* Dithering activation */
00283   HAL_LTDC_EnableDither(&LtdcHandler);
00284 }
00285 
00286 /**
00287   * @brief  Selects the LCD Layer.
00288   * @param  LayerIndex: the Layer foreground or background.
00289   */
00290 void BSP_LCD_SelectLayer(uint32_t LayerIndex)
00291 {
00292   ActiveLayer = LayerIndex;
00293 }
00294 
00295 /**
00296   * @brief  Sets a LCD Layer visible.
00297   * @param  LayerIndex: the visible Layer.
00298   * @param  state: new state of the specified layer.
00299   *    This parameter can be: ENABLE or DISABLE.  
00300   */
00301 void BSP_LCD_SetLayerVisible(uint32_t LayerIndex, FunctionalState state)
00302 {
00303   if(state == ENABLE)
00304   {
00305     __HAL_LTDC_LAYER_ENABLE(&LtdcHandler, LayerIndex);
00306   }
00307   else
00308   {
00309     __HAL_LTDC_LAYER_DISABLE(&LtdcHandler, LayerIndex);
00310   }
00311   __HAL_LTDC_RELOAD_CONFIG(&LtdcHandler);
00312 }
00313 
00314 /**
00315   * @brief  Sets an LCD Layer visible without reloading.
00316   * @param  LayerIndex: Visible Layer
00317   * @param  State: New state of the specified layer
00318   *          This parameter can be one of the following values:
00319   *            @arg  ENABLE
00320   *            @arg  DISABLE 
00321   * @retval None
00322   */
00323 void BSP_LCD_SetLayerVisible_NoReload(uint32_t LayerIndex, FunctionalState State)
00324 {
00325   if(State == ENABLE)
00326   {
00327     __HAL_LTDC_LAYER_ENABLE(&LtdcHandler, LayerIndex);
00328   }
00329   else
00330   {
00331     __HAL_LTDC_LAYER_DISABLE(&LtdcHandler, LayerIndex);
00332   }
00333   /* Do not Sets the Reload  */
00334 }
00335 
00336 /**
00337   * @brief  Configures the Transparency.
00338   * @param  LayerIndex: the Layer foreground or background.
00339   * @param  Transparency: the Transparency, 
00340   *    This parameter must range from 0x00 to 0xFF.
00341   */
00342 void BSP_LCD_SetTransparency(uint32_t LayerIndex, uint8_t Transparency)
00343 {     
00344   HAL_LTDC_SetAlpha(&LtdcHandler, Transparency, LayerIndex);
00345 }
00346 
00347 /**
00348   * @brief  Configures the transparency without reloading.
00349   * @param  LayerIndex: Layer foreground or background.
00350   * @param  Transparency: Transparency
00351   *           This parameter must be a number between Min_Data = 0x00 and Max_Data = 0xFF 
00352   * @retval None
00353   */
00354 void BSP_LCD_SetTransparency_NoReload(uint32_t LayerIndex, uint8_t Transparency)
00355 {    
00356   HAL_LTDC_SetAlpha_NoReload(&LtdcHandler, Transparency, LayerIndex);
00357 }
00358 
00359 /**
00360   * @brief  Sets a LCD layer frame buffer address.
00361   * @param  LayerIndex: specifies the Layer foreground or background
00362   * @param  Address: new LCD frame buffer value      
00363   */
00364 void BSP_LCD_SetLayerAddress(uint32_t LayerIndex, uint32_t Address)
00365 {     
00366   HAL_LTDC_SetAddress(&LtdcHandler, Address, LayerIndex);
00367 }
00368 
00369 /**
00370   * @brief  Sets an LCD layer frame buffer address without reloading.
00371   * @param  LayerIndex: Layer foreground or background
00372   * @param  Address: New LCD frame buffer value      
00373   * @retval None
00374   */
00375 void BSP_LCD_SetLayerAddress_NoReload(uint32_t LayerIndex, uint32_t Address)
00376 {
00377   HAL_LTDC_SetAddress_NoReload(&LtdcHandler, Address, LayerIndex);
00378 }
00379 
00380 /**
00381   * @brief  Sets the Display window.
00382   * @param  LayerIndex: layer index
00383   * @param  Xpos: LCD X position
00384   * @param  Ypos: LCD Y position
00385   * @param  Width: LCD window width
00386   * @param  Height: LCD window height  
00387   */
00388 void BSP_LCD_SetLayerWindow(uint16_t LayerIndex, uint16_t Xpos, uint16_t Ypos, uint16_t Width, uint16_t Height)
00389 {
00390   /* reconfigure the layer size */
00391   HAL_LTDC_SetWindowSize(&LtdcHandler, Width, Height, LayerIndex);
00392   
00393   /* reconfigure the layer position */
00394   HAL_LTDC_SetWindowPosition(&LtdcHandler, Xpos, Ypos, LayerIndex);
00395 }
00396 
00397 /**
00398   * @brief  Sets display window without reloading.
00399   * @param  LayerIndex: Layer index
00400   * @param  Xpos: LCD X position
00401   * @param  Ypos: LCD Y position
00402   * @param  Width: LCD window width
00403   * @param  Height: LCD window height  
00404   * @retval None
00405   */
00406 void BSP_LCD_SetLayerWindow_NoReload(uint16_t LayerIndex, uint16_t Xpos, uint16_t Ypos, uint16_t Width, uint16_t Height)
00407 {
00408   /* Reconfigure the layer size */
00409   HAL_LTDC_SetWindowSize_NoReload(&LtdcHandler, Width, Height, LayerIndex);
00410   
00411   /* Reconfigure the layer position */
00412   HAL_LTDC_SetWindowPosition_NoReload(&LtdcHandler, Xpos, Ypos, LayerIndex); 
00413 }
00414 
00415 /**
00416   * @brief  Configures and sets the color Keying.
00417   * @param  LayerIndex: the Layer foreground or background
00418   * @param  RGBValue: the Color reference
00419   */
00420 void BSP_LCD_SetColorKeying(uint32_t LayerIndex, uint32_t RGBValue)
00421 {  
00422   /* Configure and Enable the color Keying for LCD Layer */
00423   HAL_LTDC_ConfigColorKeying(&LtdcHandler, RGBValue, LayerIndex);
00424   HAL_LTDC_EnableColorKeying(&LtdcHandler, LayerIndex);
00425 }
00426 
00427 /**
00428   * @brief  Configures and sets the color keying without reloading.
00429   * @param  LayerIndex: Layer foreground or background
00430   * @param  RGBValue: Color reference
00431   * @retval None
00432   */
00433 void BSP_LCD_SetColorKeying_NoReload(uint32_t LayerIndex, uint32_t RGBValue)
00434 {  
00435   /* Configure and Enable the color Keying for LCD Layer */
00436   HAL_LTDC_ConfigColorKeying_NoReload(&LtdcHandler, RGBValue, LayerIndex);
00437   HAL_LTDC_EnableColorKeying_NoReload(&LtdcHandler, LayerIndex);
00438 }
00439 
00440 /**
00441   * @brief  Disables the color Keying.
00442   * @param  LayerIndex: the Layer foreground or background
00443   */
00444 void BSP_LCD_ResetColorKeying(uint32_t LayerIndex)
00445 {
00446   /* Disable the color Keying for LCD Layer */
00447   HAL_LTDC_DisableColorKeying(&LtdcHandler, LayerIndex);
00448 }
00449 
00450 /**
00451   * @brief  Disables the color keying without reloading.
00452   * @param  LayerIndex: Layer foreground or background
00453   * @retval None
00454   */
00455 void BSP_LCD_ResetColorKeying_NoReload(uint32_t LayerIndex)
00456 {   
00457   /* Disable the color Keying for LCD Layer */
00458   HAL_LTDC_DisableColorKeying_NoReload(&LtdcHandler, LayerIndex);
00459 }
00460 
00461 /**
00462   * @brief  Disables the color keying without reloading.
00463   * @param  ReloadType: can be one of the following values
00464   *         - LCD_RELOAD_IMMEDIATE
00465   *         - LCD_RELOAD_VERTICAL_BLANKING
00466   * @retval None
00467   */
00468 void BSP_LCD_Relaod(uint32_t ReloadType)
00469 {
00470   HAL_LTDC_Relaod (&LtdcHandler, ReloadType);
00471 }
00472 
00473 /**
00474   * @brief  Gets the LCD Text color.
00475   * @retval Text color
00476   */
00477 uint32_t BSP_LCD_GetTextColor(void)
00478 {
00479   return DrawProp[ActiveLayer].TextColor;
00480 }
00481 
00482 /**
00483   * @brief  Gets the LCD Background color. 
00484   * @retval Background color  
00485   */
00486 uint32_t BSP_LCD_GetBackColor(void)
00487 {
00488   return DrawProp[ActiveLayer].BackColor;
00489 }
00490 
00491 /**
00492   * @brief  Sets the Text color.
00493   * @param  Color: the Text color code ARGB(8-8-8-8)
00494   */
00495 void BSP_LCD_SetTextColor(uint32_t Color)
00496 {
00497   DrawProp[ActiveLayer].TextColor = Color;
00498 }
00499 
00500 /**
00501   * @brief  Sets the Background color.
00502   * @param  Color: the layer Background color code ARGB(8-8-8-8)
00503   */
00504 void BSP_LCD_SetBackColor(uint32_t Color)
00505 {
00506   DrawProp[ActiveLayer].BackColor = Color;
00507 }
00508 
00509 /**
00510   * @brief  Sets the Text Font.
00511   * @param  pFonts: the layer font to be used
00512   */
00513 void BSP_LCD_SetFont(sFONT *pFonts)
00514 {
00515   DrawProp[ActiveLayer].pFont = pFonts;
00516 }
00517 
00518 /**
00519   * @brief  Gets the Text Font.
00520   * @retval Layer font
00521   */
00522 sFONT *BSP_LCD_GetFont(void)
00523 {
00524   return DrawProp[ActiveLayer].pFont;
00525 }
00526 
00527 /**
00528   * @brief  Reads Pixel.
00529   * @param  Xpos: the X position
00530   * @param  Ypos: the Y position 
00531   * @retval RGB pixel color
00532   */
00533 uint32_t BSP_LCD_ReadPixel(uint16_t Xpos, uint16_t Ypos)
00534 {
00535   uint32_t ret = 0;
00536   
00537   if(LtdcHandler.LayerCfg[ActiveLayer].PixelFormat == LTDC_PIXEL_FORMAT_ARGB8888)
00538   {
00539     /* Read data value from SDRAM memory */
00540     ret = *(__IO uint32_t*) (LtdcHandler.LayerCfg[ActiveLayer].FBStartAdress + (4*(Ypos*BSP_LCD_GetXSize() + Xpos)));
00541   }
00542   else if(LtdcHandler.LayerCfg[ActiveLayer].PixelFormat == LTDC_PIXEL_FORMAT_RGB888)
00543   {
00544     /* Read data value from SDRAM memory */
00545     ret = (*(__IO uint32_t*) (LtdcHandler.LayerCfg[ActiveLayer].FBStartAdress + (4*(Ypos*BSP_LCD_GetXSize() + Xpos))) & 0x00FFFFFF);
00546   }
00547   else if((LtdcHandler.LayerCfg[ActiveLayer].PixelFormat == LTDC_PIXEL_FORMAT_RGB565) || \
00548           (LtdcHandler.LayerCfg[ActiveLayer].PixelFormat == LTDC_PIXEL_FORMAT_ARGB4444) || \
00549           (LtdcHandler.LayerCfg[ActiveLayer].PixelFormat == LTDC_PIXEL_FORMAT_AL88))  
00550   {
00551     /* Read data value from SDRAM memory */
00552     ret = *(__IO uint16_t*) (LtdcHandler.LayerCfg[ActiveLayer].FBStartAdress + (2*(Ypos*BSP_LCD_GetXSize() + Xpos)));    
00553   }
00554   else
00555   {
00556     /* Read data value from SDRAM memory */
00557     ret = *(__IO uint8_t*) (LtdcHandler.LayerCfg[ActiveLayer].FBStartAdress + (2*(Ypos*BSP_LCD_GetXSize() + Xpos)));    
00558   }
00559 
00560   return ret;
00561 }
00562 
00563 /**
00564   * @brief  Clears the hole LCD.
00565   * @param  Color: the color of the background
00566   */
00567 void BSP_LCD_Clear(uint32_t Color)
00568 { 
00569   /* Clear the LCD */ 
00570   FillBuffer(ActiveLayer, (uint32_t *)(LtdcHandler.LayerCfg[ActiveLayer].FBStartAdress), BSP_LCD_GetXSize(), BSP_LCD_GetYSize(), 0, Color);
00571 }
00572 
00573 /**
00574   * @brief  Clears the selected line.
00575   * @param  Line: the line to be cleared
00576   */
00577 void BSP_LCD_ClearStringLine(uint32_t Line)
00578 {
00579   uint32_t colorbackup = DrawProp[ActiveLayer].TextColor;
00580   DrawProp[ActiveLayer].TextColor = DrawProp[ActiveLayer].BackColor;
00581 
00582   /* Draw rectangle with background color */
00583   BSP_LCD_FillRect(0, (Line * DrawProp[ActiveLayer].pFont->Height), BSP_LCD_GetXSize(), DrawProp[ActiveLayer].pFont->Height);
00584   
00585   DrawProp[ActiveLayer].TextColor = colorbackup;
00586   BSP_LCD_SetTextColor(DrawProp[ActiveLayer].TextColor);  
00587 }
00588 
00589 /**
00590   * @brief  Displays one character.
00591   * @param  Xpos: start column address
00592   * @param  Ypos: the Line where to display the character shape
00593   * @param  Ascii: character ascii code, must be between 0x20 and 0x7E
00594   */
00595 void BSP_LCD_DisplayChar(uint16_t Xpos, uint16_t Ypos, uint8_t Ascii)
00596 {
00597   DrawChar(Xpos, Ypos, &DrawProp[ActiveLayer].pFont->table[(Ascii-' ') *\
00598               DrawProp[ActiveLayer].pFont->Height * ((DrawProp[ActiveLayer].pFont->Width + 7) / 8)]);
00599 }
00600 
00601 /**
00602   * @brief  Displays a maximum of 60 char on the LCD.
00603   * @param  X: pointer to x position (in pixel)
00604   * @param  Y: pointer to y position (in pixel)    
00605   * @param  pText: pointer to string to display on LCD
00606   * @param  mode: The display mode
00607   *    This parameter can be one of the following values:
00608   *                @arg CENTER_MODE 
00609   *                @arg RIGHT_MODE
00610   *                @arg LEFT_MODE   
00611   */
00612 void BSP_LCD_DisplayStringAt(uint16_t X, uint16_t Y, uint8_t *pText, Text_AlignModeTypdef mode)
00613 {
00614   uint16_t refcolumn = 1, i = 0;
00615   uint32_t size = 0, xsize = 0; 
00616   uint8_t  *ptr = pText;
00617   
00618   /* Get the text size */
00619   while (*ptr++) size ++ ;
00620   
00621   /* Characters number per line */
00622   xsize = (BSP_LCD_GetXSize()/DrawProp[ActiveLayer].pFont->Width);
00623   
00624   switch (mode)
00625   {
00626   case CENTER_MODE:
00627     {
00628       refcolumn = X+ ((xsize - size)* DrawProp[ActiveLayer].pFont->Width) / 2;
00629       break;
00630     }
00631   case LEFT_MODE:
00632     {
00633       refcolumn = X;
00634       break;
00635     }
00636   case RIGHT_MODE:
00637     {
00638       refcolumn = X + ((xsize - size)*DrawProp[ActiveLayer].pFont->Width);
00639       break;
00640     }
00641   default:
00642     {
00643       refcolumn = X;
00644       break;
00645     }
00646   }
00647 
00648   /* Send the string character by character on LCD */
00649   while ((*pText != 0) & (((BSP_LCD_GetXSize() - (i*DrawProp[ActiveLayer].pFont->Width)) & 0xFFFF) >= DrawProp[ActiveLayer].pFont->Width))
00650   {
00651     /* Display one character on LCD */
00652     BSP_LCD_DisplayChar(refcolumn, Y, *pText);
00653     /* Decrement the column position by 16 */
00654     refcolumn += DrawProp[ActiveLayer].pFont->Width;
00655     /* Point on the next character */
00656     pText++;
00657     i++;
00658   }  
00659 }
00660 
00661 /**
00662   * @brief  Displays a maximum of 20 char on the LCD.
00663   * @param  Line: the Line where to display the character shape
00664   * @param  ptr: pointer to string to display on LCD
00665   */
00666 void BSP_LCD_DisplayStringAtLine(uint16_t Line, uint8_t *ptr)
00667 {
00668   BSP_LCD_DisplayStringAt(0, LINE(Line), ptr, LEFT_MODE);
00669 }
00670 
00671 /**
00672   * @brief  Displays an horizontal line.
00673   * @param  Xpos: the X position
00674   * @param  Ypos: the Y position
00675   * @param  Length: line length
00676   */
00677 void BSP_LCD_DrawHLine(uint16_t Xpos, uint16_t Ypos, uint16_t Length)
00678 {
00679   uint32_t xaddress = 0;
00680   
00681   /* Get the line address */
00682   xaddress = (LtdcHandler.LayerCfg[ActiveLayer].FBStartAdress) + 4*(BSP_LCD_GetXSize()*Ypos + Xpos);
00683 
00684   /* Write line */
00685   FillBuffer(ActiveLayer, (uint32_t *)xaddress, Length, 1, 0, DrawProp[ActiveLayer].TextColor);
00686 }
00687 
00688 /**
00689   * @brief  Displays a vertical line.
00690   * @param  Xpos: the X position
00691   * @param  Ypos: the Y position
00692   * @param  Length: line length
00693   */
00694 void BSP_LCD_DrawVLine(uint16_t Xpos, uint16_t Ypos, uint16_t Length)
00695 {
00696   uint32_t xaddress = 0;
00697   
00698   /* Get the line address */
00699   xaddress = (LtdcHandler.LayerCfg[ActiveLayer].FBStartAdress) + 4*(BSP_LCD_GetXSize()*Ypos + Xpos);
00700   
00701   /* Write line */
00702   FillBuffer(ActiveLayer, (uint32_t *)xaddress, 1, Length, (BSP_LCD_GetXSize() - 1), DrawProp[ActiveLayer].TextColor);
00703 }
00704 
00705 /**
00706   * @brief  Displays an uni-line (between two points).
00707   * @param  X1: the point 1 X position
00708   * @param  Y1: the point 1 Y position
00709   * @param  X2: the point 2 X position
00710   * @param  Y2: the point 2 Y position
00711   */
00712 void BSP_LCD_DrawLine(uint16_t X1, uint16_t Y1, uint16_t X2, uint16_t Y2)
00713 {
00714   int16_t deltax = 0, deltay = 0, x = 0, y = 0, xinc1 = 0, xinc2 = 0, 
00715   yinc1 = 0, yinc2 = 0, den = 0, num = 0, numadd = 0, numpixels = 0, 
00716   curpixel = 0;
00717   
00718   deltax = ABS(X2 - X1);        /* The difference between the x's */
00719   deltay = ABS(Y2 - Y1);        /* The difference between the y's */
00720   x = X1;                       /* Start x off at the first pixel */
00721   y = Y1;                       /* Start y off at the first pixel */
00722   
00723   if (X2 >= X1)                 /* The x-values are increasing */
00724   {
00725     xinc1 = 1;
00726     xinc2 = 1;
00727   }
00728   else                          /* The x-values are decreasing */
00729   {
00730     xinc1 = -1;
00731     xinc2 = -1;
00732   }
00733   
00734   if (Y2 >= Y1)                 /* The y-values are increasing */
00735   {
00736     yinc1 = 1;
00737     yinc2 = 1;
00738   }
00739   else                          /* The y-values are decreasing */
00740   {
00741     yinc1 = -1;
00742     yinc2 = -1;
00743   }
00744   
00745   if (deltax >= deltay)         /* There is at least one x-value for every y-value */
00746   {
00747     xinc1 = 0;                  /* Don't change the x when numerator >= denominator */
00748     yinc2 = 0;                  /* Don't change the y for every iteration */
00749     den = deltax;
00750     num = deltax / 2;
00751     numadd = deltay;
00752     numpixels = deltax;         /* There are more x-values than y-values */
00753   }
00754   else                          /* There is at least one y-value for every x-value */
00755   {
00756     xinc2 = 0;                  /* Don't change the x for every iteration */
00757     yinc1 = 0;                  /* Don't change the y when numerator >= denominator */
00758     den = deltay;
00759     num = deltay / 2;
00760     numadd = deltax;
00761     numpixels = deltay;         /* There are more y-values than x-values */
00762   }
00763   
00764   for (curpixel = 0; curpixel <= numpixels; curpixel++)
00765   {
00766     BSP_LCD_DrawPixel(x, y, DrawProp[ActiveLayer].TextColor);   /* Draw the current pixel */
00767     num += numadd;                            /* Increase the numerator by the top of the fraction */
00768     if (num >= den)                           /* Check if numerator >= denominator */
00769     {
00770       num -= den;                             /* Calculate the new numerator value */
00771       x += xinc1;                             /* Change the x as appropriate */
00772       y += yinc1;                             /* Change the y as appropriate */
00773     }
00774     x += xinc2;                               /* Change the x as appropriate */
00775     y += yinc2;                               /* Change the y as appropriate */
00776   }
00777 }
00778 
00779 /**
00780   * @brief  Displays a rectangle.
00781   * @param  Xpos: the X position
00782   * @param  Ypos: the Y position
00783   * @param  Height: display rectangle height
00784   * @param  Width: display rectangle width
00785   */
00786 void BSP_LCD_DrawRect(uint16_t Xpos, uint16_t Ypos, uint16_t Width, uint16_t Height)
00787 {
00788   /* Draw horizontal lines */
00789   BSP_LCD_DrawHLine(Xpos, Ypos, Width);
00790   BSP_LCD_DrawHLine(Xpos, (Ypos+ Height), Width);
00791   
00792   /* Draw vertical lines */
00793   BSP_LCD_DrawVLine(Xpos, Ypos, Height);
00794   BSP_LCD_DrawVLine((Xpos + Width), Ypos, Height);
00795 }
00796 
00797 /**
00798   * @brief  Displays a circle.
00799   * @param  Xpos: the X position
00800   * @param  Ypos: the Y position
00801   * @param  Radius: the circle radius
00802   */
00803 void BSP_LCD_DrawCircle(uint16_t Xpos, uint16_t Ypos, uint16_t Radius)
00804 {
00805   int32_t  d;/* Decision Variable */ 
00806   uint32_t  curx;/* Current X Value */
00807   uint32_t  cury;/* Current Y Value */ 
00808   
00809   d = 3 - (Radius << 1);
00810   curx = 0;
00811   cury = Radius;
00812   
00813   while (curx <= cury)
00814   {
00815     BSP_LCD_DrawPixel((Xpos + curx), (Ypos - cury), DrawProp[ActiveLayer].TextColor);
00816     BSP_LCD_DrawPixel((Xpos - curx), (Ypos - cury), DrawProp[ActiveLayer].TextColor);
00817     BSP_LCD_DrawPixel((Xpos + cury), (Ypos - curx), DrawProp[ActiveLayer].TextColor);
00818     BSP_LCD_DrawPixel((Xpos - cury), (Ypos - curx), DrawProp[ActiveLayer].TextColor);
00819     BSP_LCD_DrawPixel((Xpos + curx), (Ypos + cury), DrawProp[ActiveLayer].TextColor);
00820     BSP_LCD_DrawPixel((Xpos - curx), (Ypos + cury), DrawProp[ActiveLayer].TextColor);
00821     BSP_LCD_DrawPixel((Xpos + cury), (Ypos + curx), DrawProp[ActiveLayer].TextColor);
00822     BSP_LCD_DrawPixel((Xpos - cury), (Ypos + curx), DrawProp[ActiveLayer].TextColor);   
00823 
00824     if (d < 0)
00825     { 
00826       d += (curx << 2) + 6;
00827     }
00828     else
00829     {
00830       d += ((curx - cury) << 2) + 10;
00831       cury--;
00832     }
00833     curx++;
00834   } 
00835 }
00836 
00837 /**
00838   * @brief  Displays an poly-line (between many points).
00839   * @param  Points: pointer to the points array
00840   * @param  PointCount: Number of points
00841   */
00842 void BSP_LCD_DrawPolygon(pPoint Points, uint16_t PointCount)
00843 {
00844   int16_t x = 0, y = 0;
00845 
00846   if(PointCount < 2)
00847   {
00848     return;
00849   }
00850 
00851   BSP_LCD_DrawLine(Points->X, Points->Y, (Points+PointCount-1)->X, (Points+PointCount-1)->Y);
00852   
00853   while(--PointCount)
00854   {
00855     x = Points->X;
00856     y = Points->Y;
00857     Points++;
00858     BSP_LCD_DrawLine(x, y, Points->X, Points->Y);
00859   }
00860 }
00861 
00862 /**
00863   * @brief  Displays an Ellipse.
00864   * @param  Xpos: the X position
00865   * @param  Ypos: the Y position
00866   * @param  XRadius: the X radius of ellipse
00867   * @param  YRadius: the Y radius of ellipse
00868   */
00869 void BSP_LCD_DrawEllipse(int Xpos, int Ypos, int XRadius, int YRadius)
00870 {
00871   int x = 0, y = -YRadius, err = 2-2*XRadius, e2;
00872   float k = 0, rad1 = 0, rad2 = 0;
00873   
00874   rad1 = XRadius;
00875   rad2 = YRadius;
00876   
00877   k = (float)(rad2/rad1);
00878   
00879   do { 
00880     BSP_LCD_DrawPixel((Xpos-(uint16_t)(x/k)), (Ypos+y), DrawProp[ActiveLayer].TextColor);
00881     BSP_LCD_DrawPixel((Xpos+(uint16_t)(x/k)), (Ypos+y), DrawProp[ActiveLayer].TextColor);
00882     BSP_LCD_DrawPixel((Xpos+(uint16_t)(x/k)), (Ypos-y), DrawProp[ActiveLayer].TextColor);
00883     BSP_LCD_DrawPixel((Xpos-(uint16_t)(x/k)), (Ypos-y), DrawProp[ActiveLayer].TextColor);      
00884     
00885     e2 = err;
00886     if (e2 <= x) {
00887       err += ++x*2+1;
00888       if (-y == x && e2 <= y) e2 = 0;
00889     }
00890     if (e2 > y) err += ++y*2+1;
00891   }
00892   while (y <= 0);
00893 }
00894 
00895 /**
00896   * @brief  Displays a bitmap picture loaded in the internal Flash (32 bpp).
00897   * @param  X: the bmp x position in the LCD
00898   * @param  Y: the bmp Y position in the LCD
00899   * @param  pBmp: Bmp picture address in the internal Flash
00900   */
00901 void BSP_LCD_DrawBitmap(uint32_t X, uint32_t Y, uint8_t *pBmp)
00902 {
00903   uint32_t index = 0, width = 0, height = 0, bitpixel = 0;
00904   uint32_t address;
00905   uint32_t inputcolormode = 0;
00906   
00907   /* Get bitmap data address offset */
00908   index = pBmp[10] + (pBmp[11] << 8) + (pBmp[12] << 16)  + (pBmp[13] << 24);
00909 
00910   /* Read bitmap width */
00911   width = pBmp[18] + (pBmp[19] << 8) + (pBmp[20] << 16)  + (pBmp[21] << 24);
00912 
00913   /* Read bitmap height */
00914   height = pBmp[22] + (pBmp[23] << 8) + (pBmp[24] << 16)  + (pBmp[25] << 24);
00915 
00916   /* Read bit/pixel */
00917   bitpixel = pBmp[28] + (pBmp[29] << 8);   
00918  
00919   /* Set Address */
00920   address = LtdcHandler.LayerCfg[ActiveLayer].FBStartAdress + (((BSP_LCD_GetXSize()*Y) + X)*(4));
00921 
00922   /* Get the Layer pixel format */    
00923   if ((bitpixel/8) == 4)
00924   {
00925     inputcolormode = CM_ARGB8888;
00926   }
00927   else if ((bitpixel/8) == 2)
00928   {
00929     inputcolormode = CM_RGB565;
00930   }
00931   else
00932   {
00933     inputcolormode = CM_RGB888;
00934   }
00935  
00936   /* bypass the bitmap header */
00937   pBmp += (index + (width * (height - 1) * (bitpixel/8)));
00938 
00939   /* Convert picture to ARGB8888 pixel format */
00940   for(index=0; index < height; index++)
00941   {
00942   /* Pixel format conversion */
00943   ConvertLineToARGB8888((uint32_t *)pBmp, (uint32_t *)address, width, inputcolormode);
00944 
00945   /* Increment the source and destination buffers */
00946   address+=  ((BSP_LCD_GetXSize() - width + width)*4);
00947   pBmp -= width*(bitpixel/8);
00948   }
00949 }
00950 
00951 /**
00952   * @brief  Displays a full rectangle.
00953   * @param  Xpos: the X position
00954   * @param  Ypos: the Y position
00955   * @param  Height: rectangle height
00956   * @param  Width: rectangle width
00957   */
00958 void BSP_LCD_FillRect(uint16_t Xpos, uint16_t Ypos, uint16_t Width, uint16_t Height)
00959 {
00960   uint32_t xaddress = 0;
00961 
00962   /* Set the text color */
00963   BSP_LCD_SetTextColor(DrawProp[ActiveLayer].TextColor);
00964 
00965   /* Get the rectangle start address */
00966   xaddress = (LtdcHandler.LayerCfg[ActiveLayer].FBStartAdress) + 4*(BSP_LCD_GetXSize()*Ypos + Xpos);
00967 
00968   /* Fill the rectangle */
00969   FillBuffer(ActiveLayer, (uint32_t *)xaddress, Width, Height, (BSP_LCD_GetXSize() - Width), DrawProp[ActiveLayer].TextColor);
00970 }
00971 
00972 /**
00973   * @brief  Displays a full circle.
00974   * @param  Xpos: the X position
00975   * @param  Ypos: the Y position
00976   * @param  Radius: the circle radius
00977   */
00978 void BSP_LCD_FillCircle(uint16_t Xpos, uint16_t Ypos, uint16_t Radius)
00979 {
00980   int32_t  d;    /* Decision Variable */ 
00981   uint32_t  curx;/* Current X Value */
00982   uint32_t  cury;/* Current Y Value */ 
00983   
00984   d = 3 - (Radius << 1);
00985 
00986   curx = 0;
00987   cury = Radius;
00988   
00989   BSP_LCD_SetTextColor(DrawProp[ActiveLayer].TextColor);
00990 
00991   while (curx <= cury)
00992   {
00993     if(cury > 0) 
00994     {
00995       BSP_LCD_DrawHLine(Xpos - cury, Ypos + curx, 2*cury);
00996       BSP_LCD_DrawHLine(Xpos - cury, Ypos - curx, 2*cury);
00997     }
00998 
00999     if(curx > 0) 
01000     {
01001       BSP_LCD_DrawHLine(Xpos - curx, Ypos - cury, 2*curx);
01002       BSP_LCD_DrawHLine(Xpos - curx, Ypos + cury, 2*curx);
01003     }
01004     if (d < 0)
01005     { 
01006       d += (curx << 2) + 6;
01007     }
01008     else
01009     {
01010       d += ((curx - cury) << 2) + 10;
01011       cury--;
01012     }
01013     curx++;
01014   }
01015 
01016   BSP_LCD_SetTextColor(DrawProp[ActiveLayer].TextColor);
01017   BSP_LCD_DrawCircle(Xpos, Ypos, Radius);
01018 }
01019 
01020 /**
01021   * @brief  Fill triangle.
01022   * @param  X1: the point 1 x position
01023   * @param  Y1: the point 1 y position
01024   * @param  X2: the point 2 x position
01025   * @param  Y2: the point 2 y position
01026   * @param  X3: the point 3 x position
01027   * @param  Y3: the point 3 y position
01028   */
01029 void BSP_LCD_FillTriangle(uint16_t X1, uint16_t X2, uint16_t X3, uint16_t Y1, uint16_t Y2, uint16_t Y3)
01030 { 
01031   int16_t deltax = 0, deltay = 0, x = 0, y = 0, xinc1 = 0, xinc2 = 0, 
01032   yinc1 = 0, yinc2 = 0, den = 0, num = 0, numadd = 0, numpixels = 0, 
01033   curpixel = 0;
01034   
01035   deltax = ABS(X2 - X1);        /* The difference between the x's */
01036   deltay = ABS(Y2 - Y1);        /* The difference between the y's */
01037   x = X1;                       /* Start x off at the first pixel */
01038   y = Y1;                       /* Start y off at the first pixel */
01039   
01040   if (X2 >= X1)                 /* The x-values are increasing */
01041   {
01042     xinc1 = 1;
01043     xinc2 = 1;
01044   }
01045   else                          /* The x-values are decreasing */
01046   {
01047     xinc1 = -1;
01048     xinc2 = -1;
01049   }
01050   
01051   if (Y2 >= Y1)                 /* The y-values are increasing */
01052   {
01053     yinc1 = 1;
01054     yinc2 = 1;
01055   }
01056   else                          /* The y-values are decreasing */
01057   {
01058     yinc1 = -1;
01059     yinc2 = -1;
01060   }
01061   
01062   if (deltax >= deltay)         /* There is at least one x-value for every y-value */
01063   {
01064     xinc1 = 0;                  /* Don't change the x when numerator >= denominator */
01065     yinc2 = 0;                  /* Don't change the y for every iteration */
01066     den = deltax;
01067     num = deltax / 2;
01068     numadd = deltay;
01069     numpixels = deltax;         /* There are more x-values than y-values */
01070   }
01071   else                          /* There is at least one y-value for every x-value */
01072   {
01073     xinc2 = 0;                  /* Don't change the x for every iteration */
01074     yinc1 = 0;                  /* Don't change the y when numerator >= denominator */
01075     den = deltay;
01076     num = deltay / 2;
01077     numadd = deltax;
01078     numpixels = deltay;         /* There are more y-values than x-values */
01079   }
01080   
01081   for (curpixel = 0; curpixel <= numpixels; curpixel++)
01082   {
01083     BSP_LCD_DrawLine(x, y, X3, Y3);
01084     
01085     num += numadd;              /* Increase the numerator by the top of the fraction */
01086     if (num >= den)             /* Check if numerator >= denominator */
01087     {
01088       num -= den;               /* Calculate the new numerator value */
01089       x += xinc1;               /* Change the x as appropriate */
01090       y += yinc1;               /* Change the y as appropriate */
01091     }
01092     x += xinc2;                 /* Change the x as appropriate */
01093     y += yinc2;                 /* Change the y as appropriate */
01094   } 
01095 }
01096 
01097 /**
01098   * @brief  Displays a full poly-line (between many points).
01099   * @param  Points: pointer to the points array
01100   * @param  PointCount: Number of points
01101   */
01102 void BSP_LCD_FillPolygon(pPoint Points, uint16_t PointCount)
01103 {
01104   
01105   int16_t x = 0, y = 0, x2 = 0, y2 = 0, xcenter = 0, ycenter = 0, xfirst = 0, yfirst = 0, pixelx = 0, pixely = 0, counter = 0;
01106   uint16_t  imageleft = 0, imageright = 0, imagetop = 0, imagebottom = 0;  
01107 
01108   imageleft = imageright = Points->X;
01109   imagetop= imagebottom = Points->Y;
01110 
01111   for(counter = 1; counter < PointCount; counter++)
01112   {
01113     pixelx = POLY_X(counter);
01114     if(pixelx < imageleft)
01115     {
01116       imageleft = pixelx;
01117     }
01118     if(pixelx > imageright)
01119     {
01120       imageright = pixelx;
01121     }
01122 
01123     pixely = POLY_Y(counter);
01124     if(pixely < imagetop)
01125     { 
01126       imagetop = pixely;
01127     }
01128     if(pixely > imagebottom)
01129     {
01130       imagebottom = pixely;
01131     }
01132   }  
01133 
01134   if(PointCount < 2)
01135   {
01136     return;
01137   }
01138 
01139   xcenter = (imageleft + imageright)/2;
01140   ycenter = (imagebottom + imagetop)/2;
01141  
01142   xfirst = Points->X;
01143   yfirst = Points->Y;
01144 
01145   while(--PointCount)
01146   {
01147     x = Points->X;
01148     y = Points->Y;
01149     Points++;
01150     x2 = Points->X;
01151     y2 = Points->Y;    
01152   
01153     BSP_LCD_FillTriangle(x, x2, xcenter, y, y2, ycenter);
01154     BSP_LCD_FillTriangle(x, xcenter, x2, y, ycenter, y2);
01155     BSP_LCD_FillTriangle(xcenter, x2, x, ycenter, y2, y);   
01156   }
01157   
01158   BSP_LCD_FillTriangle(xfirst, x2, xcenter, yfirst, y2, ycenter);
01159   BSP_LCD_FillTriangle(xfirst, xcenter, x2, yfirst, ycenter, y2);
01160   BSP_LCD_FillTriangle(xcenter, x2, xfirst, ycenter, y2, yfirst);   
01161 }
01162 
01163 /**
01164   * @brief  Draw a full ellipse.
01165   * @param  Xpos: the X position
01166   * @param  Ypos: the Y position
01167   * @param  XRadius: X radius of ellipse
01168   * @param  YRadius: Y radius of ellipse. 
01169   */
01170 void BSP_LCD_FillEllipse(int Xpos, int Ypos, int XRadius, int YRadius)
01171 {
01172   int x = 0, y = -YRadius, err = 2-2*XRadius, e2;
01173   float K = 0, rad1 = 0, rad2 = 0;
01174   
01175   rad1 = XRadius;
01176   rad2 = YRadius;
01177   K = (float)(rad2/rad1);
01178   
01179   do 
01180   { 
01181     BSP_LCD_DrawHLine((Xpos-(uint16_t)(x/K)), (Ypos+y), (2*(uint16_t)(x/K) + 1));
01182     BSP_LCD_DrawHLine((Xpos-(uint16_t)(x/K)), (Ypos-y), (2*(uint16_t)(x/K) + 1));
01183     
01184     e2 = err;
01185     if (e2 <= x) 
01186     {
01187       err += ++x*2+1;
01188       if (-y == x && e2 <= y) e2 = 0;
01189     }
01190     if (e2 > y) err += ++y*2+1;
01191   }
01192   while (y <= 0);
01193 }
01194 
01195 /**
01196   * @brief  Enables the Display.
01197   */
01198 void BSP_LCD_DisplayOn(void)
01199 {
01200   if(LcdDrv->DisplayOn != NULL)
01201   {
01202     LcdDrv->DisplayOn();
01203   }
01204 }
01205 
01206 /**
01207   * @brief  Disables the Display.
01208   */
01209 void BSP_LCD_DisplayOff(void)
01210 {
01211   if(LcdDrv->DisplayOff != NULL)
01212   {
01213     LcdDrv->DisplayOff();
01214   }
01215 }
01216 
01217 /*******************************************************************************
01218                        LTDC and DMA2D BSP Routines
01219 *******************************************************************************/
01220 
01221 /**
01222   * @brief  Initializes the LTDC MSP.
01223   */
01224 __weak void BSP_LCD_MspInit(void)
01225 {
01226   GPIO_InitTypeDef GPIO_InitStructure;
01227   
01228   /* Enable the LTDC and DMA2D Clock */
01229   __HAL_RCC_LTDC_CLK_ENABLE();
01230   __HAL_RCC_DMA2D_CLK_ENABLE(); 
01231   
01232   /* Enable GPIOs clock */
01233   __HAL_RCC_GPIOA_CLK_ENABLE();
01234   __HAL_RCC_GPIOB_CLK_ENABLE();
01235   __HAL_RCC_GPIOC_CLK_ENABLE();
01236   __HAL_RCC_GPIOD_CLK_ENABLE();
01237   __HAL_RCC_GPIOF_CLK_ENABLE();
01238   __HAL_RCC_GPIOG_CLK_ENABLE();
01239 
01240   /* GPIOs Configuration */
01241   /*
01242    +------------------------+-----------------------+----------------------------+
01243    +                       LCD pins assignment                                   +
01244    +------------------------+-----------------------+----------------------------+
01245    |  LCD_TFT R2 <-> PC.10  |  LCD_TFT G2 <-> PA.06 |  LCD_TFT B2 <-> PD.06      |
01246    |  LCD_TFT R3 <-> PB.00  |  LCD_TFT G3 <-> PG.10 |  LCD_TFT B3 <-> PG.11      |
01247    |  LCD_TFT R4 <-> PA.11  |  LCD_TFT G4 <-> PB.10 |  LCD_TFT B4 <-> PG.12      |
01248    |  LCD_TFT R5 <-> PA.12  |  LCD_TFT G5 <-> PB.11 |  LCD_TFT B5 <-> PA.03      |
01249    |  LCD_TFT R6 <-> PB.01  |  LCD_TFT G6 <-> PC.07 |  LCD_TFT B6 <-> PB.08      |
01250    |  LCD_TFT R7 <-> PG.06  |  LCD_TFT G7 <-> PD.03 |  LCD_TFT B7 <-> PB.09      |
01251    -------------------------------------------------------------------------------
01252             |  LCD_TFT HSYNC <-> PC.06  | LCDTFT VSYNC <->  PA.04 |
01253             |  LCD_TFT CLK   <-> PG.07  | LCD_TFT DE   <->  PF.10 |
01254              -----------------------------------------------------
01255   */
01256 
01257   /* GPIOA configuration */
01258   GPIO_InitStructure.Pin = GPIO_PIN_3 | GPIO_PIN_4 | GPIO_PIN_6 |
01259                            GPIO_PIN_11 | GPIO_PIN_12;
01260   GPIO_InitStructure.Mode = GPIO_MODE_AF_PP;
01261   GPIO_InitStructure.Pull = GPIO_NOPULL;
01262   GPIO_InitStructure.Speed = GPIO_SPEED_FAST;
01263   GPIO_InitStructure.Alternate= GPIO_AF14_LTDC;
01264   HAL_GPIO_Init(GPIOA, &GPIO_InitStructure);
01265 
01266  /* GPIOB configuration */
01267   GPIO_InitStructure.Pin = GPIO_PIN_8 | \
01268                            GPIO_PIN_9 | GPIO_PIN_10 | GPIO_PIN_11;
01269   HAL_GPIO_Init(GPIOB, &GPIO_InitStructure);
01270 
01271  /* GPIOC configuration */
01272   GPIO_InitStructure.Pin = GPIO_PIN_6 | GPIO_PIN_7 | GPIO_PIN_10;
01273   HAL_GPIO_Init(GPIOC, &GPIO_InitStructure);
01274 
01275  /* GPIOD configuration */
01276   GPIO_InitStructure.Pin = GPIO_PIN_3 | GPIO_PIN_6;
01277   HAL_GPIO_Init(GPIOD, &GPIO_InitStructure);
01278   
01279  /* GPIOF configuration */
01280   GPIO_InitStructure.Pin = GPIO_PIN_10;
01281   HAL_GPIO_Init(GPIOF, &GPIO_InitStructure);     
01282 
01283  /* GPIOG configuration */  
01284   GPIO_InitStructure.Pin = GPIO_PIN_6 | GPIO_PIN_7 | \
01285                            GPIO_PIN_11;
01286   HAL_GPIO_Init(GPIOG, &GPIO_InitStructure);
01287  
01288   /* GPIOB configuration */  
01289   GPIO_InitStructure.Pin = GPIO_PIN_0 | GPIO_PIN_1;
01290   GPIO_InitStructure.Alternate= GPIO_AF9_LTDC;
01291   HAL_GPIO_Init(GPIOB, &GPIO_InitStructure);
01292 
01293   /* GPIOG configuration */  
01294   GPIO_InitStructure.Pin = GPIO_PIN_10 | GPIO_PIN_12;
01295   HAL_GPIO_Init(GPIOG, &GPIO_InitStructure);
01296 }
01297 
01298 /*******************************************************************************
01299                             Static Functions
01300 *******************************************************************************/
01301 
01302 /**
01303   * @brief  Writes Pixel.
01304   * @param  Xpos: the X position
01305   * @param  Ypos: the Y position
01306   * @param  RGB_Code: the pixel color in ARGB mode (8-8-8-8)  
01307   */
01308 void BSP_LCD_DrawPixel(uint16_t Xpos, uint16_t Ypos, uint32_t RGB_Code)
01309 {
01310   /* Write data value to all SDRAM memory */
01311   *(__IO uint32_t*) (LtdcHandler.LayerCfg[ActiveLayer].FBStartAdress + (4*(Ypos*BSP_LCD_GetXSize() + Xpos))) = RGB_Code;
01312 }
01313 
01314 /**
01315   * @brief  Draws a character on LCD.
01316   * @param  Xpos: the Line where to display the character shape
01317   * @param  Ypos: start column address
01318   * @param  c: pointer to the character data
01319   */
01320 static void DrawChar(uint16_t Xpos, uint16_t Ypos, const uint8_t *c)
01321 {
01322   uint32_t i = 0, j = 0;
01323   uint16_t height, width;
01324   uint8_t offset;
01325   uint8_t *pchar;
01326   uint32_t line=0;
01327 
01328   height = DrawProp[ActiveLayer].pFont->Height;
01329   width  = DrawProp[ActiveLayer].pFont->Width;
01330 
01331   offset = 8 *((width + 7)/8) -  width ;
01332 
01333   for(i = 0; i < height; i++)
01334   {
01335     pchar = ((uint8_t *)c + (width + 7)/8 * i);
01336 
01337     switch(((width + 7)/8))
01338     {
01339     case 1:
01340       line =  pchar[0];      
01341       break;
01342       
01343     case 2:
01344       line =  (pchar[0]<< 8) | pchar[1];
01345       break;
01346 
01347     case 3:
01348     default:
01349       line =  (pchar[0]<< 16) | (pchar[1]<< 8) | pchar[2];      
01350       break;
01351     }
01352 
01353     for (j = 0; j < width; j++)
01354     {
01355       if(line & (1 << (width- j + offset- 1))) 
01356       {
01357         BSP_LCD_DrawPixel((Xpos + j), Ypos, DrawProp[ActiveLayer].TextColor);
01358       }
01359       else
01360       {
01361         BSP_LCD_DrawPixel((Xpos + j), Ypos, DrawProp[ActiveLayer].BackColor);
01362       } 
01363     }
01364     Ypos++;
01365   }
01366 }
01367 
01368 /**
01369   * @brief  Fills buffer.
01370   * @param  LayerIndex: layer index
01371   * @param  pDst: output color
01372   * @param  xSize: buffer width
01373   * @param  ySize: buffer height
01374   * @param  OffLine: offset
01375   * @param  ColorIndex: color Index  
01376   */
01377 static void FillBuffer(uint32_t LayerIndex, void * pDst, uint32_t xSize, uint32_t ySize, uint32_t OffLine, uint32_t ColorIndex) 
01378 {
01379   
01380   /* Register to memory mode with ARGB8888 as color Mode */ 
01381   Dma2dHandler.Init.Mode         = DMA2D_R2M;
01382   Dma2dHandler.Init.ColorMode    = DMA2D_ARGB8888;
01383   Dma2dHandler.Init.OutputOffset = OffLine;      
01384   
01385   Dma2dHandler.Instance = DMA2D; 
01386   
01387   /* DMA2D Initialization */
01388   if(HAL_DMA2D_Init(&Dma2dHandler) == HAL_OK) 
01389   {
01390     if(HAL_DMA2D_ConfigLayer(&Dma2dHandler, LayerIndex) == HAL_OK) 
01391     {
01392       if (HAL_DMA2D_Start(&Dma2dHandler, ColorIndex, (uint32_t)pDst, xSize, ySize) == HAL_OK)
01393       {
01394         /* Polling For DMA transfer */  
01395         HAL_DMA2D_PollForTransfer(&Dma2dHandler, 10);
01396       }
01397     }
01398   } 
01399 }
01400 
01401 /**
01402   * @brief  Converts Line to ARGB8888 pixel format.
01403   * @param  pSrc: pointer to source buffer
01404   * @param  pDst: output color
01405   * @param  xSize: buffer width
01406   * @param  ColorMode: input color mode   
01407   */
01408 static void ConvertLineToARGB8888(void * pSrc, void * pDst, uint32_t xSize, uint32_t ColorMode)
01409 {    
01410   /* Configure the DMA2D Mode, Color Mode and output offset */
01411   Dma2dHandler.Init.Mode         = DMA2D_M2M_PFC;
01412   Dma2dHandler.Init.ColorMode    = DMA2D_ARGB8888;
01413   Dma2dHandler.Init.OutputOffset = 0;     
01414   
01415   /* Foreground Configuration */
01416   Dma2dHandler.LayerCfg[1].AlphaMode = DMA2D_NO_MODIF_ALPHA;
01417   Dma2dHandler.LayerCfg[1].InputAlpha = 0xFF;
01418   Dma2dHandler.LayerCfg[1].InputColorMode = ColorMode;
01419   Dma2dHandler.LayerCfg[1].InputOffset = 0;
01420   
01421   Dma2dHandler.Instance = DMA2D; 
01422   
01423   /* DMA2D Initialization */
01424   if(HAL_DMA2D_Init(&Dma2dHandler) == HAL_OK) 
01425   {
01426     if(HAL_DMA2D_ConfigLayer(&Dma2dHandler, 1) == HAL_OK) 
01427     {
01428       if (HAL_DMA2D_Start(&Dma2dHandler, (uint32_t)pSrc, (uint32_t)pDst, xSize, 1) == HAL_OK)
01429       {
01430         /* Polling For DMA transfer */  
01431         HAL_DMA2D_PollForTransfer(&Dma2dHandler, 10);
01432       }
01433     }
01434   } 
01435 }
01436 
01437 /**
01438   * @}
01439   */ 
01440 
01441 /**
01442   * @}
01443   */ 
01444 
01445 /**
01446   * @}
01447   */ 
01448 
01449 /**
01450   * @}
01451   */ 
01452 
01453 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/