这个代码写的让我有点抓况... 很混乱... 算了... 反正只是实验阶段... 玩玩硬件.能够驱动就可以了...
得到一点教训... 寄存器的配置要额外的小心...
我把LCDCON1寄存器中的PNRMODE字段#define错了... 郁闷... TFT屏应该是11B. 而我看了一下...直接给写成0x11了...
我嘞个去.... 屏幕还是居然能亮呢.. 郁闷....
这个比VGA还复杂一些... 几个寄存器我硬是一边看手册一边计算一边写移位... 但还是出错了...悲哀...
贴一下LCD部分的代码.
/* some are hard coded.it's not that good, i know! */
static const unsigned short def_palette[]={
0x0b5e,0xce9a,0xffd9,0x9d99,0xb63a,0xae7c,0xdd71,0x6c57,0xfd4d,0x00ae,0x9c4d,0xb5f8,0xad96,0x0131,0x0176,0xefff,0xcedd,0x9556,0xe4bf,0x00b6,0x22b7,0x002b,0x89de,0x002c,0x57df,0xab5f,0x3031,0x14bf,0x797e,0x5391,0x93ab,0x7239,0x7453,0xafdf,0x71b9,0x8c92,0x014d,0x302e,0x5175,0x0029,0x0969,0x004e,0x2a6d,0x0021,0x3155,0x4b6e,0xd677,0xf6b6,0x9b5f,0x4bb5,0xffd5,0x0027,0xdfdf,0x74d8,0x1256,0x6bcd,0x9b08,0x2ab2,0xbd72,0x84b5,0xfe52,0xd4ad,0x00ad,0xfffc,0x422b,0x73b0,0x0024,0x5246,0x8e5e,0x28b3,0x0050,0x3b52,0x2a4a,0x3a74,0x8559,0x3356,0x1251,0x9abf,0x4034,0x40b1,
0x8cb9,0x00b3,0x5c55,0xdf3d,0x61b7,0x1f5f,0x00d9,0x4c59,0x0926,0xac3f,0x925f,0x85bc,0x29d2,0xc73f,0xef5c,0xcb9f,0x827b,0x5279,0x4af5,0x01b9,0x4290,0xf718,0x126d,0x21a6,0x515e,0xefbd,0xd75e,0x42ab,0x00aa,0x10b3,0x7349,0x63b5,0x61a3,0xaadf,0xcb27,0x87df,0x6359,0xc7df,0x4876,0xb5bc,0x4114,0xfe2e,0xef5e,0x65be,0x43b9,0xe5df,0x21c9,0x7d16,0x6abb,0x5c11,0x49f7,0xbc0b,0x9e1a,0x3b0f,0x202b,0xff12,0x821b,0x842f,0xbccf,0xdefb,0x8a3e,0x68fa,0xa4f1,0x38ae,0x28b7,0x21ad,0x31d7,0x0073,0x182b,0x1831,0x3415,0xbdf6,0x2dbf,0x0a5d,0xc73d,0x182c,0x293e,0x7b3d,0x643d,0x3cbd,
0x92dd,0x09d4,0x1029,0x7cdd,0x6239,0x182e,0x5aea,0x11eb,0x8abc,0x7bfa,0x00a7,0x2153,0x1853,0x1318,0x0109,0x54fa,0x72a7,0x89e3,0x01cf,0x3a07,0x7b17,0x1a14,0x2150,0x23dc,0x4142,0x1b33,0x00a4,0xf6df,0x08fc,0x18ae,0x3a7e,0x18d1,0xa51c,0xff5a,0x1a0f,0x28fa,0xdfbe,0x82de,0x60d7,0x1027,0x48fa,0x5150,0x6213,0x89d6,0x110d,0x9bbb,0xbedd,0x28e1,0x1925,0xf449,0xaa79,0xd5f4,0x693c,0x110a,0x2889,0x08a2,0x923d,0x10a6,0xd9bc,0x5b2e,0x32ec,0xcf7f,0x1025,0x2148,0x74b4,0x6d59,0x9d14,0x0132,0x00f0,0x56bf,0x00f1,0xffff,0x0173,0x0133,0x00b0,0x00b1,0xf7ff,0x08b1,0xfffe,0x08b0,
0x0171,0xf7bf,0x10f3,0xf7fe,0x08ef,0x1192,0xefbe,0x1131,0x2177,0xff9f,0x1116,0xffbc,0x5914,0x22ef,0xb285,0xa6df,
};
#define XSIZE 320
#define YSIZE 240
#define GPCCON (*(volatile unsigned long *)0x56000020)
#define GPCUP (*(volatile unsigned long *)0x56000028)
#define GPDCON (*(volatile unsigned long *)0x56000030)
#define GPDUP (*(volatile unsigned long *)0x56000038)
#define GPGCON (*(volatile unsigned long *)0x56000060)
#define GPGUP (*(volatile unsigned long *)0x56000068)
#define LCDCON1 (*(volatile unsigned long *)0x4d000000)
#define LCDCON2 (*(volatile unsigned long *)0x4d000004)
#define LCDCON3 (*(volatile unsigned long *)0x4d000008)
#define LCDCON4 (*(volatile unsigned long *)0x4d00000c)
#define LCDCON5 (*(volatile unsigned long *)0x4d000010)
#define CLKVAL (6 << 8)
#define TFT_LCD (0x3 << 5)
#define TFT_8BPP (0xb << 1)
#define ENVID (0x1)
#define VBPD (7 << 24)
#define LINEVAL ((YSIZE - 1)<< 14)
#define VFPD (6 << 6)
#define VSPW (14)
#define HBPD (22 << 19)
#define HOZVAL ((XSIZE - 1)<< 8)
#define HFPD (33)
#define HSPW (44)
#define TPAL (*(volatile unsigned long *)0x4d000050)
#define LCDSADDR1 (*(volatile unsigned long *)0x4d000014)
#define LCDSADDR2 (*(volatile unsigned long *)0x4d000018)
#define LCDSADDR3 (*(volatile unsigned long *)0x4d00001c)
#define PALETTE (unsigned long *)0x4d000400
unsigned char *frame_base;
static void lcd_gpiopin_init(void)
{
GPCUP = 0x00000000; /* disable pull-up */
GPCCON = 0xaaaaaaaa; /* VD7 - 0. signal */
GPDUP = 0x00000000;
GPDCON = 0xaaaaaaaa; /* VD23 - VD8 */
}
static void lcd_con_init(void)
{
/*
* vclk = HCLK / ((clkval + 1) * 2)
* Frame Rate = 1/[{(VSPW+1)+(VBPD+1)+(LIINEVAL+1)+(VFPD+1)}x
* {(HSPW+1)+(HBPD+1)+(HFPD+1)+(HOZVAL+1)}x
* {2x(CLKVAL+1)/(HCLK)}]
* = 60Hz
* VSPW = 14; VBPD = 7; VFPD = 6; HSPW = 44; HBPD = 33; HFPD = 22;
* CLKVAL = 6. HCLK = 100MHz, Then Frame Rate is about 60Hz
* this configuration should be working. I hope
*/
LCDCON1 = CLKVAL | TFT_LCD | TFT_8BPP;
LCDCON2 = VBPD | LINEVAL | VFPD | VSPW;
LCDCON3 = HBPD | HOZVAL | HFPD;
LCDCON4 = HSPW;
LCDCON5 = (1<<11) | (0<<10) | (1<<9) | (1<<8) | (0<<7) | (0<<6) | (1<<3) | (1<<1) | 0;
TPAL = 0;
}
#define GETLOWER21BIT(addr) \
((addr) & 0x1fffff)
#define OFFSIZE 0
void set_frame_addr(unsigned long addr)
{
LCDSADDR1 = (((addr >> 22)) << 21)| (GETLOWER21BIT(addr) >> 1);
LCDSADDR2 = GETLOWER21BIT((addr + (XSIZE + OFFSIZE) * (YSIZE)) >> 1);
LCDSADDR3 = (OFFSIZE << 11) | (XSIZE>>1);
}
void lcd_power_on(void)
{
GPGCON = (GPGCON & ~(3 << 8)) | (3 << 8);
GPGUP |= 1 << 4;
// LCDCON5 |= (1 << 5);
LCDCON5 |= 1 << 3;
}
#define ENVID_ENABLE (1)
#define ENVID_DISABLE ((~1) & 0x3ffffff)
static void __lcd_envid_con(int enable)
{
if(enable) {
LCDCON1 |= ENVID_ENABLE;
} else {
LCDCON1 &= ENVID_DISABLE;
}
}
void lcd_envid_enable(void)
{
__lcd_envid_con(1);
}
void lcd_envid_disable(void)
{
__lcd_envid_con(0);
}
void lcd_init(void)
{
lcd_gpiopin_init();
lcd_con_init();
lcd_power_on();
}
#define VSTATUS_ACTIVE (3 << 15)
#define HSTATUS_ACTIVE (3 << 13)
static inline void wait_palette(void)
{
while(LCDCON5 & (VSTATUS_ACTIVE | HSTATUS_ACTIVE)) ;
}
void default_palette_init(void)
{
int i;
unsigned long *palette = PALETTE;
for(i = 0; i < 256; i++) {
wait_palette();
palette[i] = def_palette[i];
}
}
void putpixel(int x, int y, int color)
{
unsigned char *pixel = (unsigned char *)frame_base;
pixel[y*XSIZE + x] = (unsigned char)color;
}
void clr_lcd(unsigned char color)
{
int i, j;
for(i = 0; i < YSIZE; i++)
for(j = 0; j < XSIZE; j++)
putpixel(j, i, color);
}
阅读(1994) | 评论(0) | 转发(0) |