📄 displaylib.c
字号:
delayLoop(LCD_DELAY_1MS*10);
///////////////////////////////////////////////////////////////////
// Power Setting Function 1
//////////////////////////////////////////////////////////////////
#if LTV350
Write_LDI_LTV350(0x09,0x4055);
Write_LDI_LTV350(0x0a,0x0000);
#else
Write_LDI_LTV350(0x09,0x4055);
Write_LDI_LTV350(0x0a,0x2000);
#endif
// delay about 10ms
delayLoop(LCD_DELAY_1MS*10);
/////////////////////////////////////////////////////////////////////
// Power Setting 2
/////////////////////////////////////////////////////////////////////
#if LTV350
Write_LDI_LTV350(0x0a,0x2000);
#else
Write_LDI_LTV350(0x09,0x4055);
#endif
// delay about 50ms
delayLoop(LCD_DELAY_1MS*50);
///////////////////////////////////////////////////////////////////
// Instruction Setting
///////////////////////////////////////////////////////////////////
#if LTV350
Write_LDI_LTV350(0x01,0x409d);
Write_LDI_LTV350(0x02,0x0204);
Write_LDI_LTV350(0x03,0x2100);
Write_LDI_LTV350(0x04,0x1000);
Write_LDI_LTV350(0x05,0x5003);
Write_LDI_LTV350(0x06,0x0009); //vbp
Write_LDI_LTV350(0x07,0x000f); //hbp
Write_LDI_LTV350(0x08,0x0800);
Write_LDI_LTV350(0x10,0x0000);
Write_LDI_LTV350(0x11,0x0000);
Write_LDI_LTV350(0x12,0x000f);
Write_LDI_LTV350(0x13,0x1f00);
Write_LDI_LTV350(0x14,0x0000);
Write_LDI_LTV350(0x15,0x0000);
Write_LDI_LTV350(0x16,0x0000);
Write_LDI_LTV350(0x17,0x0000);
Write_LDI_LTV350(0x18,0x0000);
Write_LDI_LTV350(0x19,0x0000);
#else
Write_LDI_LTV350(0x01,0x409d);
Write_LDI_LTV350(0x02,0x0204);
Write_LDI_LTV350(0x03,0x0100);
Write_LDI_LTV350(0x04,0x3000);
Write_LDI_LTV350(0x05,0x4003);
Write_LDI_LTV350(0x06,0x0009); //vbp
Write_LDI_LTV350(0x07,0x000f); //hbp
Write_LDI_LTV350(0x08,0x0c00);
Write_LDI_LTV350(0x10,0x0103);
Write_LDI_LTV350(0x11,0x0301);
Write_LDI_LTV350(0x12,0x1f0f);
Write_LDI_LTV350(0x13,0x1f0f);
Write_LDI_LTV350(0x14,0x0707);
Write_LDI_LTV350(0x15,0x0307);
Write_LDI_LTV350(0x16,0x0707);
Write_LDI_LTV350(0x17,0x0000);
Write_LDI_LTV350(0x18,0x0004);
Write_LDI_LTV350(0x19,0x0000);
#endif
// delay about 2 frames
delayLoop(LCD_DELAY_1MS*50);
///////////////////////////////////////////////////////////////////
// Display On Sequence
///////////////////////////////////////////////////////////////////
#if LTV350
Write_LDI_LTV350(0x09,0x4a55);
Write_LDI_LTV350(0x0a,0x2000);
#else
Write_LDI_LTV350(0x09,0x4a55);
Write_LDI_LTV350(0x05,0x5003);
#endif
}
void Write_LDI_LTV350(int address, int data)
{
uint8 dev_id_code=0x1D;
int j;
unsigned char DELAY=50;
if(debug_continue)
{
Temp_forDebug(address,data);
}
LCD_DEN_Hi; // EN = High CS high
LCD_DCLK_Hi; // SCL High
LCD_DSERI_Hi; // Data Low
delayLoop(DELAY);
LCD_DEN_Lo; // EN = Low CS Low
delayLoop(DELAY);
for (j = 5; j >= 0; j--)
{
LCD_DCLK_Lo; // SCL Low
if ((dev_id_code >> j) & 0x0001) // DATA HIGH or LOW
{
LCD_DSERI_Hi;
}
else
{
LCD_DSERI_Lo;
}
delayLoop(DELAY);
LCD_DCLK_Hi; // CLOCK = High
delayLoop(DELAY);
}
// RS = "0" : index data
LCD_DCLK_Lo; // CLOCK = Low
LCD_DSERI_Lo;
delayLoop(DELAY);
LCD_DCLK_Hi; // CLOCK = High
delayLoop(DELAY);
// Write
LCD_DCLK_Lo; // CLOCK = Low
LCD_DSERI_Lo;
delayLoop(DELAY);
LCD_DCLK_Hi; // CLOCK = High
delayLoop(DELAY);
for (j = 15; j >= 0; j--)
{
LCD_DCLK_Lo; // SCL Low
if ((address >> j) & 0x0001) // DATA HIGH or LOW
{
LCD_DSERI_Hi;
}
else
{
LCD_DSERI_Lo;
}
delayLoop(DELAY);
LCD_DCLK_Hi; // CLOCK = High
delayLoop(DELAY);
}
LCD_DSERI_Hi;
delayLoop(DELAY);
LCD_DEN_Hi; // EN = High
delayLoop(DELAY*10);
LCD_DEN_Lo; // EN = Low CS Low
delayLoop(DELAY);
for (j = 5; j >= 0; j--)
{
LCD_DCLK_Lo; // SCL Low
if ((dev_id_code >> j) & 0x0001) // DATA HIGH or LOW
{
LCD_DSERI_Hi;
}
else
{
LCD_DSERI_Lo;
}
delayLoop(DELAY);
LCD_DCLK_Hi; // CLOCK = High
delayLoop(DELAY);
}
// RS = "1" instruction data
LCD_DCLK_Lo; // CLOCK = Low
LCD_DSERI_Hi;
delayLoop(DELAY);
LCD_DCLK_Hi; // CLOCK = High
delayLoop(DELAY);
// Write
LCD_DCLK_Lo; // CLOCK = Low
LCD_DSERI_Lo;
delayLoop(DELAY);
LCD_DCLK_Hi; // CLOCK = High
delayLoop(DELAY);
for (j = 15; j >= 0; j--)
{
LCD_DCLK_Lo; // SCL Low
if ((data >> j) & 0x0001) // DATA HIGH or LOW
{
LCD_DSERI_Hi;
}
else
{
LCD_DSERI_Lo;
}
delayLoop(DELAY);
LCD_DCLK_Hi; // CLOCK = High
delayLoop(DELAY);
}
LCD_DEN_Hi; // EN = High
delayLoop(DELAY);
}
//========================================================================================
// library function for Camera test
//========================================================================================
void Setup_RgbIf( void)
{
uint32 LcdBppMode;
rMISCCR |= (1<<28); // select LCD controller for TFT lcd controller
SetLcdPort();
Init_LDI();
LcdWindowOnOff(LCD_WIN_ALL,LCD_OFF);
LcdEnvidOnOff(LCD_OFF);
printf("\nSelect Display BPP mode\n\n 0: RGB 16bpp (565) 1: RGB 24bpp (888)\n");
LcdBppMode = GetIntNum();
//if((LcdBppMode<0)||(LcdBppMode>1))
if((LcdBppMode>1))
LcdBppMode = 0;
switch(LcdBppMode)
{
case 0 : LcdBppMode = WINCONx_16BPP_565;
break;
case 1 : LcdBppMode = WINCONx_24BPP_888;
break;
}
Basic_Display_Setting(LCD_WIN_0,LCD_BUF_0,LcdBppMode,lcd_horizon_value,lcd_line_value);
if (LcdBppMode == WINCONx_16BPP_565)
*WINCONx_Reg_Addr[LCD_WIN_0] |= (1<<WINCON_SWAP_S);
Display_Start(LCD_WIN_0);
}
//
//===================================================
//
//===================================================
// General Library for Font and drawing...
//
void _PutPixel1Bit(uint32 x,uint32 y,uint32 c)
{
if(x<screen_width && y<screen_height)
*(uint32 *)(lcd_framebuffer+y*screen_width/32+x/32)= (*(uint32 *)(lcd_framebuffer+y*screen_width/32+x/32)
& ~(0x80000000>>(x%32)*1))| ((c&0x00000001)<<((32-1-(x%32))*1));
}
void _PutPixel2Bit(uint32 x,uint32 y,uint32 c)
{
if(x<screen_width && y<screen_height)
*(uint32 *)(lcd_framebuffer+y*screen_width/16+x/16)= (*(uint32 *)(lcd_framebuffer+y*screen_width/16+x/16)
& ~(0xc0000000>>(x%16)*2))| ((c&0x00000003)<<((16-1-(x%16))*2));
}
void _PutPixel4Bit(uint32 x,uint32 y,uint32 c)
{
if(x<screen_width && y<screen_height)
*(uint32 *)(lcd_framebuffer+y*screen_width/8+x/8)= (*(uint32 *)(lcd_framebuffer+y*screen_width/8+x/8)
& ~(0xf0000000>>(x%8)*4))| ((c&0x0000000f)<<((8-1-(x%8))*4));
}
void _PutPixel8Bit(uint32 x,uint32 y,uint32 c)
{
if(x<screen_width && y<screen_height)
*(uint32 *)(lcd_framebuffer+y*screen_width/4+x/4)= (*(uint32 *)(lcd_framebuffer+y*screen_width/4+x/4)
& ~(0xff000000>>(x%4)*8))| ((c&0x000000ff)<<((4-1-(x%4))*8));
}
void _PutPixel16Bit(uint32 x,uint32 y,uint32 c)
{
if(x<screen_width && y<screen_height)
*(uint32 *)(lcd_framebuffer+y*screen_width/2+x/2)= (*(uint32 *)(lcd_framebuffer+y*screen_width/2+x/2)
& ~(0xffff0000>>(x%2)*16))|((c&0x0000ffff)<<((2-1-(x%2))*16));
}
void _PutPixel32Bit(uint32 x,uint32 y,uint32 c)
{
if(x<screen_width && y<screen_height)
*(uint32 *)(lcd_framebuffer+y*screen_width+x)=c;
}
void LCD_Rectangle(int32 x1,int32 y1,int32 x2,int32 y2,int32 color)
{
LCD_Line(x1,y1,x2,y1,color);
LCD_Line(x2,y1,x2,y2,color);
LCD_Line(x1,y2,x2,y2,color);
LCD_Line(x1,y1,x1,y2,color);
}
void LCD_FilledRectangle(int32 x1,int32 y1,int32 x2,int32 y2,int32 color)
{
int32 i;
for(i=y1;i<=y2;i++)
LCD_Line(x1,i,x2,i,color);
}
// 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 LCD_Line(int32 x1,int32 y1,int32 x2,int32 y2,int32 color)
{
int32 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 LCD_ClearScr(uint32 c)
{
int32 i,j;
for(j=0;j<screen_height;j++)
for(i=0;i<screen_width;i++)
PutPixel(i,j,c);
}
void lputs(uint32 x, uint32 y, uint32 c, char *str)
{
int i,j,k;
int oneLine;
for(i=0;i<strlen(str);i++)
{
for(j=0; j<16; j++)
{
if ((str[i]>=0x20)&&(str[i]<0x80))
oneLine=chr_font8X16[str[i]-0x20][j];
else
oneLine=0;
for(k=0;k<8;k++)
{
if(oneLine&(1<<k))
PutPixel(x+7-k,y+j,c);
}
}
x+=8;
}
}
void lprintf(uint32 x, uint32 y, uint32 c, const char *fmt,...)
{
va_list ap;
char string[256];
va_start(ap,fmt);
vsprintf(string,fmt,ap);
lputs(x,y,c,string);
va_end(ap);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -