📄 lcdhal.c
字号:
/**
******************************************************************************
* @file LcdHal.c
* @author MCD Application Team
* @version V2.0.0
* @date 11-July-2011
* @brief This file contains all the LCD functions whose
* implementation depends on the LCD Type used in your Application.
* You only need to change these functions implementations
* in order to reuse this code with other LCD
******************************************************************************
* @attention
*
* THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
* WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE
* TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY
* DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING
* FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE
* CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
*
* <h2><center>© COPYRIGHT 2011 STMicroelectronics</center></h2>
******************************************************************************
*/
/* Includes ------------------------------------------------------------------*/
#include <stdlib.h>
#include "LcdHal.h"
#include "gl_fonts.h"
/** @addtogroup Embedded_GUI_Library
* @{
*/
/** @defgroup LcdHal
* @brief LcdHal main functions
* @{
*/
/* External variables --------------------------------------------------------*/
/* Private typedef -----------------------------------------------------------*/
typedef struct
{
__IO uint16_t LCD_REG;
__IO uint16_t LCD_RAM;
} GL_LCD_TypeDef;
/* Private defines -----------------------------------------------------------*/
#ifdef USE_STM3210E_EVAL
/* Note: LCD /CS is CE4 - Bank 4 of NOR/SRAM Bank 1~4 */
#define GL_LCD_BASE ((uint32_t)(0x60000000 | 0x0C000000))
#elif USE_STM322xG_EVAL
/* Note: LCD /CS is NE3 - Bank 3 of NOR/SRAM Bank 1~4 */
#define GL_LCD_BASE ((uint32_t)(0x60000000 | 0x08000000))
#elif USE_STM32100E_EVAL
/* Note: LCD /CS is CE4 - Bank 4 of NOR/SRAM Bank 1~4 */
#define GL_LCD_BASE ((uint32_t)(0x60000000 | 0x0C000000))
#endif
#define GL_LCD ((__IO GL_LCD_TypeDef *) GL_LCD_BASE)
#define RCC_AHBPeriph_FSMC ((uint32_t)0x00000100)
/* Private macros ------------------------------------------------------------*/
/* Private variables ---------------------------------------------------------*/
/* WARNING: If LcdHal functions are used by more Graphic Applications, remember that the
following static variables will be shared among the several Graphic Objects applications */
/* Global variables to handle the right font */
__IO uint8_t GL_Font = GL_FONT_BIG;
__IO uint8_t GL_FontWidth = GL_FONT_BIG_WIDTH;
__IO uint8_t GL_FontHeight = GL_FONT_BIG_HEIGHT;
uint16_t LCD_Height = 240;
uint16_t LCD_Width = 320;
LCD_Direction_TypeDef LCD_Direction = _0_degree;
/* LCD Hardware Parameters Structure */
LCD_HW_Parameters_TypeDef pLcdHwParam;
#if !defined(LCD_ILI9320)
#define LCD_ILI9320 0x9320
#endif
#if !defined(LCD_SPFD5408)
#define LCD_SPFD5408 0x5408
#endif
#if !defined(LCDType)
__IO uint32_t LCDType = LCD_ILI9320;
#else
extern __IO uint32_t LCDType;
#endif
__IO uint16_t GL_TextColor;
__IO uint16_t GL_BackColor;
/* Private function prototypes -----------------------------------------------*/
static void BmpBuffer32BitRead(uint32_t* ptr32BitBuffer, uint8_t* ptrBitmap);
/* Private functions ---------------------------------------------------------*/
/**
* @brief Create and initialize a new Lcd Hw Parameter structure object
* @param None
* @retval LCD_HW_Parameters_TypeDef* - The created Object pointer
*/
LCD_HW_Parameters_TypeDef* NewLcdHwParamObj ( void )
{
return &pLcdHwParam;
}
/**
* @brief Sets the Text color.
* @param Color: specifies the Text color code RGB(5-6-5).
* @param GL_TextColor: Text color global variable used by GL_DrawChar
* and GL_DrawPicture functions.
* @retval None
*/
void GL_SetTextColor(__IO uint16_t GL_NewTextColor)
{
GL_TextColor = GL_NewTextColor;
LCD_SetTextColor(GL_TextColor);
}
/**
* @brief Sets the Background color.
* @param Color: specifies the Background color code RGB(5-6-5).
* @param GL_BackColor: Background color global variable used by
* GL_DrawChar and GL_DrawPicture functions.
* @retval None
*/
void GL_SetBackColor(__IO uint16_t GL_NewBackColor)
{
GL_BackColor = GL_NewBackColor;
LCD_SetBackColor(GL_BackColor);
}
/**
* @brief Clears the whole LCD.
* @param Color: specifies the Background color code RGB(5-6-5) for the Display.
* @retval None
*/
void GL_Clear(uint16_t Color)
{
LCD_Clear(Color);
}
/**
* @brief Draws a character on LCD without background.
* @param Xpos: the Line where to display the character shape.
* This parameter can be one of the following values:
* @param Ypos: start column address.
* @param c: pointer to the character data.
* @retval None
*/
void GL_LCD_DrawCharTransparent(uint16_t Xpos, uint16_t Ypos, const uint16_t *c) /* 16bit char */
{
uint32_t line_index = 0, pixel_index = 0;
uint8_t Xaddress = 0;
uint16_t Yaddress = 0;
Xaddress = Xpos;
Yaddress = Ypos;
for (line_index = 0; line_index < GL_FontHeight; line_index++)
{
for (pixel_index = 0; pixel_index < GL_FontWidth; pixel_index++)
{
/* SmallFonts have bytes in reverse order */
if (( GL_Font == GL_FONT_BIG && (((const uint16_t*)c)[line_index] & (1 << pixel_index)) == 0x00) ||
( GL_Font == GL_FONT_SMALL && (((const uint16_t*)c)[line_index] & (0x80 >> pixel_index)) == 0x00))
{
Yaddress--;
}
else
{
LCD_PutPixel(Xaddress, Yaddress--, GL_TextColor, SinglePixel);
}
}
Xaddress++;
Yaddress = Ypos;
}
}
/**
* @brief Displays a maximum of 20 char on the LCD.
* @param Line: the Line where to display the character shape.
* @param *ptr: pointer to the string to display on LCD.
* @param Transparent_Flag: if TRUE the character is printed without changing the background
* @retval None
*/
void GL_DisplayAdjStringLine(uint16_t Line, uint16_t Column, uint8_t *ptr, GL_bool Transparent_Flag)
{
uint32_t index = 0;
uint32_t iMaxChar = (Column / (GL_FontWidth - 1));
/* Send the string character by character on lCD */
while ((*ptr != 0) & (index < iMaxChar))
{ /* Display one character on LCD */
GL_LCD_DisplayChar(Line, Column, *ptr, Transparent_Flag);
/* Decrement the column position by GL_FontWidth */
if ( *ptr == 'A' || *ptr == 'G' || *ptr == 'M' || *ptr == 'O' || *ptr == 'Q' || *ptr == 'X' || *ptr == 'm')
Column -= (GL_FontWidth);
else
Column -= (GL_FontWidth - 1);
/* Point on the next character */
ptr++;
/* Increment the character counter */
index++;
}
}
/**
* @brief Displays one character (16dots width, 24dots height).
* @param Line: the Line where to display the character shape.
* This parameter can be one of the following values:
* @arg - Linex: where x can be 0..9
* @param Column: start column address.
* @param Ascii: character ascii code, must be between 0x20 and 0x7E.
* @param GL_bool Trasparent_Flag, if TRUE it does not print the GL_BackColor
* @retval None
*/
void GL_LCD_DisplayChar(uint16_t Line, uint16_t Column, uint8_t Ascii, GL_bool Transparent_Flag)
{
Ascii -= 32;
switch (GL_Font)
{
case GL_FONT_BIG:
if (Transparent_Flag == GL_TRUE)
GL_LCD_DrawCharTransparent(Line, Column, &GL_Font16x24.table[Ascii * GL_FontHeight] );
else
GL_LCD_DrawChar(Line, Column, (&GL_Font16x24.table[Ascii * GL_FontHeight]));
break;
case GL_FONT_SMALL:
if (Transparent_Flag == GL_TRUE)
GL_LCD_DrawCharTransparent(Line, Column, &GL_Font8x12_bold.table[Ascii * GL_FontHeight] );
else
GL_LCD_DrawChar(Line, Column, &GL_Font8x12_bold.table[Ascii * GL_FontHeight]);
break;
default:
break;
}
}
/**
* @brief Sets a display window
* @param Xpos: specifies the X bottom left position.
* @param Ypos: specifies the Y bottom left position.
* @param Height: display window height.
* @param Width: display window width.
* @retval None
*/
void GL_SetDisplayWindow(uint16_t Xpos, uint16_t Ypos, uint16_t Height, uint16_t Width)
{
LCD_SetDisplayWindow(Xpos, Ypos, Height, Width);
}
/**
* @brief Displays a line.
* @param Xpos: specifies the X position.
* @param Ypos: specifies the Y position.
* @param Length: line length.
* @param Direction: line direction.
* This parameter can be one of the following values:
* @arg Vertical
* @arg Horizontal
* @retval None
*/
void GL_DrawLine(uint16_t Ypos, uint16_t Xpos, uint16_t Length, uint8_t Direction)
{
LCD_DrawLine(Ypos, Xpos, Length, Direction);
}
/**
* @brief Displays a rectangle.
* @param Xpos: specifies the X position.
* @param Ypos: specifies the Y position.
* @param Height: display rectangle height.
* @param Width: display rectangle width.
* @retval None
*/
void GL_LCD_DrawRect(uint8_t Xpos, uint16_t Ypos, uint8_t Height, uint16_t Width)
{
GL_DrawLine(Xpos, Ypos, Width, Horizontal);
GL_DrawLine((Xpos + Height), Ypos, Width, Horizontal);
GL_DrawLine(Xpos, Ypos, Height, Vertical);
GL_DrawLine(Xpos, (Ypos - Width + 1), Height, Vertical);
}
/**
* @brief Displays a circle.
* @param Xpos: specifies the X position.
* @param Ypos: specifies the Y position.
* @param Radius: the radius size of the circle
* @retval None
*/
void GL_LCD_DrawCircle(uint8_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)
{
LCD_SetCursor(Xpos + CurX, Ypos + CurY);
LCD_WriteRAMWord(GL_TextColor);
LCD_SetCursor(Xpos + CurX, Ypos - CurY);
LCD_WriteRAMWord(GL_TextColor);
LCD_SetCursor(Xpos - CurX, Ypos + CurY);
LCD_WriteRAMWord(GL_TextColor);
LCD_SetCursor(Xpos - CurX, Ypos - CurY);
LCD_WriteRAMWord(GL_TextColor);
LCD_SetCursor(Xpos + CurY, Ypos + CurX);
LCD_WriteRAMWord(GL_TextColor);
LCD_SetCursor(Xpos + CurY, Ypos - CurX);
LCD_WriteRAMWord(GL_TextColor);
LCD_SetCursor(Xpos - CurY, Ypos + CurX);
LCD_WriteRAMWord(GL_TextColor);
LCD_SetCursor(Xpos - CurY, Ypos - CurX);
LCD_WriteRAMWord(GL_TextColor);
if (D < 0)
{
D += (CurX << 2) + 6;
}
else
{
D += ((CurX - CurY) << 2) + 10;
CurY--;
}
CurX++;
}
}
/**
* @brief Displays a bitmap picture
* @param BmpAddress: Bmp picture address
* @retval None
*/
void GL_DrawBMP(uint8_t* ptrBitmap)
{
uint32_t uDataAddr = 0, uBmpSize = 0;
uint16_t uBmpData;
BmpBuffer32BitRead(&uBmpSize, ptrBitmap + 2);
BmpBuffer32BitRead(&uDataAddr, ptrBitmap + 10);
/* Set GRAM write direction and BGR = 1 */
/* I/D=00 (Horizontal : decrement, Vertical : decrement) */
/* AM=1 (address is updated in vertical writing direction) */
LCD_WriteReg(R3, 0x1008);
LCD_WriteRAM_Prepare(); /* Prepare to write GRAM */
/* Read bitmap data and write them to LCD */
for (; uDataAddr < uBmpSize; uDataAddr += 2)
{
uBmpData = (uint16_t)(*(ptrBitmap + uDataAddr)) + (uint16_t)((*(ptrBitmap + uDataAddr + 1)) << 8);
LCD_WriteRAM( uBmpData );
}
if ( pLcdHwParam.LCD_Connection_Mode == GL_SPI )
GL_LCD_CtrlLinesWrite(pLcdHwParam.LCD_Ctrl_Port_NCS, pLcdHwParam.LCD_Ctrl_Pin_NCS, GL_HIGH);
/* Set GRAM write direction and BGR = 1 */
/* I/D = 01 (Horizontal : increment, Vertical : decrement) */
/* AM = 1 (address is updated in vertical writing direction) */
LCD_WriteReg(R3, 0x1018);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -