lcd.c.org
来自「ADS下的bios工程」· ORG 代码 · 共 532 行
ORG
532 行
#include <bios/s3c2410x.h>#include <bios/stdio.h>#include <bios/stdioint.h>#include <bios/config.h>#include <bios/lcd.h>#include <stdarg.h>#include "font-8x15.c"#include "logo.c" #define SET_RC(r, c) (fb->row = r, fb->col = c)#define INC_ROW (fb->row++)#define DEC_ROW (fb->row--)#define INC_COL (fb->col++)#define DEC_COL (fb->col--)#define SET_COL(c) (fb->col = c)#define SET_ROW(r) (fb->row = r)#if defined(CONFIG_LCD_MONO320X240) || defined(CONFIG_LCD_GRAY320X240)#define BK_GR 0x00000000 /* black *///#define BK_GR 0x88888888 /* middle gray */#define FR_GR 0xFFFFFFFF /* white *///#define BK_GR 0x88888888 /* middle gray */#else#define BK_GR 0xFFFFFFFF /* white *///#define BK_GR 0x03030303 /* blue */#define FR_GR 0x00000000 /* black *///#define FR_GR 0x03030303 /* blue */#endifvoid lcd_init(void);extern void debug(unsigned char *);static FB *fb ;static struct font_header *fh ;static int flw ;extern FB SAis_Frame ;int do_kbd_init;int do_scroll;int lcd_printf(const char *fmt, ...);void LCDPutChar(unsigned char c) ;void do_logo(void);#ifdef CONFIG_LCD_GRAY320X240static unsigned int pixel_table[] = { 0x00000000, 0xF0F0F0F0, 0x0F0F0F0F, 0xFFFFFFFF// 0x00000000, 0x80808080, 0x08080808, 0x88888888 /* text middle gray */// 0x88888888, 0xF8F8F8F8, 0x8F8F8F8F, 0xFFFFFFFF /* back-ground middle gray */};#else /* CONFIG_LCD_STN320X240 */#define convert(a) (a)?FR_GR:BK_GR#endifvoid do_logo(void){ unsigned char *pixel, *buf; int i, j, k; lcd_init(); clrScreen();#if 0 pixel = &fb->pixel[0][0]; printf("frame buffer address : %x\n", pixel); while(1) { for(j=0; j<240; j++) { printf("line number : %d\n", j); for(i=0; i<320; i++) { printf("colum number : %d\n", i); *(pixel+i+(j*320)) = 0x0; getc(); } } }#endif setRC(1,12); lcd_printf("vitals system\n\n"); pixel = &fb->pixel[0][0]; buf = logo; for(i=0; i<(3*(fh->high)); i++) {#if defined(CONFIG_LCD_MONO320X240) for(k=0; k<4; k++) fb->pixel[i][(26+k)] = logo_mono[(i*4)+k];#elif defined(CONFIG_LCD_GRAY320X240) for(j=0; j<4; j++) for(k=0; k<4; k++) fb->pixel[i][((26+k)*BPP)+j] = (unsigned char)pixel_table[(logo[(i*4)+k] >> (j*2)) & 0x3];#elif defined(CONFIG_LCD_STN320X240) for(j=0; j<8; j++) for(k=0; k<4; k++) fb->pixel[i][((26+k)*8)+j] = convert((logo[(i*4)+k]>>j) & 0x1);#endif }}void lcd_prints(char *buff, int nr){ int i; for(i=0; i<nr; i++) LCDPutChar(buff[i]);}int lcd_printf(const char *fmt, ...){ char buf[128]; va_list ap; int len; va_start(ap, fmt); len = vsprintf(buf, fmt, ap); va_end(ap); lcd_prints(buf, len); return len;}#define v_to_p(v_addr) ((unsigned long)((*(unsigned long *)((RESET_SDRAM_BASE+0x4000)+(v_addr>>18))) & 0xFFFFF000) + (v_addr & 0xFFFFF))//char v_fontP[0x598];void lcd_init(void){ unsigned int x; unsigned char *pixel; unsigned int lcdbank, lcdbaseu, lcdbasel;#if 0 /* khjung */ for(x=0; x<sizeof(fontP); x++) v_fontP[x] = fontP[x]; fh = (struct font_header *) v_fontP;// printf("sizeof(fontP)[%x][%x]\n", sizeof(fontP), fh);#else fh = (struct font_header *) fontP;#endif flw = fh->wide * fh->count; /* ??? */ while (flw % 4 != 0) flw++; /* At 12M in non-cached, unbuffered RAM, for now */ fb = (struct FrameBuffer *)LCD_FRAME_BUFFER; /* virtual : 0xC1F00000 */ /* Special Register Base Address Setting */ x = (unsigned int)&fb->pixel[0][0];// printf("Frame Buffer : virt(%x), phys(%x), %x, %x\n", x, v_to_p(x), x>>18, (RESET_SDRAM_BASE+0x4000)+(x>>18)); x = v_to_p(x);// printf("x(%x)\n", x); lcdbank = (unsigned int)x >> 22; lcdbaseu = ((unsigned int)x & 0x3fffff) >> 1; lcdbasel = (lcdbaseu + ((bPAGEWIDTH+bOFFSIZE) * FR_HEIGHT)); CSR_WRITE(LCDCON1, bLCDCON1); CSR_WRITE(LCDCON2, bLCDCON2); CSR_WRITE(LCDCON3, bLCDCON3); CSR_WRITE(LCDCON4, bLCDCON4); CSR_WRITE(LCDCON5, bLCDCON5); CSR_WRITE(LCDSADDR1, ((lcdbank)<<21) | (lcdbaseu)); CSR_WRITE(LCDSADDR2, lcdbasel); CSR_WRITE(LCDSADDR3, (bOFFSIZE<<11) | bPAGEWIDTH);#if defined(CONFIG_LCD_MONO320X240)#elif defined(CONFIG_LCD_GRAY320X240)#elif defined(CONFIG_LCD_STN320X240) CSR_WRITE(REDLUT, 0xfdb96420); CSR_WRITE(GREENLUT, 0xfdb96420); CSR_WRITE(BLUELUT, 0xfb40); /* IO Port Initialize */// CSR_WRITE(PDCON, ((CSR_READ(PDCON)&0x3FFCFF)|0x100)); /* GPD4 : output mode */// CSR_WRITE(PDDAT, CSR_READ(PDDAT) | 0x10); /* DISP Enable */ CSR_WRITE(DITHMODE, 0x12210);#elif defined(CONFIG_LCD_STN640X480)#elif defined(CONFIG_LCD_TFT320X240)#endif{ // khjung// printf("LCDCON1(%x), LCDCON2(%x), LCDCON3(%x)\n", CSR_READ(LCDCON1), CSR_READ(LCDCON2), CSR_READ(LCDCON3)); // printf("LCDCON4(%x:%x), LCDCON5(%x)\n", bLCDCON4, CSR_READ(LCDCON4), CSR_READ(LCDCON5)); // printf("LCDADDR1(%x), LCDADDR2(%x), LCDADDR3(%x)\n", CSR_READ(LCDSADDR1), CSR_READ(LCDSADDR2), CSR_READ(LCDSADDR3)); } CSR_WRITE(LCDCON1, CSR_READ(LCDCON1) | 1); setRC(0,0); pixel = &fb->pixel[0][0] ;#if 0#if defined(CONFIG_LCD_GRAY320X240) /* for test */ for(y=0; y<FR_HEIGHT; y++){ for(x=0; x<((FR_WIDTH*BPP)/8); x++){ value = (x/40)+((y/60)*4); value = value | (value<<4); *(pixel+x+(y*(FR_WIDTH*BPP)/8)) = value; } }#endif#endif for (x = FR_HEIGHT * ((FR_WIDTH*BPP)/8); x > 0; x--) *(pixel+x) = (unsigned char)BK_GR;}/* setting row / col in Frame Buffer */void setRC (int r, int c) { fb->row=r, fb->col = c;}void incRC (int ir, int ic) { fb->row += ir; fb->col += ic;}void setRow (int r) { fb->row = r;}void setCol (int c) { fb->col = c;}int getCol () { return fb->col;}int getRow () { return fb->row;}/* * the following code sets up the LCD as terminal screen for the itsy screen * it uses a 16x9 fixed font so gets a 11 rows of 32 chars *//* * fast screen cleaner */void clrScreen(void){ int i, *p; /* get pointer to start of frame buffer */ p = (int *) fb->pixel; /* clear all of buffer */ for (i = 0; i < ((((FR_WIDTH*BPP)/fh->wide) * FR_HEIGHT) / 4); i++) *p++ = BK_GR; do_scroll = 0; fb->row = 0; fb->col = 0;}/* * fast char row cleaner */void clrCharRow (int row){ int *p, i ; /* get pointer to start of row in frame buffer */ p = (int *) (&fb->pixel[0][0] + (row * (fh->high * ((FR_WIDTH*BPP)/fh->wide)))); /* clear a row of char in frame buffer */ for (i = ((((FR_WIDTH*BPP)/fh->wide) * fh->high) / 4); i > 0; i--) *p++ = BK_GR;}void putcToFBrc (char c, unsigned int row, unsigned int col){ char *buf; volatile unsigned char *pix; int i; /* check row/col in range */ /* FR_HEIGHT(240), fh->high(15), FR_WIDTH(320), fh->wide(8) */ if ((row > FR_HEIGHT / fh->high) || (col >= FR_WIDTH / fh->wide)) { return ; } /* gen pointer into fb at upper left corner of char cell */ pix = &fb->pixel[(row * fh->high)][col*BPP]; buf = fontP + 6; for (i = 0; i < fh->high; i++) {#if defined(CONFIG_LCD_MONO320X240) *pix = buf[i * fh->count + (c - fh->start)];#elif defined(CONFIG_LCD_GRAY320X240) int j; for(j=0; j<4; j++) *(pix+j) = (unsigned char)pixel_table[(buf[(i*fh->count)+(c - fh->start)] >> (j*2)) & 0x3];#elif defined CONFIG_LCD_STN320X240 int j; for(j=0; j<8; j++) *(pix+j) = (unsigned char)convert( (buf[i * fh->count+(c - fh->start)]>>j) & 0x1);#else /* CONFIG_LCD_STN640X480 */#endif pix += ((FR_WIDTH*BPP) / fh->wide); } return ;}void drawBox (int x1, int y1, int x2, int y2, int c) /* ??? */{ unsigned char *pix; /* Should I check out of range? */ pix = &fb->pixel[x1][y1]; /* ??? */}/* * position cursor */void setCursor (int row, int col) /* ??? */{ unsigned char *pix;#if 1 /* check row/col in range */ if ((row > 10) || (col > 31)) { return ; } /* gen pointer into fb at lower left corner of char cell */ pix = &fb->pixel[((row * 18) + 1 + 17)][col * 10]; *pix++ = 0x11; *pix++ = 0x11; *pix++ = 0x11; *pix++ = 0x11; *pix++ = 0x11; fb->row = row; fb->col = col;#else int i, j; /* check row/col in range */ /* FR_HEIGHT(240), fh->high(15), FR_WIDTH(320), fh->wide(8) */ if ((row > FR_HEIGHT / fh->high) || (col >= FR_WIDTH / fh->wide)) { return ; } /* gen pointer into fb at lower left corner of char cell */ pix = &fb->pixel[(row * fh->high)][col*fh->wide]; /* pixel current address */ for (i = 0; i < fh->high; i++) { if(i == 14 || i == 15) { for(j=0; j<8; j++) *(pix+j) = (unsigned char)convert( (0xff>>j) & 0x1); } pix += FR_WIDTH; }#endif return ;}/* * clear cursor */void clearCursor () /* ??? */{#if 0#ifdef CONFIG_LCD_STN320X240 unsigned int *pix; int i, j; /* gen pointer into fb at lower left corner of char cell */ pix = &fb->pixel[(fb->row * fh->high)][fb->col*fh->wide]; /* pixel current address */ for (i = 0; i < fh->high; i++) { if(i==14 || i==15) *pix++ = BK_GR; pix += FR_WIDTH; }#endif#endif return ;}/* * move cursor */int moveCursor (int r, int c) /* ??? */{ unsigned char *pix; /* check row/col in range */ if ((r > 10) || (c > 31)) { return -1; } /* gen pointer into fb at lower left corner of current char cell */ pix = &fb->pixel[((r * 18) + 1 + 17)][c * 5]; *pix++ = 0x0; *pix++ = 0x0; *pix++ = 0x0; *pix++ = 0x0; *pix++ = 0x0; /* gen pointer into fb at lower left corner of new char cell */ pix = &fb->pixel[((r * 18) + 1 + 17)][c * 5]; *pix++ = 0x11; *pix++ = 0x11; *pix++ = 0x11; *pix++ = 0x11; *pix++ = 0x11; fb->row = r; fb->col = c; return (0);}/* * Fast scroll up one line */void scroll(void){ int *f, *t, size, j; /* get pointer to start of row 1 in frame buffer */ f = (int *) (&fb->pixel[0][0]); /* get pointer to start of row 0 in frame buffer */ t = (int *) (&fb->pixel[15][0]); //#ifdef CONFIG_LCD_MONO320X240 /* Get size of one row(word size) */ size = (fh->high * ((FR_WIDTH*BPP)/fh->wide))/4 ; /* move all ten rows up one */ for(j=0; j<((FR_HEIGHT/fh->high)*size); j++) {//#else// /* Get size of one row(word size) */// size = (fh->high * ((FR_WIDTH*BPP)/fh->wide))/4 ;// /* move all ten rows up one */// for(j=0; j<(((FR_HEIGHT/fh->high)-1)*size); j++) {//#endif *f++ = *t++; } /* clear new row */ clrCharRow((FR_HEIGHT/fh->high) - 1); }/* move curser point to next line */void new_line(void){ fb->row++; fb->col=0; if(fb->row == (FR_HEIGHT/fh->high)){ do_scroll = 1; fb->row = 15; } if(do_scroll) { scroll(); } return;}void putcToFB (char c){ putcToFBrc(c, fb->row, fb->col);}void putcToFBi (char c) { switch(c){ case '\n': case '\r': new_line(); break; case '\t': /* 0x09(tab) */ lcd_prints(" ", 5); break; case '\b': case 0x7F: /* DEL */ if(fb->col) { fb->col--; LCDPutChar(0x20); fb->col--; } break; case 0x0C: /* CLEAR */ clrScreen(); break; default: putcToFBrc(c, fb->row, fb->col); fb->col++; if (fb->col >= (FR_WIDTH / fh->wide)) { new_line(); } break; }}void putcToFBd (char c){ putcToFBrc(c, fb->row, fb->col); if (fb->col > 0) fb->col--;}void putsToFB (char *cp){ while (*cp != 0) putcToFBi(*cp++);}extern int WriteSibFrame(int, int) ;void do_init_if_necessary(void){ if (do_kbd_init) { do_kbd_init = 0; lcd_init(); setRC(0,0); }}void screen_phex(int ls) /* ??? */{ int i, v; for (i = 8 ; i > 0 ; i--) { v = (ls & 0xf0000000) >> 28; if (v < 10) LCDPutChar(v + 48); else LCDPutChar(v - 10 + 97); ls = ls << 4; } LCDPutChar(10);}void LCDPutChar(unsigned char c) { do_init_if_necessary(); putcToFBi(c);}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?