/**************************************************************
The initial and control for 640×480 16Bpp TFT LCD----VGA
**************************************************************/
#include "def.h"
#include "option.h"
#include "2440addr.h"
#include "2440lib.h"
#include "2440slib.h"
extern const unsigned char sunflower_240x320[];
extern const unsigned char sunflower_800x480[];
extern const unsigned char sunflower_1024x768[];
extern const unsigned char sunflower_640x480[];
extern const unsigned char sunflower_320x240[];
#define LCD_XSIZE LCD_WIDTH
#define LCD_YSIZE LCD_HEIGHT
#define SCR_XSIZE LCD_WIDTH
#define SCR_YSIZE LCD_HEIGHT
#define REQCNT 100 //*
#define ADC_FREQ 2500000 //*
#define LOOP 10000 //*
volatile U32 preScaler; //*
volatile static unsigned short LCD_BUFFER[SCR_YSIZE][SCR_XSIZE];
unsigned char Ji[]={
0x00,0x80,0x10,0x86,0x38,0x88,0x04,0x90,0x02,0xA0,0x7F,0xFF,0x00,0x88,0x1F,0xF8,
0x00,0x88,0x0F,0xF8,0x00,0x89,0x0F,0xFA,0x00,0x8C,0x1F,0xF8,0x09,0x10,0x00,0x90};//"集",0
unsigned char Mei[]={
0x20,0x07,0x78,0x18,0x06,0x20,0x01,0x40,0x00,0x80,0x3F,0xFE,0x10,0x80,0x00,0x80,
0x7F,0xFF,0x00,0x80,0x1F,0xFC,0x00,0x80,0x3F,0xFE,0x11,0x40,0x06,0x60,0x04,0x10};//"美",1
unsigned char Da[]={
0x00,0x00,0x20,0x06,0x70,0x08,0x08,0x10,0x04,0x20,0x02,0x20,0x02,0x40,0x01,0x40,
0x01,0x40,0x00,0x80,0x7F,0xFF,0x20,0x80,0x00,0x80,0x00,0x80,0x00,0x80,0x00,0x80};//"大",2
unsigned char Xue[]={
0x00,0x40,0x00,0xA0,0x00,0x80,0x00,0x80,0x00,0x80,0x7F,0xFF,0x21,0x80,0x02,0x00,
0x07,0xF8,0x20,0x01,0x40,0x02,0x7F,0xFE,0x04,0x00,0x08,0x88,0x10,0x88,0x10,0x44};//"学",3
unsigned char Huan[]={
0x20,0x30,0x70,0x40,0x10,0x80,0x08,0x81,0x05,0x22,0x05,0x24,0x02,0x14,0x02,0x08,
0x02,0x14,0x02,0x14,0x12,0x62,0x20,0xA2,0x3F,0x20,0x01,0x3F,0x01,0x00,0x01,0x00};//"欢",4
unsigned char Ying[]={
0x00,0x00,0x3F,0xE2,0x62,0x14,0x02,0x08,0x02,0x08,0x12,0x28,0x2A,0x68,0x22,0xA8,
0x23,0x28,0x22,0x2F,0x22,0x20,0x22,0x20,0x22,0x28,0x7E,0x64,0x21,0x82,0x00,0x00};//"迎",5
unsigned char Ni[]={
0x01,0x04,0x02,0x84,0x02,0x04,0x02,0x04,0x22,0x24,0x32,0x44,0x12,0x84,0x0A,0x84,
0x02,0x04,0x02,0x15,0x10,0x26,0x20,0x44,0x3F,0xC4,0x00,0x88,0x00,0x88,0x00,0x88};//"你",6
unsigned char s[]={
0x00,0x00,0x18,0x24,0x20,0x30,0x18,0x24,0x24,0x3C,0x00,0x00,0x00,0x00,0x00,0x00};//"s"
unsigned char M[]={
0x00,0x00,0x00,0x92,0x92,0x92,0x9A,0xAA,0xAA,0xA6,0x46,0x46,0x42,0x00,0x00,0x00};//"M"
unsigned char p[]={
0x0E,0x04,0x1C,0x24,0x44,0x44,0x44,0x44,0x44,0x3C,0x00,0x00,0x00,0x00,0x00,0x00};//"p"
unsigned char a[]={
0x00,0x00,0x2C,0x52,0x12,0x16,0x18,0x12,0x12,0x1C,0x00,0x00,0x00,0x00,0x00,0x00};//"a"
unsigned char o[]={
0x00,0x00,0x18,0x24,0x66,0x42,0x42,0x42,0x42,0x42,0x42,0x22,0x3C,0x00,0x00,0x00};//"o"
/**************************************************************
640×480 TFT LCD数据和控制端口初始化
**************************************************************/
static void Lcd_Port_Init( void )
{
rGPCUP=0xffffffff; // Disable Pull-up register
rGPCCON=0xaaaa02a8; //Initialize VD[7:0],VM,VFRAME,VLINE,VCLK
rGPDUP=0xffffffff; // Disable Pull-up register
rGPDCON=0xaaaaaaaa; //Initialize VD[15:8]
}
/**************************************************************
640×480 TFT LCD功能模块初始化
**************************************************************/
static void LCD_Init(void)
{
#define M5D(n) ((n)&0x1fffff)
#define LCD_ADDR ((U32)LCD_BUFFER)
rLCDCON1 = (LCD_PIXCLOCK << 8) | (3 << 5) | (12 << 1);
rLCDCON2 = (LCD_UPPER_MARGIN << 24) | ((LCD_HEIGHT - 1) << 14) | (LCD_LOWER_MARGIN << 6) | (LCD_VSYNC_LEN << 0);
rLCDCON3 = (LCD_RIGHT_MARGIN << 19) | ((LCD_WIDTH - 1) << 8) | (LCD_LEFT_MARGIN << 0);
rLCDCON4 = (13 << 8) | (LCD_HSYNC_LEN << 0);
#if !defined(LCD_CON5)
# define LCD_CON5 ((1<<11) | (1 << 9) | (1 << 8) | (1 << 3) | (1 << 0))
#endif
rLCDCON5 = LCD_CON5;
rLCDSADDR1 = ((LCD_ADDR >> 22) << 21) | ((M5D(LCD_ADDR >> 1)) << 0);
rLCDSADDR2 = M5D((LCD_ADDR + LCD_WIDTH * LCD_HEIGHT * 2) >> 1);
rLCDSADDR3 = LCD_WIDTH;
rLCDINTMSK |= 3;
rTCONSEL &= (~7);
rTPAL = 0x0;
rTCONSEL &= ~((1<<4) | 1);
}
/**************************************************************
LCD视频和控制信号输出或者停止,1开启视频输出
**************************************************************/
static void Lcd_EnvidOnOff(int onoff)
{
if(onoff==1)
rLCDCON1|=1; // ENVID=ON
else
rLCDCON1 =rLCDCON1 & 0x3fffe; // ENVID Off
}
/**************************************************************
320×240 8Bpp TFT LCD 电源控制引脚使能
**************************************************************/
static void Lcd_PowerEnable(int invpwren,int pwren)
{
//GPG4 is setted as LCD_PWREN
rGPGUP = rGPGUP|(1<<4); // Pull-up disable
rGPGCON = rGPGCON|(3<<8); //GPG4=LCD_PWREN
//Enable LCD POWER ENABLE Function
rLCDCON5 = rLCDCON5&(~(1<<3))|(pwren<<3); // PWREN
rLCDCON5 = rLCDCON5&(~(1<<5))|(invpwren<<5); // INVPWREN
}
/**************************************************************
640×480 TFT LCD单个象素的显示数据输出
**************************************************************/
static void PutPixel(U32 x,U32 y,U16 c)
{
if(x<SCR_XSIZE && y<SCR_YSIZE)
LCD_BUFFER[(y)][(x)] = c;
}
/**************************************************************
640×480 TFT LCD全屏填充特定颜色单元或清屏
**************************************************************/
static void Lcd_ClearScr( U16 c)
{
unsigned int x,y ;
for( y = 0 ; y < SCR_YSIZE ; y++ )
{
for( x = 0 ; x < SCR_XSIZE ; x++ )
{
LCD_BUFFER[y][x] = c ;
}
}
}
//**************************************************************/
static void Glib_Line(int x1,int y1,int x2,int y2, U16 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;
}
}
}
}
}
//==================================================================================
int ReadAdc(int ch)
{
int i;
static int prevCh=-1;
rADCCON = (1<<14)|(preScaler<<6)|(ch<<3); //setup channel
if(prevCh!=ch)
{
rADCCON = (1<<14)|(preScaler<<6)|(ch<<3); //setup channel
for(i=0;i<LOOP;i++); //delay to set up the next channel
prevCh=ch;
}
rADCCON|=0x1; //start ADC