分类: 嵌入式
2009-07-30 17:34:46
#define CONFIG_DRIVER_LCD
/*suport LCD*/
#endif /* __CONFIG_H */
在/board/Embest/edukit2410/目录下建立文件,命名为lcd.c,并将以下代码拷贝到该文件中。
/******************************************************************************************
* File�� lcdapp.c
* Author: Embest
* Desc�� LCD_Test
* History:
*************************************************************************************/
/*------------------------------------------------------------------------------------------*/
/* include files */
/*------------------------------------------------------------------------------------------*/
//#include "2410lib.h"
//#include "lcdlib.h"
#define UINT32T unsigned int
#define INT16T short int
#define UINT8T unsigned char
/*------------------------------------------------------------------------------------------*/
/* constant define */
/*------------------------------------------------------------------------------------------*/
#define LCD_BUF_SIZE (SCR_XSIZE_TFT_640480*SCR_YSIZE_TFT_640480/2)
#define LCD_ACTIVE_BUFFER (0x33800000)
#define LCD_VIRTUAL_BUFFER (0x33800000 + LCD_BUF_SIZE)
#define LCD_D_OFF rGPCDAT &= ~(1 << 4);
#define LCD_D_ON rGPCDAT |= (1 << 4);
#define MODE_TFT_16BIT_640480 (0x4204)
//Timing parameter for V
#define VBPD_640480 ((33-1)&0xff)
#define VFPD_640480 ((10-1)&0xff)
#define VSPW_640480 ((2-1) &0x
#define HBPD_640480 ((48-1)&0x
#define HFPD_640480 ((16-1)&0xff)
#define HSPW_640480 ((96-1)&0xff)
#define MVAL (13)
#define MVAL_USED (0)
#define M5D(n) ((n) & 0x1fffff) // To get lower 21bits
#define CLKVAL_TFT_640480 (1)
//53.5hz @90Mhz
//VSYNC,HSYNC should be inverted
#ifndef CONFIG_LCD_BMP
extern const UINT8T g_ucBitmap[][76800];
#endif //HBPD=47VCLK,HFPD=15VCLK,HSPW=95VCLK
//VBPD=32HSYNC,VFPD=9HSYNC,VSPW=1HSYNC
#define LCDFRAMEBUFFER 0x31000000 //_NONCACHE_STARTADDRESS
// 1. The LCD frame buffer should be write-through or non-cachable.
// 2. The total frame memory should be inside 4MB.
// 3. To meet above 2 conditions, the frame buffer should be
// inside the following regions.
// 0x31000000~0x313ffffff,
// 0x31400000~0x317ffffff,
// 0x31800000~0x31bffffff,
// .....
// 0x33800000~0x33bffffff
// LCD CONTROLLER
#define rLCDCON1 (*(volatile unsigned *)0x4d000000) //LCD control 1
#define rLCDCON2 (*(volatile unsigned *)0x4d000004) //LCD control 2
#define rLCDCON3 (*(volatile unsigned *)0x4d000008) //LCD control 3
#define rLCDCON4 (*(volatile unsigned *)0x4d
#define rLCDCON5 (*(volatile unsigned *)0x4d000010) //LCD control 5
#define rLCDSADDR1 (*(volatile unsigned *)0x4d000014) //STN/TFT Frame buffer start address 1
#define rLCDSADDR2 (*(volatile unsigned *)0x4d000018) //STN/TFT Frame buffer start address 2
#define rLCDSADDR3 (*(volatile unsigned *)0x4d
#define rREDLUT (*(volatile unsigned *)0x4d000020) //STN Red lookup table
#define rGREENLUT (*(volatile unsigned *)0x4d000024) //STN Green lookup table
#define rBLUELUT (*(volatile unsigned *)0x4d000028) //STN Blue lookup table
#define rDITHMODE (*(volatile unsigned *)0x4d
#define rTPAL (*(volatile unsigned *)0x4d000050) //TFT Temporary palette
#define rLCDINTPND (*(volatile unsigned *)0x4d000054) //LCD Interrupt pending
#define rLCDSRCPND (*(volatile unsigned *)0x4d000058) //LCD Interrupt source
#define rLCDINTMSK (*(volatile unsigned *)0x4d
#define rLPCSEL (*(volatile unsigned *)0x4d000060) //LPC3600 Control
#define PALETTE 0x4d000400 //Palette start address
#define rGPCCON (*(volatile unsigned *)0x56000020) //Port C control
#define rGPCDAT (*(volatile unsigned *)0x56000024) //Port C data
#define rGPCUP (*(volatile unsigned *)0x56000028) //Pull-up control C
#define rGPDCON (*(volatile unsigned *)0x56000030) //Port D control
#define rGPDDAT (*(volatile unsigned *)0x56000034) //Port D data
#define rGPDUP (*(volatile unsigned *)0x56000038) //Pull-up control D
#define rGPGCON (*(volatile unsigned *)0x56000060) //Port G control
#define rGPGDAT (*(volatile unsigned *)0x56000064) //Port G data
#define rGPGUP (*(volatile unsigned *)0x56000068) //Pull-up control G
#define LCD_XSIZE_TFT_640480 (640)
#define LCD_YSIZE_TFT_640480 (480)
#define HOZVAL_TFT_640480 (LCD_XSIZE_TFT_640480-1)
#define LINEVAL_TFT_640480 (LCD_YSIZE_TFT_640480-1)
#define SCR_XSIZE_TFT_640480 (LCD_XSIZE_TFT_640480*2)
#define SCR_YSIZE_TFT_640480 (LCD_YSIZE_TFT_640480*2)
UINT32T (*frameBuffer16BitTft640480)[SCR_XSIZE_TFT_640480/2];
void (*PutPixel)(UINT32T,UINT32T,UINT32T);
void (*BitmapView)(UINT8T *pBuffer);
void BitmapViewTft16Bit_640480(UINT8T *pBuffer);
extern void Lcd_Port_Return(void);
unsigned save_rGPCUP,save_rGPCDAT,save_rGPCCON;
unsigned save_rGPDUP,save_rGPDDAT,save_rGPDCON;
void Lcd_port_init(void)
{
save_rGPCCON=rGPCCON;
save_rGPCDAT=rGPCDAT;
save_rGPCUP=rGPCUP;
save_rGPDCON=rGPDCON;
save_rGPDDAT=rGPDDAT;
save_rGPDUP=rGPDUP;
rGPCUP=0xffffffff; // Disable Pull-up register
// rGPCCON=0xaaaaa9aa; // Initialize VD[7:0],LCDVF[2:0],VM,VFRAME,VLINE,VCLK,LEND
rGPCCON=0xaaaaaaaa;
rGPDUP=0xffffffff; // Disable Pull-up register
rGPDCON=0xaaaaaaaa; // Initialize VD[23:8]
// uart_printf(" Initializing GPIO ports..........\n");
}
/***************************************************
* name: Lcd_Port_Return()
* func: Return lcd port configuration
void Lcd_Port_Return(void)
{
rGPCCON=save_rGPCCON;
rGPCDAT=save_rGPCDAT;
rGPCUP=save_rGPCUP;
rGPDCON=save_rGPDCON;
rGPDDAT=save_rGPDDAT;
rGPDUP=save_rGPDUP;
}
/*************************************************
* name: _PutTft16Bit_640480()
* func: put pixel to 16bpp 640*480 TFT
* para: UINT32T x -- x coordinate
* UINT32T y -- y coordinate
* UINT32T c -- color value
void _PutTft16Bit_640480(UINT32T x,UINT32T y,UINT32T c)
{
if(x
frameBuffer16BitTft640480[(y)][(x)/2]=( frameBuffer16BitTft640480[(y)][x/2]
& ~(0xffff0000>>((x)%2)*16) ) | ( (c&0x0000ffff)<<((2-1-((x)%2))*16) );
}
void Lcd_Init(int type)
{
frameBuffer16BitTft640480=(UINT32T (*)[SCR_XSIZE_TFT_640480/2])LCDFRAMEBUFFER;
rLCDCON1=(CLKVAL_TFT_640480<<8)|(MVAL_USED<<7)|(3<<5)|(12<<1)|0;
// TFT LCD panel,16bpp TFT,ENVID=off
rLCDCON2=(VBPD_640480<<24)|(LINEVAL_TFT_640480<<14)|(VFPD_640480<<6)|(VSPW_640480);
rLCDCON3=(HBPD_640480<<19)|(HOZVAL_TFT_640480<<8)|(HFPD_640480);
rLCDCON4=(MVAL<<8)|(HSPW_640480);
rLCDCON5=(1<<11)|(1<<9)|(1<<8); //FRM5:6:5,HSYNC and VSYNC are inverted
rLCDSADDR1=(((UINT32T)frameBuffer16BitTft640480>>22)<<21)|M5D((UINT32T)frameBuffer16BitTft640480>>1);
rLCDSADDR2=M5D( ((UINT32T)frameBuffer16BitTft640480+(SCR_XSIZE_TFT_640480*LCD_YSIZE_TFT_640480*2))>>1 );
rLCDSADDR3=(((SCR_XSIZE_TFT_640480-LCD_XSIZE_TFT_640480)/1)<<11)|(LCD_XSIZE_TFT_640480/1);
rLCDINTMSK|=(3); // MASK LCD Sub Interrupt
rLPCSEL&=(~7); // Disable LPC3600
rTPAL=0; // Disable Temp Palette
}
void Glib_Init(int type)
{
PutPixel=_PutTft16Bit_640480;
BitmapView=BitmapViewTft16Bit_640480;
}
void Glib_ClearScr(UINT32T c, int type)
{
int i,j;
// type:MODE_TFT_1BIT_640480|MODE_TFT_8BIT_640480|MODE_TFT_16BIT_640480
for(j=0;j<20;j++)
for(i=0;i<20;i++)
PutPixel(i,j,c);
}
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
//Enable LCD POWER ENABLE Function
rLCDCON5=rLCDCON5&(~(1<<3))|(pwren<<3); // PWREN
rLCDCON5=rLCDCON5&(~(1<<5))|(invpwren<<5); // INVPWREN
}
/************************************************************
* name: Lcd_EnvidOnOff
* func: lcd Envid onoff configuration
* para: int onoff -- Envid configuration
void Lcd_EnvidOnOff(int onoff)
{
if(onoff==1)
rLCDCON1|=0x00000001; // ENVID=ON
else
rLCDCON1 =rLCDCON1 & 0x3fffe; // ENVID Off
}
/************************************************************
* name: lcd_init_app
* func: lcd application initialization code
void lcd_init_app()
{
Lcd_port_init();
Lcd_Init(MODE_TFT_16BIT_640480);
Glib_Init(MODE_TFT_16BIT_640480);
Glib_ClearScr(0, MODE_TFT_16BIT_640480);
Lcd_PowerEnable(0, 1);
Lcd_EnvidOnOff(1);
}
/********************************************************
* name: lcd_init_app_end
* func: end lcd application initialization
**********************************************************/
void lcd_init_app_end()
{
Lcd_EnvidOnOff(0);
Lcd_Port_Return();
}
/***********************************************************
* name: lcd_clr_rect
* func: fill appointed area with appointed color
* para: usLeft,usTop,usRight,usBottom -- area's rectangle acme coordinate
* ucColor -- appointed color value
void lcd_clr_rect(INT16T usLeft, INT16T usTop, INT16T usRight, INT16T usBottom, UINT8T ucColor)
{
UINT32T i, j;
// UINT8T *pDisp = (UINT8T*)LCD_ACTIVE_BUFFER;
for (i = usLeft; i < usRight; i++)
for (j = usTop; j < usBottom; j++)
{
PutPixel(i,j,ucColor);
//*(pDisp+i+j) = ucColor;
}
}
void lcd_clean(UINT32T c)
{
UINT32T i, j;
UINT32T *pView = (UINT32T*)frameBuffer16BitTft640480;
for (i = 0; i < LCD_YSIZE_TFT_640480; i++)
{
for (j = 0; j < LCD_XSIZE_TFT_640480/2 ; j++)
{
//pView[j] = ((*(pBuffer+3)) << 24) + ((*(pBuffer+2)) << 16) + ((*(pBuffer+1)) << 8) + (*(pBuffer));
pView[j] = c;
//pBuffer += 4;
}
pView+=LCD_XSIZE_TFT_640480;
}
}
/***********************************************************
* name: color_lcd_test()
* func: LCD test function
**************************************************************/
void color_lcd_init(void)
{
printf("lcd initial start\n");
lcd_init_app();
lcd_clean(0x66665555);
printf("lcd initial end\n");
}