123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020 |
- /**
- ******************************************************************************
- * @file stm322xg_eval_lcd.c
- * @author MCD Application Team
- * @brief This file includes the driver for Liquid Crystal Display (LCD) module
- * mounted on STM322xG-EVAL evaluation board.
- ******************************************************************************
- * @attention
- *
- * <h2><center>© COPYRIGHT(c) 2017 STMicroelectronics</center></h2>
- *
- * Redistribution and use in source and binary forms, with or without modification,
- * are permitted provided that the following conditions are met:
- * 1. Redistributions of source code must retain the above copyright notice,
- * this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright notice,
- * this list of conditions and the following disclaimer in the documentation
- * and/or other materials provided with the distribution.
- * 3. Neither the name of STMicroelectronics nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
- * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
- * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
- * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- ******************************************************************************
- */
- /* File Info : -----------------------------------------------------------------
- User NOTES
- 1. How To use this driver:
- --------------------------
- - This driver is used to drive indirectly an LCD TFT.
- - This driver supports the ILI9325 LCD mounted on MB785 daughter board
- - The ILI9325 component driver MUST be included with this driver.
- 2. Driver description:
- ---------------------
- + Initialization steps:
- o Initialize the LCD using the BSP_LCD_Init() function.
-
- + Display on LCD
- o Clear the hole LCD using yhe BSP_LCD_Clear() function or only one specified
- string line using the BSP_LCD_ClearStringLine() function.
- o Display a character on the specified line and column using the BSP_LCD_DisplayChar()
- function or a complete string line using the BSP_LCD_DisplayStringAtLine() function.
- o Display a string line on the specified position (x,y in pixel) and align mode
- using the BSP_LCD_DisplayStringAtLine() function.
- o Draw and fill basic shapes (dot, line, rectangle, circle, ellipse, .. bitmap, raw picture)
- on LCD using a set of functions.
-
- ------------------------------------------------------------------------------*/
-
- /* Includes ------------------------------------------------------------------*/
- #include "stm322xg_eval_lcd.h"
- #include "../../../Utilities/Fonts/fonts.h"
- #include "../../../Utilities/Fonts/font24.c"
- #include "../../../Utilities/Fonts/font20.c"
- #include "../../../Utilities/Fonts/font16.c"
- #include "../../../Utilities/Fonts/font12.c"
- #include "../../../Utilities/Fonts/font8.c"
- /** @addtogroup BSP
- * @{
- */
- /** @addtogroup STM322xG_EVAL
- * @{
- */
-
- /** @defgroup STM322xG_EVAL_LCD STM322xG EVAL LCD
- * @{
- */
- /** @defgroup STM322xG_EVAL_LCD_Private_Defines STM322xG EVAL LCD Private Defines
- * @{
- */
- #define POLY_X(Z) ((int32_t)((Points + (Z))->X))
- #define POLY_Y(Z) ((int32_t)((Points + (Z))->Y))
- /**
- * @}
- */
- /** @defgroup STM322xG_EVAL_LCD_Private_Macros STM322xG EVAL LCD Private Macros
- * @{
- */
- #define ABS(X) ((X) > 0 ? (X) : -(X))
- /**
- * @}
- */
-
- /** @defgroup STM322xG_EVAL_LCD_Private_Variables STM322xG EVAL LCD Private Variables
- * @{
- */
- LCD_DrawPropTypeDef DrawProp;
- static LCD_DrvTypeDef *lcd_drv;
- /**
- * @}
- */
- /** @defgroup STM322xG_EVAL_LCD_Private_FunctionPrototypes STM322xG EVAL LCD Private FunctionPrototypes
- * @{
- */
- static void DrawChar(uint16_t Xpos, uint16_t Ypos, const uint8_t *c);
- static void SetDisplayWindow(uint16_t Xpos, uint16_t Ypos, uint16_t Width, uint16_t Height);
- static void FillTriangle(uint16_t x1, uint16_t x2, uint16_t x3, uint16_t y1, uint16_t y2, uint16_t y3);
- /**
- * @}
- */
- /** @defgroup STM322xG_EVAL_LCD_Private_Functions STM322xG EVAL LCD Private Functions
- * @{
- */
- /**
- * @brief Initializes the LCD.
- * @retval LCD state
- */
- uint8_t BSP_LCD_Init(void)
- {
- uint8_t ret = LCD_ERROR;
-
- /* Default value for draw propriety */
- DrawProp.BackColor = 0xFFFF;
- DrawProp.pFont = &Font24;
- DrawProp.TextColor = 0x0000;
-
- if(ili9325_drv.ReadID() == ILI9325_ID)
- {
- lcd_drv = &ili9325_drv;
- /* LCD Init */
- lcd_drv->Init();
-
- /* Initialize the font */
- BSP_LCD_SetFont(&LCD_DEFAULT_FONT);
- ret = LCD_OK;
- }
-
- return ret;
- }
- /**
- * @brief Gets the LCD X size.
- * @retval Used LCD X size
- */
- uint32_t BSP_LCD_GetXSize(void)
- {
- return(lcd_drv->GetLcdPixelWidth());
- }
- /**
- * @brief Gets the LCD Y size.
- * @retval Used LCD Y size
- */
- uint32_t BSP_LCD_GetYSize(void)
- {
- return(lcd_drv->GetLcdPixelHeight());
- }
- /**
- * @brief Gets the LCD text color.
- * @retval Used text color.
- */
- uint16_t BSP_LCD_GetTextColor(void)
- {
- return DrawProp.TextColor;
- }
- /**
- * @brief Gets the LCD background color.
- * @retval Used background color
- */
- uint16_t BSP_LCD_GetBackColor(void)
- {
- return DrawProp.BackColor;
- }
- /**
- * @brief Sets the LCD text color.
- * @param Color: Text color code RGB(5-6-5)
- */
- void BSP_LCD_SetTextColor(uint16_t Color)
- {
- DrawProp.TextColor = Color;
- }
- /**
- * @brief Sets the LCD background color.
- * @param Color: Background color code RGB(5-6-5)
- */
- void BSP_LCD_SetBackColor(uint16_t Color)
- {
- DrawProp.BackColor = Color;
- }
- /**
- * @brief Sets the LCD text font.
- * @param fonts: Font to be used
- */
- void BSP_LCD_SetFont(sFONT *fonts)
- {
- DrawProp.pFont = fonts;
- }
- /**
- * @brief Gets the LCD text font.
- * @retval Used font
- */
- sFONT *BSP_LCD_GetFont(void)
- {
- return DrawProp.pFont;
- }
- /**
- * @brief Clears the hole LCD.
- * @param Color: Color of the background
- */
- void BSP_LCD_Clear(uint16_t Color)
- {
- uint32_t counter = 0;
- uint32_t color_backup = DrawProp.TextColor;
- DrawProp.TextColor = Color;
-
- for(counter = 0; counter < BSP_LCD_GetYSize(); counter++)
- {
- BSP_LCD_DrawHLine(0, counter, BSP_LCD_GetXSize());
- }
- DrawProp.TextColor = color_backup;
- BSP_LCD_SetTextColor(DrawProp.TextColor);
- }
- /**
- * @brief Clears the selected line.
- * @param Line: Line to be cleared
- * This parameter can be one of the following values:
- * @arg 0..9: if the Current fonts is Font16x24
- * @arg 0..19: if the Current fonts is Font12x12 or Font8x12
- * @arg 0..29: if the Current fonts is Font8x8
- */
- void BSP_LCD_ClearStringLine(uint16_t Line)
- {
- uint32_t color_backup = DrawProp.TextColor;
- DrawProp.TextColor = DrawProp.BackColor;;
-
- /* Draw a rectangle with background color */
- BSP_LCD_FillRect(0, (Line * DrawProp.pFont->Height), BSP_LCD_GetXSize(), DrawProp.pFont->Height);
-
- DrawProp.TextColor = color_backup;
- BSP_LCD_SetTextColor(DrawProp.TextColor);
- }
- /**
- * @brief Displays one character.
- * @param Xpos: Start column address
- * @param Ypos: Line where to display the character shape.
- * @param Ascii: Character ascii code
- * This parameter must be a number between Min_Data = 0x20 and Max_Data = 0x7E
- */
- void BSP_LCD_DisplayChar(uint16_t Xpos, uint16_t Ypos, uint8_t Ascii)
- {
- DrawChar(Xpos, Ypos, &DrawProp.pFont->table[(Ascii-' ') *\
- DrawProp.pFont->Height * ((DrawProp.pFont->Width + 7) / 8)]);
- }
- /**
- * @brief Displays characters on the LCD.
- * @param Xpos: X position (in pixel)
- * @param Ypos: Y position (in pixel)
- * @param Text: Pointer to string to display on LCD
- * @param Mode: Display mode
- * This parameter can be one of the following values:
- * @arg CENTER_MODE
- * @arg RIGHT_MODE
- * @arg LEFT_MODE
- */
- void BSP_LCD_DisplayStringAt(uint16_t Xpos, uint16_t Ypos, uint8_t *Text, Line_ModeTypdef Mode)
- {
- uint16_t refcolumn = 1, i = 0;
- uint32_t size = 0, xsize = 0;
- uint8_t *ptr = Text;
-
- /* Get the text size */
- while (*ptr++) size ++ ;
-
- /* Characters number per line */
- xsize = (BSP_LCD_GetXSize()/DrawProp.pFont->Width);
-
- switch (Mode)
- {
- case CENTER_MODE:
- {
- refcolumn = Xpos + ((xsize - size)* DrawProp.pFont->Width) / 2;
- break;
- }
- case LEFT_MODE:
- {
- refcolumn = Xpos;
- break;
- }
- case RIGHT_MODE:
- {
- refcolumn = - Xpos + ((xsize - size)*DrawProp.pFont->Width);
- break;
- }
- default:
- {
- refcolumn = Xpos;
- break;
- }
- }
-
- /* Send the string character by character on lCD */
- while ((*Text != 0) & (((BSP_LCD_GetXSize() - (i*DrawProp.pFont->Width)) & 0xFFFF) >= DrawProp.pFont->Width))
- {
- /* Display one character on LCD */
- BSP_LCD_DisplayChar(refcolumn, Ypos, *Text);
- /* Decrement the column position by 16 */
- refcolumn += DrawProp.pFont->Width;
- /* Point on the next character */
- Text++;
- i++;
- }
- }
- /**
- * @brief Displays a character on the LCD.
- * @param Line: Line where to display the character shape
- * This parameter can be one of the following values:
- * @arg 0..9: if the Current fonts is Font16x24
- * @arg 0..19: if the Current fonts is Font12x12 or Font8x12
- * @arg 0..29: if the Current fonts is Font8x8
- * @param ptr: Pointer to string to display on LCD
- */
- void BSP_LCD_DisplayStringAtLine(uint16_t Line, uint8_t *ptr)
- {
- BSP_LCD_DisplayStringAt(0, LINE(Line), ptr, LEFT_MODE);
- }
- /**
- * @brief Reads an LCD pixel.
- * @param Xpos: X position
- * @param Ypos: Y position
- * @retval RGB pixel color
- */
- uint16_t BSP_LCD_ReadPixel(uint16_t Xpos, uint16_t Ypos)
- {
- uint16_t ret = 0;
-
- if(lcd_drv->ReadPixel != NULL)
- {
- ret = lcd_drv->ReadPixel(Xpos, Ypos);
- }
-
- return ret;
- }
- /**
- * @brief Draws a pixel on LCD.
- * @param Xpos: X position
- * @param Ypos: Y position
- * @param RGB_Code: Pixel color in RGB mode (5-6-5)
- */
- void BSP_LCD_DrawPixel(uint16_t Xpos, uint16_t Ypos, uint16_t RGB_Code)
- {
- if(lcd_drv->WritePixel != NULL)
- {
- lcd_drv->WritePixel(Xpos, Ypos, RGB_Code);
- }
- }
-
- /**
- * @brief Draws an horizontal line.
- * @param Xpos: X position
- * @param Ypos: Y position
- * @param Length: Line length
- */
- void BSP_LCD_DrawHLine(uint16_t Xpos, uint16_t Ypos, uint16_t Length)
- {
- uint32_t index = 0;
-
- if(lcd_drv->DrawHLine != NULL)
- {
- lcd_drv->DrawHLine(DrawProp.TextColor, Xpos, Ypos, Length);
- }
- else
- {
- for(index = 0; index < Length; index++)
- {
- BSP_LCD_DrawPixel((Xpos + index), Ypos, DrawProp.TextColor);
- }
- }
- }
- /**
- * @brief Draws a vertical line.
- * @param Xpos: X position
- * @param Ypos: Y position
- * @param Length: Line length
- */
- void BSP_LCD_DrawVLine(uint16_t Xpos, uint16_t Ypos, uint16_t Length)
- {
- uint32_t index = 0;
-
- if(lcd_drv->DrawVLine != NULL)
- {
- lcd_drv->DrawVLine(DrawProp.TextColor, Xpos, Ypos, Length);
- }
- else
- {
- for(index = 0; index < Length; index++)
- {
- BSP_LCD_DrawPixel(Xpos, Ypos + index, DrawProp.TextColor);
- }
- }
- }
- /**
- * @brief Draws an uni-line (between two points).
- * @param x1: Point 1 X position
- * @param y1: Point 1 Y position
- * @param x2: Point 2 X position
- * @param y2: Point 2 Y position
- */
- void BSP_LCD_DrawLine(uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2)
- {
- int16_t deltax = 0, deltay = 0, x = 0, y = 0, xinc1 = 0, xinc2 = 0,
- yinc1 = 0, yinc2 = 0, den = 0, num = 0, numadd = 0, numpixels = 0,
- curpixel = 0;
-
- deltax = ABS(x2 - x1); /* The difference between the x's */
- deltay = ABS(y2 - y1); /* The difference between the y's */
- x = x1; /* Start x off at the first pixel */
- y = y1; /* Start y off at the first pixel */
-
- if (x2 >= x1) /* The x-values are increasing */
- {
- xinc1 = 1;
- xinc2 = 1;
- }
- else /* The x-values are decreasing */
- {
- xinc1 = -1;
- xinc2 = -1;
- }
-
- if (y2 >= y1) /* The y-values are increasing */
- {
- yinc1 = 1;
- yinc2 = 1;
- }
- else /* The y-values are decreasing */
- {
- yinc1 = -1;
- yinc2 = -1;
- }
-
- if (deltax >= deltay) /* There is at least one x-value for every y-value */
- {
- xinc1 = 0; /* Don't change the x when numerator >= denominator */
- yinc2 = 0; /* Don't change the y for every iteration */
- den = deltax;
- num = deltax / 2;
- numadd = deltay;
- numpixels = deltax; /* There are more x-values than y-values */
- }
- else /* There is at least one y-value for every x-value */
- {
- xinc2 = 0; /* Don't change the x for every iteration */
- yinc1 = 0; /* Don't change the y when numerator >= denominator */
- den = deltay;
- num = deltay / 2;
- numadd = deltax;
- numpixels = deltay; /* There are more y-values than x-values */
- }
-
- for (curpixel = 0; curpixel <= numpixels; curpixel++)
- {
- BSP_LCD_DrawPixel(x, y, DrawProp.TextColor); /* Draw the current pixel */
- num += numadd; /* Increase the numerator by the top of the fraction */
- if (num >= den) /* Check if numerator >= denominator */
- {
- num -= den; /* Calculate the new numerator value */
- x += xinc1; /* Change the x as appropriate */
- y += yinc1; /* Change the y as appropriate */
- }
- x += xinc2; /* Change the x as appropriate */
- y += yinc2; /* Change the y as appropriate */
- }
- }
- /**
- * @brief Draws a rectangle.
- * @param Xpos: X position
- * @param Ypos: Y position
- * @param Width: Rectangle width
- * @param Height: Rectangle height
- */
- void BSP_LCD_DrawRect(uint16_t Xpos, uint16_t Ypos, uint16_t Width, uint16_t Height)
- {
- /* Draw horizontal lines */
- BSP_LCD_DrawHLine(Xpos, Ypos, Width);
- BSP_LCD_DrawHLine(Xpos, (Ypos+ Height), Width);
-
- /* Draw vertical lines */
- BSP_LCD_DrawVLine(Xpos, Ypos, Height);
- BSP_LCD_DrawVLine((Xpos + Width), Ypos, Height);
- }
-
- /**
- * @brief Draws a circle.
- * @param Xpos: X position
- * @param Ypos: Y position
- * @param Radius: Circle radius
- */
- void BSP_LCD_DrawCircle(uint16_t Xpos, uint16_t Ypos, uint16_t Radius)
- {
- int32_t D; /* Decision Variable */
- uint32_t CurX; /* Current X Value */
- uint32_t CurY; /* Current Y Value */
-
- D = 3 - (Radius << 1);
- CurX = 0;
- CurY = Radius;
-
- while (CurX <= CurY)
- {
- BSP_LCD_DrawPixel((Xpos + CurX), (Ypos - CurY), DrawProp.TextColor);
- BSP_LCD_DrawPixel((Xpos - CurX), (Ypos - CurY), DrawProp.TextColor);
- BSP_LCD_DrawPixel((Xpos + CurY), (Ypos - CurX), DrawProp.TextColor);
- BSP_LCD_DrawPixel((Xpos - CurY), (Ypos - CurX), DrawProp.TextColor);
- BSP_LCD_DrawPixel((Xpos + CurX), (Ypos + CurY), DrawProp.TextColor);
- BSP_LCD_DrawPixel((Xpos - CurX), (Ypos + CurY), DrawProp.TextColor);
- BSP_LCD_DrawPixel((Xpos + CurY), (Ypos + CurX), DrawProp.TextColor);
- BSP_LCD_DrawPixel((Xpos - CurY), (Ypos + CurX), DrawProp.TextColor);
- /* Initialize the font */
- BSP_LCD_SetFont(&LCD_DEFAULT_FONT);
- if (D < 0)
- {
- D += (CurX << 2) + 6;
- }
- else
- {
- D += ((CurX - CurY) << 2) + 10;
- CurY--;
- }
- CurX++;
- }
- }
- /**
- * @brief Draws an poly-line (between many points).
- * @param Points: Pointer to the points array
- * @param PointCount: Number of points
- */
- void BSP_LCD_DrawPolygon(pPoint Points, uint16_t PointCount)
- {
- int16_t X = 0, Y = 0;
- if(PointCount < 2)
- {
- return;
- }
- BSP_LCD_DrawLine(Points->X, Points->Y, (Points+PointCount-1)->X, (Points+PointCount-1)->Y);
-
- while(--PointCount)
- {
- X = Points->X;
- Y = Points->Y;
- Points++;
- BSP_LCD_DrawLine(X, Y, Points->X, Points->Y);
- }
-
- }
- /**
- * @brief Draws an ellipse on LCD.
- * @param Xpos: X position
- * @param Ypos: Y position
- * @param XRadius: Ellipse X radius
- * @param YRadius: Ellipse Y radius
- */
- void BSP_LCD_DrawEllipse(int Xpos, int Ypos, int XRadius, int YRadius)
- {
- int x = 0, y = -YRadius, err = 2-2*XRadius, e2;
- float K = 0, rad1 = 0, rad2 = 0;
-
- rad1 = XRadius;
- rad2 = YRadius;
-
- K = (float)(rad2/rad1);
-
- do {
- BSP_LCD_DrawPixel((Xpos-(uint16_t)(x/K)), (Ypos+y), DrawProp.TextColor);
- BSP_LCD_DrawPixel((Xpos+(uint16_t)(x/K)), (Ypos+y), DrawProp.TextColor);
- BSP_LCD_DrawPixel((Xpos+(uint16_t)(x/K)), (Ypos-y), DrawProp.TextColor);
- BSP_LCD_DrawPixel((Xpos-(uint16_t)(x/K)), (Ypos-y), DrawProp.TextColor);
-
- e2 = err;
- if (e2 <= x) {
- err += ++x*2+1;
- if (-y == x && e2 <= y) e2 = 0;
- }
- if (e2 > y) err += ++y*2+1;
- }
- while (y <= 0);
- }
- /**
- * @brief Draws a bitmap picture (16 bpp).
- * @param Xpos: Bmp X position in the LCD
- * @param Ypos: Bmp Y position in the LCD
- * @param pbmp: Pointer to Bmp picture address.
- */
- void BSP_LCD_DrawBitmap(uint16_t Xpos, uint16_t Ypos, uint8_t *pbmp)
- {
- uint32_t height = 0;
- uint32_t width = 0;
- /* Read bitmap width */
- width = pbmp[18] + (pbmp[19] << 8) + (pbmp[20] << 16) + (pbmp[21] << 24);
- /* Read bitmap height */
- height = pbmp[22] + (pbmp[23] << 8) + (pbmp[24] << 16) + (pbmp[25] << 24);
- SetDisplayWindow(Xpos, Ypos, width, height);
-
- if(lcd_drv->DrawBitmap != NULL)
- {
- lcd_drv->DrawBitmap(Xpos, Ypos, pbmp);
- }
- SetDisplayWindow(0, 0, BSP_LCD_GetXSize(), BSP_LCD_GetYSize());
- }
- /**
- * @brief Draws RGB Image (16 bpp).
- * @param Xpos: X position in the LCD
- * @param Ypos: Y position in the LCD
- * @param Xsize: X size in the LCD
- * @param Ysize: Y size in the LCD
- * @param pdata: Pointer to the RGB Image address.
- */
- void BSP_LCD_DrawRGBImage(uint16_t Xpos, uint16_t Ypos, uint16_t Xsize, uint16_t Ysize, uint8_t *pdata)
- {
-
- SetDisplayWindow(Xpos, Ypos, Xsize, Ysize);
-
- if(lcd_drv->DrawRGBImage != NULL)
- {
- lcd_drv->DrawRGBImage(Xpos, Ypos, Xsize, Ysize, pdata);
- }
- SetDisplayWindow(0, 0, BSP_LCD_GetXSize(), BSP_LCD_GetYSize());
- }
- /**
- * @brief Draws a full rectangle.
- * @param Xpos: X position
- * @param Ypos: Y position
- * @param Width: Rectangle width
- * @param Height: Rectangle height
- */
- void BSP_LCD_FillRect(uint16_t Xpos, uint16_t Ypos, uint16_t Width, uint16_t Height)
- {
- BSP_LCD_SetTextColor(DrawProp.TextColor);
- do
- {
- BSP_LCD_DrawHLine(Xpos, Ypos++, Width);
- }
- while(Height--);
- }
- /**
- * @brief Draws a full circle.
- * @param Xpos: X position
- * @param Ypos: Y position
- * @param Radius: Circle radius
- */
- void BSP_LCD_FillCircle(uint16_t Xpos, uint16_t Ypos, uint16_t Radius)
- {
- int32_t D; /* Decision Variable */
- uint32_t CurX; /* Current X Value */
- uint32_t CurY; /* Current Y Value */
-
- D = 3 - (Radius << 1);
- CurX = 0;
- CurY = Radius;
-
- BSP_LCD_SetTextColor(DrawProp.TextColor);
- while (CurX <= CurY)
- {
- if(CurY > 0)
- {
- BSP_LCD_DrawHLine(Xpos - CurY, Ypos + CurX, 2*CurY);
- BSP_LCD_DrawHLine(Xpos - CurY, Ypos - CurX, 2*CurY);
- }
- if(CurX > 0)
- {
- BSP_LCD_DrawHLine(Xpos - CurX, Ypos - CurY, 2*CurX);
- BSP_LCD_DrawHLine(Xpos - CurX, Ypos + CurY, 2*CurX);
- }
- if (D < 0)
- {
- D += (CurX << 2) + 6;
- }
- else
- {
- D += ((CurX - CurY) << 2) + 10;
- CurY--;
- }
- CurX++;
- }
- BSP_LCD_SetTextColor(DrawProp.TextColor);
- BSP_LCD_DrawCircle(Xpos, Ypos, Radius);
- }
- /**
- * @brief Draws a full poly-line (between many points).
- * @param Points: Pointer to the points array
- * @param PointCount: Number of points
- */
- void BSP_LCD_FillPolygon(pPoint Points, uint16_t PointCount)
- {
-
- 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;
- uint16_t IMAGE_LEFT = 0, IMAGE_RIGHT = 0, IMAGE_TOP = 0, IMAGE_BOTTOM = 0;
-
- IMAGE_LEFT = IMAGE_RIGHT = Points->X;
- IMAGE_TOP= IMAGE_BOTTOM = Points->Y;
-
- for(counter = 1; counter < PointCount; counter++)
- {
- pixelX = POLY_X(counter);
- if(pixelX < IMAGE_LEFT)
- {
- IMAGE_LEFT = pixelX;
- }
- if(pixelX > IMAGE_RIGHT)
- {
- IMAGE_RIGHT = pixelX;
- }
-
- pixelY = POLY_Y(counter);
- if(pixelY < IMAGE_TOP)
- {
- IMAGE_TOP = pixelY;
- }
- if(pixelY > IMAGE_BOTTOM)
- {
- IMAGE_BOTTOM = pixelY;
- }
- }
-
- if(PointCount < 2)
- {
- return;
- }
-
- X_center = (IMAGE_LEFT + IMAGE_RIGHT)/2;
- Y_center = (IMAGE_BOTTOM + IMAGE_TOP)/2;
-
- X_first = Points->X;
- Y_first = Points->Y;
-
- while(--PointCount)
- {
- X = Points->X;
- Y = Points->Y;
- Points++;
- X2 = Points->X;
- Y2 = Points->Y;
-
- FillTriangle(X, X2, X_center, Y, Y2, Y_center);
- FillTriangle(X, X_center, X2, Y, Y_center, Y2);
- FillTriangle(X_center, X2, X, Y_center, Y2, Y);
- }
-
- FillTriangle(X_first, X2, X_center, Y_first, Y2, Y_center);
- FillTriangle(X_first, X_center, X2, Y_first, Y_center, Y2);
- FillTriangle(X_center, X2, X_first, Y_center, Y2, Y_first);
- }
- /**
- * @brief Draws a full ellipse.
- * @param Xpos: X position
- * @param Ypos: Y position
- * @param XRadius: Ellipse X radius
- * @param YRadius: Ellipse Y radius
- */
- void BSP_LCD_FillEllipse(int Xpos, int Ypos, int XRadius, int YRadius)
- {
- int x = 0, y = -YRadius, err = 2-2*XRadius, e2;
- float K = 0, rad1 = 0, rad2 = 0;
-
- rad1 = XRadius;
- rad2 = YRadius;
-
- K = (float)(rad2/rad1);
-
- do
- {
- BSP_LCD_DrawHLine((Xpos-(uint16_t)(x/K)), (Ypos+y), (2*(uint16_t)(x/K) + 1));
- BSP_LCD_DrawHLine((Xpos-(uint16_t)(x/K)), (Ypos-y), (2*(uint16_t)(x/K) + 1));
-
- e2 = err;
- if (e2 <= x)
- {
- err += ++x*2+1;
- if (-y == x && e2 <= y) e2 = 0;
- }
- if (e2 > y) err += ++y*2+1;
- }
- while (y <= 0);
- }
- /**
- * @brief Enables the display.
- */
- void BSP_LCD_DisplayOn(void)
- {
- lcd_drv->DisplayOn();
- }
- /**
- * @brief Disables the display.
- */
- void BSP_LCD_DisplayOff(void)
- {
- lcd_drv->DisplayOff();
- }
- /******************************************************************************
- Static Function
- *******************************************************************************/
- /**
- * @brief Draws a character on LCD.
- * @param Xpos: Line where to display the character shape
- * @param Ypos: Start column address
- * @param c: Pointer to the character data
- */
- static void DrawChar(uint16_t Xpos, uint16_t Ypos, const uint8_t *c)
- {
- uint32_t i = 0, j = 0;
- uint16_t height, width;
- uint8_t offset;
- uint8_t *pchar;
- uint32_t line;
-
- height = DrawProp.pFont->Height;
- width = DrawProp.pFont->Width;
-
- offset = 8 *((width + 7)/8) - width ;
-
- for(i = 0; i < height; i++)
- {
- pchar = ((uint8_t *)c + (width + 7)/8 * i);
-
- switch(((width + 7)/8))
- {
- case 1:
- line = pchar[0];
- break;
- case 2:
- line = (pchar[0]<< 8) | pchar[1];
- break;
-
- case 3:
- default:
- line = (pchar[0]<< 16) | (pchar[1]<< 8) | pchar[2];
- break;
- }
-
- for (j = 0; j < width; j++)
- {
- if(line & (1 << (width- j + offset- 1)))
- {
- BSP_LCD_DrawPixel((Xpos + j), Ypos, DrawProp.TextColor);
- }
- else
- {
- BSP_LCD_DrawPixel((Xpos + j), Ypos, DrawProp.BackColor);
- }
- }
- Ypos++;
- }
- }
- /**
- * @brief Sets display window.
- * @param Xpos: LCD X position
- * @param Ypos: LCD Y position
- * @param Width: LCD window width
- * @param Height: LCD window height
- */
- static void SetDisplayWindow(uint16_t Xpos, uint16_t Ypos, uint16_t Width, uint16_t Height)
- {
- if(lcd_drv->SetDisplayWindow != NULL)
- {
- lcd_drv->SetDisplayWindow(Xpos, Ypos, Width, Height);
- }
- }
- /**
- * @brief Fills a triangle (between 3 points).
- * @param x1: Point 1 X position
- * @param y1: Point 1 Y position
- * @param x2: Point 2 X position
- * @param y2: Point 2 Y position
- * @param x3: Point 3 X position
- * @param y3: Point 3 Y position
- */
- static void FillTriangle(uint16_t x1, uint16_t x2, uint16_t x3, uint16_t y1, uint16_t y2, uint16_t y3)
- {
- int16_t deltax = 0, deltay = 0, x = 0, y = 0, xinc1 = 0, xinc2 = 0,
- yinc1 = 0, yinc2 = 0, den = 0, num = 0, numadd = 0, numpixels = 0,
- curpixel = 0;
-
- deltax = ABS(x2 - x1); /* The difference between the x's */
- deltay = ABS(y2 - y1); /* The difference between the y's */
- x = x1; /* Start x off at the first pixel */
- y = y1; /* Start y off at the first pixel */
-
- if (x2 >= x1) /* The x-values are increasing */
- {
- xinc1 = 1;
- xinc2 = 1;
- }
- else /* The x-values are decreasing */
- {
- xinc1 = -1;
- xinc2 = -1;
- }
-
- if (y2 >= y1) /* The y-values are increasing */
- {
- yinc1 = 1;
- yinc2 = 1;
- }
- else /* The y-values are decreasing */
- {
- yinc1 = -1;
- yinc2 = -1;
- }
-
- if (deltax >= deltay) /* There is at least one x-value for every y-value */
- {
- xinc1 = 0; /* Don't change the x when numerator >= denominator */
- yinc2 = 0; /* Don't change the y for every iteration */
- den = deltax;
- num = deltax / 2;
- numadd = deltay;
- numpixels = deltax; /* There are more x-values than y-values */
- }
- else /* There is at least one y-value for every x-value */
- {
- xinc2 = 0; /* Don't change the x for every iteration */
- yinc1 = 0; /* Don't change the y when numerator >= denominator */
- den = deltay;
- num = deltay / 2;
- numadd = deltax;
- numpixels = deltay; /* There are more y-values than x-values */
- }
-
- for (curpixel = 0; curpixel <= numpixels; curpixel++)
- {
- BSP_LCD_DrawLine(x, y, x3, y3);
-
- num += numadd; /* Increase the numerator by the top of the fraction */
- if (num >= den) /* Check if numerator >= denominator */
- {
- num -= den; /* Calculate the new numerator value */
- x += xinc1; /* Change the x as appropriate */
- y += yinc1; /* Change the y as appropriate */
- }
- x += xinc2; /* Change the x as appropriate */
- y += yinc2; /* Change the y as appropriate */
- }
- }
- /**
- * @}
- */
-
- /**
- * @}
- */
-
- /**
- * @}
- */
- /**
- * @}
- */
- /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|