📄 drv_glcd.c
字号:
LCD_CTRL_bit.LcdPwr= 1; // enable power
}
else
{
LCD_CTRL_bit.LcdPwr= 0; // disable power
for(volatile Int32U i = C_GLCD_PWR_ENA_DIS_DLY; i; i--);
LCD_CTRL_bit.LcdEn = 0;
}
}
/*************************************************************************
* Function Name: GLCD_SetFont
* Parameters: pFontType_t pFont, LdcPixel_t Color
* LdcPixel_t BackgndColor
*
* Return: none
*
* Description: Set current font, font color and background color
*
*************************************************************************/
void GLCD_SetFont(pFontType_t pFont, LdcPixel_t Color, LdcPixel_t BackgndColor)
{
pCurrFont = pFont;
TextColour = Color;
TextBackgndColour = BackgndColor;
}
/*************************************************************************
* Function Name: GLCD_SetWindow
* Parameters: Int32U X_Left, Int32U Y_Up,
* Int32U X_Right, Int32U Y_Down
*
* Return: none
*
* Description: Set draw window XY coordinate in pixels
*
*************************************************************************/
void GLCD_SetWindow(Int32U X_Left, Int32U Y_Up,
Int32U X_Right, Int32U Y_Down)
{
assert(X_Right < C_GLCD_H_SIZE);
assert(Y_Down < C_GLCD_V_SIZE);
assert(X_Left < X_Right);
assert(Y_Up < Y_Down);
XL_Win = X_Left;
YU_Win = Y_Up;
XR_Win = X_Right;
YD_Win = Y_Down;
}
/*************************************************************************
* Function Name: GLCD_TextSetPos
* Parameters: Int32U X_UpLeft, Int32U Y_UpLeft,
* Int32U X_DownLeft, Int32U Y_DownLeft
*
* Return: none
*
* Description: Set text X,Y coordinate in characters
*
*************************************************************************/
void GLCD_TextSetPos(Int32U X, Int32U Y)
{
TextX_Pos = X;
TextY_Pos = Y;
}
/*************************************************************************
* Function Name: GLCD_TextSetTabSize
* Parameters: Int32U Size
*
* Return: none
*
* Description: Set text tab size in characters
*
*************************************************************************/
void GLCD_TextSetTabSize(Int32U Size)
{
TabSize = Size;
}
/*************************************************************************
* Function Name: LCD_SET_WINDOW
* Parameters: int c
*
* Return: none
*
* Description: Put char function
*
*************************************************************************/
static
void LCD_SET_WINDOW (Int32U X_Left, Int32U X_Right,
Int32U Y_Up, Int32U Y_Down)
{
pPix = pWind = ((pInt32U)0xA0000000) + X_Left + (Y_Up*C_GLCD_H_SIZE);
WindX_Size = X_Right - X_Left;
WindY_Size = Y_Down - Y_Up;
CurrX_Size = CurrY_Size = 0;
}
/*************************************************************************
* Function Name: LCD_SET_WINDOW
* Parameters: int c
*
* Return: none
*
* Description: Put char function
*
*************************************************************************/
static
void LCD_WRITE_PIXEL (Int32U Pixel)
{
*pPix++ = Pixel;
if (++CurrX_Size > WindX_Size)
{
CurrX_Size = 0;
if(++CurrY_Size > WindY_Size)
{
CurrY_Size = 0;
}
pPix = pWind + CurrY_Size * C_GLCD_H_SIZE;
}
}
/*************************************************************************
* Function Name: GLCD_TextCalcWindow
* Parameters: pInt32U pXL, pInt32U pXR,
* pInt32U pYU, pInt32U pYD,
* pInt32U pH_Size, pInt32U pV_Size
*
* Return: Boolean
* FALSE - out of window coordinate aren't valid
* TRUE - the returned coordinate are valid
*
* Description: Calculate character window
*
*************************************************************************/
static
Boolean GLCD_TextCalcWindow (pInt32U pXL, pInt32U pXR,
pInt32U pYU, pInt32U pYD,
pInt32U pH_Size, pInt32U pV_Size)
{
*pH_Size = pCurrFont->H_Size;
*pV_Size = pCurrFont->V_Size;
*pXL = XL_Win + (TextX_Pos*pCurrFont->H_Size);
if(*pXL > XR_Win)
{
return(FALSE);
}
*pYU = YU_Win + (TextY_Pos*pCurrFont->V_Size);
if(*pYU > YD_Win)
{
return(FALSE);
}
*pXR = XL_Win + ((TextX_Pos+1)*pCurrFont->H_Size) - 1;
if(*pXR > XR_Win)
{
*pH_Size -= *pXR - XR_Win;
*pXR = XR_Win;
}
*pYD = YU_Win + ((TextY_Pos+1)*pCurrFont->V_Size) - 1;
if(*pYD > YD_Win)
{
*pV_Size -= *pYD - YD_Win;
*pYD = YD_Win;
}
return(TRUE);
}
/*************************************************************************
* Function Name: putchar
* Parameters: int c
*
* Return: none
*
* Description: Put char function
*
*************************************************************************/
int putchar (int c)
{
pInt8U pSrc;
Int32U H_Line;
Int32U xl,xr,yu,yd,Temp,V_Size, H_Size, SrcInc = 1;
Int32U WhiteSpaceNumb;
if(pCurrFont == NULL)
{
return(EOF);
}
H_Line = (pCurrFont->H_Size / 8) + ((pCurrFont->H_Size % 8)?1:0);
switch(c)
{
case '\n': // go to begin of next line (NewLine)
++TextY_Pos;
break;
case '\r': // go to begin of this line (Carriage Return)
// clear from current position to end of line
while(GLCD_TextCalcWindow(&xl,&xr,&yu,&yd,&H_Size,&V_Size))
{
LCD_SET_WINDOW(xl,xr,yu,yd);
for(Int32U i = 0; i < V_Size; ++i)
{
for(Int32U j = 0; j < H_Size; ++j)
{
LCD_WRITE_PIXEL(TextBackgndColour);
}
}
++TextX_Pos;
}
TextX_Pos = 0;
break;
case '\b': // go back one position (BackSpace)
if(TextX_Pos)
{
--TextX_Pos;
// del current position
if(GLCD_TextCalcWindow(&xl,&xr,&yu,&yd,&H_Size,&V_Size))
{
LCD_SET_WINDOW(xl,xr,yu,yd);
for(Int32U i = 0; i < V_Size; ++i)
{
for(Int32U j = 0; j < H_Size; ++j)
{
LCD_WRITE_PIXEL(TextBackgndColour);
}
}
}
}
break;
case '\t': // go to next Horizontal Tab stop
WhiteSpaceNumb = TabSize - (TextX_Pos%TabSize);
for(Int32U k = 0; k < WhiteSpaceNumb; ++k)
{
LCD_SET_WINDOW(xl,xr,yu,yd);
if(GLCD_TextCalcWindow(&xl,&xr,&yu,&yd,&H_Size,&V_Size))
{
for(Int32U i = 0; i < V_Size; ++i)
{
for(Int32U j = 0; j < H_Size; ++j)
{
LCD_WRITE_PIXEL(TextBackgndColour);
}
}
++TextX_Pos;
}
else
{
break;
}
}
break;
case '\f': // go to top of page (Form Feed)
// clear entire window
H_Size = XR_Win - XL_Win;
V_Size = YD_Win - YU_Win;
// set character window X left, Y right
LCD_SET_WINDOW(XL_Win,XR_Win,YU_Win,YD_Win);
// Fill window with background font color
for(Int32U i = 0; i <= V_Size; ++i)
{
for(Int32U j = 0; j <= H_Size; ++j)
{
LCD_WRITE_PIXEL(TextBackgndColour);
}
}
TextX_Pos = TextY_Pos = 0;
break;
case '\a': // signal an alert (BELl)
TEXT_BEL1_FUNC();
break;
default:
// Calculate the current character base address from stream
// and the character position
if((c < pCurrFont->CharacterOffset) &&
(c >= pCurrFont->CharactersNuber))
{
c = 0;
}
else
{
c -= pCurrFont->CharacterOffset;
}
pSrc = pCurrFont->pFontStream + (H_Line * pCurrFont->V_Size * c);
// Calculate character window and fit it in the text window
if(GLCD_TextCalcWindow(&xl,&xr,&yu,&yd,&H_Size,&V_Size))
{
// set character window X left, Y right
LCD_SET_WINDOW(xl,xr,yu,yd);
// Send char data
for(Int32U i = 0; i < V_Size; ++i)
{
SrcInc = H_Line;
for(Int32U j = 0; j < H_Size; ++j)
{
Temp = (*pSrc & (1UL << (j&0x7)))?TextColour:TextBackgndColour;
LCD_WRITE_PIXEL(Temp);
if((j&0x7) == 7)
{
++pSrc;
--SrcInc;
}
}
// next line of character
pSrc += SrcInc;
}
}
++TextX_Pos;
}
return(c);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -