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