📄 lcdlib.c
字号:
#include "44b.h"
#include "def.h"
#include "option.h"
#include "utils.h"
#include "GUI.h"
#include "lcd.h"
#include "lcdlib.h"
#include "glib.h"
#include "slib.h"
#include "..\include\math.h"
extern int EnableInterrupt( void ) ;
extern int DisableInterrupt( void ) ;
//SCR_XSIZE,SCR_YSIZE,LCD_XSIZE,LCD_YSIZE are defined in lcd.h
#define M5D(n) ((n) & 0x1fffff)
#define ARRAY_SIZE_MONO (SCR_XSIZE/8*SCR_YSIZE)
#define ARRAY_SIZE_G4 (SCR_XSIZE/4*SCR_YSIZE)
#define ARRAY_SIZE_G16 (SCR_XSIZE/2*SCR_YSIZE)
#define ARRAY_SIZE_COLOR (SCR_XSIZE/1*SCR_YSIZE)
#define HOZVAL (LCD_XSIZE/4-1)
#define HOZVAL_COLOR (LCD_XSIZE*3/8-1)
#define LINEVAL (LCD_YSIZE/2-1)
#define MVAL (13)
#define BSWP (0)//这个决定了每4 个字节的顺序是否进行交换
#define CLKVAL_MONO (6)
#define CLKVAL_G4 (6)
#define CLKVAL_G16 (6)
#define CLKVAL_COLOR (6)
#define MVAL_USED 0
U32 (*frameBuffer1)[SCR_XSIZE/32];
unsigned int (*frameBuffer4)[SCR_XSIZE/16];
unsigned int (*frameBuffer16)[SCR_XSIZE/8];
unsigned int (*frameBuffer256)[SCR_XSIZE/4];
#define MVAL_USED 0
//***************************************************************************
#define STACKSIZE 0xa00
//SVC satck size(do not use user stack)
#define HEAPEND (_ISR_STARTADDRESS-STACKSIZE-0x500) // = 0xc7ff000
//SVC Stack Area:0xc(e)7ff000-0xc(e)7ffaff
extern char Image$$RW$$Limit[];
void *mallocPt=Image$$RW$$Limit;
/******************************************************************************
******************************************************************************/
void * malloc(unsigned nbyte)
/*Very simple; Use malloc() & free() like Stack*/
//void *mallocPt=Image$$RW$$Limit;
{
void *returnPt=mallocPt;
mallocPt= (int *)mallocPt+nbyte/4+((nbyte%4)>0); //to align 4byte
if( (int)mallocPt > HEAPEND )
{
mallocPt=returnPt;
return NULL;
}
return returnPt;
}
//*****************************************************************************
void free(void *pt)
{
mallocPt=pt;
}
/****************************************************************************
【功能说明】
****************************************************************************/
void Lcd_Init(int depth)
{ U32 j,i;
if((U32)frameBuffer4==0)
{
frameBuffer4=(U32 (*)[SCR_XSIZE/16])malloc(ARRAY_SIZE_G4);
}
rLCDCON1=(0)|(1<<1)|(0<<5)|(MVAL_USED<<7)|(0x3<<8)|(0x3<<10)|(CLKVAL_G4<<12);
// disable,4B_dual_SCAN,WDLY=8clk,WLH=8clk,
rLCDCON2=(LINEVAL)|(HOZVAL<<10)|(10<<21);
//LINEBLANK=10 (without any calculation)
rLCDSADDR1= (0x1<<27) | ( ((U32)frameBuffer4>>22)<<21 ) | M5D((U32)frameBuffer4>>1);
// 4-gray, LCDBANK, LCDBASEU
rLCDSADDR2= M5D((((U32)frameBuffer4+(SCR_XSIZE*LCD_YSIZE/8))>>1)) | (MVAL<<21);
rLCDSADDR3= (LCD_XSIZE/8) | ( ((SCR_XSIZE-LCD_XSIZE)/8)<<9 );
//The following value has to be changed for better display.
//Select 4 levels among 16 gray levels.
rBLUELUT=0xfa40;
rDITHMODE=0x0;
rDP1_2 =0xa5a5;
rDP4_7 =0xba5da65;
rDP3_5 =0xa5a5f;
rDP2_3 =0xd6b;
rDP5_7 =0xeb7b5ed;
rDP3_4 =0x7dbe;
rDP4_5 =0x7ebdf;
rDP6_7 =0x7fdfbfe;
rLCDCON1=(1)|(1<<1)|(0<<5)|(MVAL_USED<<7)|(0x3<<8)|(0x3<<10)|(CLKVAL_G4<<12);
// enable,4B_dual_SCAN,WDLY=8clk,WLH=8clk,
for(j=0;j<1024;j++)
{for(i=0;i<40;i++)
{frameBuffer4[j][i]=0x00000000;
}
}
}
//***************************************************************************
/****************************************************************************
【功能说明】
****************************************************************************/
void Lcd_MoveViewPort(int vx,int vy,int depth)
{
U32 addr;
switch(depth)
{
case 4:
//The processor mode should be superviser mode.
DisableInterrupt();
#if (LCD_XSIZE<256)
while((rLCDCON1>>22)<=1); // if x<256
#else
while((rLCDCON1>>22)==0); // if x>256
#endif
addr=(U32)frameBuffer4+(vx/4)+vy*(SCR_XSIZE/4);
rLCDSADDR1= (0x1<<27) | ( (addr>>22)<<21 ) | M5D(addr>>1);
// 4-gray, LCDBANK, LCDBASEU
rLCDSADDR2= M5D(((addr+(SCR_XSIZE*LCD_YSIZE/4))>>1)) | (MVAL<<21);
EnableInterrupt();
break;
}
}
/***************************************************************************/
/****************************************************************************
【功能说明】
****************************************************************************/
void LCD_DispON(void)
{
Delay(5);
rPCONE = rPCONE & (~(0xf<<6)) | (0x5<<6) ;
rPDATE = ( rPDATE | (3<<3) );
Delay(5);
}
/***************************************************************************/
/****************************************************************************
【功能说明】
****************************************************************************/
void Lcd_DispOFF(void)
{
Delay(5);
rPCONE = rPCONE & (~(0xf<<6)) | (0x5<<6) ;
rPDATE = ( rPDATE & (~(3<<3)) );
Delay(5);
}
/***************************************************************************/
void LCD_Off (void)
{
Delay(5);
rPCONE = rPCONE & (~(0xf<<6)) | (0x5<<6) ;
rPDATE = ( rPDATE & (~(3<<3)) );
//rPDATC = ( rPDATC | (1<<8) );
Delay(5);
}
void LCD_On (void)
{
Delay(5);
rPCONE = rPCONE & (~(0xf<<6)) | (0x5<<6) ;
rPDATE = ( rPDATE | (3<<3) );
//rPDATC = ( rPDATC & (~(1<<8)) );
Delay(5);
}
/****************************************************************************
【功能说明】画4色图片
****************************************************************************/
/*void Lcd_G4_Bmp( U16 x0, U16 y0, U16 x1, U16 y1 , unsigned char *bmp )
{
int x, y ;
int m = 0;
for( y = y1; y > y0; y-- ) //画16色图片
{
for( x = x1; x > x0; x-=4 )
{
PutPixel( (x-4), (y-1), ( *bmp&0x03) );
PutPixel( (x-3), (y-1), ((*bmp>>2)&0x03) );
PutPixel( (x-2), (y-1), ((*bmp>>4)&0x03) );
PutPixel( (x-1), (y-1), (*bmp>>6) );
bmp++ ;
}
}
}*/
//***************************************************************************
/****************************************************************************
【功能说明】
****************************************************************************/
U8 High_Low( U8 x )
{
x = ( (x>>1)&0x1c ) | (x>>6) | (x<<5);
return x ;
}
//***************************************************************************
void Lcd_G4_Bmp_All(unsigned char *bmp ,U8 rev)
{
int x, y ,i;
for( y = 0; y < 480; y++ ) //画4色图片
{
for( x = 0; x < 40; x++ )
{
frameBuffer4[(y)][(x)]=0;
for (i=0;i<3;i++)
{
frameBuffer4[(y)][(x)]+=*bmp;
frameBuffer4[(y)][(x)]=frameBuffer4[(y)][(x)]<<8;
bmp++ ;
}
frameBuffer4[(y)][(x)]+=*bmp;
if (rev!=0)frameBuffer4[(y)][(x)]=~frameBuffer4[(y)][(x)];
bmp++ ;
}
}
}
void Lcd_G4_Bmp( U16 x0, U16 y0, U16 x1, U16 y1 , unsigned char *bmp ,U8 rev)
{
int x, y ;
if (rev==0)
{
for( y = y0; y < y0+y1; y++ ) //画4色图片
{
for( x = x0; x < x0+x1; x+=4 )
{
_PutPixelG4( (x+3), (y),( *bmp&0x03) );
_PutPixelG4( (x+2), (y), ((*bmp>>2)&0x03) );
_PutPixelG4( (x+1), (y), ((*bmp>>4)&0x03) );
_PutPixelG4( (x+0), (y), (*bmp>>6) );
bmp++ ;
}
}
}
else
{
for( y = y0; y < y0+y1; y++ ) //画4色图片
{
for( x = x0; x < x0+x1; x+=4 )
{
_PutPixelG4( (x+3), (y), (~( *bmp &0x03))&0x03);
_PutPixelG4( (x+2), (y), (~((*bmp>>2)&0x03))&0x03);
_PutPixelG4( (x+1), (y), (~((*bmp>>4)&0x03))&0x03);
_PutPixelG4( (x+0), (y), (~(*bmp>>6))&0x03);
bmp++ ;
}
}
}
}
void Lcd_G4_Bmp_Rev( U16 x0, U16 y0, U16 x1, U16 y1,U8 srv)
{
int x, y ;
for( y = y0; y < y0+y1; y++ ) //画4色图片
{
for( x = x0; x < x0+x1; x+=4 )
{
_RevPixelG4( (x+3), (y),srv);
_RevPixelG4( (x+2), (y),srv);
_RevPixelG4( (x+1), (y),srv);
_RevPixelG4( (x+0), (y),srv);
}
}
}
void Lcd_G4_Char( U16 x0, U16 y0, U16 x1, U16 y1 , const U8 *bmp,U8 rev,U8 Color)
{
int x, y ;
if (rev==0)
{
for( y = y0; y < y1; y++ ) //画4色图片
{
for( x = x0; x < x1; x+=8 )
{
_PutPixelG4( (x+8), (y),((*bmp)&0x1)? Color:0);
_PutPixelG4( (x+7), (y),((*bmp>>1)&0x1)? Color:0);
_PutPixelG4( (x+6), (y),((*bmp>>2)&0x1)? Color:0);
_PutPixelG4( (x+5), (y),((*bmp>>3)&0x1)? Color:0);
_PutPixelG4( (x+4), (y),((*bmp>>4)&0x1)? Color:0);
_PutPixelG4( (x+3), (y),((*bmp>>5)&0x1)? Color:0);
_PutPixelG4( (x+2), (y),((*bmp>>6)&0x1)? Color:0);
_PutPixelG4( (x+1), (y),((*bmp>>7)&0x1)? Color:0);
bmp++ ;
}
}
}
else
{
for( y = y0; y < y1; y++ ) //画4色图片
{
for( x = x0; x < x1; x+=8 )
{
_PutPixelG4( (x+8), (y),((*bmp)&0x1)? ((~Color)&3):3);
_PutPixelG4( (x+7), (y),((*bmp>>1)&0x1)? ((~Color)&3):3);
_PutPixelG4( (x+6), (y),((*bmp>>2)&0x1)? ((~Color)&3):3);
_PutPixelG4( (x+5), (y),((*bmp>>3)&0x1)? ((~Color)&3):3);
_PutPixelG4( (x+4), (y),((*bmp>>4)&0x1)? ((~Color)&3):3);
_PutPixelG4( (x+3), (y),((*bmp>>5)&0x1)? ((~Color)&3):3);
_PutPixelG4( (x+2), (y),((*bmp>>6)&0x1)? ((~Color)&3):3);
_PutPixelG4( (x+1), (y),((*bmp>>7)&0x1)? ((~Color)&3):3);
bmp++ ;
}
}
}
}
void Lcd_G42432_Char( U16 x0, U16 y0, U8 Char,U8 rev,U8 Color)
{
Lcd_G4_Char(x0,y0,x0+24,y0+32,acFont24x32+Char*96,rev,Color);
}
void Lcd_G43264_Char( U16 x0, U16 y0, U8 Char,U8 rev,U8 Color)
{
Lcd_G4_Char(x0,y0,x0+32,y0+64,acFont32x64+Char*256,rev,Color);
}
void Lcd_G43232_Char( U16 x0, U16 y0, U16 Char,U8 rev,U8 Color)
{
Lcd_G4_Char(x0,y0,x0+32,y0+32,HzFont32x32+Char*128,rev,Color);
}
void Lcd_G42424_Char( U16 x0, U16 y0, U16 Char,U8 rev,U8 Color)
{
Lcd_G4_Char(x0,y0,x0+24,y0+24,HzFont24x24+Char*72,rev,Color);
}
void Lcd_G4X24_Char( U16 x0, U16 y0,U8 pstr,U8 rev,U8 Color)
{
CXZKF24B(pstr);
Lcd_G4_Char(x0,y0,x0+XXX,y0+24,PP,rev,Color);
}
void Lcd_G4816_Char( U16 x0, U16 y0, U8 Char,U8 rev,U8 Color)
{
Lcd_G4_Char(x0,y0,x0+8,y0+16,Ascii+Char*16,rev,Color);
}
void Lcd_Char( U16 x0, U16 y0, U8 Char,U8 rev,U8 Color,U8 type)
{
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -