STM32F723E-Discovery BSP User Manual
|
stm32f723e_discovery_lcd.c
Go to the documentation of this file.
00001 /** 00002 ****************************************************************************** 00003 * @file stm32f723e_discovery_lcd.c 00004 * @author MCD Application Team 00005 * @version V1.0.0 00006 * @date 30-December-2016 00007 * @brief This file includes the driver for Liquid Crystal Display (LCD) module 00008 * mounted on STM32F723E-DISCOVERY board. 00009 ****************************************************************************** 00010 * @attention 00011 * 00012 * <h2><center>© COPYRIGHT(c) 2016 STMicroelectronics</center></h2> 00013 * 00014 * Redistribution and use in source and binary forms, with or without modification, 00015 * are permitted provided that the following conditions are met: 00016 * 1. Redistributions of source code must retain the above copyright notice, 00017 * this list of conditions and the following disclaimer. 00018 * 2. Redistributions in binary form must reproduce the above copyright notice, 00019 * this list of conditions and the following disclaimer in the documentation 00020 * and/or other materials provided with the distribution. 00021 * 3. Neither the name of STMicroelectronics nor the names of its contributors 00022 * may be used to endorse or promote products derived from this software 00023 * without specific prior written permission. 00024 * 00025 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 00026 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 00027 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 00028 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 00029 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 00030 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 00031 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 00032 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 00033 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 00034 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00035 * 00036 ****************************************************************************** 00037 */ 00038 00039 /* File Info : ----------------------------------------------------------------- 00040 User NOTES 00041 1. How To use this driver: 00042 -------------------------- 00043 - This driver is used to drive indirectly an LCD TFT. 00044 - This driver supports the ST7789H2 LCD. 00045 - The ST7789H2 component driver MUST be included with this driver. 00046 00047 2. Driver description: 00048 --------------------- 00049 + Initialization steps: 00050 o Initialize the LCD using the BSP_LCD_Init() function. 00051 00052 + Display on LCD 00053 o Clear the hole LCD using BSP_LCD_Clear() function or only one specified string 00054 line using the BSP_LCD_ClearStringLine() function. 00055 o Display a character on the specified line and column using the BSP_LCD_DisplayChar() 00056 function or a complete string line using the BSP_LCD_DisplayStringAtLine() function. 00057 o Display a string line on the specified position (x,y in pixel) and align mode 00058 using the BSP_LCD_DisplayStringAtLine() function. 00059 o Draw and fill a basic shapes (dot, line, rectangle, circle, ellipse, .. bitmap) 00060 on LCD using the available set of functions. 00061 00062 ------------------------------------------------------------------------------*/ 00063 00064 /* Includes ------------------------------------------------------------------*/ 00065 #include "stm32f723e_discovery_lcd.h" 00066 #include "../../../Utilities/Fonts/fonts.h" 00067 #include "../../../Utilities/Fonts/font24.c" 00068 #include "../../../Utilities/Fonts/font20.c" 00069 #include "../../../Utilities/Fonts/font16.c" 00070 #include "../../../Utilities/Fonts/font12.c" 00071 #include "../../../Utilities/Fonts/font8.c" 00072 00073 /** @addtogroup BSP 00074 * @{ 00075 */ 00076 00077 /** @addtogroup STM32F723E_DISCOVERY 00078 * @{ 00079 */ 00080 00081 /** @defgroup STM32F723E_DISCOVERY_LCD STM32F723E-DISCOVERY LCD 00082 * @{ 00083 */ 00084 00085 /** @defgroup STM32F723E_DISCOVERY_LCD_Private_TypesDefinitions STM32F723E Discovery Lcd Private TypesDef 00086 * @{ 00087 */ 00088 /** 00089 * @} 00090 */ 00091 00092 /** @defgroup STM32F723E_DISCOVERY_LCD_Private_Defines STM32F723E Discovery Lcd Private Defines 00093 * @{ 00094 */ 00095 #define POLY_X(Z) ((int32_t)((Points + Z)->X)) 00096 #define POLY_Y(Z) ((int32_t)((Points + Z)->Y)) 00097 /** 00098 * @} 00099 */ 00100 00101 /** @defgroup STM32F723E_DISCOVERY_LCD_Private_Macros STM32F723E Discovery Lcd Private Macros 00102 * @{ 00103 */ 00104 #define ABS(X) ((X) > 0 ? (X) : -(X)) 00105 /** 00106 * @} 00107 */ 00108 00109 /** @defgroup STM32F723E_DISCOVERY_LCD_Private_Variables STM32F723E Discovery Lcd Private Variables 00110 * @{ 00111 */ 00112 LCD_DrawPropTypeDef DrawProp; 00113 static LCD_DrvTypeDef *LcdDrv; 00114 00115 /** 00116 * @} 00117 */ 00118 00119 /** @defgroup STM32F723E_DISCOVERY_LCD_Private_FunctionPrototypes STM32F723E Discovery Lcd Private Prototypes 00120 * @{ 00121 */ 00122 static void DrawChar(uint16_t Xpos, uint16_t Ypos, const uint8_t *c); 00123 static void SetDisplayWindow(uint16_t Xpos, uint16_t Ypos, uint16_t Width, uint16_t Height); 00124 static void FillTriangle(uint16_t x1, uint16_t x2, uint16_t x3, uint16_t y1, uint16_t y2, uint16_t y3); 00125 /** 00126 * @} 00127 */ 00128 00129 /** @defgroup STM32F723E_DISCOVERY_LCD_Private_Functions STM32F723E Discovery Lcd Private Functions 00130 * @{ 00131 */ 00132 /** 00133 * @brief Initializes the LCD. 00134 * @retval LCD state 00135 */ 00136 uint8_t BSP_LCD_Init(void) 00137 { 00138 return (BSP_LCD_InitEx(LCD_ORIENTATION_LANDSCAPE)); 00139 } 00140 /** 00141 * @brief Initializes the LCD with a given orientation. 00142 * @param orientation: LCD_ORIENTATION_PORTRAIT or LCD_ORIENTATION_LANDSCAPE 00143 * @retval LCD state 00144 */ 00145 uint8_t BSP_LCD_InitEx(uint32_t orientation) 00146 { 00147 uint8_t ret = LCD_ERROR; 00148 00149 /* Default value for draw propriety */ 00150 DrawProp.BackColor = 0xFFFF; 00151 DrawProp.pFont = &Font24; 00152 DrawProp.TextColor = 0x0000; 00153 00154 /* Initialize LCD special pins GPIOs */ 00155 BSP_LCD_MspInit(); 00156 00157 /* Backlight control signal assertion */ 00158 HAL_GPIO_WritePin(LCD_BL_CTRL_GPIO_PORT, LCD_BL_CTRL_PIN, GPIO_PIN_SET); 00159 00160 /* Apply hardware reset according to procedure indicated in FRD154BP2901 documentation */ 00161 HAL_GPIO_WritePin(LCD_RESET_GPIO_PORT, LCD_RESET_PIN, GPIO_PIN_RESET); 00162 HAL_Delay(5); /* Reset signal asserted during 5ms */ 00163 HAL_GPIO_WritePin(LCD_RESET_GPIO_PORT, LCD_RESET_PIN, GPIO_PIN_SET); 00164 HAL_Delay(10); /* Reset signal released during 10ms */ 00165 HAL_GPIO_WritePin(LCD_RESET_GPIO_PORT, LCD_RESET_PIN, GPIO_PIN_RESET); 00166 HAL_Delay(20); /* Reset signal asserted during 20ms */ 00167 HAL_GPIO_WritePin(LCD_RESET_GPIO_PORT, LCD_RESET_PIN, GPIO_PIN_SET); 00168 HAL_Delay(10); /* Reset signal released during 10ms */ 00169 00170 if(ST7789H2_drv.ReadID() == ST7789H2_ID) 00171 { 00172 LcdDrv = &ST7789H2_drv; 00173 00174 /* LCD Init */ 00175 LcdDrv->Init(); 00176 00177 if(orientation == LCD_ORIENTATION_PORTRAIT) 00178 { 00179 ST7789H2_SetOrientation(LCD_ORIENTATION_PORTRAIT); 00180 } 00181 else if(orientation == LCD_ORIENTATION_LANDSCAPE_ROT180) 00182 { 00183 ST7789H2_SetOrientation(LCD_ORIENTATION_LANDSCAPE_ROT180); 00184 } 00185 else 00186 { 00187 /* Default landscape orientation is selected */ 00188 } 00189 /* Initialize the font */ 00190 BSP_LCD_SetFont(&LCD_DEFAULT_FONT); 00191 00192 ret = LCD_OK; 00193 } 00194 00195 return ret; 00196 } 00197 00198 /** 00199 * @brief DeInitializes the LCD. 00200 * @retval LCD state 00201 */ 00202 uint8_t BSP_LCD_DeInit(void) 00203 { 00204 /* Actually LcdDrv does not provide a DeInit function */ 00205 return LCD_OK; 00206 } 00207 00208 /** 00209 * @brief Gets the LCD X size. 00210 * @retval Used LCD X size 00211 */ 00212 uint32_t BSP_LCD_GetXSize(void) 00213 { 00214 return(LcdDrv->GetLcdPixelWidth()); 00215 } 00216 00217 /** 00218 * @brief Gets the LCD Y size. 00219 * @retval Used LCD Y size 00220 */ 00221 uint32_t BSP_LCD_GetYSize(void) 00222 { 00223 return(LcdDrv->GetLcdPixelHeight()); 00224 } 00225 00226 /** 00227 * @brief Gets the LCD text color. 00228 * @retval Used text color. 00229 */ 00230 uint16_t BSP_LCD_GetTextColor(void) 00231 { 00232 return DrawProp.TextColor; 00233 } 00234 00235 /** 00236 * @brief Gets the LCD background color. 00237 * @retval Used background color 00238 */ 00239 uint16_t BSP_LCD_GetBackColor(void) 00240 { 00241 return DrawProp.BackColor; 00242 } 00243 00244 /** 00245 * @brief Sets the LCD text color. 00246 * @param Color: Text color code RGB(5-6-5) 00247 * @retval None 00248 */ 00249 void BSP_LCD_SetTextColor(uint16_t Color) 00250 { 00251 DrawProp.TextColor = Color; 00252 } 00253 00254 /** 00255 * @brief Sets the LCD background color. 00256 * @param Color: Background color code RGB(5-6-5) 00257 * @retval None 00258 */ 00259 void BSP_LCD_SetBackColor(uint16_t Color) 00260 { 00261 DrawProp.BackColor = Color; 00262 } 00263 00264 /** 00265 * @brief Sets the LCD text font. 00266 * @param fonts: Font to be used 00267 * @retval None 00268 */ 00269 void BSP_LCD_SetFont(sFONT *fonts) 00270 { 00271 DrawProp.pFont = fonts; 00272 } 00273 00274 /** 00275 * @brief Gets the LCD text font. 00276 * @retval Used font 00277 */ 00278 sFONT *BSP_LCD_GetFont(void) 00279 { 00280 return DrawProp.pFont; 00281 } 00282 00283 /** 00284 * @brief Clears the hole LCD. 00285 * @param Color: Color of the background 00286 * @retval None 00287 */ 00288 void BSP_LCD_Clear(uint16_t Color) 00289 { 00290 uint32_t counter = 0; 00291 uint32_t y_size = 0; 00292 uint32_t color_backup = DrawProp.TextColor; 00293 00294 DrawProp.TextColor = Color; 00295 y_size = BSP_LCD_GetYSize(); 00296 00297 for(counter = 0; counter < y_size; counter++) 00298 { 00299 BSP_LCD_DrawHLine(0, counter, BSP_LCD_GetXSize()); 00300 } 00301 DrawProp.TextColor = color_backup; 00302 BSP_LCD_SetTextColor(DrawProp.TextColor); 00303 } 00304 00305 /** 00306 * @brief Clears the selected line. 00307 * @param Line: Line to be cleared 00308 * This parameter can be one of the following values: 00309 * @arg 0..9: if the Current fonts is Font16x24 00310 * @arg 0..19: if the Current fonts is Font12x12 or Font8x12 00311 * @arg 0..29: if the Current fonts is Font8x8 00312 * @retval None 00313 */ 00314 void BSP_LCD_ClearStringLine(uint16_t Line) 00315 { 00316 uint32_t color_backup = DrawProp.TextColor; 00317 00318 DrawProp.TextColor = DrawProp.BackColor; 00319 00320 /* Draw a rectangle with background color */ 00321 BSP_LCD_FillRect(0, (Line * DrawProp.pFont->Height), BSP_LCD_GetXSize(), DrawProp.pFont->Height); 00322 00323 DrawProp.TextColor = color_backup; 00324 BSP_LCD_SetTextColor(DrawProp.TextColor); 00325 } 00326 00327 /** 00328 * @brief Displays one character. 00329 * @param Xpos: Start column address 00330 * @param Ypos: Line where to display the character shape. 00331 * @param Ascii: Character ascii code 00332 * This parameter must be a number between Min_Data = 0x20 and Max_Data = 0x7E 00333 * @retval None 00334 */ 00335 void BSP_LCD_DisplayChar(uint16_t Xpos, uint16_t Ypos, uint8_t Ascii) 00336 { 00337 DrawChar(Xpos, Ypos, &DrawProp.pFont->table[(Ascii-' ') *\ 00338 DrawProp.pFont->Height * ((DrawProp.pFont->Width + 7) / 8)]); 00339 } 00340 00341 /** 00342 * @brief Displays characters on the LCD. 00343 * @param Xpos: X position (in pixel) 00344 * @param Ypos: Y position (in pixel) 00345 * @param Text: Pointer to string to display on LCD 00346 * @param Mode: Display mode 00347 * This parameter can be one of the following values: 00348 * @arg CENTER_MODE 00349 * @arg RIGHT_MODE 00350 * @arg LEFT_MODE 00351 * @retval None 00352 */ 00353 void BSP_LCD_DisplayStringAt(uint16_t Xpos, uint16_t Ypos, uint8_t *Text, Line_ModeTypdef Mode) 00354 { 00355 uint16_t refcolumn = 1, i = 0; 00356 uint32_t size = 0, xsize = 0; 00357 uint8_t *ptr = Text; 00358 00359 /* Get the text size */ 00360 while (*ptr++) size ++ ; 00361 00362 /* Characters number per line */ 00363 xsize = (BSP_LCD_GetXSize()/DrawProp.pFont->Width); 00364 00365 switch (Mode) 00366 { 00367 case CENTER_MODE: 00368 { 00369 refcolumn = Xpos + ((xsize - size)* DrawProp.pFont->Width) / 2; 00370 break; 00371 } 00372 case LEFT_MODE: 00373 { 00374 refcolumn = Xpos; 00375 break; 00376 } 00377 case RIGHT_MODE: 00378 { 00379 refcolumn = - Xpos + ((xsize - size)*DrawProp.pFont->Width); 00380 break; 00381 } 00382 default: 00383 { 00384 refcolumn = Xpos; 00385 break; 00386 } 00387 } 00388 00389 /* Check that the Start column is located in the screen */ 00390 if ((refcolumn < 1) || (refcolumn >= 0x8000)) 00391 { 00392 refcolumn = 1; 00393 } 00394 00395 /* Send the string character by character on lCD */ 00396 while ((*Text != 0) & (((BSP_LCD_GetXSize() - (i*DrawProp.pFont->Width)) & 0xFFFF) >= DrawProp.pFont->Width)) 00397 { 00398 /* Display one character on LCD */ 00399 BSP_LCD_DisplayChar(refcolumn, Ypos, *Text); 00400 /* Decrement the column position by 16 */ 00401 refcolumn += DrawProp.pFont->Width; 00402 /* Point on the next character */ 00403 Text++; 00404 i++; 00405 } 00406 } 00407 00408 /** 00409 * @brief Displays a character on the LCD. 00410 * @param Line: Line where to display the character shape 00411 * This parameter can be one of the following values: 00412 * @arg 0..9: if the Current fonts is Font16x24 00413 * @arg 0..19: if the Current fonts is Font12x12 or Font8x12 00414 * @arg 0..29: if the Current fonts is Font8x8 00415 * @param ptr: Pointer to string to display on LCD 00416 * @retval None 00417 */ 00418 void BSP_LCD_DisplayStringAtLine(uint16_t Line, uint8_t *ptr) 00419 { 00420 BSP_LCD_DisplayStringAt(0, LINE(Line), ptr, LEFT_MODE); 00421 } 00422 00423 /** 00424 * @brief Reads an LCD pixel. 00425 * @param Xpos: X position 00426 * @param Ypos: Y position 00427 * @retval RGB pixel color 00428 */ 00429 uint16_t BSP_LCD_ReadPixel(uint16_t Xpos, uint16_t Ypos) 00430 { 00431 uint16_t ret = 0; 00432 00433 if(LcdDrv->ReadPixel != NULL) 00434 { 00435 ret = LcdDrv->ReadPixel(Xpos, Ypos); 00436 } 00437 00438 return ret; 00439 } 00440 00441 /** 00442 * @brief Draws a pixel on LCD. 00443 * @param Xpos: X position 00444 * @param Ypos: Y position 00445 * @param RGB_Code: Pixel color in RGB mode (5-6-5) 00446 * @retval None 00447 */ 00448 void BSP_LCD_DrawPixel(uint16_t Xpos, uint16_t Ypos, uint16_t RGB_Code) 00449 { 00450 if(LcdDrv->WritePixel != NULL) 00451 { 00452 LcdDrv->WritePixel(Xpos, Ypos, RGB_Code); 00453 } 00454 } 00455 00456 /** 00457 * @brief Draws an horizontal line. 00458 * @param Xpos: X position 00459 * @param Ypos: Y position 00460 * @param Length: Line length 00461 * @retval None 00462 */ 00463 void BSP_LCD_DrawHLine(uint16_t Xpos, uint16_t Ypos, uint16_t Length) 00464 { 00465 uint32_t index = 0; 00466 00467 if(LcdDrv->DrawHLine != NULL) 00468 { 00469 LcdDrv->DrawHLine(DrawProp.TextColor, Xpos, Ypos, Length); 00470 } 00471 else 00472 { 00473 for(index = 0; index < Length; index++) 00474 { 00475 BSP_LCD_DrawPixel((Xpos + index), Ypos, DrawProp.TextColor); 00476 } 00477 } 00478 } 00479 00480 /** 00481 * @brief Draws a vertical line. 00482 * @param Xpos: X position 00483 * @param Ypos: Y position 00484 * @param Length: Line length 00485 * @retval None 00486 */ 00487 void BSP_LCD_DrawVLine(uint16_t Xpos, uint16_t Ypos, uint16_t Length) 00488 { 00489 uint32_t index = 0; 00490 00491 if(LcdDrv->DrawVLine != NULL) 00492 { 00493 LcdDrv->DrawVLine(DrawProp.TextColor, Xpos, Ypos, Length); 00494 } 00495 else 00496 { 00497 for(index = 0; index < Length; index++) 00498 { 00499 BSP_LCD_DrawPixel(Xpos, Ypos + index, DrawProp.TextColor); 00500 } 00501 } 00502 } 00503 00504 /** 00505 * @brief Draws an uni-line (between two points). 00506 * @param x1: Point 1 X position 00507 * @param y1: Point 1 Y position 00508 * @param x2: Point 2 X position 00509 * @param y2: Point 2 Y position 00510 * @retval None 00511 */ 00512 void BSP_LCD_DrawLine(uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2) 00513 { 00514 int16_t deltax = 0, deltay = 0, x = 0, y = 0, xinc1 = 0, xinc2 = 0, 00515 yinc1 = 0, yinc2 = 0, den = 0, num = 0, numadd = 0, numpixels = 0, 00516 curpixel = 0; 00517 00518 deltax = ABS(x2 - x1); /* The difference between the x's */ 00519 deltay = ABS(y2 - y1); /* The difference between the y's */ 00520 x = x1; /* Start x off at the first pixel */ 00521 y = y1; /* Start y off at the first pixel */ 00522 00523 if (x2 >= x1) /* The x-values are increasing */ 00524 { 00525 xinc1 = 1; 00526 xinc2 = 1; 00527 } 00528 else /* The x-values are decreasing */ 00529 { 00530 xinc1 = -1; 00531 xinc2 = -1; 00532 } 00533 00534 if (y2 >= y1) /* The y-values are increasing */ 00535 { 00536 yinc1 = 1; 00537 yinc2 = 1; 00538 } 00539 else /* The y-values are decreasing */ 00540 { 00541 yinc1 = -1; 00542 yinc2 = -1; 00543 } 00544 00545 if (deltax >= deltay) /* There is at least one x-value for every y-value */ 00546 { 00547 xinc1 = 0; /* Don't change the x when numerator >= denominator */ 00548 yinc2 = 0; /* Don't change the y for every iteration */ 00549 den = deltax; 00550 num = deltax / 2; 00551 numadd = deltay; 00552 numpixels = deltax; /* There are more x-values than y-values */ 00553 } 00554 else /* There is at least one y-value for every x-value */ 00555 { 00556 xinc2 = 0; /* Don't change the x for every iteration */ 00557 yinc1 = 0; /* Don't change the y when numerator >= denominator */ 00558 den = deltay; 00559 num = deltay / 2; 00560 numadd = deltax; 00561 numpixels = deltay; /* There are more y-values than x-values */ 00562 } 00563 00564 for (curpixel = 0; curpixel <= numpixels; curpixel++) 00565 { 00566 BSP_LCD_DrawPixel(x, y, DrawProp.TextColor); /* Draw the current pixel */ 00567 num += numadd; /* Increase the numerator by the top of the fraction */ 00568 if (num >= den) /* Check if numerator >= denominator */ 00569 { 00570 num -= den; /* Calculate the new numerator value */ 00571 x += xinc1; /* Change the x as appropriate */ 00572 y += yinc1; /* Change the y as appropriate */ 00573 } 00574 x += xinc2; /* Change the x as appropriate */ 00575 y += yinc2; /* Change the y as appropriate */ 00576 } 00577 } 00578 00579 /** 00580 * @brief Draws a rectangle. 00581 * @param Xpos: X position 00582 * @param Ypos: Y position 00583 * @param Width: Rectangle width 00584 * @param Height: Rectangle height 00585 * @retval None 00586 */ 00587 void BSP_LCD_DrawRect(uint16_t Xpos, uint16_t Ypos, uint16_t Width, uint16_t Height) 00588 { 00589 /* Draw horizontal lines */ 00590 BSP_LCD_DrawHLine(Xpos, Ypos, Width); 00591 BSP_LCD_DrawHLine(Xpos, (Ypos+ Height), Width); 00592 00593 /* Draw vertical lines */ 00594 BSP_LCD_DrawVLine(Xpos, Ypos, Height); 00595 BSP_LCD_DrawVLine((Xpos + Width), Ypos, Height); 00596 } 00597 00598 /** 00599 * @brief Draws a circle. 00600 * @param Xpos: X position 00601 * @param Ypos: Y position 00602 * @param Radius: Circle radius 00603 * @retval None 00604 */ 00605 void BSP_LCD_DrawCircle(uint16_t Xpos, uint16_t Ypos, uint16_t Radius) 00606 { 00607 int32_t decision; /* Decision Variable */ 00608 uint32_t current_x; /* Current X Value */ 00609 uint32_t current_y; /* Current Y Value */ 00610 00611 decision = 3 - (Radius << 1); 00612 current_x = 0; 00613 current_y = Radius; 00614 00615 while (current_x <= current_y) 00616 { 00617 BSP_LCD_DrawPixel((Xpos + current_x), (Ypos - current_y), DrawProp.TextColor); 00618 00619 BSP_LCD_DrawPixel((Xpos - current_x), (Ypos - current_y), DrawProp.TextColor); 00620 00621 BSP_LCD_DrawPixel((Xpos + current_y), (Ypos - current_x), DrawProp.TextColor); 00622 00623 BSP_LCD_DrawPixel((Xpos - current_y), (Ypos - current_x), DrawProp.TextColor); 00624 00625 BSP_LCD_DrawPixel((Xpos + current_x), (Ypos + current_y), DrawProp.TextColor); 00626 00627 BSP_LCD_DrawPixel((Xpos - current_x), (Ypos + current_y), DrawProp.TextColor); 00628 00629 BSP_LCD_DrawPixel((Xpos + current_y), (Ypos + current_x), DrawProp.TextColor); 00630 00631 BSP_LCD_DrawPixel((Xpos - current_y), (Ypos + current_x), DrawProp.TextColor); 00632 00633 /* Initialize the font */ 00634 BSP_LCD_SetFont(&LCD_DEFAULT_FONT); 00635 00636 if (decision < 0) 00637 { 00638 decision += (current_x << 2) + 6; 00639 } 00640 else 00641 { 00642 decision += ((current_x - current_y) << 2) + 10; 00643 current_y--; 00644 } 00645 current_x++; 00646 } 00647 } 00648 00649 /** 00650 * @brief Draws an poly-line (between many points). 00651 * @param Points: Pointer to the points array 00652 * @param PointCount: Number of points 00653 * @retval None 00654 */ 00655 void BSP_LCD_DrawPolygon(pPoint Points, uint16_t PointCount) 00656 { 00657 int16_t x = 0, y = 0; 00658 00659 if(PointCount < 2) 00660 { 00661 return; 00662 } 00663 00664 BSP_LCD_DrawLine(Points->X, Points->Y, (Points+PointCount-1)->X, (Points+PointCount-1)->Y); 00665 00666 while(--PointCount) 00667 { 00668 x = Points->X; 00669 y = Points->Y; 00670 Points++; 00671 BSP_LCD_DrawLine(x, y, Points->X, Points->Y); 00672 } 00673 } 00674 00675 /** 00676 * @brief Draws an ellipse on LCD. 00677 * @param Xpos: X position 00678 * @param Ypos: Y position 00679 * @param XRadius: Ellipse X radius 00680 * @param YRadius: Ellipse Y radius 00681 * @retval None 00682 */ 00683 void BSP_LCD_DrawEllipse(int Xpos, int Ypos, int XRadius, int YRadius) 00684 { 00685 int x = 0, y = -YRadius, err = 2-2*XRadius, e2; 00686 float k = 0, rad1 = 0, rad2 = 0; 00687 00688 rad1 = XRadius; 00689 rad2 = YRadius; 00690 00691 k = (float)(rad2/rad1); 00692 00693 do { 00694 BSP_LCD_DrawPixel((Xpos-(uint16_t)(x/k)), (Ypos+y), DrawProp.TextColor); 00695 BSP_LCD_DrawPixel((Xpos+(uint16_t)(x/k)), (Ypos+y), DrawProp.TextColor); 00696 BSP_LCD_DrawPixel((Xpos+(uint16_t)(x/k)), (Ypos-y), DrawProp.TextColor); 00697 BSP_LCD_DrawPixel((Xpos-(uint16_t)(x/k)), (Ypos-y), DrawProp.TextColor); 00698 00699 e2 = err; 00700 if (e2 <= x) { 00701 err += ++x*2+1; 00702 if (-y == x && e2 <= y) e2 = 0; 00703 } 00704 if (e2 > y) err += ++y*2+1; 00705 } 00706 while (y <= 0); 00707 } 00708 00709 /** 00710 * @brief Draws a bitmap picture (16 bpp). 00711 * @param Xpos: Bmp X position in the LCD 00712 * @param Ypos: Bmp Y position in the LCD 00713 * @param pbmp: Pointer to Bmp picture address. 00714 * @retval None 00715 */ 00716 void BSP_LCD_DrawBitmap(uint16_t Xpos, uint16_t Ypos, uint8_t *pbmp) 00717 { 00718 uint32_t height = 0; 00719 uint32_t width = 0; 00720 00721 00722 /* Read bitmap width */ 00723 width = *(uint16_t *) (pbmp + 18); 00724 width |= (*(uint16_t *) (pbmp + 20)) << 16; 00725 00726 /* Read bitmap height */ 00727 height = *(uint16_t *) (pbmp + 22); 00728 height |= (*(uint16_t *) (pbmp + 24)) << 16; 00729 00730 SetDisplayWindow(Xpos, Ypos, width, height); 00731 00732 if(LcdDrv->DrawBitmap != NULL) 00733 { 00734 LcdDrv->DrawBitmap(Xpos, Ypos, pbmp); 00735 } 00736 SetDisplayWindow(0, 0, BSP_LCD_GetXSize(), BSP_LCD_GetYSize()); 00737 } 00738 00739 /** 00740 * @brief Draws RGB Image (16 bpp). 00741 * @param Xpos: X position in the LCD 00742 * @param Ypos: Y position in the LCD 00743 * @param Xsize: X size in the LCD 00744 * @param Ysize: Y size in the LCD 00745 * @param pdata: Pointer to the RGB Image address. 00746 * @retval None 00747 */ 00748 void BSP_LCD_DrawRGBImage(uint16_t Xpos, uint16_t Ypos, uint16_t Xsize, uint16_t Ysize, uint8_t *pdata) 00749 { 00750 00751 SetDisplayWindow(Xpos, Ypos, Xsize, Ysize); 00752 00753 if(LcdDrv->DrawRGBImage != NULL) 00754 { 00755 LcdDrv->DrawRGBImage(Xpos, Ypos, Xsize, Ysize, pdata); 00756 } 00757 SetDisplayWindow(0, 0, BSP_LCD_GetXSize(), BSP_LCD_GetYSize()); 00758 } 00759 00760 /** 00761 * @brief Draws a full rectangle. 00762 * @param Xpos: X position 00763 * @param Ypos: Y position 00764 * @param Width: Rectangle width 00765 * @param Height: Rectangle height 00766 * @retval None 00767 */ 00768 void BSP_LCD_FillRect(uint16_t Xpos, uint16_t Ypos, uint16_t Width, uint16_t Height) 00769 { 00770 BSP_LCD_SetTextColor(DrawProp.TextColor); 00771 do 00772 { 00773 BSP_LCD_DrawHLine(Xpos, Ypos++, Width); 00774 } 00775 while(Height--); 00776 } 00777 00778 /** 00779 * @brief Draws a full circle. 00780 * @param Xpos: X position 00781 * @param Ypos: Y position 00782 * @param Radius: Circle radius 00783 * @retval None 00784 */ 00785 void BSP_LCD_FillCircle(uint16_t Xpos, uint16_t Ypos, uint16_t Radius) 00786 { 00787 int32_t decision; /* Decision Variable */ 00788 uint32_t current_x; /* Current X Value */ 00789 uint32_t current_y; /* Current Y Value */ 00790 00791 decision = 3 - (Radius << 1); 00792 00793 current_x = 0; 00794 current_y = Radius; 00795 00796 BSP_LCD_SetTextColor(DrawProp.TextColor); 00797 00798 while (current_x <= current_y) 00799 { 00800 if(current_y > 0) 00801 { 00802 BSP_LCD_DrawHLine(Xpos - current_y, Ypos + current_x, 2*current_y); 00803 BSP_LCD_DrawHLine(Xpos - current_y, Ypos - current_x, 2*current_y); 00804 } 00805 00806 if(current_x > 0) 00807 { 00808 BSP_LCD_DrawHLine(Xpos - current_x, Ypos - current_y, 2*current_x); 00809 BSP_LCD_DrawHLine(Xpos - current_x, Ypos + current_y, 2*current_x); 00810 } 00811 if (decision < 0) 00812 { 00813 decision += (current_x << 2) + 6; 00814 } 00815 else 00816 { 00817 decision += ((current_x - current_y) << 2) + 10; 00818 current_y--; 00819 } 00820 current_x++; 00821 } 00822 00823 BSP_LCD_SetTextColor(DrawProp.TextColor); 00824 BSP_LCD_DrawCircle(Xpos, Ypos, Radius); 00825 } 00826 00827 /** 00828 * @brief Draws a full poly-line (between many points). 00829 * @param Points: Pointer to the points array 00830 * @param PointCount: Number of points 00831 * @retval None 00832 */ 00833 void BSP_LCD_FillPolygon(pPoint Points, uint16_t PointCount) 00834 { 00835 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; 00836 uint16_t IMAGE_LEFT = 0, IMAGE_RIGHT = 0, IMAGE_TOP = 0, IMAGE_BOTTOM = 0; 00837 00838 IMAGE_LEFT = IMAGE_RIGHT = Points->X; 00839 IMAGE_TOP= IMAGE_BOTTOM = Points->Y; 00840 00841 for(counter = 1; counter < PointCount; counter++) 00842 { 00843 pixelX = POLY_X(counter); 00844 if(pixelX < IMAGE_LEFT) 00845 { 00846 IMAGE_LEFT = pixelX; 00847 } 00848 if(pixelX > IMAGE_RIGHT) 00849 { 00850 IMAGE_RIGHT = pixelX; 00851 } 00852 00853 pixelY = POLY_Y(counter); 00854 if(pixelY < IMAGE_TOP) 00855 { 00856 IMAGE_TOP = pixelY; 00857 } 00858 if(pixelY > IMAGE_BOTTOM) 00859 { 00860 IMAGE_BOTTOM = pixelY; 00861 } 00862 } 00863 00864 if(PointCount < 2) 00865 { 00866 return; 00867 } 00868 00869 X_center = (IMAGE_LEFT + IMAGE_RIGHT)/2; 00870 Y_center = (IMAGE_BOTTOM + IMAGE_TOP)/2; 00871 00872 X_first = Points->X; 00873 Y_first = Points->Y; 00874 00875 while(--PointCount) 00876 { 00877 X = Points->X; 00878 Y = Points->Y; 00879 Points++; 00880 X2 = Points->X; 00881 Y2 = Points->Y; 00882 00883 FillTriangle(X, X2, X_center, Y, Y2, Y_center); 00884 FillTriangle(X, X_center, X2, Y, Y_center, Y2); 00885 FillTriangle(X_center, X2, X, Y_center, Y2, Y); 00886 } 00887 00888 FillTriangle(X_first, X2, X_center, Y_first, Y2, Y_center); 00889 FillTriangle(X_first, X_center, X2, Y_first, Y_center, Y2); 00890 FillTriangle(X_center, X2, X_first, Y_center, Y2, Y_first); 00891 } 00892 00893 /** 00894 * @brief Draws a full ellipse. 00895 * @param Xpos: X position 00896 * @param Ypos: Y position 00897 * @param XRadius: Ellipse X radius 00898 * @param YRadius: Ellipse Y radius 00899 * @retval None 00900 */ 00901 void BSP_LCD_FillEllipse(int Xpos, int Ypos, int XRadius, int YRadius) 00902 { 00903 int x = 0, y = -YRadius, err = 2-2*XRadius, e2; 00904 float k = 0, rad1 = 0, rad2 = 0; 00905 00906 rad1 = XRadius; 00907 rad2 = YRadius; 00908 00909 k = (float)(rad2/rad1); 00910 00911 do 00912 { 00913 BSP_LCD_DrawHLine((Xpos-(uint16_t)(x/k)), (Ypos+y), (2*(uint16_t)(x/k) + 1)); 00914 BSP_LCD_DrawHLine((Xpos-(uint16_t)(x/k)), (Ypos-y), (2*(uint16_t)(x/k) + 1)); 00915 00916 e2 = err; 00917 if (e2 <= x) 00918 { 00919 err += ++x*2+1; 00920 if (-y == x && e2 <= y) e2 = 0; 00921 } 00922 if (e2 > y) err += ++y*2+1; 00923 } 00924 while (y <= 0); 00925 } 00926 00927 /** 00928 * @brief Enables the display. 00929 * @retval None 00930 */ 00931 void BSP_LCD_DisplayOn(void) 00932 { 00933 LcdDrv->DisplayOn(); 00934 } 00935 00936 /** 00937 * @brief Disables the display. 00938 * @retval None 00939 */ 00940 void BSP_LCD_DisplayOff(void) 00941 { 00942 LcdDrv->DisplayOff(); 00943 } 00944 00945 00946 /** 00947 * @brief Initializes the LCD GPIO special pins MSP. 00948 * @retval None 00949 */ 00950 __weak void BSP_LCD_MspInit(void) 00951 { 00952 GPIO_InitTypeDef gpio_init_structure; 00953 00954 /* Enable GPIOs clock */ 00955 LCD_RESET_GPIO_CLK_ENABLE(); 00956 LCD_TE_GPIO_CLK_ENABLE(); 00957 LCD_BL_CTRL_GPIO_CLK_ENABLE(); 00958 00959 /* LCD_RESET GPIO configuration */ 00960 gpio_init_structure.Pin = LCD_RESET_PIN; /* LCD_RESET pin has to be manually controlled */ 00961 gpio_init_structure.Pull = GPIO_NOPULL; 00962 gpio_init_structure.Speed = GPIO_SPEED_FAST; 00963 gpio_init_structure.Mode = GPIO_MODE_OUTPUT_PP; 00964 HAL_GPIO_Init(LCD_RESET_GPIO_PORT, &gpio_init_structure); 00965 HAL_GPIO_WritePin( LCD_RESET_GPIO_PORT, LCD_RESET_PIN, GPIO_PIN_RESET); 00966 00967 /* LCD_TE GPIO configuration */ 00968 gpio_init_structure.Pin = LCD_TE_PIN; /* LCD_TE pin has to be manually managed */ 00969 gpio_init_structure.Mode = GPIO_MODE_INPUT; 00970 HAL_GPIO_Init(LCD_TE_GPIO_PORT, &gpio_init_structure); 00971 00972 /* LCD_BL_CTRL GPIO configuration */ 00973 gpio_init_structure.Pin = LCD_BL_CTRL_PIN; /* LCD_BL_CTRL pin has to be manually controlled */ 00974 gpio_init_structure.Mode = GPIO_MODE_OUTPUT_PP; 00975 gpio_init_structure.Speed = GPIO_SPEED_FREQ_LOW; 00976 HAL_GPIO_Init(LCD_BL_CTRL_GPIO_PORT, &gpio_init_structure); 00977 } 00978 00979 /** 00980 * @brief DeInitializes LCD GPIO special pins MSP. 00981 * @retval None 00982 */ 00983 __weak void BSP_LCD_MspDeInit(void) 00984 { 00985 GPIO_InitTypeDef gpio_init_structure; 00986 00987 /* LCD_RESET GPIO deactivation */ 00988 gpio_init_structure.Pin = LCD_RESET_PIN; 00989 HAL_GPIO_DeInit(LCD_RESET_GPIO_PORT, gpio_init_structure.Pin); 00990 00991 /* LCD_TE GPIO deactivation */ 00992 gpio_init_structure.Pin = LCD_TE_PIN; 00993 HAL_GPIO_DeInit(LCD_TE_GPIO_PORT, gpio_init_structure.Pin); 00994 00995 /* LCD_BL_CTRL GPIO deactivation */ 00996 gpio_init_structure.Pin = LCD_BL_CTRL_PIN; 00997 HAL_GPIO_DeInit(LCD_BL_CTRL_GPIO_PORT, gpio_init_structure.Pin); 00998 00999 /* GPIO pins clock can be shut down in the application 01000 by surcharging this __weak function */ 01001 } 01002 01003 /****************************************************************************** 01004 Static Functions 01005 *******************************************************************************/ 01006 01007 /** 01008 * @brief Draws a character on LCD. 01009 * @param Xpos: Line where to display the character shape 01010 * @param Ypos: Start column address 01011 * @param c: Pointer to the character data 01012 * @retval None 01013 */ 01014 static void DrawChar(uint16_t Xpos, uint16_t Ypos, const uint8_t *c) 01015 { 01016 uint32_t i = 0, j = 0; 01017 uint16_t height, width; 01018 uint8_t offset; 01019 uint8_t *pchar; 01020 uint32_t line; 01021 01022 height = DrawProp.pFont->Height; 01023 width = DrawProp.pFont->Width; 01024 01025 offset = 8 *((width + 7)/8) - width ; 01026 01027 for(i = 0; i < height; i++) 01028 { 01029 pchar = ((uint8_t *)c + (width + 7)/8 * i); 01030 01031 switch(((width + 7)/8)) 01032 { 01033 case 1: 01034 line = pchar[0]; 01035 break; 01036 01037 case 2: 01038 line = (pchar[0]<< 8) | pchar[1]; 01039 break; 01040 01041 case 3: 01042 default: 01043 line = (pchar[0]<< 16) | (pchar[1]<< 8) | pchar[2]; 01044 break; 01045 } 01046 01047 for (j = 0; j < width; j++) 01048 { 01049 if(line & (1 << (width- j + offset- 1))) 01050 { 01051 BSP_LCD_DrawPixel((Xpos + j), Ypos, DrawProp.TextColor); 01052 } 01053 else 01054 { 01055 BSP_LCD_DrawPixel((Xpos + j), Ypos, DrawProp.BackColor); 01056 } 01057 } 01058 Ypos++; 01059 } 01060 } 01061 01062 /** 01063 * @brief Sets display window. 01064 * @param Xpos: LCD X position 01065 * @param Ypos: LCD Y position 01066 * @param Width: LCD window width 01067 * @param Height: LCD window height 01068 * @retval None 01069 */ 01070 static void SetDisplayWindow(uint16_t Xpos, uint16_t Ypos, uint16_t Width, uint16_t Height) 01071 { 01072 if(LcdDrv->SetDisplayWindow != NULL) 01073 { 01074 LcdDrv->SetDisplayWindow(Xpos, Ypos, Width, Height); 01075 } 01076 } 01077 01078 /** 01079 * @brief Fills a triangle (between 3 points). 01080 * @param x1: Point 1 X position 01081 * @param y1: Point 1 Y position 01082 * @param x2: Point 2 X position 01083 * @param y2: Point 2 Y position 01084 * @param x3: Point 3 X position 01085 * @param y3: Point 3 Y position 01086 * @retval None 01087 */ 01088 static void FillTriangle(uint16_t x1, uint16_t x2, uint16_t x3, uint16_t y1, uint16_t y2, uint16_t y3) 01089 { 01090 int16_t deltax = 0, deltay = 0, x = 0, y = 0, xinc1 = 0, xinc2 = 0, 01091 yinc1 = 0, yinc2 = 0, den = 0, num = 0, numadd = 0, numpixels = 0, 01092 curpixel = 0; 01093 01094 deltax = ABS(x2 - x1); /* The difference between the x's */ 01095 deltay = ABS(y2 - y1); /* The difference between the y's */ 01096 x = x1; /* Start x off at the first pixel */ 01097 y = y1; /* Start y off at the first pixel */ 01098 01099 if (x2 >= x1) /* The x-values are increasing */ 01100 { 01101 xinc1 = 1; 01102 xinc2 = 1; 01103 } 01104 else /* The x-values are decreasing */ 01105 { 01106 xinc1 = -1; 01107 xinc2 = -1; 01108 } 01109 01110 if (y2 >= y1) /* The y-values are increasing */ 01111 { 01112 yinc1 = 1; 01113 yinc2 = 1; 01114 } 01115 else /* The y-values are decreasing */ 01116 { 01117 yinc1 = -1; 01118 yinc2 = -1; 01119 } 01120 01121 if (deltax >= deltay) /* There is at least one x-value for every y-value */ 01122 { 01123 xinc1 = 0; /* Don't change the x when numerator >= denominator */ 01124 yinc2 = 0; /* Don't change the y for every iteration */ 01125 den = deltax; 01126 num = deltax / 2; 01127 numadd = deltay; 01128 numpixels = deltax; /* There are more x-values than y-values */ 01129 } 01130 else /* There is at least one y-value for every x-value */ 01131 { 01132 xinc2 = 0; /* Don't change the x for every iteration */ 01133 yinc1 = 0; /* Don't change the y when numerator >= denominator */ 01134 den = deltay; 01135 num = deltay / 2; 01136 numadd = deltax; 01137 numpixels = deltay; /* There are more y-values than x-values */ 01138 } 01139 01140 for (curpixel = 0; curpixel <= numpixels; curpixel++) 01141 { 01142 BSP_LCD_DrawLine(x, y, x3, y3); 01143 01144 num += numadd; /* Increase the numerator by the top of the fraction */ 01145 if (num >= den) /* Check if numerator >= denominator */ 01146 { 01147 num -= den; /* Calculate the new numerator value */ 01148 x += xinc1; /* Change the x as appropriate */ 01149 y += yinc1; /* Change the y as appropriate */ 01150 } 01151 x += xinc2; /* Change the x as appropriate */ 01152 y += yinc2; /* Change the y as appropriate */ 01153 } 01154 } 01155 01156 /** 01157 * @} 01158 */ 01159 01160 /** 01161 * @} 01162 */ 01163 01164 /** 01165 * @} 01166 */ 01167 01168 /** 01169 * @} 01170 */ 01171 01172 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
Generated on Mon Jan 2 2017 09:52:50 for STM32F723E-Discovery BSP User Manual by
