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