Stepan Snigirev / BSP_DISCO_F469NI
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 
00423     /* Desactivate XRES */
00424     HAL_GPIO_WritePin(GPIOH, GPIO_PIN_7, GPIO_PIN_SET);
00425 
00426     /* Wait for 10ms after releasing XRES before sending commands */
00427     //HAL_Delay(10);
00428     wait_ms(10);
00429 #else
00430 
00431 #endif /* USE_STM32469I_DISCO_REVA == 0 */
00432 }
00433 
00434 /**
00435   * @brief  Gets the LCD X size.
00436   * @retval Used LCD X size
00437   */
00438 uint32_t BSP_LCD_GetXSize(void)
00439 {
00440   return (lcd_x_size);
00441 }
00442 
00443 /**
00444   * @brief  Gets the LCD Y size.
00445   * @retval Used LCD Y size
00446   */
00447 uint32_t BSP_LCD_GetYSize(void)
00448 {
00449   return (lcd_y_size);
00450 }
00451 
00452 /**
00453   * @brief  Set the LCD X size.
00454   * @param  imageWidthPixels : uint32_t image width in pixels unit
00455   */
00456 void BSP_LCD_SetXSize(uint32_t imageWidthPixels)
00457 {
00458   hltdc_eval.LayerCfg[ActiveLayer].ImageWidth = imageWidthPixels;
00459 }
00460 
00461 /**
00462   * @brief  Set the LCD Y size.
00463   * @param  imageHeightPixels : uint32_t image height in lines unit
00464   */
00465 void BSP_LCD_SetYSize(uint32_t imageHeightPixels)
00466 {
00467   hltdc_eval.LayerCfg[ActiveLayer].ImageHeight = imageHeightPixels;
00468 }
00469 
00470 
00471 /**
00472   * @brief  Initializes the LCD layers.
00473   * @param  LayerIndex: Layer foreground or background
00474   * @param  FB_Address: Layer frame buffer
00475   */
00476 void BSP_LCD_LayerDefaultInit(uint16_t LayerIndex, uint32_t FB_Address)
00477 {
00478     LCD_LayerCfgTypeDef  Layercfg;
00479 
00480   /* Layer Init */
00481   Layercfg.WindowX0 = 0;
00482   Layercfg.WindowX1 = BSP_LCD_GetXSize();
00483   Layercfg.WindowY0 = 0;
00484   Layercfg.WindowY1 = BSP_LCD_GetYSize();
00485   Layercfg.PixelFormat = OTM8009A_FORMAT_RBG565;
00486   Layercfg.FBStartAdress = FB_Address;
00487   Layercfg.Alpha = 255;
00488   Layercfg.Alpha0 = 0;
00489   Layercfg.Backcolor.Blue = 0;
00490   Layercfg.Backcolor.Green = 0;
00491   Layercfg.Backcolor.Red = 0;
00492   Layercfg.BlendingFactor1 = LTDC_BLENDING_FACTOR1_PAxCA;
00493   Layercfg.BlendingFactor2 = LTDC_BLENDING_FACTOR2_PAxCA;
00494   Layercfg.ImageWidth = BSP_LCD_GetXSize();
00495   Layercfg.ImageHeight = BSP_LCD_GetYSize();
00496 
00497   HAL_LTDC_ConfigLayer(&hltdc_eval, &Layercfg, LayerIndex);
00498 
00499   DrawProp[LayerIndex].BackColor = LCD_COLOR_WHITE;
00500   DrawProp[LayerIndex].pFont     = &Font24;
00501   DrawProp[LayerIndex].TextColor = LCD_COLOR_BLACK;
00502 }
00503 
00504 
00505 /**
00506   * @brief  Selects the LCD Layer.
00507   * @param  LayerIndex: Layer foreground or background
00508   */
00509 void BSP_LCD_SelectLayer(uint32_t LayerIndex)
00510 {
00511   ActiveLayer = LayerIndex;
00512 }
00513 
00514 /**
00515   * @brief  Sets an LCD Layer visible
00516   * @param  LayerIndex: Visible Layer
00517   * @param  State: New state of the specified layer
00518   *          This parameter can be one of the following values:
00519   *            @arg  ENABLE
00520   *            @arg  DISABLE
00521   */
00522 void BSP_LCD_SetLayerVisible(uint32_t LayerIndex, FunctionalState State)
00523 {
00524   if(State == ENABLE)
00525   {
00526     __HAL_LTDC_LAYER_ENABLE(&(hltdc_eval), LayerIndex);
00527   }
00528   else
00529   {
00530     __HAL_LTDC_LAYER_DISABLE(&(hltdc_eval), LayerIndex);
00531   }
00532   __HAL_LTDC_RELOAD_IMMEDIATE_CONFIG(&(hltdc_eval));
00533 
00534 }
00535 
00536 /**
00537   * @brief  Configures the transparency.
00538   * @param  LayerIndex: Layer foreground or background.
00539   * @param  Transparency: Transparency
00540   *           This parameter must be a number between Min_Data = 0x00 and Max_Data = 0xFF
00541   */
00542 void BSP_LCD_SetTransparency(uint32_t LayerIndex, uint8_t Transparency)
00543 {
00544 
00545   HAL_LTDC_SetAlpha(&(hltdc_eval), Transparency, LayerIndex);
00546 
00547 }
00548 
00549 /**
00550   * @brief  Sets an LCD layer frame buffer address.
00551   * @param  LayerIndex: Layer foreground or background
00552   * @param  Address: New LCD frame buffer value
00553   */
00554 void BSP_LCD_SetLayerAddress(uint32_t LayerIndex, uint32_t Address)
00555 {
00556 
00557   HAL_LTDC_SetAddress(&(hltdc_eval), Address, LayerIndex);
00558 
00559 }
00560 
00561 /**
00562   * @brief  Sets display window.
00563   * @param  LayerIndex: Layer index
00564   * @param  Xpos: LCD X position
00565   * @param  Ypos: LCD Y position
00566   * @param  Width: LCD window width
00567   * @param  Height: LCD window height
00568   */
00569 void BSP_LCD_SetLayerWindow(uint16_t LayerIndex, uint16_t Xpos, uint16_t Ypos, uint16_t Width, uint16_t Height)
00570 {
00571   /* Reconfigure the layer size */
00572   HAL_LTDC_SetWindowSize(&(hltdc_eval), Width, Height, LayerIndex);
00573 
00574   /* Reconfigure the layer position */
00575   HAL_LTDC_SetWindowPosition(&(hltdc_eval), Xpos, Ypos, LayerIndex);
00576 
00577 }
00578 
00579 /**
00580   * @brief  Configures and sets the color keying.
00581   * @param  LayerIndex: Layer foreground or background
00582   * @param  RGBValue: Color reference
00583   */
00584 void BSP_LCD_SetColorKeying(uint32_t LayerIndex, uint32_t RGBValue)
00585 {
00586   /* Configure and Enable the color Keying for LCD Layer */
00587   HAL_LTDC_ConfigColorKeying(&(hltdc_eval), RGBValue, LayerIndex);
00588   HAL_LTDC_EnableColorKeying(&(hltdc_eval), LayerIndex);
00589 }
00590 
00591 /**
00592   * @brief  Disables the color keying.
00593   * @param  LayerIndex: Layer foreground or background
00594   */
00595 void BSP_LCD_ResetColorKeying(uint32_t LayerIndex)
00596 {
00597   /* Disable the color Keying for LCD Layer */
00598   HAL_LTDC_DisableColorKeying(&(hltdc_eval), LayerIndex);
00599 }
00600 
00601 /**
00602   * @brief  Sets the LCD text color.
00603   * @param  Color: Text color code ARGB(8-8-8-8)
00604   */
00605 void BSP_LCD_SetTextColor(uint32_t Color)
00606 {
00607   DrawProp[ActiveLayer].TextColor = Color;
00608 }
00609 
00610 /**
00611   * @brief  Gets the LCD text color.
00612   * @retval Used text color.
00613   */
00614 uint32_t BSP_LCD_GetTextColor(void)
00615 {
00616   return DrawProp[ActiveLayer].TextColor;
00617 }
00618 
00619 /**
00620   * @brief  Sets the LCD background color.
00621   * @param  Color: Layer background color code ARGB(8-8-8-8)
00622   */
00623 void BSP_LCD_SetBackColor(uint32_t Color)
00624 {
00625   DrawProp[ActiveLayer].BackColor = Color;
00626 }
00627 
00628 /**
00629   * @brief  Gets the LCD background color.
00630   * @retval Used background color
00631   */
00632 uint32_t BSP_LCD_GetBackColor(void)
00633 {
00634   return DrawProp[ActiveLayer].BackColor;
00635 }
00636 
00637 /**
00638   * @brief  Sets the LCD text font.
00639   * @param  fonts: Layer font to be used
00640   */
00641 void BSP_LCD_SetFont(sFONT *fonts)
00642 {
00643   DrawProp[ActiveLayer].pFont = fonts;
00644 }
00645 
00646 /**
00647   * @brief  Gets the LCD text font.
00648   * @retval Used layer font
00649   */
00650 sFONT *BSP_LCD_GetFont(void)
00651 {
00652   return DrawProp[ActiveLayer].pFont;
00653 }
00654 
00655 /**
00656   * @brief  Reads an LCD pixel.
00657   * @param  Xpos: X position
00658   * @param  Ypos: Y position
00659   * @retval RGB pixel color
00660   */
00661 uint32_t BSP_LCD_ReadPixel(uint16_t Xpos, uint16_t Ypos)
00662 {
00663   uint32_t ret = 0;
00664 
00665   if(hltdc_eval.LayerCfg[ActiveLayer].PixelFormat == LTDC_PIXEL_FORMAT_ARGB8888)
00666   {
00667     /* Read data value from SDRAM memory */
00668     ret = *(__IO uint32_t*) (hltdc_eval.LayerCfg[ActiveLayer].FBStartAdress + (4*(Ypos*BSP_LCD_GetXSize() + Xpos)));
00669   }
00670   else if(hltdc_eval.LayerCfg[ActiveLayer].PixelFormat == LTDC_PIXEL_FORMAT_RGB888)
00671   {
00672     /* Read data value from SDRAM memory */
00673     ret = (*(__IO uint32_t*) (hltdc_eval.LayerCfg[ActiveLayer].FBStartAdress + (4*(Ypos*BSP_LCD_GetXSize() + Xpos))) & 0x00FFFFFF);
00674   }
00675   else if((hltdc_eval.LayerCfg[ActiveLayer].PixelFormat == LTDC_PIXEL_FORMAT_RGB565) || \
00676           (hltdc_eval.LayerCfg[ActiveLayer].PixelFormat == LTDC_PIXEL_FORMAT_ARGB4444) || \
00677           (hltdc_eval.LayerCfg[ActiveLayer].PixelFormat == LTDC_PIXEL_FORMAT_AL88))
00678   {
00679     /* Read data value from SDRAM memory */
00680     ret = *(__IO uint16_t*) (hltdc_eval.LayerCfg[ActiveLayer].FBStartAdress + (2*(Ypos*BSP_LCD_GetXSize() + Xpos)));
00681   }
00682   else
00683   {
00684     /* Read data value from SDRAM memory */
00685     ret = *(__IO uint8_t*) (hltdc_eval.LayerCfg[ActiveLayer].FBStartAdress + (2*(Ypos*BSP_LCD_GetXSize() + Xpos)));
00686   }
00687 
00688   return ret;
00689 }
00690 
00691 /**
00692   * @brief  Clears the whole currently active layer of LTDC.
00693   * @param  Color: Color of the background
00694   */
00695 void BSP_LCD_Clear(uint32_t Color)
00696 {
00697   /* Clear the LCD */
00698   LL_FillBuffer(ActiveLayer, (uint32_t *)(hltdc_eval.LayerCfg[ActiveLayer].FBStartAdress), BSP_LCD_GetXSize(), BSP_LCD_GetYSize(), 0, Color);
00699 }
00700 
00701 /**
00702   * @brief  Clears the selected line in currently active layer.
00703   * @param  Line: Line to be cleared
00704   */
00705 void BSP_LCD_ClearStringLine(uint32_t Line)
00706 {
00707   uint32_t color_backup = DrawProp[ActiveLayer].TextColor;
00708   DrawProp[ActiveLayer].TextColor = DrawProp[ActiveLayer].BackColor;
00709 
00710   /* Draw rectangle with background color */
00711   BSP_LCD_FillRect(0, (Line * DrawProp[ActiveLayer].pFont->Height), BSP_LCD_GetXSize(), DrawProp[ActiveLayer].pFont->Height);
00712 
00713   DrawProp[ActiveLayer].TextColor = color_backup;
00714   BSP_LCD_SetTextColor(DrawProp[ActiveLayer].TextColor);
00715 }
00716 
00717 /**
00718   * @brief  Displays one character in currently active layer.
00719   * @param  Xpos: Start column address
00720   * @param  Ypos: Line where to display the character shape.
00721   * @param  Ascii: Character ascii code
00722   *           This parameter must be a number between Min_Data = 0x20 and Max_Data = 0x7E
00723   */
00724 void BSP_LCD_DisplayChar(uint16_t Xpos, uint16_t Ypos, uint8_t Ascii)
00725 {
00726   DrawChar(Xpos, Ypos, &DrawProp[ActiveLayer].pFont->table[(Ascii-' ') *\
00727     DrawProp[ActiveLayer].pFont->Height * ((DrawProp[ActiveLayer].pFont->Width + 7) / 8)]);
00728 }
00729 
00730 /**
00731   * @brief  Displays characters in currently active layer.
00732   * @param  Xpos: X position (in pixel)
00733   * @param  Ypos: Y position (in pixel)
00734   * @param  Text: Pointer to string to display on LCD
00735   * @param  Mode: Display mode
00736   *          This parameter can be one of the following values:
00737   *            @arg  CENTER_MODE
00738   *            @arg  RIGHT_MODE
00739   *            @arg  LEFT_MODE
00740   */
00741 void BSP_LCD_DisplayStringAt(uint16_t Xpos, uint16_t Ypos, uint8_t *Text, Text_AlignModeTypdef Mode)
00742 {
00743   uint16_t refcolumn = 1, i = 0;
00744   uint32_t size = 0, xsize = 0;
00745   uint8_t  *ptr = Text;
00746 
00747   /* Get the text size */
00748   while (*ptr++) size ++ ;
00749 
00750   /* Characters number per line */
00751   xsize = (BSP_LCD_GetXSize()/DrawProp[ActiveLayer].pFont->Width);
00752 
00753   switch (Mode)
00754   {
00755   case CENTER_MODE:
00756     {
00757       refcolumn = Xpos + ((xsize - size)* DrawProp[ActiveLayer].pFont->Width) / 2;
00758       break;
00759     }
00760   case LEFT_MODE:
00761     {
00762       refcolumn = Xpos;
00763       break;
00764     }
00765   case RIGHT_MODE:
00766     {
00767       refcolumn = - Xpos + ((xsize - size)*DrawProp[ActiveLayer].pFont->Width);
00768       break;
00769     }
00770   default:
00771     {
00772       refcolumn = Xpos;
00773       break;
00774     }
00775   }
00776 
00777   /* Check that the Start column is located in the screen */
00778   if ((refcolumn < 1) || (refcolumn >= 0x8000))
00779   {
00780     refcolumn = 1;
00781   }
00782 
00783   /* Send the string character by character on LCD */
00784   while ((*Text != 0) & (((BSP_LCD_GetXSize() - (i*DrawProp[ActiveLayer].pFont->Width)) & 0xFFFF) >= DrawProp[ActiveLayer].pFont->Width))
00785   {
00786     /* Display one character on LCD */
00787     BSP_LCD_DisplayChar(refcolumn, Ypos, *Text);
00788     /* Decrement the column position by 16 */
00789     refcolumn += DrawProp[ActiveLayer].pFont->Width;
00790 
00791     /* Point on the next character */
00792     Text++;
00793     i++;
00794   }
00795 
00796 }
00797 
00798 /**
00799   * @brief  Displays a maximum of 60 characters on the LCD.
00800   * @param  Line: Line where to display the character shape
00801   * @param  ptr: Pointer to string to display on LCD
00802   */
00803 void BSP_LCD_DisplayStringAtLine(uint16_t Line, uint8_t *ptr)
00804 {
00805   BSP_LCD_DisplayStringAt(0, LINE(Line), ptr, LEFT_MODE);
00806 }
00807 
00808 /**
00809   * @brief  Draws an horizontal line in currently active layer.
00810   * @param  Xpos: X position
00811   * @param  Ypos: Y position
00812   * @param  Length: Line length
00813   */
00814 void BSP_LCD_DrawHLine(uint16_t Xpos, uint16_t Ypos, uint16_t Length)
00815 {
00816   uint32_t  Xaddress = 0;
00817 
00818   /* Get the line address */
00819   Xaddress = (hltdc_eval.LayerCfg[ActiveLayer].FBStartAdress) + 4*(BSP_LCD_GetXSize()*Ypos + Xpos);
00820 
00821   /* Write line */
00822   LL_FillBuffer(ActiveLayer, (uint32_t *)Xaddress, Length, 1, 0, DrawProp[ActiveLayer].TextColor);
00823 }
00824 
00825 /**
00826   * @brief  Draws a vertical line in currently active layer.
00827   * @param  Xpos: X position
00828   * @param  Ypos: Y position
00829   * @param  Length: Line length
00830   */
00831 void BSP_LCD_DrawVLine(uint16_t Xpos, uint16_t Ypos, uint16_t Length)
00832 {
00833   uint32_t  Xaddress = 0;
00834 
00835   /* Get the line address */
00836   Xaddress = (hltdc_eval.LayerCfg[ActiveLayer].FBStartAdress) + 4*(BSP_LCD_GetXSize()*Ypos + Xpos);
00837 
00838   /* Write line */
00839   LL_FillBuffer(ActiveLayer, (uint32_t *)Xaddress, 1, Length, (BSP_LCD_GetXSize() - 1), DrawProp[ActiveLayer].TextColor);
00840 }
00841 
00842 /**
00843   * @brief  Draws an uni-line (between two points) in currently active layer.
00844   * @param  x1: Point 1 X position
00845   * @param  y1: Point 1 Y position
00846   * @param  x2: Point 2 X position
00847   * @param  y2: Point 2 Y position
00848   */
00849 void BSP_LCD_DrawLine(uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2)
00850 {
00851   int16_t deltax = 0, deltay = 0, x = 0, y = 0, xinc1 = 0, xinc2 = 0,
00852   yinc1 = 0, yinc2 = 0, den = 0, num = 0, numadd = 0, numpixels = 0,
00853   curpixel = 0;
00854 
00855   deltax = ABS(x2 - x1);        /* The difference between the x's */
00856   deltay = ABS(y2 - y1);        /* The difference between the y's */
00857   x = x1;                       /* Start x off at the first pixel */
00858   y = y1;                       /* Start y off at the first pixel */
00859 
00860   if (x2 >= x1)                 /* The x-values are increasing */
00861   {
00862     xinc1 = 1;
00863     xinc2 = 1;
00864   }
00865   else                          /* The x-values are decreasing */
00866   {
00867     xinc1 = -1;
00868     xinc2 = -1;
00869   }
00870 
00871   if (y2 >= y1)                 /* The y-values are increasing */
00872   {
00873     yinc1 = 1;
00874     yinc2 = 1;
00875   }
00876   else                          /* The y-values are decreasing */
00877   {
00878     yinc1 = -1;
00879     yinc2 = -1;
00880   }
00881 
00882   if (deltax >= deltay)         /* There is at least one x-value for every y-value */
00883   {
00884     xinc1 = 0;                  /* Don't change the x when numerator >= denominator */
00885     yinc2 = 0;                  /* Don't change the y for every iteration */
00886     den = deltax;
00887     num = deltax / 2;
00888     numadd = deltay;
00889     numpixels = deltax;         /* There are more x-values than y-values */
00890   }
00891   else                          /* There is at least one y-value for every x-value */
00892   {
00893     xinc2 = 0;                  /* Don't change the x for every iteration */
00894     yinc1 = 0;                  /* Don't change the y when numerator >= denominator */
00895     den = deltay;
00896     num = deltay / 2;
00897     numadd = deltax;
00898     numpixels = deltay;         /* There are more y-values than x-values */
00899   }
00900 
00901   for (curpixel = 0; curpixel <= numpixels; curpixel++)
00902   {
00903     BSP_LCD_DrawPixel(x, y, DrawProp[ActiveLayer].TextColor);   /* Draw the current pixel */
00904     num += numadd;                            /* Increase the numerator by the top of the fraction */
00905     if (num >= den)                           /* Check if numerator >= denominator */
00906     {
00907       num -= den;                             /* Calculate the new numerator value */
00908       x += xinc1;                             /* Change the x as appropriate */
00909       y += yinc1;                             /* Change the y as appropriate */
00910     }
00911     x += xinc2;                               /* Change the x as appropriate */
00912     y += yinc2;                               /* Change the y as appropriate */
00913   }
00914 }
00915 
00916 /**
00917   * @brief  Draws a rectangle in currently active layer.
00918   * @param  Xpos: X position
00919   * @param  Ypos: Y position
00920   * @param  Width: Rectangle width
00921   * @param  Height: Rectangle height
00922   */
00923 void BSP_LCD_DrawRect(uint16_t Xpos, uint16_t Ypos, uint16_t Width, uint16_t Height)
00924 {
00925   /* Draw horizontal lines */
00926   BSP_LCD_DrawHLine(Xpos, Ypos, Width);
00927   BSP_LCD_DrawHLine(Xpos, (Ypos+ Height), Width);
00928 
00929   /* Draw vertical lines */
00930   BSP_LCD_DrawVLine(Xpos, Ypos, Height);
00931   BSP_LCD_DrawVLine((Xpos + Width), Ypos, Height);
00932 }
00933 
00934 /**
00935   * @brief  Draws a circle in currently active layer.
00936   * @param  Xpos: X position
00937   * @param  Ypos: Y position
00938   * @param  Radius: Circle radius
00939   */
00940 void BSP_LCD_DrawCircle(uint16_t Xpos, uint16_t Ypos, uint16_t Radius)
00941 {
00942   int32_t   D;    /* Decision Variable */
00943   uint32_t  CurX; /* Current X Value */
00944   uint32_t  CurY; /* Current Y Value */
00945 
00946   D = 3 - (Radius << 1);
00947   CurX = 0;
00948   CurY = Radius;
00949 
00950   while (CurX <= CurY)
00951   {
00952     BSP_LCD_DrawPixel((Xpos + CurX), (Ypos - CurY), DrawProp[ActiveLayer].TextColor);
00953 
00954     BSP_LCD_DrawPixel((Xpos - CurX), (Ypos - CurY), DrawProp[ActiveLayer].TextColor);
00955 
00956     BSP_LCD_DrawPixel((Xpos + CurY), (Ypos - CurX), DrawProp[ActiveLayer].TextColor);
00957 
00958     BSP_LCD_DrawPixel((Xpos - CurY), (Ypos - CurX), DrawProp[ActiveLayer].TextColor);
00959 
00960     BSP_LCD_DrawPixel((Xpos + CurX), (Ypos + CurY), DrawProp[ActiveLayer].TextColor);
00961 
00962     BSP_LCD_DrawPixel((Xpos - CurX), (Ypos + CurY), DrawProp[ActiveLayer].TextColor);
00963 
00964     BSP_LCD_DrawPixel((Xpos + CurY), (Ypos + CurX), DrawProp[ActiveLayer].TextColor);
00965 
00966     BSP_LCD_DrawPixel((Xpos - CurY), (Ypos + CurX), DrawProp[ActiveLayer].TextColor);
00967 
00968     if (D < 0)
00969     {
00970       D += (CurX << 2) + 6;
00971     }
00972     else
00973     {
00974       D += ((CurX - CurY) << 2) + 10;
00975       CurY--;
00976     }
00977     CurX++;
00978   }
00979 }
00980 
00981 /**
00982   * @brief  Draws an poly-line (between many points) in currently active layer.
00983   * @param  Points: Pointer to the points array
00984   * @param  PointCount: Number of points
00985   */
00986 void BSP_LCD_DrawPolygon(pPoint Points, uint16_t PointCount)
00987 {
00988   int16_t X = 0, Y = 0;
00989 
00990   if(PointCount < 2)
00991   {
00992     return;
00993   }
00994 
00995   BSP_LCD_DrawLine(Points->X, Points->Y, (Points+PointCount-1)->X, (Points+PointCount-1)->Y);
00996 
00997   while(--PointCount)
00998   {
00999     X = Points->X;
01000     Y = Points->Y;
01001     Points++;
01002     BSP_LCD_DrawLine(X, Y, Points->X, Points->Y);
01003   }
01004 }
01005 
01006 /**
01007   * @brief  Draws an ellipse on LCD in currently active layer.
01008   * @param  Xpos: X position
01009   * @param  Ypos: Y position
01010   * @param  XRadius: Ellipse X radius
01011   * @param  YRadius: Ellipse Y radius
01012   */
01013 void BSP_LCD_DrawEllipse(int Xpos, int Ypos, int XRadius, int YRadius)
01014 {
01015   int x = 0, y = -YRadius, err = 2-2*XRadius, e2;
01016   float K = 0, rad1 = 0, rad2 = 0;
01017 
01018   rad1 = XRadius;
01019   rad2 = YRadius;
01020 
01021   K = (float)(rad2/rad1);
01022 
01023   do {
01024     BSP_LCD_DrawPixel((Xpos-(uint16_t)(x/K)), (Ypos+y), DrawProp[ActiveLayer].TextColor);
01025     BSP_LCD_DrawPixel((Xpos+(uint16_t)(x/K)), (Ypos+y), DrawProp[ActiveLayer].TextColor);
01026     BSP_LCD_DrawPixel((Xpos+(uint16_t)(x/K)), (Ypos-y), DrawProp[ActiveLayer].TextColor);
01027     BSP_LCD_DrawPixel((Xpos-(uint16_t)(x/K)), (Ypos-y), DrawProp[ActiveLayer].TextColor);
01028 
01029     e2 = err;
01030     if (e2 <= x) {
01031       err += ++x*2+1;
01032       if (-y == x && e2 <= y) e2 = 0;
01033     }
01034     if (e2 > y) err += ++y*2+1;
01035   }
01036   while (y <= 0);
01037 }
01038 
01039 /**
01040   * @brief  Draws a bitmap picture loaded in the internal Flash (32 bpp) in currently active layer.
01041   * @param  Xpos: Bmp X position in the LCD
01042   * @param  Ypos: Bmp Y position in the LCD
01043   * @param  pbmp: Pointer to Bmp picture address in the internal Flash
01044   */
01045 void BSP_LCD_DrawBitmap(uint32_t Xpos, uint32_t Ypos, uint8_t *pbmp)
01046 {
01047   uint32_t index = 0, width = 0, height = 0, bit_pixel = 0;
01048   uint32_t Address;
01049   uint32_t InputColorMode = 0;
01050 
01051   /* Get bitmap data address offset */
01052   index = pbmp[10] + (pbmp[11] << 8) + (pbmp[12] << 16)  + (pbmp[13] << 24);
01053 
01054   /* Read bitmap width */
01055   width = pbmp[18] + (pbmp[19] << 8) + (pbmp[20] << 16)  + (pbmp[21] << 24);
01056 
01057   /* Read bitmap height */
01058   height = pbmp[22] + (pbmp[23] << 8) + (pbmp[24] << 16)  + (pbmp[25] << 24);
01059 
01060   /* Read bit/pixel */
01061   bit_pixel = pbmp[28] + (pbmp[29] << 8);
01062 
01063   /* Set the address */
01064   Address = hltdc_eval.LayerCfg[ActiveLayer].FBStartAdress + (((BSP_LCD_GetXSize()*Ypos) + Xpos)*(4));
01065 
01066   /* Get the layer pixel format */
01067   if ((bit_pixel/8) == 4)
01068   {
01069     InputColorMode = CM_ARGB8888;
01070   }
01071   else if ((bit_pixel/8) == 2)
01072   {
01073     InputColorMode = CM_RGB565;
01074   }
01075   else
01076   {
01077     InputColorMode = CM_RGB888;
01078   }
01079 
01080   /* Bypass the bitmap header */
01081   pbmp += (index + (width * (height - 1) * (bit_pixel/8)));
01082 
01083   /* Convert picture to ARGB8888 pixel format */
01084   for(index=0; index < height; index++)
01085   {
01086     /* Pixel format conversion */
01087     LL_ConvertLineToARGB8888((uint32_t *)pbmp, (uint32_t *)Address, width, InputColorMode);
01088 
01089     /* Increment the source and destination buffers */
01090     Address+=  (BSP_LCD_GetXSize()*4);
01091     pbmp -= width*(bit_pixel/8);
01092   }
01093 }
01094 
01095 /**
01096   * @brief  Draws a full rectangle in currently active layer.
01097   * @param  Xpos: X position
01098   * @param  Ypos: Y position
01099   * @param  Width: Rectangle width
01100   * @param  Height: Rectangle height
01101   */
01102 void BSP_LCD_FillRect(uint16_t Xpos, uint16_t Ypos, uint16_t Width, uint16_t Height)
01103 {
01104   uint32_t  Xaddress = 0;
01105 
01106   /* Set the text color */
01107   BSP_LCD_SetTextColor(DrawProp[ActiveLayer].TextColor);
01108 
01109   /* Get the rectangle start address */
01110   Xaddress = (hltdc_eval.LayerCfg[ActiveLayer].FBStartAdress) + 4*(BSP_LCD_GetXSize()*Ypos + Xpos);
01111 
01112   /* Fill the rectangle */
01113   LL_FillBuffer(ActiveLayer, (uint32_t *)Xaddress, Width, Height, (BSP_LCD_GetXSize() - Width), DrawProp[ActiveLayer].TextColor);
01114 }
01115 
01116 /**
01117   * @brief  Draws a full circle in currently active layer.
01118   * @param  Xpos: X position
01119   * @param  Ypos: Y position
01120   * @param  Radius: Circle radius
01121   */
01122 void BSP_LCD_FillCircle(uint16_t Xpos, uint16_t Ypos, uint16_t Radius)
01123 {
01124   int32_t  D;     /* Decision Variable */
01125   uint32_t  CurX; /* Current X Value */
01126   uint32_t  CurY; /* Current Y Value */
01127 
01128   D = 3 - (Radius << 1);
01129 
01130   CurX = 0;
01131   CurY = Radius;
01132 
01133   BSP_LCD_SetTextColor(DrawProp[ActiveLayer].TextColor);
01134 
01135   while (CurX <= CurY)
01136   {
01137     if(CurY > 0)
01138     {
01139       BSP_LCD_DrawHLine(Xpos - CurY, Ypos + CurX, 2*CurY);
01140       BSP_LCD_DrawHLine(Xpos - CurY, Ypos - CurX, 2*CurY);
01141     }
01142 
01143     if(CurX > 0)
01144     {
01145       BSP_LCD_DrawHLine(Xpos - CurX, Ypos - CurY, 2*CurX);
01146       BSP_LCD_DrawHLine(Xpos - CurX, Ypos + CurY, 2*CurX);
01147     }
01148     if (D < 0)
01149     {
01150       D += (CurX << 2) + 6;
01151     }
01152     else
01153     {
01154       D += ((CurX - CurY) << 2) + 10;
01155       CurY--;
01156     }
01157     CurX++;
01158   }
01159 
01160   BSP_LCD_SetTextColor(DrawProp[ActiveLayer].TextColor);
01161   BSP_LCD_DrawCircle(Xpos, Ypos, Radius);
01162 }
01163 
01164 /**
01165   * @brief  Draws a full poly-line (between many points) in currently active layer.
01166   * @param  Points: Pointer to the points array
01167   * @param  PointCount: Number of points
01168   */
01169 void BSP_LCD_FillPolygon(pPoint Points, uint16_t PointCount)
01170 {
01171   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;
01172   uint16_t  IMAGE_LEFT = 0, IMAGE_RIGHT = 0, IMAGE_TOP = 0, IMAGE_BOTTOM = 0;
01173 
01174   IMAGE_LEFT = IMAGE_RIGHT = Points->X;
01175   IMAGE_TOP= IMAGE_BOTTOM = Points->Y;
01176 
01177   for(counter = 1; counter < PointCount; counter++)
01178   {
01179     pixelX = POLY_X(counter);
01180     if(pixelX < IMAGE_LEFT)
01181     {
01182       IMAGE_LEFT = pixelX;
01183     }
01184     if(pixelX > IMAGE_RIGHT)
01185     {
01186       IMAGE_RIGHT = pixelX;
01187     }
01188 
01189     pixelY = POLY_Y(counter);
01190     if(pixelY < IMAGE_TOP)
01191     {
01192       IMAGE_TOP = pixelY;
01193     }
01194     if(pixelY > IMAGE_BOTTOM)
01195     {
01196       IMAGE_BOTTOM = pixelY;
01197     }
01198   }
01199 
01200   if(PointCount < 2)
01201   {
01202     return;
01203   }
01204 
01205   X_center = (IMAGE_LEFT + IMAGE_RIGHT)/2;
01206   Y_center = (IMAGE_BOTTOM + IMAGE_TOP)/2;
01207 
01208   X_first = Points->X;
01209   Y_first = Points->Y;
01210 
01211   while(--PointCount)
01212   {
01213     X = Points->X;
01214     Y = Points->Y;
01215     Points++;
01216     X2 = Points->X;
01217     Y2 = Points->Y;
01218 
01219     FillTriangle(X, X2, X_center, Y, Y2, Y_center);
01220     FillTriangle(X, X_center, X2, Y, Y_center, Y2);
01221     FillTriangle(X_center, X2, X, Y_center, Y2, Y);
01222   }
01223 
01224   FillTriangle(X_first, X2, X_center, Y_first, Y2, Y_center);
01225   FillTriangle(X_first, X_center, X2, Y_first, Y_center, Y2);
01226   FillTriangle(X_center, X2, X_first, Y_center, Y2, Y_first);
01227 }
01228 
01229 /**
01230   * @brief  Draws a full ellipse in currently active layer.
01231   * @param  Xpos: X position
01232   * @param  Ypos: Y position
01233   * @param  XRadius: Ellipse X radius
01234   * @param  YRadius: Ellipse Y radius
01235   */
01236 void BSP_LCD_FillEllipse(int Xpos, int Ypos, int XRadius, int YRadius)
01237 {
01238   int x = 0, y = -YRadius, err = 2-2*XRadius, e2;
01239   float K = 0, rad1 = 0, rad2 = 0;
01240 
01241   rad1 = XRadius;
01242   rad2 = YRadius;
01243 
01244   K = (float)(rad2/rad1);
01245 
01246   do
01247   {
01248     BSP_LCD_DrawHLine((Xpos-(uint16_t)(x/K)), (Ypos+y), (2*(uint16_t)(x/K) + 1));
01249     BSP_LCD_DrawHLine((Xpos-(uint16_t)(x/K)), (Ypos-y), (2*(uint16_t)(x/K) + 1));
01250 
01251     e2 = err;
01252     if (e2 <= x)
01253     {
01254       err += ++x*2+1;
01255       if (-y == x && e2 <= y) e2 = 0;
01256     }
01257     if (e2 > y) err += ++y*2+1;
01258   }
01259   while (y <= 0);
01260 }
01261 
01262 /**
01263   * @brief  Switch back on the display if was switched off by previous call of BSP_LCD_DisplayOff().
01264   *         Exit DSI ULPM mode if was allowed and configured in Dsi Configuration.
01265   */
01266 void BSP_LCD_DisplayOn(void)
01267 {
01268   /* Send Display on DCS command to display */
01269   HAL_DSI_ShortWrite(&(hdsi_eval),
01270                      hdsivideo_handle.VirtualChannelID,
01271                      DSI_DCS_SHORT_PKT_WRITE_P1,
01272                      OTM8009A_CMD_DISPON,
01273                      0x00);
01274 
01275 }
01276 
01277 /**
01278   * @brief  Switch Off the display.
01279   *         Enter DSI ULPM mode if was allowed and configured in Dsi Configuration.
01280   */
01281 void BSP_LCD_DisplayOff(void)
01282 {
01283   /* Send Display off DCS Command to display */
01284   HAL_DSI_ShortWrite(&(hdsi_eval),
01285                      hdsivideo_handle.VirtualChannelID,
01286                      DSI_DCS_SHORT_PKT_WRITE_P1,
01287                      OTM8009A_CMD_DISPOFF,
01288                      0x00);
01289 
01290 }
01291 
01292 /**
01293   * @brief  DCS or Generic short/long write command
01294   * @param  NbrParams: Number of parameters. It indicates the write command mode:
01295   *                 If inferior to 2, a long write command is performed else short.
01296   * @param  pParams: Pointer to parameter values table.
01297   * @retval HAL status
01298   */
01299 void DSI_IO_WriteCmd(uint32_t NbrParams, uint8_t *pParams)
01300 {
01301   if(NbrParams <= 1)
01302   {
01303    HAL_DSI_ShortWrite(&hdsi_eval, LCD_OTM8009A_ID, DSI_DCS_SHORT_PKT_WRITE_P1, pParams[0], pParams[1]);
01304   }
01305   else
01306   {
01307    HAL_DSI_LongWrite(&hdsi_eval,  LCD_OTM8009A_ID, DSI_DCS_LONG_PKT_WRITE, NbrParams, pParams[NbrParams], pParams);
01308   }
01309 }
01310 
01311 /*******************************************************************************
01312                        LTDC, DMA2D and DSI BSP Routines
01313 *******************************************************************************/
01314 /**
01315   * @brief  Handles DMA2D interrupt request.
01316   * @note : Can be surcharged by application code implementation of the function.
01317   */
01318 __weak void BSP_LCD_DMA2D_IRQHandler(void)
01319 {
01320   HAL_DMA2D_IRQHandler(&hdma2d_eval);
01321 }
01322 
01323 /**
01324   * @brief  Handles DSI interrupt request.
01325   * @note : Can be surcharged by application code implementation of the function.
01326   */
01327 __weak void BSP_LCD_DSI_IRQHandler(void)
01328 {
01329   HAL_DSI_IRQHandler(&(hdsi_eval));
01330 }
01331 
01332 
01333 /**
01334   * @brief  Handles LTDC interrupt request.
01335   * @note : Can be surcharged by application code implementation of the function.
01336   */
01337 __weak void BSP_LCD_LTDC_IRQHandler(void)
01338 {
01339   HAL_LTDC_IRQHandler(&(hltdc_eval));
01340 }
01341 
01342 /**
01343   * @brief  De-Initializes the BSP LCD Msp
01344   * Application can surcharge if needed this function implementation.
01345   */
01346 __weak void BSP_LCD_MspDeInit(void)
01347 {
01348   /** @brief Disable IRQ of LTDC IP */
01349   HAL_NVIC_DisableIRQ(LTDC_IRQn);
01350 
01351   /** @brief Disable IRQ of DMA2D IP */
01352   HAL_NVIC_DisableIRQ(DMA2D_IRQn);
01353 
01354   /** @brief Disable IRQ of DSI IP */
01355   HAL_NVIC_DisableIRQ(DSI_IRQn);
01356 
01357   /** @brief Force and let in reset state LTDC, DMA2D and DSI Host + Wrapper IPs */
01358   __HAL_RCC_LTDC_FORCE_RESET();
01359   __HAL_RCC_DMA2D_FORCE_RESET();
01360   __HAL_RCC_DSI_FORCE_RESET();
01361 
01362   /** @brief Disable the LTDC, DMA2D and DSI Host and Wrapper clocks */
01363   __HAL_RCC_LTDC_CLK_DISABLE();
01364   __HAL_RCC_DMA2D_CLK_DISABLE();
01365   __HAL_RCC_DSI_CLK_DISABLE();
01366 }
01367 
01368 /**
01369   * @brief  Initialize the BSP LCD Msp.
01370   * Application can surcharge if needed this function implementation
01371   */
01372 __weak void BSP_LCD_MspInit(void)
01373 {
01374   /** @brief Enable the LTDC clock */
01375   __HAL_RCC_LTDC_CLK_ENABLE();
01376 
01377   /** @brief Toggle Sw reset of LTDC IP */
01378   __HAL_RCC_LTDC_FORCE_RESET();
01379   __HAL_RCC_LTDC_RELEASE_RESET();
01380 
01381   /** @brief Enable the DMA2D clock */
01382   __HAL_RCC_DMA2D_CLK_ENABLE();
01383 
01384   /** @brief Toggle Sw reset of DMA2D IP */
01385   __HAL_RCC_DMA2D_FORCE_RESET();
01386   __HAL_RCC_DMA2D_RELEASE_RESET();
01387 
01388   /** @brief Enable DSI Host and wrapper clocks */
01389   __HAL_RCC_DSI_CLK_ENABLE();
01390 
01391   /** @brief Soft Reset the DSI Host and wrapper */
01392   __HAL_RCC_DSI_FORCE_RESET();
01393   __HAL_RCC_DSI_RELEASE_RESET();
01394 
01395   /** @brief NVIC configuration for LTDC interrupt that is now enabled */
01396   HAL_NVIC_SetPriority(LTDC_IRQn, 3, 0);
01397   HAL_NVIC_EnableIRQ(LTDC_IRQn);
01398 
01399   /** @brief NVIC configuration for DMA2D interrupt that is now enabled */
01400   HAL_NVIC_SetPriority(DMA2D_IRQn, 3, 0);
01401   HAL_NVIC_EnableIRQ(DMA2D_IRQn);
01402 
01403   /** @brief NVIC configuration for DSI interrupt that is now enabled */
01404   HAL_NVIC_SetPriority(DSI_IRQn, 3, 0);
01405   HAL_NVIC_EnableIRQ(DSI_IRQn);
01406 }
01407 
01408 /**
01409   * @brief  This function handles LTDC Error interrupt Handler.
01410   * @note : Can be surcharged by application code implementation of the function.
01411   */
01412 
01413 __weak void BSP_LCD_LTDC_ER_IRQHandler(void)
01414 {
01415   HAL_LTDC_IRQHandler(&(hltdc_eval));
01416 }
01417 
01418 
01419 /**
01420   * @brief  Draws a pixel on LCD.
01421   * @param  Xpos: X position
01422   * @param  Ypos: Y position
01423   * @param  RGB_Code: Pixel color in ARGB mode (8-8-8-8)
01424   */
01425 void BSP_LCD_DrawPixel(uint16_t Xpos, uint16_t Ypos, uint32_t RGB_Code)
01426 {
01427   /* Write data value to all SDRAM memory */
01428   *(__IO uint32_t*) (hltdc_eval.LayerCfg[ActiveLayer].FBStartAdress + (4*(Ypos*BSP_LCD_GetXSize() + Xpos))) = RGB_Code;
01429 }
01430 
01431 
01432 /**
01433   * @brief  Draws a character on LCD.
01434   * @param  Xpos: Line where to display the character shape
01435   * @param  Ypos: Start column address
01436   * @param  c: Pointer to the character data
01437   */
01438 static void DrawChar(uint16_t Xpos, uint16_t Ypos, const uint8_t *c)
01439 {
01440   uint32_t i = 0, j = 0;
01441   uint16_t height, width;
01442   uint8_t  offset;
01443   uint8_t  *pchar;
01444   uint32_t line;
01445 
01446   height = DrawProp[ActiveLayer].pFont->Height;
01447   width  = DrawProp[ActiveLayer].pFont->Width;
01448 
01449   offset =  8 *((width + 7)/8) -  width ;
01450 
01451   for(i = 0; i < height; i++)
01452   {
01453     pchar = ((uint8_t *)c + (width + 7)/8 * i);
01454 
01455     switch(((width + 7)/8))
01456     {
01457 
01458     case 1:
01459       line =  pchar[0];
01460       break;
01461 
01462     case 2:
01463       line =  (pchar[0]<< 8) | pchar[1];
01464       break;
01465 
01466     case 3:
01467     default:
01468       line =  (pchar[0]<< 16) | (pchar[1]<< 8) | pchar[2];
01469       break;
01470     }
01471 
01472     for (j = 0; j < width; j++)
01473     {
01474       if(line & (1 << (width- j + offset- 1)))
01475       {
01476         BSP_LCD_DrawPixel((Xpos + j), Ypos, DrawProp[ActiveLayer].TextColor);
01477       }
01478       else
01479       {
01480         BSP_LCD_DrawPixel((Xpos + j), Ypos, DrawProp[ActiveLayer].BackColor);
01481       }
01482     }
01483     Ypos++;
01484   }
01485 }
01486 
01487 /**
01488   * @brief  Fills a triangle (between 3 points).
01489   * @param  x1: Point 1 X position
01490   * @param  y1: Point 1 Y position
01491   * @param  x2: Point 2 X position
01492   * @param  y2: Point 2 Y position
01493   * @param  x3: Point 3 X position
01494   * @param  y3: Point 3 Y position
01495   */
01496 static void FillTriangle(uint16_t x1, uint16_t x2, uint16_t x3, uint16_t y1, uint16_t y2, uint16_t y3)
01497 {
01498   int16_t deltax = 0, deltay = 0, x = 0, y = 0, xinc1 = 0, xinc2 = 0,
01499   yinc1 = 0, yinc2 = 0, den = 0, num = 0, numadd = 0, numpixels = 0,
01500   curpixel = 0;
01501 
01502   deltax = ABS(x2 - x1);        /* The difference between the x's */
01503   deltay = ABS(y2 - y1);        /* The difference between the y's */
01504   x = x1;                       /* Start x off at the first pixel */
01505   y = y1;                       /* Start y off at the first pixel */
01506 
01507   if (x2 >= x1)                 /* The x-values are increasing */
01508   {
01509     xinc1 = 1;
01510     xinc2 = 1;
01511   }
01512   else                          /* The x-values are decreasing */
01513   {
01514     xinc1 = -1;
01515     xinc2 = -1;
01516   }
01517 
01518   if (y2 >= y1)                 /* The y-values are increasing */
01519   {
01520     yinc1 = 1;
01521     yinc2 = 1;
01522   }
01523   else                          /* The y-values are decreasing */
01524   {
01525     yinc1 = -1;
01526     yinc2 = -1;
01527   }
01528 
01529   if (deltax >= deltay)         /* There is at least one x-value for every y-value */
01530   {
01531     xinc1 = 0;                  /* Don't change the x when numerator >= denominator */
01532     yinc2 = 0;                  /* Don't change the y for every iteration */
01533     den = deltax;
01534     num = deltax / 2;
01535     numadd = deltay;
01536     numpixels = deltax;         /* There are more x-values than y-values */
01537   }
01538   else                          /* There is at least one y-value for every x-value */
01539   {
01540     xinc2 = 0;                  /* Don't change the x for every iteration */
01541     yinc1 = 0;                  /* Don't change the y when numerator >= denominator */
01542     den = deltay;
01543     num = deltay / 2;
01544     numadd = deltax;
01545     numpixels = deltay;         /* There are more y-values than x-values */
01546   }
01547 
01548   for (curpixel = 0; curpixel <= numpixels; curpixel++)
01549   {
01550     BSP_LCD_DrawLine(x, y, x3, y3);
01551 
01552     num += numadd;              /* Increase the numerator by the top of the fraction */
01553     if (num >= den)             /* Check if numerator >= denominator */
01554     {
01555       num -= den;               /* Calculate the new numerator value */
01556       x += xinc1;               /* Change the x as appropriate */
01557       y += yinc1;               /* Change the y as appropriate */
01558     }
01559     x += xinc2;                 /* Change the x as appropriate */
01560     y += yinc2;                 /* Change the y as appropriate */
01561   }
01562 }
01563 
01564 /**
01565   * @brief  Fills a buffer.
01566   * @param  LayerIndex: Layer index
01567   * @param  pDst: Pointer to destination buffer
01568   * @param  xSize: Buffer width
01569   * @param  ySize: Buffer height
01570   * @param  OffLine: Offset
01571   * @param  ColorIndex: Color index
01572   */
01573 static void LL_FillBuffer(uint32_t LayerIndex, void *pDst, uint32_t xSize, uint32_t ySize, uint32_t OffLine, uint32_t ColorIndex)
01574 {
01575   /* Register to memory mode with ARGB8888 as color Mode */
01576   hdma2d_eval.Init.Mode         = DMA2D_R2M;
01577   hdma2d_eval.Init.ColorMode    = DMA2D_ARGB8888;
01578   hdma2d_eval.Init.OutputOffset = OffLine;
01579 
01580   hdma2d_eval.Instance = DMA2D;
01581 
01582   /* DMA2D Initialization */
01583   if(HAL_DMA2D_Init(&hdma2d_eval) == HAL_OK)
01584   {
01585     if(HAL_DMA2D_ConfigLayer(&hdma2d_eval, LayerIndex) == HAL_OK)
01586     {
01587       if (HAL_DMA2D_Start(&hdma2d_eval, ColorIndex, (uint32_t)pDst, xSize, ySize) == HAL_OK)
01588       {
01589         /* Polling For DMA transfer */
01590         HAL_DMA2D_PollForTransfer(&hdma2d_eval, 10);
01591       }
01592     }
01593   }
01594 }
01595 
01596 /**
01597   * @brief  Converts a line to an ARGB8888 pixel format.
01598   * @param  pSrc: Pointer to source buffer
01599   * @param  pDst: Output color
01600   * @param  xSize: Buffer width
01601   * @param  ColorMode: Input color mode
01602   */
01603 static void LL_ConvertLineToARGB8888(void *pSrc, void *pDst, uint32_t xSize, uint32_t ColorMode)
01604 {
01605   /* Configure the DMA2D Mode, Color Mode and output offset */
01606   hdma2d_eval.Init.Mode         = DMA2D_M2M_PFC;
01607   hdma2d_eval.Init.ColorMode    = DMA2D_ARGB8888;
01608   hdma2d_eval.Init.OutputOffset = 0;
01609 
01610   /* Foreground Configuration */
01611   hdma2d_eval.LayerCfg[1].AlphaMode = DMA2D_NO_MODIF_ALPHA;
01612   hdma2d_eval.LayerCfg[1].InputAlpha = 0xFF;
01613   hdma2d_eval.LayerCfg[1].InputColorMode = ColorMode;
01614   hdma2d_eval.LayerCfg[1].InputOffset = 0;
01615 
01616   hdma2d_eval.Instance = DMA2D;
01617 
01618   /* DMA2D Initialization */
01619   if(HAL_DMA2D_Init(&hdma2d_eval) == HAL_OK)
01620   {
01621     if(HAL_DMA2D_ConfigLayer(&hdma2d_eval, 1) == HAL_OK)
01622     {
01623       if (HAL_DMA2D_Start(&hdma2d_eval, (uint32_t)pSrc, (uint32_t)pDst, xSize, 1) == HAL_OK)
01624       {
01625         /* Polling For DMA transfer */
01626         HAL_DMA2D_PollForTransfer(&hdma2d_eval, 10);
01627       }
01628     }
01629   }
01630 }
01631 
01632 /**
01633   * @}
01634   */
01635 
01636 /**
01637   * @}
01638   */
01639 
01640 /**
01641   * @}
01642   */
01643 
01644 /**
01645   * @}
01646   */
01647 
01648 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/