STM32072B_EVAL BSP User Manual
|
stm32072b_eval_lcd.c
Go to the documentation of this file.
00001 /** 00002 ****************************************************************************** 00003 * @file stm32072b_eval_lcd.c 00004 * @author MCD Application Team 00005 * @brief This file includes the driver for Liquid Crystal Display modules 00006 * mounted on STM32072B-EVAL evaluation board. 00007 ****************************************************************************** 00008 * @attention 00009 * 00010 * <h2><center>© COPYRIGHT(c) 2016 STMicroelectronics</center></h2> 00011 * 00012 * Redistribution and use in source and binary forms, with or without modification, 00013 * are permitted provided that the following conditions are met: 00014 * 1. Redistributions of source code must retain the above copyright notice, 00015 * this list of conditions and the following disclaimer. 00016 * 2. Redistributions in binary form must reproduce the above copyright notice, 00017 * this list of conditions and the following disclaimer in the documentation 00018 * and/or other materials provided with the distribution. 00019 * 3. Neither the name of STMicroelectronics nor the names of its contributors 00020 * may be used to endorse or promote products derived from this software 00021 * without specific prior written permission. 00022 * 00023 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 00024 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 00025 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 00026 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 00027 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 00028 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 00029 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 00030 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 00031 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 00032 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00033 * 00034 ****************************************************************************** 00035 */ 00036 00037 /* File Info : ----------------------------------------------------------------- 00038 User NOTES 00039 1. How To use this driver: 00040 -------------------------- 00041 - This driver is used to drive indirectly an LCD TFT. 00042 - This driver supports the AM-240320LDTNQW00H (SPFD5408D) and 00043 AM240320LGTNQW00H (HX8347D) LCD mounted on MB895 daughter board 00044 - The SPFD5408D and HX8347D components driver MUST be included with this driver. 00045 00046 2. Driver description: 00047 --------------------- 00048 + Initialization steps: 00049 o Initialize the LCD using the LCD_Init() function. 00050 00051 + Display on LCD 00052 o Clear the hole LCD using yhe LCD_Clear() function or only one specified 00053 string line using the LCD_ClearStringLine() function. 00054 o Display a character on the specified line and column using the LCD_DisplayChar() 00055 function or a complete string line using the LCD_DisplayStringAtLine() function. 00056 o Display a string line on the specified position (x,y in pixel) and align mode 00057 using the LCD_DisplayStringAtLine() function. 00058 o Draw and fill a basic shapes (dot, line, rectangle, circle, ellipse, .. bitmap) 00059 on LCD using a set of functions. 00060 00061 ------------------------------------------------------------------------------*/ 00062 00063 /* Includes ------------------------------------------------------------------*/ 00064 #include "stm32072b_eval_lcd.h" 00065 #include "../../../Utilities/Fonts/fonts.h" 00066 #include "../../../Utilities/Fonts/font24.c" 00067 #include "../../../Utilities/Fonts/font20.c" 00068 #include "../../../Utilities/Fonts/font16.c" 00069 #include "../../../Utilities/Fonts/font12.c" 00070 #include "../../../Utilities/Fonts/font8.c" 00071 00072 /** @addtogroup BSP 00073 * @{ 00074 */ 00075 00076 /** @addtogroup STM32072B_EVAL 00077 * @{ 00078 */ 00079 00080 /** @addtogroup STM32072B_EVAL_LCD 00081 * @{ 00082 */ 00083 00084 /** @defgroup STM32072B_EVAL_LCD_Private_Constants Private Constants 00085 * @{ 00086 */ 00087 #define POLY_X(Z) ((int32_t)((pPoints + (Z))->X)) 00088 #define POLY_Y(Z) ((int32_t)((pPoints + (Z))->Y)) 00089 00090 #define MAX_HEIGHT_FONT 17 00091 #define MAX_WIDTH_FONT 24 00092 #define OFFSET_BITMAP 54 00093 /** 00094 * @} 00095 */ 00096 00097 /** @defgroup STM32072B_EVAL_LCD_Private_Macros Private Macros 00098 * @{ 00099 */ 00100 #define ABS(X) ((X) > 0 ? (X) : -(X)) 00101 00102 /** 00103 * @} 00104 */ 00105 00106 /** @defgroup STM32072B_EVAL_LCD_Private_Variables Private Variables 00107 * @{ 00108 */ 00109 LCD_DrawPropTypeDef DrawProp; 00110 00111 static LCD_DrvTypeDef *lcd_drv; 00112 00113 /* Max size of bitmap will based on a font24 (17x24) */ 00114 static uint8_t bitmap[MAX_HEIGHT_FONT*MAX_WIDTH_FONT*2+OFFSET_BITMAP] = {0}; 00115 00116 /** 00117 * @} 00118 */ 00119 00120 /** @defgroup STM32072B_EVAL_LCD_Private_Functions Private Functions 00121 * @{ 00122 */ 00123 static void LCD_DrawPixel(uint16_t Xpos, uint16_t Ypos, uint16_t RGBCode); 00124 static void LCD_DrawChar(uint16_t Xpos, uint16_t Ypos, const uint8_t *pChar); 00125 static void LCD_SetDisplayWindow(uint16_t Xpos, uint16_t Ypos, uint16_t Width, uint16_t Height); 00126 /** 00127 * @} 00128 */ 00129 00130 /** @addtogroup STM32072B_EVAL_LCD_Exported_Functions 00131 * @{ 00132 */ 00133 00134 /** 00135 * @brief Initializes the LCD. 00136 * @retval LCD state 00137 */ 00138 uint8_t BSP_LCD_Init(void) 00139 { 00140 uint8_t ret = LCD_ERROR; 00141 00142 /* Default value for draw propriety */ 00143 DrawProp.BackColor = 0xFFFF; 00144 DrawProp.pFont = &Font24; 00145 DrawProp.TextColor = 0x0000; 00146 00147 if(spfd5408_drv.ReadID() == SPFD5408_ID) 00148 { 00149 lcd_drv = &spfd5408_drv; 00150 ret = LCD_OK; 00151 } 00152 else 00153 { 00154 /*HX8347D_ID connected*/ 00155 lcd_drv = &hx8347d_drv; 00156 ret = LCD_OK; 00157 } 00158 00159 if(ret != LCD_ERROR) 00160 { 00161 /* LCD Init */ 00162 lcd_drv->Init(); 00163 00164 /* Initialize the font */ 00165 BSP_LCD_SetFont(&LCD_DEFAULT_FONT); 00166 } 00167 00168 return ret; 00169 } 00170 00171 /** 00172 * @brief Gets the LCD X size. 00173 * @retval Used LCD X size 00174 */ 00175 uint32_t BSP_LCD_GetXSize(void) 00176 { 00177 return(lcd_drv->GetLcdPixelWidth()); 00178 } 00179 00180 /** 00181 * @brief Gets the LCD Y size. 00182 * @retval Used LCD Y size 00183 */ 00184 uint32_t BSP_LCD_GetYSize(void) 00185 { 00186 return(lcd_drv->GetLcdPixelHeight()); 00187 } 00188 00189 /** 00190 * @brief Gets the LCD text color. 00191 * @retval Used text color. 00192 */ 00193 uint16_t BSP_LCD_GetTextColor(void) 00194 { 00195 return DrawProp.TextColor; 00196 } 00197 00198 /** 00199 * @brief Gets the LCD background color. 00200 * @retval Used background color 00201 */ 00202 uint16_t BSP_LCD_GetBackColor(void) 00203 { 00204 return DrawProp.BackColor; 00205 } 00206 00207 /** 00208 * @brief Sets the LCD text color. 00209 * @param Color Text color code RGB(5-6-5) 00210 * @retval None 00211 */ 00212 void BSP_LCD_SetTextColor(uint16_t Color) 00213 { 00214 DrawProp.TextColor = Color; 00215 } 00216 00217 /** 00218 * @brief Sets the LCD background color. 00219 * @param Color Background color code RGB(5-6-5) 00220 * @retval None 00221 */ 00222 void BSP_LCD_SetBackColor(uint16_t Color) 00223 { 00224 DrawProp.BackColor = Color; 00225 } 00226 00227 /** 00228 * @brief Sets the LCD text font. 00229 * @param pFonts Font to be used 00230 * @retval None 00231 */ 00232 void BSP_LCD_SetFont(sFONT *pFonts) 00233 { 00234 DrawProp.pFont = pFonts; 00235 } 00236 00237 /** 00238 * @brief Gets the LCD text font. 00239 * @retval Used font 00240 */ 00241 sFONT *BSP_LCD_GetFont(void) 00242 { 00243 return DrawProp.pFont; 00244 } 00245 00246 /** 00247 * @brief Clears the hole LCD. 00248 * @param Color Color of the background 00249 * @retval None 00250 */ 00251 void BSP_LCD_Clear(uint16_t Color) 00252 { 00253 uint32_t counter = 0; 00254 00255 uint32_t color_backup = DrawProp.TextColor; 00256 DrawProp.TextColor = Color; 00257 00258 for(counter = 0; counter < BSP_LCD_GetYSize(); counter++) 00259 { 00260 BSP_LCD_DrawHLine(0, counter, BSP_LCD_GetXSize()); 00261 } 00262 00263 DrawProp.TextColor = color_backup; 00264 BSP_LCD_SetTextColor(DrawProp.TextColor); 00265 } 00266 00267 /** 00268 * @brief Clears the selected line. 00269 * @param Line Line to be cleared 00270 * This parameter can be one of the following values: 00271 * @arg 0..9: if the Current fonts is Font16x24 00272 * @arg 0..19: if the Current fonts is Font12x12 or Font8x12 00273 * @arg 0..29: if the Current fonts is Font8x8 00274 * @retval None 00275 */ 00276 void BSP_LCD_ClearStringLine(uint16_t Line) 00277 { 00278 uint32_t colorbackup = DrawProp.TextColor; 00279 DrawProp.TextColor = DrawProp.BackColor;; 00280 00281 /* Draw a rectangle with background color */ 00282 BSP_LCD_FillRect(0, (Line * DrawProp.pFont->Height), BSP_LCD_GetXSize(), DrawProp.pFont->Height); 00283 00284 DrawProp.TextColor = colorbackup; 00285 BSP_LCD_SetTextColor(DrawProp.TextColor); 00286 } 00287 00288 /** 00289 * @brief Displays one character. 00290 * @param Xpos Start column address 00291 * @param Ypos Line where to display the character shape. 00292 * @param Ascii Character ascii code 00293 * This parameter must be a number between Min_Data = 0x20 and Max_Data = 0x7E 00294 * @retval None 00295 */ 00296 void BSP_LCD_DisplayChar(uint16_t Xpos, uint16_t Ypos, uint8_t Ascii) 00297 { 00298 LCD_DrawChar(Ypos, Xpos, &DrawProp.pFont->table[(Ascii-' ') *\ 00299 DrawProp.pFont->Height * ((DrawProp.pFont->Width + 7) / 8)]); 00300 } 00301 00302 /** 00303 * @brief Displays characters on the LCD. 00304 * @param Xpos X position (in pixel) 00305 * @param Ypos Y position (in pixel) 00306 * @param pText Pointer to string to display on LCD 00307 * @param Mode Display mode 00308 * This parameter can be one of the following values: 00309 * @arg CENTER_MODE 00310 * @arg RIGHT_MODE 00311 * @arg LEFT_MODE 00312 * @retval None 00313 */ 00314 void BSP_LCD_DisplayStringAt(uint16_t Xpos, uint16_t Ypos, uint8_t *pText, Line_ModeTypdef Mode) 00315 { 00316 uint16_t refcolumn = 1, counter = 0; 00317 uint32_t size = 0, ysize = 0; 00318 uint8_t *ptr = pText; 00319 00320 /* Get the text size */ 00321 while (*ptr++) size ++ ; 00322 00323 /* Characters number per line */ 00324 ysize = (BSP_LCD_GetXSize()/DrawProp.pFont->Width); 00325 00326 switch (Mode) 00327 { 00328 case CENTER_MODE: 00329 { 00330 refcolumn = Xpos + ((ysize - size)* DrawProp.pFont->Width) / 2; 00331 break; 00332 } 00333 case LEFT_MODE: 00334 { 00335 refcolumn = Xpos; 00336 break; 00337 } 00338 case RIGHT_MODE: 00339 { 00340 refcolumn = Xpos + ((ysize - size)*DrawProp.pFont->Width); 00341 break; 00342 } 00343 default: 00344 { 00345 refcolumn = Xpos; 00346 break; 00347 } 00348 } 00349 00350 /* Send the string character by character on lCD */ 00351 while ((*pText != 0) & (((BSP_LCD_GetXSize() - (counter*DrawProp.pFont->Width)) & 0xFFFF) >= DrawProp.pFont->Width)) 00352 { 00353 /* Display one character on LCD */ 00354 BSP_LCD_DisplayChar(refcolumn, Ypos, *pText); 00355 /* Decrement the column position by 16 */ 00356 refcolumn += DrawProp.pFont->Width; 00357 /* Point on the next character */ 00358 pText++; 00359 counter++; 00360 } 00361 } 00362 00363 /** 00364 * @brief Displays a character on the LCD. 00365 * @param Line Line where to display the character shape 00366 * This parameter can be one of the following values: 00367 * @arg 0..9: if the Current fonts is Font16x24 00368 * @arg 0..19: if the Current fonts is Font12x12 or Font8x12 00369 * @arg 0..29: if the Current fonts is Font8x8 00370 * @param pText Pointer to string to display on LCD 00371 * @retval None 00372 */ 00373 void BSP_LCD_DisplayStringAtLine(uint16_t Line, uint8_t *pText) 00374 { 00375 BSP_LCD_DisplayStringAt(0, LINE(Line),pText, LEFT_MODE); 00376 } 00377 00378 /** 00379 * @brief Reads an LCD pixel. 00380 * @param Xpos X position 00381 * @param Ypos Y position 00382 * @retval RGB pixel color 00383 */ 00384 uint16_t BSP_LCD_ReadPixel(uint16_t Xpos, uint16_t Ypos) 00385 { 00386 uint16_t ret = 0; 00387 00388 if(lcd_drv->ReadPixel != NULL) 00389 { 00390 ret = lcd_drv->ReadPixel(Xpos, Ypos); 00391 } 00392 00393 return ret; 00394 } 00395 00396 /** 00397 * @brief Draws an horizontal line. 00398 * @param Xpos X position 00399 * @param Ypos Y position 00400 * @param Length Line length 00401 * @retval None 00402 */ 00403 void BSP_LCD_DrawHLine(uint16_t Xpos, uint16_t Ypos, uint16_t Length) 00404 { 00405 uint32_t index = 0; 00406 00407 if(lcd_drv->DrawHLine != NULL) 00408 { 00409 lcd_drv->DrawHLine(DrawProp.TextColor, Ypos, Xpos, Length); 00410 } 00411 else 00412 { 00413 for(index = 0; index < Length; index++) 00414 { 00415 LCD_DrawPixel((Ypos + index), Xpos, DrawProp.TextColor); 00416 } 00417 } 00418 } 00419 00420 /** 00421 * @brief Draws a vertical line. 00422 * @param Xpos X position 00423 * @param Ypos Y position 00424 * @param Length Line length 00425 * @retval None 00426 */ 00427 void BSP_LCD_DrawVLine(uint16_t Xpos, uint16_t Ypos, uint16_t Length) 00428 { 00429 uint32_t index = 0; 00430 00431 if(lcd_drv->DrawVLine != NULL) 00432 { 00433 LCD_SetDisplayWindow(Ypos, Xpos, 1, Length); 00434 lcd_drv->DrawVLine(DrawProp.TextColor, Ypos, Xpos, Length); 00435 LCD_SetDisplayWindow(0, 0, BSP_LCD_GetXSize(), BSP_LCD_GetYSize()); 00436 } 00437 else 00438 { 00439 for(index = 0; index < Length; index++) 00440 { 00441 LCD_DrawPixel(Ypos, Xpos + index, DrawProp.TextColor); 00442 } 00443 } 00444 } 00445 00446 /** 00447 * @brief Draws an uni-line (between two points). 00448 * @param X1 Point 1 X position 00449 * @param Y1 Point 1 Y position 00450 * @param X2 Point 2 X position 00451 * @param Y2 Point 2 Y position 00452 * @retval None 00453 */ 00454 void BSP_LCD_DrawLine(uint16_t X1, uint16_t Y1, uint16_t X2, uint16_t Y2) 00455 { 00456 int16_t deltax = 0, deltay = 0, x = 0, y = 0, xinc1 = 0, xinc2 = 0, 00457 yinc1 = 0, yinc2 = 0, den = 0, num = 0, numadd = 0, numpixels = 0, 00458 curpixel = 0; 00459 00460 deltax = ABS(Y2 - Y1); /* The difference between the x's */ 00461 deltay = ABS(X2 - X1); /* The difference between the y's */ 00462 x = Y1; /* Start x off at the first pixel */ 00463 y = X1; /* Start y off at the first pixel */ 00464 00465 if (Y2 >= Y1) /* The x-values are increasing */ 00466 { 00467 xinc1 = 1; 00468 xinc2 = 1; 00469 } 00470 else /* The x-values are decreasing */ 00471 { 00472 xinc1 = -1; 00473 xinc2 = -1; 00474 } 00475 00476 if (X2 >= X1) /* The y-values are increasing */ 00477 { 00478 yinc1 = 1; 00479 yinc2 = 1; 00480 } 00481 else /* The y-values are decreasing */ 00482 { 00483 yinc1 = -1; 00484 yinc2 = -1; 00485 } 00486 00487 if (deltax >= deltay) /* There is at least one x-value for every y-value */ 00488 { 00489 xinc1 = 0; /* Don't change the x when numerator >= denominator */ 00490 yinc2 = 0; /* Don't change the y for every iteration */ 00491 den = deltax; 00492 num = deltax / 2; 00493 numadd = deltay; 00494 numpixels = deltax; /* There are more x-values than y-values */ 00495 } 00496 else /* There is at least one y-value for every x-value */ 00497 { 00498 xinc2 = 0; /* Don't change the x for every iteration */ 00499 yinc1 = 0; /* Don't change the y when numerator >= denominator */ 00500 den = deltay; 00501 num = deltay / 2; 00502 numadd = deltax; 00503 numpixels = deltay; /* There are more y-values than x-values */ 00504 } 00505 00506 for (curpixel = 0; curpixel <= numpixels; curpixel++) 00507 { 00508 LCD_DrawPixel(x, y, DrawProp.TextColor); /* Draw the current pixel */ 00509 num += numadd; /* Increase the numerator by the top of the fraction */ 00510 if (num >= den) /* Check if numerator >= denominator */ 00511 { 00512 num -= den; /* Calculate the new numerator value */ 00513 x += xinc1; /* Change the x as appropriate */ 00514 y += yinc1; /* Change the y as appropriate */ 00515 } 00516 x += xinc2; /* Change the x as appropriate */ 00517 y += yinc2; /* Change the y as appropriate */ 00518 } 00519 } 00520 00521 /** 00522 * @brief Draws a rectangle. 00523 * @param Xpos X position 00524 * @param Ypos Y position 00525 * @param Width Rectangle width 00526 * @param Height Rectangle height 00527 * @retval None 00528 */ 00529 void BSP_LCD_DrawRect(uint16_t Xpos, uint16_t Ypos, uint16_t Width, uint16_t Height) 00530 { 00531 /* Draw horizontal lines */ 00532 BSP_LCD_DrawHLine(Xpos, Ypos, Width); 00533 BSP_LCD_DrawHLine(Xpos, (Ypos+ Height), Width); 00534 00535 /* Draw vertical lines */ 00536 BSP_LCD_DrawVLine(Xpos, Ypos, Height); 00537 BSP_LCD_DrawVLine((Xpos + Width), Ypos, Height); 00538 } 00539 00540 /** 00541 * @brief Draws a circle. 00542 * @param Xpos X position 00543 * @param Ypos Y position 00544 * @param Radius Circle radius 00545 * @retval None 00546 */ 00547 void BSP_LCD_DrawCircle(uint16_t Xpos, uint16_t Ypos, uint16_t Radius) 00548 { 00549 int32_t decision; /* Decision Variable */ 00550 uint32_t curx; /* Current X Value */ 00551 uint32_t cury; /* Current Y Value */ 00552 00553 decision = 3 - (Radius << 1); 00554 curx = 0; 00555 cury = Radius; 00556 00557 while (curx <= cury) 00558 { 00559 LCD_DrawPixel((Ypos + curx), (Xpos - cury), DrawProp.TextColor); 00560 00561 LCD_DrawPixel((Ypos - curx), (Xpos - cury), DrawProp.TextColor); 00562 00563 LCD_DrawPixel((Ypos + cury), (Xpos - curx), DrawProp.TextColor); 00564 00565 LCD_DrawPixel((Ypos - cury), (Xpos - curx), DrawProp.TextColor); 00566 00567 LCD_DrawPixel((Ypos + curx), (Xpos + cury), DrawProp.TextColor); 00568 00569 LCD_DrawPixel((Ypos - curx), (Xpos + cury), DrawProp.TextColor); 00570 00571 LCD_DrawPixel((Ypos + cury), (Xpos + curx), DrawProp.TextColor); 00572 00573 LCD_DrawPixel((Ypos - cury), (Xpos + curx), DrawProp.TextColor); 00574 00575 /* Initialize the font */ 00576 BSP_LCD_SetFont(&LCD_DEFAULT_FONT); 00577 00578 if (decision < 0) 00579 { 00580 decision += (curx << 2) + 6; 00581 } 00582 else 00583 { 00584 decision += ((curx - cury) << 2) + 10; 00585 cury--; 00586 } 00587 curx++; 00588 } 00589 } 00590 00591 /** 00592 * @brief Draws an poly-line (between many points). 00593 * @param pPoints Pointer to the points array 00594 * @param PointCount Number of points 00595 * @retval None 00596 */ 00597 void BSP_LCD_DrawPolygon(pPoint pPoints, uint16_t PointCount) 00598 { 00599 int16_t x = 0, y = 0; 00600 00601 if(PointCount < 2) 00602 { 00603 return; 00604 } 00605 00606 BSP_LCD_DrawLine(pPoints->X, pPoints->Y, (pPoints+PointCount-1)->X, (pPoints+PointCount-1)->Y); 00607 00608 while(--PointCount) 00609 { 00610 x = pPoints->X; 00611 y = pPoints->Y; 00612 pPoints++; 00613 BSP_LCD_DrawLine(x, y, pPoints->X, pPoints->Y); 00614 } 00615 00616 } 00617 00618 /** 00619 * @brief Draws an ellipse on LCD. 00620 * @param Xpos X position 00621 * @param Ypos Y position 00622 * @param XRadius Ellipse X radius 00623 * @param YRadius Ellipse Y radius 00624 * @retval None 00625 */ 00626 void BSP_LCD_DrawEllipse(int Xpos, int Ypos, int XRadius, int YRadius) 00627 { 00628 int x = 0, y = -XRadius, err = 2-2*YRadius, e2; 00629 float k = 0, rad1 = 0, rad2 = 0; 00630 00631 rad1 = YRadius; 00632 rad2 = XRadius; 00633 00634 k = (float)(rad2/rad1); 00635 00636 do { 00637 LCD_DrawPixel((Ypos-(uint16_t)(x/k)), (Xpos+y), DrawProp.TextColor); 00638 LCD_DrawPixel((Ypos+(uint16_t)(x/k)), (Xpos+y), DrawProp.TextColor); 00639 LCD_DrawPixel((Ypos+(uint16_t)(x/k)), (Xpos-y), DrawProp.TextColor); 00640 LCD_DrawPixel((Ypos-(uint16_t)(x/k)), (Xpos-y), DrawProp.TextColor); 00641 00642 e2 = err; 00643 if (e2 <= x) { 00644 err += ++x*2+1; 00645 if (-y == x && e2 <= y) e2 = 0; 00646 } 00647 if (e2 > y) err += ++y*2+1; 00648 } 00649 while (y <= 0); 00650 } 00651 00652 /** 00653 * @brief Draws a bitmap picture loaded in the internal Flash (32 bpp). 00654 * @param Xpos Bmp X position in the LCD 00655 * @param Ypos Bmp Y position in the LCD 00656 * @param pBmp Pointer to Bmp picture address in the internal Flash 00657 * @retval None 00658 */ 00659 void BSP_LCD_DrawBitmap(uint16_t Xpos, uint16_t Ypos, uint8_t *pBmp) 00660 { 00661 uint32_t height = 0, width = 0; 00662 00663 /* Read bitmap width */ 00664 width = *(uint16_t *) (pBmp + 18); 00665 width |= (*(uint16_t *) (pBmp + 20)) << 16; 00666 00667 /* Read bitmap height */ 00668 height = *(uint16_t *) (pBmp + 22); 00669 height |= (*(uint16_t *) (pBmp + 24)) << 16; 00670 00671 /* Remap Ypos, hx8347d works with inverted X in case of bitmap */ 00672 /* X = 0, cursor is on Bottom corner */ 00673 if(lcd_drv == &hx8347d_drv) 00674 { 00675 Ypos = BSP_LCD_GetYSize() - Ypos - height; 00676 } 00677 00678 LCD_SetDisplayWindow(Ypos, Xpos, width, height); 00679 00680 if(lcd_drv->DrawBitmap != NULL) 00681 { 00682 lcd_drv->DrawBitmap(Ypos, Xpos, pBmp); 00683 } 00684 LCD_SetDisplayWindow(0, 0, BSP_LCD_GetXSize(), BSP_LCD_GetYSize()); 00685 } 00686 00687 /** 00688 * @brief Draws a full rectangle. 00689 * @param Xpos X position 00690 * @param Ypos Y position 00691 * @param Width Rectangle width 00692 * @param Height Rectangle height 00693 * @retval None 00694 */ 00695 void BSP_LCD_FillRect(uint16_t Xpos, uint16_t Ypos, uint16_t Width, uint16_t Height) 00696 { 00697 BSP_LCD_SetTextColor(DrawProp.TextColor); 00698 do 00699 { 00700 BSP_LCD_DrawHLine(Xpos, Ypos++, Width); 00701 } 00702 while(Height--); 00703 } 00704 00705 /** 00706 * @brief Draws a full circle. 00707 * @param Xpos X position 00708 * @param Ypos Y position 00709 * @param Radius Circle radius 00710 * @retval None 00711 */ 00712 void BSP_LCD_FillCircle(uint16_t Xpos, uint16_t Ypos, uint16_t Radius) 00713 { 00714 int32_t decision; /* Decision Variable */ 00715 uint32_t curx; /* Current X Value */ 00716 uint32_t cury; /* Current Y Value */ 00717 00718 decision = 3 - (Radius << 1); 00719 00720 curx = 0; 00721 cury = Radius; 00722 00723 BSP_LCD_SetTextColor(DrawProp.TextColor); 00724 00725 while (curx <= cury) 00726 { 00727 if(cury > 0) 00728 { 00729 BSP_LCD_DrawVLine(Xpos + curx, Ypos - cury, 2*cury); 00730 BSP_LCD_DrawVLine(Xpos - curx, Ypos - cury, 2*cury); 00731 } 00732 00733 if(curx > 0) 00734 { 00735 BSP_LCD_DrawVLine(Xpos - cury, Ypos - curx, 2*curx); 00736 BSP_LCD_DrawVLine(Xpos + cury, Ypos - curx, 2*curx); 00737 } 00738 if (decision < 0) 00739 { 00740 decision += (curx << 2) + 6; 00741 } 00742 else 00743 { 00744 decision += ((curx - cury) << 2) + 10; 00745 cury--; 00746 } 00747 curx++; 00748 } 00749 00750 BSP_LCD_SetTextColor(DrawProp.TextColor); 00751 BSP_LCD_DrawCircle(Xpos, Ypos, Radius); 00752 } 00753 00754 /** 00755 * @brief Draws a full ellipse. 00756 * @param Xpos X position 00757 * @param Ypos Y position 00758 * @param XRadius Ellipse X radius 00759 * @param YRadius Ellipse Y radius 00760 * @retval None 00761 */ 00762 void BSP_LCD_FillEllipse(int Xpos, int Ypos, int XRadius, int YRadius) 00763 { 00764 int x = 0, y = -XRadius, err = 2-2*YRadius, e2; 00765 float k = 0, rad1 = 0, rad2 = 0; 00766 00767 rad1 = YRadius; 00768 rad2 = XRadius; 00769 00770 k = (float)(rad2/rad1); 00771 00772 do 00773 { 00774 BSP_LCD_DrawVLine((Xpos+y), (Ypos-(uint16_t)(x/k)), (2*(uint16_t)(x/k) + 1)); 00775 BSP_LCD_DrawVLine((Xpos-y), (Ypos-(uint16_t)(x/k)), (2*(uint16_t)(x/k) + 1)); 00776 00777 e2 = err; 00778 if (e2 <= x) 00779 { 00780 err += ++x*2+1; 00781 if (-y == x && e2 <= y) e2 = 0; 00782 } 00783 if (e2 > y) err += ++y*2+1; 00784 } 00785 while (y <= 0); 00786 } 00787 00788 /** 00789 * @brief Enables the display. 00790 * @retval None 00791 */ 00792 void BSP_LCD_DisplayOn(void) 00793 { 00794 lcd_drv->DisplayOn(); 00795 } 00796 00797 /** 00798 * @brief Disables the display. 00799 * @retval None 00800 */ 00801 void BSP_LCD_DisplayOff(void) 00802 { 00803 lcd_drv->DisplayOff(); 00804 } 00805 00806 /** 00807 * @} 00808 */ 00809 00810 /** @defgroup STM32072B_EVAL_LCD_Private_Functions Private Functions 00811 * @{ 00812 */ 00813 /****************************************************************************** 00814 Static Function 00815 *******************************************************************************/ 00816 /** 00817 * @brief Draws a pixel on LCD. 00818 * @param Xpos X position 00819 * @param Ypos Y position 00820 * @param RGBCode Pixel color in RGB mode (5-6-5) 00821 * @retval None 00822 */ 00823 static void LCD_DrawPixel(uint16_t Xpos, uint16_t Ypos, uint16_t RGBCode) 00824 { 00825 if(lcd_drv->WritePixel != NULL) 00826 { 00827 lcd_drv->WritePixel(Xpos, Ypos, RGBCode); 00828 } 00829 } 00830 00831 /** 00832 * @brief Draws a character on LCD. 00833 * @param Xpos Line where to display the character shape 00834 * @param Ypos Start column address 00835 * @param pChar Pointer to the character data 00836 * @retval None 00837 */ 00838 static void LCD_DrawChar(uint16_t Xpos, uint16_t Ypos, const uint8_t *pChar) 00839 { 00840 uint32_t counterh = 0, counterw = 0, index = 0; 00841 uint16_t height = 0, width = 0; 00842 uint8_t offset = 0; 00843 uint8_t *pchar = NULL; 00844 uint32_t line = 0; 00845 00846 height = DrawProp.pFont->Height; 00847 width = DrawProp.pFont->Width; 00848 00849 /* Fill bitmap header*/ 00850 *(uint16_t *) (bitmap + 2) = (uint16_t)(height*width*2+OFFSET_BITMAP); 00851 *(uint16_t *) (bitmap + 4) = (uint16_t)((height*width*2+OFFSET_BITMAP)>>16); 00852 *(uint16_t *) (bitmap + 10) = OFFSET_BITMAP; 00853 *(uint16_t *) (bitmap + 18) = (uint16_t)(width); 00854 *(uint16_t *) (bitmap + 20) = (uint16_t)((width)>>16); 00855 *(uint16_t *) (bitmap + 22) = (uint16_t)(height); 00856 *(uint16_t *) (bitmap + 24) = (uint16_t)((height)>>16); 00857 00858 offset = 8 *((width + 7)/8) - width ; 00859 00860 for(counterh = 0; counterh < height; counterh++) 00861 { 00862 pchar = ((uint8_t *)pChar + (width + 7)/8 * counterh); 00863 00864 if(((width + 7)/8) == 3) 00865 { 00866 line = (pchar[0]<< 16) | (pchar[1]<< 8) | pchar[2]; 00867 } 00868 00869 if(((width + 7)/8) == 2) 00870 { 00871 line = (pchar[0]<< 8) | pchar[1]; 00872 } 00873 00874 if(((width + 7)/8) == 1) 00875 { 00876 line = pchar[0]; 00877 } 00878 00879 for (counterw = 0; counterw < width; counterw++) 00880 { 00881 /* Image in the bitmap is written from the bottom to the top */ 00882 /* Need to invert image in the bitmap */ 00883 index = (((height-counterh-1)*width)+(counterw))*2+OFFSET_BITMAP; 00884 if(line & (1 << (width- counterw + offset- 1))) 00885 { 00886 bitmap[index] = (uint8_t)DrawProp.TextColor; 00887 bitmap[index+1] = (uint8_t)(DrawProp.TextColor >> 8); 00888 } 00889 else 00890 { 00891 bitmap[index] = (uint8_t)DrawProp.BackColor; 00892 bitmap[index+1] = (uint8_t)(DrawProp.BackColor >> 8); 00893 } 00894 } 00895 } 00896 00897 BSP_LCD_DrawBitmap(Ypos, Xpos, bitmap); 00898 } 00899 00900 /** 00901 * @brief Sets display window. 00902 * @param Xpos LCD X position 00903 * @param Ypos LCD Y position 00904 * @param Width LCD window width 00905 * @param Height LCD window height 00906 * @retval None 00907 */ 00908 static void LCD_SetDisplayWindow(uint16_t Xpos, uint16_t Ypos, uint16_t Width, uint16_t Height) 00909 { 00910 if(lcd_drv->SetDisplayWindow != NULL) 00911 { 00912 lcd_drv->SetDisplayWindow(Xpos, Ypos, Width, Height); 00913 } 00914 } 00915 00916 /** 00917 * @} 00918 */ 00919 00920 /** 00921 * @} 00922 */ 00923 00924 /** 00925 * @} 00926 */ 00927 00928 /** 00929 * @} 00930 */ 00931 00932 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
Generated on Wed Jul 5 2017 08:56:10 for STM32072B_EVAL BSP User Manual by
