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