📄 displaylib.c
字号:
*WINxMAP_Reg_Addr[win_num] = 0;
if (win_num>0)
{
*VIDOSDxC_Reg_Addr[win_num] = 0;
*WxKEYCON0_Reg_Addr[win_num] = 0;
*WxKEYCON1_Reg_Addr[win_num] = 0;
}
}
void Basic_Display_Setting_CPUIF_OUTPUT_FORMAT( int32 win_num,int32 buf_num, int32 bpp, uint32 width, uint32 height)
{
uint32 pagewidth_in_byte=0,offsize_in_byte=0;
uint32 pagewidth,offsize;
lcd_bpp = bpp;
screen_width=width;
screen_height=height;
pagewidth=lcd_horizon_value;
offsize = screen_width - lcd_horizon_value;
switch(bpp)
{
case WINCONx_1BPP_PALLET:
PutPixel=_PutPixel1Bit;
break;
case WINCONx_2BPP_PALLET:
PutPixel=_PutPixel2Bit;
break;
case WINCONx_4BPP_PALLET:
PutPixel=_PutPixel4Bit;
break;
case WINCONx_8BPP_PALLET:
case WINCONx_8BPP_NO_PALLET:
PutPixel=_PutPixel8Bit;
break;
case WINCONx_16BPP_565:
case WINCONx_16BPP_A555:
case WINCONx_16BPP_1555:
PutPixel=_PutPixel16Bit;
break;
case WINCONx_18BPP_666:
case WINCONx_18BPP_A665:
case WINCONx_19BPP_A666:
case WINCONx_24BPP_888:
case WINCONx_24BPP_A887:
case WINCONx_25BPP_A888:
PutPixel=_PutPixel32Bit;
break;
}
// 2006.06.02
// Frame buffer address setting : Windows0 have the two buffer like as buffer0, buffer1.
// Each buffer have the register for setting the start and end address. But Window1 have one buffer
// base lcd_framebuffer = Noncache address(0x31000000)
pagewidth_in_byte = pagewidth/8*lcd_bit_order[bpp];
if((pagewidth_in_byte%lcd_burst_in_byte[lcd_burst_mode])!=0)
{
pagewidth_in_byte += lcd_burst_in_byte[lcd_burst_mode] - (pagewidth_in_byte%lcd_burst_in_byte[lcd_burst_mode]);
}
offsize_in_byte = offsize/8*lcd_bit_order[bpp];
LCDC_Common_Init_CPUIF_OUTPUT_FORMAT();
*WINCONx_Reg_Addr[win_num] = (buf_num<<WINCON_BUFSEL)|(0<<WINCON_BUFAUTOEN)|(0<<WINCON_SWAP_S)|(lcd_burst_mode<<WINCON_BURSTLEN_S)|(bpp<<WINCON_BPP_S); // 4word burst, 16bpp,
*VIDOSDxA_Reg_Addr[win_num] = (0<<VIDOSDxAB_HORIZON_X_S)|(0);
*VIDOSDxB_Reg_Addr[win_num] = ((lcd_horizon_value-1)<<VIDOSDxAB_HORIZON_X_S)|(lcd_line_value-1);
lcd_framebuffer = (uint32 *)lcd_frame_buffer[win_num][buf_num];
// buffer start address
*VIDWxADD0_Reg_Addr[win_num][buf_num] = (uint32)lcd_framebuffer;
// buffer end address
*VIDWxADD1_Reg_Addr[win_num][buf_num] = (uint32)lcd_framebuffer + (pagewidth_in_byte+offsize_in_byte)*(lcd_line_value);
// buffer size
*VIDWxADD2_Reg_Addr[win_num][buf_num] = (offsize_in_byte<<VIDWxADD2_OFFSET_SIZE_S)|pagewidth_in_byte;
*WINxMAP_Reg_Addr[win_num] = 0;
if (win_num>0)
{
*VIDOSDxC_Reg_Addr[win_num] = 0;
*WxKEYCON0_Reg_Addr[win_num] = 0;
*WxKEYCON1_Reg_Addr[win_num] = 0;
}
}
void LCDC_Common_Init_CPUIF_OUTPUT_FORMAT(void)
{
uint8 clkval=0;
uint16 hcync_cnt,vclk_cnt;
hcync_cnt = (lcd_vbpd+lcd_vfpd+lcd_vspw+lcd_line_value);
vclk_cnt = (lcd_hbpd+lcd_hfpd+lcd_hspw+lcd_horizon_value);
rVIDCON0 = VIDCON0_S_CPU_IF_MAIN|VIDCON0_CPU_16plus2|VIDCON0_S_RGB_PAR|VIDCON0_S_VCLK_GATING_OFF|VIDCON0_S_CLKDIR_DIVIDED|VIDCON0_S_CLKSEL_HCLK;
if(rVIDCON0 & (1<<2)) //ePLL
{
clkval = (uint8)(((float)96000000/(float)(hcync_cnt*vclk_cnt*lcd_frame_rate*2))+0.5)-1;
rEPLLCON = (40<<16)|(1<<8)|(1<<0); // M=40;P=1, S=1);
rEPLLCON &= ~(1<<24); // epll on
}
else //HCLK
{
clkval = (uint8)(((float)HCLK/(float)(hcync_cnt*vclk_cnt*lcd_frame_rate*2))+0.5)-1;
}
rVIDCON0 |= (clkval <<VIDCON0_CLKVAL_F_SHIFT);
//check point
rSYSIFCON0 = (lcd_cs_setup<<16)|(lcd_wr_setup<<12)|(lcd_wr_act<<8)|(lcd_wr_hold<<4)|(1<<2)|(1<<1)|(1); // CS_SETUP=0xf, WR_SETUP=0xf, WR_ACT=0xf, WR_HOLD=0xf, RSPOL=HIGH, SUCCEUP=One time, SYSIFEN=Enable
rVIDTCON2 = ((lcd_line_value-1)<<VIDTCON2_LINEVAL_S)|(lcd_horizon_value-1);
}
void Display_Start(int8 win_num)
{
LcdWindowOnOff(win_num,LCD_ON);
LcdEnvidOnOff(LCD_ON);
return;
}
void Display_Start_CPUIF(int8 win_num)
{
LcdWindowOnOff(win_num,LCD_ON);
LcdEnvidOnOff(LCD_ON);
Delay(1);
rCPUTRIGCON2 = 1;
return;
}
void Display_End(int8 win_num)
{
printf("\nIf you want to end this test, press any key\n");
while(!(Uart_getc()));
LcdWindowOnOff(win_num,LCD_OFF);
LcdEnvidOnOff(LCD_OFF);
return;
}
void Prepare_Image(int8 win_num, int8 bpp)
{
uint32 i, j;
uint32 *framebuffer,data;
framebuffer = lcd_framebuffer;
if(bpp<=WINCONx_8BPP_PALLET)
Prepare_Pallet(win_num,bpp);
switch(bpp)
{
case WINCONx_1BPP_PALLET:
for(i=0;i<2;i++)
{
LCD_FilledRectangle(0, screen_height/2*i, screen_width-1, screen_height/2*(i+1)-1, i);
lprintf(50,screen_height/2*i,i^0x1,"Color %d",i);
}
break;
case WINCONx_2BPP_PALLET:
for(i=0;i<4;i++)
{
LCD_FilledRectangle(0, screen_height/4*i, screen_width-1, screen_height/4*(i+1)-1, i);
lprintf(50,screen_height/4*i,i^0x3,"Color %d",i);
}
break;
case WINCONx_4BPP_PALLET:
for(i=0;i<16;i++)
{
LCD_FilledRectangle(0, screen_height/16*i, screen_width-1, screen_height/16*(i+1)-1, i);
lprintf(50,screen_height/16*i,i^0xf,"Color %d",i);
}
break;
case WINCONx_8BPP_PALLET:
if(lcd_type == LCD_MODULE_LTS222)
{
for(i=0; i<(screen_width*screen_height*lcd_bit_order[bpp]/32); i++)
{
data =(DEMO256[i*4]<<24);
data |= (DEMO256[i*4+1] <<16);
data |= (DEMO256[i*4+2] <<8);
data |= DEMO256[i*4+3];
*framebuffer++ = data;
}
lprintf(0,0,0xff,"8BPP paletteized mode.");
}
else
printf("This test for the LCD type is not prepared\n");
break;
case WINCONx_8BPP_NO_PALLET:
if (win_num==0)
printf("This mode is not supported in window 0.\n");
else
{
for(i=0;i<screen_width;i++)
for(j=0;j<screen_height;j++)
PutPixel(i,j,(i*j)&0xff);
lprintf(0,0,0xff,"8BPP(A232) Non-paletteized mode.");
}
break;
case WINCONx_16BPP_565:
for(i=0;i<screen_width;i++)
for(j=0;j<screen_height;j++)
PutPixel(i,j,(i*j)&0xffff);
lprintf(0,0,0xffff,"16BPP(565) Non-paletteized mode.");
break;
case WINCONx_16BPP_A555:
if (win_num==0)
printf("This mode is not supported in window 0.\n");
else
{
for(i=0;i<screen_width;i++)
for(j=0;j<screen_height;j++)
PutPixel(i,j,(i*j)&0xffff);
lprintf(0,0,0xffff,"16BPP(A555) Non-paletteized mode.");
}
break;
case WINCONx_16BPP_1555:
for(i=0;i<screen_width;i++)
for(j=0;j<screen_height;j++)
PutPixel(i,j,(i*j)&0xffff);
lprintf(0,0,0xffff,"16BPP(1555) Non-paletteized mode.");
break;
case WINCONx_18BPP_666:
for(i=0;i<screen_width;i++)
for(j=0;j<screen_height;j++)
PutPixel(i,j,(i*j)&0x3ffff);
lprintf(0,0,0x3ffff,"18BPP(666) Non-paletteized mode.");
break;
case WINCONx_18BPP_A665:
if (win_num==0)
printf("This mode is not supported in window 0.\n");
else
{
for(i=0;i<screen_width;i++)
for(j=0;j<screen_height;j++)
PutPixel(i,j,(i*j)&0x3ffff);
lprintf(0,0,0x3ffff,"18BPP(A665) Non-paletteized mode.");
}
break;
case WINCONx_19BPP_A666:
if (win_num==0)
printf("This mode is not supported in window 0.\n");
else
{
for(i=0;i<screen_width;i++)
for(j=0;j<screen_height;j++)
PutPixel(i,j,(i*j)&0x7ffff);
lprintf(0,0,0x7ffff,"19BPP(A666) Non-paletteized mode.");
}
break;
case WINCONx_24BPP_888:
for(i=0;i<screen_width;i++)
for(j=0;j<screen_height;j++)
PutPixel(i,j,(i*j)&0xffffff);
lprintf(0,0,0xffffff,"24BPP(888) Non-paletteized mode.");
break;
case WINCONx_24BPP_A887:
if (win_num==0)
printf("This mode is not supported in window 0.\n");
else
{
for(i=0;i<screen_width;i++)
for(j=0;j<screen_height;j++)
PutPixel(i,j,(i*j)&0xffffff);
lprintf(0,0,0xffffff,"24BPP(A887) Non-paletteized mode.");
}
break;
case WINCONx_25BPP_A888:
if (win_num==0)
printf("This mode is not supported in window 0.\n");
else
{
for(i=0;i<screen_width;i++)
for(j=0;j<screen_height;j++)
PutPixel(i,j,(i*j)&0x1ffffff);
lprintf(0,0,0x1ffffff,"25BPP(A888) Non-paletteized mode.");
}
break;
default:
break;
}
}
void Prepare_Pallet(int8 win_num, int8 bpp)
{
uint32 *pallet_ptr, i;
//pallet format => 16bit(565)
rWPALCON = (6<<3)|(6<<0);
// palette can be updated
rWPALCON |= (1<<9);
pallet_ptr =(uint32 *)WINxPalletBase[win_num];
switch(bpp)
{
case WINCONx_1BPP_PALLET:
*(pallet_ptr+0) = 0x0000;
*(pallet_ptr+1) = 0xffff;
break;
case WINCONx_2BPP_PALLET:
*(pallet_ptr+0) = 0x0000;
*(pallet_ptr+1) = 0xf800;
*(pallet_ptr+2) = 0x07e0;
*(pallet_ptr+3) = 0x001f;
break;
case WINCONx_4BPP_PALLET:
*(pallet_ptr+0) = 0x0000;
*(pallet_ptr+1) = 0xf800;
*(pallet_ptr+2) = 0x07e0;
*(pallet_ptr+3) = 0x001f;
*(pallet_ptr+4) = 0xf81f;
*(pallet_ptr+5) = 0xffe0;
*(pallet_ptr+6) = 0x07ff;
*(pallet_ptr+7) = 0xffff;
*(pallet_ptr+8) = 0x18e3;
*(pallet_ptr+9) = 0x7800;
*(pallet_ptr+10) = 0x03e0;
*(pallet_ptr+11) = 0x000f;
*(pallet_ptr+12) = 0x780f;
*(pallet_ptr+13) = 0x7be0;
*(pallet_ptr+14) = 0x03ef;
*(pallet_ptr+15) = 0x7bef;
break;
case WINCONx_8BPP_PALLET:
for(i=0;i<256;i++)
*(pallet_ptr+i) = (uint32)DEMO256pal[i];
break;
default :
break;
}
rWPALCON &= ~(1<<9);
}
void LcdEnvidOnOff(uint8 onoff)
{
if(onoff==LCD_ON)
rVIDCON0 |= (3); // ENVID On using Per Frame method
else
rVIDCON0 &= (~3); // ENVID Off using Per Frame method
}
void LcdWindowOnOff(uint8 num, uint8 onoff)
{
switch(num)
{
case LCD_WIN_0:
if(onoff==LCD_ON)
rWINCON0 |= 0x01;
else
rWINCON0 &= ~0x01;
break;
case LCD_WIN_1:
if(onoff==LCD_ON)
rWINCON1 |= 0x01;
else
rWINCON1 &= ~0x01;
break;
case LCD_WIN_ALL:
if(onoff==LCD_ON)
{
rWINCON0 |= 0x01;
rWINCON1 |= 0x01;
}
else
{
rWINCON0 &= ~0x01;
rWINCON1 &= ~0x01;
}
default:
break;
}
return;
}
//
//===================================================
//===================================================
//
//
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
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -