📄 lcd.c.tft
字号:
#include <asm/hardware.h>#include <bios/stdio.h>#include <bios/stdioint.h>#include <bios/config.h>#include <bios/types.h>#include <stdarg.h>#include "font-8x15.c"//#include "vgafonts.c"#include "logo.c"#include <bios/lcd.h> #define LCDDEBUG#undef LCDDEBUG#ifdef LCDDEBUG#define LCDPRINTF(fmt, args...) printf("%s-%s()[%d]: " fmt, __FILE__, __FUNCTION__, __LINE__,args)#else#define LCDPRINTF(fmt, args...)#endif#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)#define BK_GR 0xFFFFFFFF /* white */#define FR_GR 0x00000000 /* black */void 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);#define convert(a) (a)?FR_GR:BK_GRvoid do_logo(void){ unsigned char *pixel, *buf; int i, j, k; clrScreen(); setRC(1,12); lcd_printf("vitals system\n\n"); pixel = &fb->pixel[0][0]; buf = logo; for(i=0; i<(3*(fh->high)); i++) { 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); }}int lcd_prints(char *buff, int nr){ int i; for(i=0; i<nr; i++) LCDPutChar(buff[i]); return 0;}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;}void lcd_init(void){ fh = (struct font_header *) fontP; flw = fh->wide * fh->count; while (flw % 4 != 0) flw++; Lcd_Port_Init(); Lcd_Init(MODE_TFT_16BIT_240320); Glib_Init(MODE_TFT_16BIT_240320); LCD_DisplayControl(1);#if 1 { int i; int *temp=(int *)0xc1f00000; for(i=0; i<0x40000; i++) *(temp+i) = BK_GR; }#endif setRC(0,0);}/* 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;// LCDPRINTF("row, col = [%d, %d]\n", row, col); /* check raw/col in range */ /* FR_HEIGHT(240), fh->high(15), FR_WIDTH(320), fh->wide(8) */// LCDPRINTF("fh->high : fh->wide = [%x:%x]\n", fh->high, fh->wide); 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];// LCDPRINTF("pix:fb->pixel[0][0] = [%x:%x]\n", pix,&fb->pixel[0][0]); buf = fontP + 6;// LCDPRINTF("buf = [%x]\n", buf); for (i = 0; i < fh->high; i++) { int j; for(j=0; j<8; j++) *(pix+j) = (unsigned char)convert( (buf[i * fh->count+(c - fh->start)]>>j) & 0x1); 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; /* 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; return ;}/* * clear cursor */void clearCursor () /* ??? */{ 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]); /* 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++) { *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 = 20; } if(do_scroll) { scroll(); } return;}void putcToFB (char c){ putcToFBrc(c, fb->row, fb->col);}void putcToFBi (char c) {// LCDPRINTF("ptcToFBi function = [%c]\n", c);// LCDPRINTF("fb->raw = [%d], fb->col = [%d]\n", fb->row, fb->col); 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();// LCDPRINTF("LCDPutChar function = [%c]\n", c); putcToFBi(c);}/**********************************************//* Description the s3c2400x reference board *//**********************************************//* Made by Myunghui Ryu *//* Copyright by Myunghui Ryu and V.S.I. *//* 25.Feb.2002 *//**********************************************/unsigned static int srpccon, srpdcon;void Lcd_Port_Init(void){ srpccon = CSR_READ(PCCON); srpdcon = CSR_READ(PDCON); CSR_WRITE(PCCON, 0xaaaaaaaa); //VD[15:0] Initialization CSR_WRITE(PDCON, (CSR_READ(PDCON) & 0xfffffc00)); //VCLK,VLINE,VM,VFRAME,LEND CSR_WRITE(PDCON, (CSR_READ(PDCON) | 0x2aa)); //VCLK,VLINE,VM,VFRAME,LEND CSR_WRITE(PDUP, (CSR_READ(PDUP) | 0x1f));}u32 (*frameBuffer16BitTft240320)[SCR_XSIZE_TFT_240320/2];void Lcd_Init(int type){ switch(type) { case MODE_TFT_16BIT_240320: frameBuffer16BitTft240320=(u32 (*)[SCR_XSIZE_TFT_240320/2])LCDFRAMEBUFFER;// (u32) fb = LCDFRAMEBUFFER; (u32) fb = frameBuffer16BitTft240320; CSR_WRITE(LCDCON1, ((CLKVAL_TFT_240320<<8)|(MVAL_USED<<7)|(0x3<<5)|(0xC<<1)|0)); // TFT LCD panel,12bpp TFT,ENVID=off CSR_WRITE(LCDCON2, ((VBPD_240320<<24)|(LINEVAL_TFT_240320<<14)|(VFPD_240320<<6)|(VSPW_240320))); CSR_WRITE(LCDCON3, ((HBPD_240320<<19)|(HOZVAL_TFT_240320<<8)|(HFPD_240320))); CSR_WRITE(LCDCON4, ((MVAL<<8)|(HSPW_240320))); CSR_WRITE(LCDCON5, ((1<<9)|(1<<8)|(1<<1))); CSR_WRITE(LCDSADDR1, ((((u32)0xdf00000>>22)<<21)|M5D((u32)0xdf00000>>1))); CSR_WRITE(LCDSADDR2, (M5D( ((u32)0xdf00000+(SCR_XSIZE_TFT_240320*LCD_YSIZE_TFT_240320*2))>>1 ))); CSR_WRITE(LCDSADDR3, ((((SCR_XSIZE_TFT_240320-LCD_XSIZE_TFT_240320)/1)<<11)|(LCD_XSIZE_TFT_240320/1))); CSR_WRITE(TPAL, 0x0); break; default: break; }}void LCD_DisplayControl(int onoff){ // 1:LCD on 0:LCD off if(onoff==1) { CSR_WRITE(LCDCON1, (CSR_READ(LCDCON1) | 1)); } else { CSR_WRITE(LCDCON1, (CSR_READ(LCDCON1) & 0x3fffe)); } CSR_WRITE(PDDAT, ((CSR_READ(PDDAT)&(~(1<<9)))|(onoff<<9))); CSR_WRITE(PDCON, ((CSR_READ(PDCON)&(~(3<<18)))|(1<<18)));}void (*PutPixel)(u32,u32,u32);void Glib_Init(int type){ switch(type) { case MODE_TFT_16BIT_240320: PutPixel=_PutTft16Bit_240320; break; default: break; }}void _PutTft16Bit_240320(u32 x,u32 y,u32 c){ if(x<SCR_XSIZE_TFT_240320 && y<SCR_YSIZE_TFT_240320) { frameBuffer16BitTft240320[(y)][(x)/2] = (frameBuffer16BitTft240320[(y)][x/2] & ~(0xffff0000>>((x)%2)*16) ) | ( (c&0x0000ffff)<<((2-1-((x)%2))*16)); }}void Glib_ClearScr(u32 c, int type){ int i,j; for(j=0;j<SCR_YSIZE_TFT_240320;j++) { for(i=0;i<SCR_XSIZE_TFT_240320;i++) {// printf("i=[%d], j=[%d], c=[%d]\n",i, j, c); PutPixel(i,j,c); } }}void Glib_Rectangle(int x1,int y1,int x2,int y2,int color){ Glib_Line(x1,y1,x2,y1,color); Glib_Line(x2,y1,x2,y2,color); Glib_Line(x1,y2,x2,y2,color); Glib_Line(x1,y1,x1,y2,color);}void Glib_FilledRectangle(int x1,int y1,int x2,int y2,int color){ int i; for(i=y1;i<=y2;i++) Glib_Line(x1,i,x2,i,color);}void Glib_Line(int x1,int y1,int x2,int y2,int 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; } } } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -