📄 lcdlib.c
字号:
/*****************************************
NAME: lcdlib.c
DESC: lcd configuration low-level codes
HISTORY:
2002.03.13:draft ver 0.0
*****************************************/
#include <string.h>
#include "2410addr.h"
#include "2410lib.h"
#include "def.h"
//#include "option.h"
//#include "24xslib.h"
#include "lcdlib.h"
//Color STN
U32 (*frameBuffer8Bit)[SCR_XSIZE_CSTN/4];
void Lcd_Init()
{
//case MODE_CSTN_8BIT:
frameBuffer8Bit=(U32 (*)[SCR_XSIZE_CSTN/4])LCDFRAMEBUFFER;
rLCDCON1=(CLKVAL_CSTN<<8)|(MVAL_USED<<7)|(2<<5)|(3<<1)|0;
// 8-bit single scan,8bpp CSTN,ENVID=off
rLCDCON2=(0<<24)|(LINEVAL_CSTN<<14)|(0<<6)|(0<<0);
rLCDCON3=(WDLY_CSTN<<19)|(HOZVAL_CSTN<<8)|(LINEBLANK_CSTN<<0);
rLCDCON4=(MVAL<<8)|(WLH_CSTN<<0);
rLCDCON5=0;
//BPP24BL:x,FRM565:x,INVVCLK:x,INVVLINE:x,INVVFRAME:x,INVVD:x,
//INVVDEN:x,INVPWREN:x,INVLEND:x,PWREN:x,ENLEND:x,BSWP:x,HWSWP:x
rLCDSADDR1=(((U32)frameBuffer8Bit>>22)<<21 )|M5D((U32)frameBuffer8Bit>>1);
rLCDSADDR2=M5D( ((U32)frameBuffer8Bit+(SCR_XSIZE_CSTN*LCD_YSIZE_CSTN/1))>>1 );
//rLCDSADDR3=(((SCR_XSIZE_CSTN-LCD_XSIZE_CSTN)/2)<<11)|(LCD_XSIZE_CSTN/2);
rLCDSADDR3=(((SCR_XSIZE_CSTN-LCD_XSIZE_CSTN)/2<<11)|(LCD_XSIZE_CSTN/2));
rDITHMODE=0x0;
rREDLUT =0xfdb96420;
rGREENLUT=0xfdb96420;
rBLUELUT =0xfb40;
rGPGCON =(rGPGCON | (0x3<<8));
}
//tur on or off the lcd
void Lcd_CstnOnOff(int onoff)
{
// 1:CSTN Panel on 0:CSTN Panel off //
if(onoff==1)
{
rLCDCON1|=1; // ENVID=ON
rLCDCON5= rLCDCON5 | (0x1<<3);
}
else
{
rLCDCON1 =rLCDCON1 & 0x3fffe; // ENVID Off
rLCDCON5 =(rLCDCON5 & ~(0x1<<3));
}
rGPBUP=rGPBUP|(1<<5); // Pull-up disable
rGPBDAT=rGPBDAT&(~(1<<5))|(onoff<<5); // GPB5=On or Off
rGPBCON=rGPBCON&(~(3<<10))|(1<<10); //GPD9=output
}
//set the pixel
void PutPixel(U32 x,U32 y,U32 c)
{
if(x<SCR_XSIZE_CSTN&& y<SCR_YSIZE_CSTN)
frameBuffer8Bit[(y)][(x)/4]=( frameBuffer8Bit[(y)][x/4]
& ~(0xff000000>>((x)%4)*8) ) | ( (c&0x000000ff)<<((4-1-((x)%4))*8) );
}
//draw a rectgangle
void Glib_Rectangle(int x1,int y1,int x2,int y2,int color)
{
Glib_Line(x1,y1,x2,y1,color);
Glib_Line(x2,y1,x2,y2,color);
Glib_Line(x1,y2,x2,y2,color);
Glib_Line(x1,y1,x1,y2,color);
}
//fill a rectangle
void Glib_FilledRectangle(int x1,int y1,int x2,int y2,int color)
{
int i;
for(i=y1;i<=y2;i++)
Glib_Line(x1,i,x2,i,color);
}
//draw a line
// LCD display is flipped vertically
// But, think the algorithm by mathematics point.
// 3I2
// 4 I 1
// --+-- <-8 octants mathematical cordinate
// 5 I 8
// 6I7
void Glib_Line(int x1,int y1,int x2,int y2,int color)
{
int dx,dy,e;
dx=x2-x1;
dy=y2-y1;
if(dx>=0)
{
if(dy >= 0) // dy>=0
{
if(dx>=dy) // 1/8 octant
{
e=dy-dx/2;
while(x1<=x2)
{
PutPixel(x1,y1,color);
if(e>0){y1+=1;e-=dx;}
x1+=1;
e+=dy;
}
}
else // 2/8 octant
{
e=dx-dy/2;
while(y1<=y2)
{
PutPixel(x1,y1,color);
if(e>0){x1+=1;e-=dy;}
y1+=1;
e+=dx;
}
}
}
else // dy<0
{
dy=-dy; // dy=abs(dy)
if(dx>=dy) // 8/8 octant
{
e=dy-dx/2;
while(x1<=x2)
{
PutPixel(x1,y1,color);
if(e>0){y1-=1;e-=dx;}
x1+=1;
e+=dy;
}
}
else // 7/8 octant
{
e=dx-dy/2;
while(y1>=y2)
{
PutPixel(x1,y1,color);
if(e>0){x1+=1;e-=dy;}
y1-=1;
e+=dx;
}
}
}
}
else //dx<0
{
dx=-dx; //dx=abs(dx)
if(dy >= 0) // dy>=0
{
if(dx>=dy) // 4/8 octant
{
e=dy-dx/2;
while(x1>=x2)
{
PutPixel(x1,y1,color);
if(e>0){y1+=1;e-=dx;}
x1-=1;
e+=dy;
}
}
else // 3/8 octant
{
e=dx-dy/2;
while(y1<=y2)
{
PutPixel(x1,y1,color);
if(e>0){x1-=1;e-=dy;}
y1+=1;
e+=dx;
}
}
}
else // dy<0
{
dy=-dy; // dy=abs(dy)
if(dx>=dy) // 5/8 octant
{
e=dy-dx/2;
while(x1>=x2)
{
PutPixel(x1,y1,color);
if(e>0){y1-=1;e-=dx;}
x1-=1;
e+=dy;
}
}
else // 6/8 octant
{
e=dx-dy/2;
while(y1>=y2)
{
PutPixel(x1,y1,color);
if(e>0){x1-=1;e-=dy;}
y1-=1;
e+=dx;
}
}
}
}
}
void Glib_ClearScr(U32 c)
{
//Very inefficient function.
int i,j;
for(j=0;j<240;j++)
{
for(i=0;i<320;i++)
{
PutPixel(i,j,c);
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -