#include "includes.h"
#include "consol.h"
#include "fb.h"
//volatile
volatile unsigned int LCD_BUFFER[(SRCEEN_H*SRCEEN_W)/2] __attribute((aligned(256))); //定义成整形,编译对齐!!!
#define M5D(n) ((n) & 0x1fffff) // To get lower 21bits
//Timing parameter
#define VBPD (4) //垂直同步信号的后肩
#define VFPD (1) //垂直同步信号的前肩
#define VSPW (1) //垂直同步信号的脉宽
#define HBPD (32) //水平同步信号的后肩
#define HFPD (1) //水平同步信号的前肩
#define HSPW (1) //水平同步信号的脉宽
#define CLKVAL (1) //刷新时钟//LCDCLK=HCLK/((CLKVAL+1)*2)
#define MVAL (13)
#define MVAL_USED (0) //0=each frame 1=rate by MVAL
#define INVVDEN (1) //0=normal 1=inverted
#define BSWP (0) //Byte swap control
#define HWSWP (1) //Half word swap control
/**************************************************************
LCD全屏填充特定颜色单元或清屏
**************************************************************/
static void Lcd_ClearScr( U32 c)
{
unsigned int x,y ;
unsigned short *lcd=(unsigned short *)LCD_BUFFER;
for ( y = 0 ; y < SRCEEN_H ; y++ )
{
for ( x = 0 ; x < SRCEEN_W ; x++ )
{
lcd[(y)*SRCEEN_W+(x)] = c ;
}
}
}
/**************************************************************
LCD视频和控制信号输出或者停止,1开启视频输出
**************************************************************/
static void Lcd_EnvidOnOff(int onoff)
{
if (onoff==1)
rLCDCON1|=1; // ENVID=ON
else
rLCDCON1 =rLCDCON1 & 0x3fffe; // ENVID Off
}
/**************************************************************
电源控制引脚使能
**************************************************************/
static void Lcd_PowerEnable(int invpwren,int pwren)
{
//GPG4 is setted as LCD_PWREN
rGPGUP=(rGPGUP&(~(1<<4)))|(1<<4); // Pull-up disable
rGPGCON=(rGPGCON&(~(3<<8)))|(3<<8); //GPG4=LCD_PWREN
rGPGDAT = (rGPGDAT | (1<<4)) ;
// invpwren=pwren;
//Enable LCD POWER ENABLE Function
rLCDCON5=(rLCDCON5&(~(1<<3)))|(pwren<<3); // PWREN
rLCDCON5=(rLCDCON5&(~(1<<5)))|(invpwren<<5); // INVPWREN
}
void Lcd_Init(void)
{
rGPCUP = 0x00000000;
rGPCCON = 0xaaaa02a9;
// rGPDUP=0xffffffff; // Disable Pull-up register
rGPDUP = 0x00000000;
rGPDCON = 0xaaaaaaaa; //Initialize VD[15:8]
rLCDCON1=(CLKVAL<<8)|(MVAL_USED<<7)|(3<<5)|(12<<1)|0;
//CLKVAL:确定VCLK的频率 VCLK=HCLK/[(CLKVAL+1)*2](CLKVAL>=0);MMODE:确定VM的启动方式;
//PNRMODE[6:5]:TFT显示器;BPPMODE:TFT16位;ENVID[0]:0禁止视频输出和LCD控制信号
// TFT LCD panel,12bpp TFT,ENVID=off
rLCDCON2=(VBPD<<24)|((SRCEEN_H-1)<<14)|(VFPD<<6)|(VSPW);
//VBPD:垂直同步信号的后肩;SRCEEN_H-1:LCD屏的垂直尺寸;VFPD:垂直同步信号的前肩;VSPW:垂直同步信号的脉宽
rLCDCON3=(HBPD<<19)|((SRCEEN_W-1)<<8)|(HFPD);
//HBPD:水平同步信号的后肩;SRCEEN_W-1:LCD屏的水平尺寸;HFPD:水平同步信号的前肩;
rLCDCON4=(MVAL<<8)|(HSPW);
//MVAL:如果MMODE=1,该位定义VM信号的启动速率;HSPW:水平同步信号的脉宽;
rLCDCON5 = (1<<11) | (1<<10) | (1<<9) | (1<<8) | (0<<7) | (0<<6)
| (1<<3) |(BSWP<<1) | (HWSWP);
//INVVCLK[11]:5:6:5 Format;INVCLK[10]:在VCLK上升沿视频数据被取走;INVVLINE[9]:设置行脉冲的极性1:翻转
//INVVFRAME[8]:设置VFRAME脉冲的极性 1:翻转;INVVD[7]:设置VD(视频数据)脉冲的极性;INVVDEN[6]:VDENsignal 翻转
//INVPWREN[5]:设置PWREN信号的极性;INVLEND[4];PWREN[3];BSWP[1]:字节交换控制位;HWSWP[0]:半字节交换控制位
rLCDSADDR1=(((U32)LCD_BUFFER>>22)<<21)|M5D((U32)LCD_BUFFER>>1);
//LCDBANK[29:21]:用于指示视频缓冲区在系统存储器中的段地址A[30:22];LCDBASEU[20:0]:用于在单扫描LCD中指示
//LCD帧缓冲区起始地址A[21:1];
rLCDSADDR2=M5D(((U32)(LCD_BUFFER+(SRCEEN_H*SRCEEN_W)/2))>>1 );
//指示针缓冲区结束地址A[21:1];计算LCDBASEL的公式:LCDBASEL=(帧结束地址>>1)+1
rLCDSADDR3=(((SRCEEN_W-SRCEEN_W)/1)<<11)|(SRCEEN_W/1);
//OFFSIZE[21:11]:用于设置虚拟屏偏移量(即半字的数量)
//PAGEWIDTH[10:0]:用于设置虚拟屏的页宽度
rLCDINTMSK|=(3); // MASK LCD Sub Interrupt
rTCONSEL &= (~7) ; // Disable LPC3480
rTPAL=0; // Disable Temp Palette
Lcd_PowerEnable(1, 1);
Lcd_EnvidOnOff(1); //turn on vedio
}