Contains the BSP driver for the DISCO_F413ZH board.

Dependents:   DISCO_F413ZH-LCD-demo DISCO_F413ZH-touch-screen-demo DISCO_F413ZH-SD-demo DISCO_F413ZH-PSRAM-demo ... more

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers stm32f413h_discovery_lcd.c Source File

stm32f413h_discovery_lcd.c

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