/**
******************************************************************************
* @file stm32072b_eval_lcd.c
* @author MCD Application Team
* @brief This file includes the driver for Liquid Crystal Display modules
* mounted on STM32072B-EVAL evaluation board.
******************************************************************************
* @attention
*
* <h2><center>© COPYRIGHT(c) 2016 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 AM-240320LDTNQW00H (SPFD5408D) and
AM240320LGTNQW00H (HX8347D) LCD mounted on MB895 daughter board
- The SPFD5408D and HX8347D components driver MUST be included with this driver.
2. Driver description:
---------------------
+ Initialization steps:
o Initialize the LCD using the LCD_Init() function.
+ Display on LCD
o Clear the hole LCD using yhe LCD_Clear() function or only one specified
string line using the LCD_ClearStringLine() function.
o Display a character on the specified line and column using the LCD_DisplayChar()
function or a complete string line using the LCD_DisplayStringAtLine() function.
o Display a string line on the specified position (x,y in pixel) and align mode
using the LCD_DisplayStringAtLine() function.
o Draw and fill a basic shapes (dot, line, rectangle, circle, ellipse, .. bitmap)
on LCD using a set of functions.
------------------------------------------------------------------------------*/
/* Includes ------------------------------------------------------------------*/
#include "stm32072b_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 STM32072B_EVAL
* @{
*/
/** @addtogroup STM32072B_EVAL_LCD
* @{
*/
/** @defgroup STM32072B_EVAL_LCD_Private_Constants Private Constants
* @{
*/
#define POLY_X(Z) ((int32_t)((pPoints + (Z))->X))
#define POLY_Y(Z) ((int32_t)((pPoints + (Z))->Y))
#define MAX_HEIGHT_FONT 17
#define MAX_WIDTH_FONT 24
#define OFFSET_BITMAP 54
/**
* @}
*/
/** @defgroup STM32072B_EVAL_LCD_Private_Macros Private Macros
* @{
*/
#define ABS(X) ((X) > 0 ? (X) : -(X))
/**
* @}
*/
/** @defgroup STM32072B_EVAL_LCD_Private_Variables Private Variables
* @{
*/
LCD_DrawPropTypeDef DrawProp;
static LCD_DrvTypeDef *lcd_drv;
/* Max size of bitmap will based on a font24 (17x24) */
static uint8_t bitmap[MAX_HEIGHT_FONT*MAX_WIDTH_FONT*2+OFFSET_BITMAP] = {0};
/**
* @}
*/
/** @defgroup STM32072B_EVAL_LCD_Private_Functions Private Functions
* @{
*/
static void LCD_DrawPixel(uint16_t Xpos, uint16_t Ypos, uint16_t RGBCode);
static void LCD_DrawChar(uint16_t Xpos, uint16_t Ypos, const uint8_t *pChar);
static void LCD_SetDisplayWindow(uint16_t Xpos, uint16_t Ypos, uint16_t Width, uint16_t Height);
/**
* @}
*/
/** @addtogroup STM32072B_EVAL_LCD_Exported_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(spfd5408_drv.ReadID() == SPFD5408_ID)
{
lcd_drv = &spfd5408_drv;
ret = LCD_OK;
}
else
{
/*HX8347D_ID connected*/
lcd_drv = &hx8347d_drv;
ret = LCD_OK;
}
if(ret != LCD_ERROR)
{
/* LCD Init */
lcd_drv->Init();
/* Initialize the font */
BSP_LCD_SetFont(&LCD_DEFAULT_FONT);
}
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)
* @retval None
*/
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)
* @retval None
*/
void BSP_LCD_SetBackColor(uint16_t Color)
{
DrawProp.BackColor = Color;
}
/**
* @brief Sets the LCD text font.
* @param pFonts Font to be used
* @retval None
*/
void BSP_LCD_SetFont(sFONT *pFonts)
{
DrawProp.pFont = pFonts;
}
/**
* @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
* @retval None
*/
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