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