📄 lcd.c
字号:
/*********************************************************************************************
* File: lcd.c
* Author: embest
* Desc: LCD control and display functions
* History:
*********************************************************************************************/
#include "44b.h"
#include "44blib.h"
#include "lcd.h"
#include "bmp.h"
/*------------------------------------------------------------------------------------------*/
/* macro define */
/*------------------------------------------------------------------------------------------*/
#define DMA_Byte (0)
#define DMA_HW (1)
#define DMA_Word (2)
#define DW DMA_Byte // set ZDMA0 as half-word
#define CHINESE_VERSION 1
/*------------------------------------------------------------------------------------------*/
/* extern variables */
/*------------------------------------------------------------------------------------------*/
extern UINT8T g_ucAscii6x8[];
extern UINT8T g_ucAscii8x16[];
#ifdef CHINESE_VERSION
extern const UINT8T g_ucHZK16[];
#endif
extern STRU_BITMAP g_struBitmapMouse;
extern STRU_BITMAP g_struBitmapMouse1;
/*------------------------------------------------------------------------------------------*/
/* global variables */
/*------------------------------------------------------------------------------------------*/
static UINT8T f_ucZdma0Done=1; // When DMA is finish, f_ucZdma0Done is cleared to Zero
/*********************************************************************************************
* name: lcd_init()
* func: Initialize LCD Controller
* para: none
* ret: none
* modify:
* comment:
*********************************************************************************************/
void lcd_init(void)
{
rDITHMODE = 0x1223a;
rDP1_2 = 0x5a5a;
rDP4_7 = 0x366cd9b;
rDP3_5 = 0xda5a7;
rDP2_3 = 0xad7;
rDP5_7 = 0xfeda5b7;
rDP3_4 = 0xebd7;
rDP4_5 = 0xebfd7;
rDP6_7 = 0x7efdfbf;
rLCDCON1 = (0) | (1<<5) | (MVAL_USED<<7) | (0x0<<8) | (0x0<<10) | (CLKVAL_GREY16<<12);
rLCDCON2 = (LINEVAL) | (HOZVAL<<10) | (10<<21);
rLCDSADDR1 = (0x2<<27) | ( ((LCD_ACTIVE_BUFFER>>22)<<21 ) | M5D(LCD_ACTIVE_BUFFER>>1));
rLCDSADDR2 = M5D(((LCD_ACTIVE_BUFFER+(SCR_XSIZE*LCD_YSIZE/2))>>1)) | (MVAL<<21);
rLCDSADDR3 = (LCD_XSIZE/4) | ( ((SCR_XSIZE-LCD_XSIZE)/4)<<9 );
// Enable,4B_SNGL_SCAN,WDLY=8clk,WLH=8clk,
rLCDCON1 = (1) | (1<<5) | (MVAL_USED<<7) | (0x3<<8) | (0x3<<10) | (CLKVAL_GREY16<<12);
rBLUELUT = 0xfa40;
// Enable LCD Logic and EL back-light.
rPDATE=rPDATE&0x0e;
}
/*********************************************************************************************
* name: lcd_active_clr()
* func: clear LCD screen
* para: none
* ret: none
* modify:
* comment:
*********************************************************************************************/
void lcd_active_clr(void)
{
UINT32T i;
UINT32T *pDisp = (UINT32T *)LCD_ACTIVE_BUFFER;
for( i = 0; i < (SCR_XSIZE*SCR_YSIZE/2/4); i++ )
{
*pDisp++ = WHITE;
}
}
/*********************************************************************************************
* name: lcd_clr()
* func: clear virtual screen
* para: none
* ret: none
* modify:
* comment:
*********************************************************************************************/
void lcd_clr(void)
{
UINT32T i;
UINT32T *pDisp = (UINT32T*)LCD_VIRTUAL_BUFFER;
for( i = 0; i < (SCR_XSIZE*SCR_YSIZE/2/4); i++ )
{
*pDisp++ = WHITE;
}
}
/*********************************************************************************************
* name: lcd_getpixel()
* func: Get appointed point's color value
* para: usX,usY -- pot's X-Y coordinate
* ret: pot's color value
* modify:
* comment:
*********************************************************************************************/
UINT8T lcd_getpixel(UINT16T usX, UINT16T usY)
{
UINT8T ucColor;
ucColor = *((UINT8T*)(LCD_VIRTUAL_BUFFER + usY*SCR_XSIZE/2 + usX/8*4 + 3 - (usX%8)/2));
ucColor = (ucColor >> ((1-(usX%2))*4)) & 0x0f;
return ucColor;
}
/*********************************************************************************************
* name: lcd_clr_rect()
* func: fill appointed area with appointed color
* para: usLeft,usTop,usRight,usBottom -- area's rectangle acme coordinate
* ucColor -- appointed color value
* ret: none
* modify:
* comment: also as clear screen function
*********************************************************************************************/
void lcd_clr_rect(INT16T usLeft, INT16T usTop, INT16T usRight, INT16T usBottom, UINT8T ucColor)
{
INT16T i,j,k,l;
UINT32T ulColor = (ucColor << 28) | (ucColor << 24) | (ucColor << 20) | (ucColor << 16) |
(ucColor << 12) | (ucColor << 8) | (ucColor << 4) | ucColor;
i = j = k = l = 0;
if( (usRight-usLeft) <= 8 )
{
for( i=usTop; i<=usBottom; i++)
{
for( l=usLeft; l<=usRight; l++)
LCD_PUT_PIXEL(l, i, ucColor);
}
return;
}
// check borderline
if( 0 == (usLeft%8) )
j=usLeft;
else
j=(usLeft/8)*8+8;
if( 0 == (usRight%8) )
k= usRight;
else
k=(usRight/8)*8;
for( i=usTop; i<=usBottom; i++ )
{
for( l=usLeft; l<=(j-1); l++ )
LCD_PUT_PIXEL(l, i, ucColor);
for( l=j; l<k; l+=8 )
(*(UINT32T*)(LCD_VIRTUAL_BUFFER + i * SCR_XSIZE / 2 + l / 2)) = ulColor;
for( l=k; l<=usRight; l++ )
LCD_PUT_PIXEL(l, i, ucColor);
}
}
/*********************************************************************************************
* name: lcd_draw_box()
* func: Draw rectangle with appointed color
* para: usLeft,usTop,usRight,usBottom -- rectangle's acme coordinate
* ucColor -- appointed color value
* ret: none
* modify:
* comment:
*********************************************************************************************/
void lcd_draw_box(INT16T usLeft, INT16T usTop, INT16T usRight, INT16T usBottom, UINT8T ucColor)
{
lcd_draw_hline(usLeft, usRight, usTop, ucColor, 1);
lcd_draw_hline(usLeft, usRight, usBottom, ucColor, 1);
lcd_draw_vline(usTop, usBottom, usLeft, ucColor, 1);
lcd_draw_vline(usTop, usBottom, usRight, ucColor, 1);
}
/*********************************************************************************************
* name: lcd_draw_line()
* func: Draw line with appointed color
* para: usX0,usY0 -- input, line's start point coordinate
* usX1,usY1 -- input, line's end point coordinate
* ucColor -- input, appointed color value
* usWidth -- input, line's width
* ret: none
* modify:
* comment:
*********************************************************************************************/
void lcd_draw_line(INT16T usX0, INT16T usY0, INT16T usX1, INT16T usY1, UINT8T ucColor, UINT16T usWidth)
{
INT16T usDx;
INT16T usDy;
INT16T ucYSign;
INT16T ucXSign;
INT16T ucDecision;
INT16T wCurx, wCury, wNextx, wNexty, wpy, wpx;
if( usY0 == usY1 )
{
lcd_draw_hline (usX0, usX1, usY0, ucColor, usWidth);
return;
}
if( usX0 == usX1 )
{
lcd_draw_vline (usY0, usY1, usX0, ucColor, usWidth);
return;
}
usDx = abs(usX0 - usX1);
usDy = abs(usY0 - usY1);
if( ((usDx >= usDy && (usX0 > usX1)) ||
((usDy > usDx) && (usY0 > usY1))) )
{
GUISWAP(usX1, usX0);
GUISWAP(usY1, usY0);
}
ucYSign = (usY1 - usY0) / usDy;
ucXSign = (usX1 - usX0) / usDx;
if( usDx >= usDy )
{
for( wCurx = usX0, wCury = usY0, wNextx = usX1,
wNexty = usY1, ucDecision = (usDx >> 1);
wCurx <= wNextx; wCurx++, wNextx--, ucDecision += usDy )
{
if( ucDecision >= usDx )
{
ucDecision -= usDx;
wCury += ucYSign;
wNexty -= ucYSign;
}
for( wpy = wCury - usWidth / 2;
wpy <= wCury + usWidth / 2; wpy++ )
{
LCD_PUT_PIXEL(wCurx, wpy, ucColor);
}
for( wpy = wNexty - usWidth / 2;
wpy <= wNexty + usWidth / 2; wpy++ )
{
LCD_PUT_PIXEL(wNextx, wpy, ucColor);
}
}
}
else
{
for( wCurx = usX0, wCury = usY0, wNextx = usX1,
wNexty = usY1, ucDecision = (usDy >> 1);
wCury <= wNexty; wCury++, wNexty--, ucDecision += usDx )
{
if( ucDecision >= usDy )
{
ucDecision -= usDy;
wCurx += ucXSign;
wNextx -= ucXSign;
}
for(wpx = wCurx-usWidth/2; wpx <= wCurx+usWidth/2; wpx++ )
{
LCD_PUT_PIXEL(wpx, wCury, ucColor);
}
for(wpx = wNextx-usWidth/2; wpx <= wNextx+usWidth/2; wpx++)
{
LCD_PUT_PIXEL(wpx, wNexty, ucColor);
}
}
}
}
/*********************************************************************************************
* name: lcd_draw_hline()
* func: Draw horizontal line with appointed color
* para: usX0,usY0 -- line's start point coordinate
* usX1 -- line's end point X-coordinate
* ucColor -- appointed color value
* usWidth -- line's width
* ret: none
* modify:
* comment:
*********************************************************************************************/
void lcd_draw_hline(INT16T usX0, INT16T usX1, INT16T usY0, UINT8T ucColor, UINT16T usWidth)
{
INT16T usLen;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -