ST / BSP_DISCO_F469NI

Dependents:   Configurable_Robots DISCO-F469NI_LCD_demo DISCO-F469NI_SD_demo DISCO-F469NI_EEPROM_demo ... more

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers stm32469i_discovery_lcd.c Source File

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