lcd_driver.c

来自「S3c44b0x下的ucgui」· C语言 代码 · 共 793 行 · 第 1/2 页

C
793
字号
  x+=2;  pixels = *(++p);  goto WriteTBit0;}#endif/*    *********************************************    *                                           *    *      Draw Bitmap 8 BPP  (256 colors)      *    *                                           *    **********************************************/#if (LCD_MAX_LOG_COLORS > 16)static void  DrawBitLine8BPP(int x, int y, U8 const*p, int xsize, const LCD_PIXELINDEX*pTrans) {  LCD_PIXELINDEX pixel;  if ((GUI_Context.DrawMode & LCD_DRAWMODE_TRANS)==0) {    if (pTrans) {      for (;xsize > 0; xsize--,x++,p++) {        pixel = *p;        SETPIXEL(x, y, *(pTrans+pixel));      }    } else {      for (;xsize > 0; xsize--,x++,p++) {        SETPIXEL(x, y, *p);      }    }  } else {   /* Handle transparent bitmap */    if (pTrans) {      for (; xsize > 0; xsize--, x++, p++) {        pixel = *p;        if (pixel) {          SETPIXEL(x+0, y, *(pTrans+pixel));        }      }    } else {      for (; xsize > 0; xsize--, x++, p++) {        pixel = *p;        if (pixel) {          SETPIXEL(x+0, y, pixel);        }      }    }  }}#endif/*    *********************************************    *                                           *    *      Draw Bitmap 16 BPP  (65536 colors)   *    *                                           *    **********************************************/#if (LCD_BITSPERPIXEL > 8)static void  DrawBitLine16BPP(int x, int y, U16 const*p, int xsize, const LCD_PIXELINDEX*pTrans) {  LCD_PIXELINDEX pixel;  if ((GUI_Context.DrawMode & LCD_DRAWMODE_TRANS)==0) {    if (pTrans) {      for (;xsize > 0; xsize--,x++,p++) {        pixel = *p;        SETPIXEL(x, y, *(pTrans+pixel));      }    } else {      for (;xsize > 0; xsize--,x++,p++) {        SETPIXEL(x, y, *p);      }    }  } else {   /* Handle transparent bitmap */    if (pTrans) {      for (; xsize > 0; xsize--, x++, p++) {        pixel = *p;        if (pixel) {          SETPIXEL(x+0, y, *(pTrans+pixel));        }      }    } else {      for (; xsize > 0; xsize--, x++, p++) {        pixel = *p;        if (pixel) {          SETPIXEL(x+0, y, pixel);        }      }    }  }}#endif/*        *********************************************************        *                                                       *        *         Universal draw Bitmap routine                 *        *                                                       *        **********************************************************/void LCD_L0_DrawBitmap   (int x0, int y0,                       int xsize, int ysize,                       int BitsPerPixel,                        int BytesPerLine,                       const U8* pData, int Diff,                       const LCD_PIXELINDEX* pTrans){  int i;  /*     Use DrawBitLineXBPP  */  for (i=0; i<ysize; i++) {    switch (BitsPerPixel) {    case 1:      DrawBitLine1BPP(x0, i+y0, pData, Diff, xsize, pTrans);      break;    #if (LCD_MAX_LOG_COLORS > 2)      case 2:        DrawBitLine2BPP(x0, i+y0, pData, Diff, xsize, pTrans);        break;    #endif    #if (LCD_MAX_LOG_COLORS > 4)      case 4:        DrawBitLine4BPP(x0, i+y0, pData, Diff, xsize, pTrans);        break;    #endif    #if (LCD_MAX_LOG_COLORS > 16)      case 8:        DrawBitLine8BPP(x0, i+y0, pData, xsize, pTrans);        break;    #endif    #if (LCD_BITSPERPIXEL > 8)      case 16:        DrawBitLine16BPP(x0, i+y0, (const U16 *)pData, xsize, pTrans);        break;    #endif    }    pData += BytesPerLine;  }}/**********************************************************       LCD_L0_SetOrg**********************************************************Purpose:        Sets the original position of the virtual display.                Has no function at this point with the PC-driver.*/int OrgX, OrgY;void LCD_L0_SetOrg(int x, int y) {  OrgX = x;  OrgY = y;}/*        *********************************************************        *                                                       *        *           Support for verification                    *        *                                                       *        *********************************************************The following routines are implemented, but have no functionilityat this point. The reason is that these functions are supposedto supervise the hardware, which for obvious reasons can not bedone in a simulation.*/#if LCD_VERIFYint  LCD_GetErrStat(void) {  return 0;}void LCD_ClrErrStat(void) {}int  LCD_GetErrCnt (void) {  return 0;}#endif  /*        *********************************************************        *                                                       *        *       LCD_On                                          *        *       LCD_Off                                         *        *                                                       *        *********************************************************(Not supported in Simulation)*/void LCD_Off          (void) {    Delay(100);    rPDATC = ( rPDATC | (1<<8) );    Delay(100);}void LCD_On           (void) {	Delay(100);    rPDATC = ( rPDATC & (~(1<<8)) );    Delay(100);}/*        *********************************************************        *                                                       *        *       LUT routines (lookup tables)                    *        *                                                       *        **********************************************************/void LCD_L0_SetLUTEntry(U8 Pos, LCD_COLOR color) {  LCDSIM_SetLUTEntry(Pos, color);}#define SCR_XSIZE 			(320)  #define SCR_YSIZE 			(240)#define LCD_XSIZE 			(320)#define LCD_YSIZE 			(240)#define M5D(n)				((n) & 0x1fffff)#define MVAL_USED (0)#define MVAL (13)//#define INVCLK (0)//#define INVFRAME (0)//#define INVLINE (0)//#define CLKVAL_SL (8) //VCLK=MCLK/(CLKVAL*2) (CLKVAL >= 2)#define M5D(n) ((n) & 0x1fffff)#define ARRAY_SIZE_G16 (SCR_XSIZE*SCR_YSIZE)#define ARRAY_SIZE_COLOR 	(SCR_XSIZE/2*SCR_YSIZE)#define CLKVAL_GREY16 		(12)#define HOZVAL (LCD_XSIZE/4-1)#define LINEVAL (LCD_YSIZE-1)#define MVAL (13)unsigned char frameBuffer[ARRAY_SIZE_COLOR];//unsigned char *display_buffer = frameBuffer;//#define BSWP (1)//这个决定了每4 个字节的顺序是否进行交换//#define MODESEL (2)//Gray 16/*        *********************************************************        *                                                       *        *          LCD_Init_Controller                          *        *                                                       *        **********************************************************/void LCD_Init_Controller(){         	    /* The following value has to be changed for better display.*/	rREDLUT  =0xfdb96420;	rGREENLUT=0xfdb96420;	rBLUELUT =0xfb40;//	rDITHMODE=0x0;	rDITHMODE=0x1223a;	rDP1_2 =0x5a5a;      	rDP4_7 =0x366cd9b;	rDP3_5 =0xda5a7;	rDP2_3 =0xad7;	rDP5_7 =0xfeda5b7;	rDP3_4 =0xebd7;	rDP4_5 =0xebfd7;	rDP6_7 =0x7efdfbf;	rLCDCON1=(0)|(1<<5)|(MVAL_USED<<7)|(0x0<<8)|(0x0<<10)|(CLKVAL_GREY16<<12);	rLCDCON2=(LINEVAL)|(HOZVAL<<10)|(10<<21); 	rLCDSADDR1= (0x2<<27) | ( (((U32)frameBuffer>>22)<<21 ) | M5D((U32)frameBuffer>>1)); 	rLCDSADDR2= M5D((((U32)frameBuffer+(SCR_XSIZE*LCD_YSIZE/2))>>1)) | (MVAL<<21);	rLCDSADDR3= (LCD_XSIZE/4) | ( ((SCR_XSIZE-LCD_XSIZE)/4)<<9 );	// enable,4B_SNGL_SCAN,WDLY=8clk,WLH=8clk,	rLCDCON1=(1)|(1<<5)|(MVAL_USED<<7)|(0x3<<8)|(0x3<<10)|(CLKVAL_GREY16<<12);	//rBLUELUT=0xfa40;	//Enable LCD Logic and EL back-light.	rPDATE=rPDATE&0x0e;}/*        *********************************************************        *                                                       *        *                lcd_put_pixel                          *        *                                                       *        **********************************************************/void lcd_put_pixel(int x,int y,int c){        if(x<SCR_XSIZE && y<SCR_YSIZE) {    (*(INT32U *)(frameBuffer + (y) * SCR_XSIZE / 2 + ((x)) / 8 * 4)) = \	(*(INT32U *)(frameBuffer + (y) * SCR_XSIZE / 2 + ((x)) / 8 * 4)) & \	(~(0xf0000000 >> ((((x))%8)*4))) |((c) << (7 - ((x))%8) * 4);	}	}/*        *********************************************************        *                                                       *        *       LCD_Init : Init the display                     *        *                                                       *        **********************************************************/int  LCD_L0_Init(void) {  int x,y;  LCD_Init_Controller();  // Create Bitmaps to simulate LCD (pages)  for (x=0; x< LCD_XSIZE; x++)    for (y=0; y< LCD_YSIZE; y++)        SETPIXEL( x, y, BKCOLORINDEX);        //SETPIXEL( x, y, LCD_Color2Index_4(GUI_WHITE));	return 0;}int  LCD_L0_CheckInit(void) {  return 0;} /*        ******************************************        *                                        *        *    Re-initialize LCD                   *        *                                        *        ******************************************This routine is supplied for compatibility and interchangability of"C"-sources with embedded versions of the driver. It has no realeffect in the PC-version as there is simply no need to re-initializethe LCD since it is just simulated anyhow.*/void LCD_L0_ReInit       (void) {}unsigned LCD_L0_GetPixelIndex(int x, int y)  {  return LCDSIM_GetPixelIndex(x,y);}/*        *********************************************************        *                                                       *        *       LCD_L0_XorPixel                                 *        *                                                       *        *********************************************************Purpose:  This routine is called by emWin. It writes 1 pixel into the          display.*/void LCD_L0_XorPixel(int x, int y) {  XORPIXEL(x, y);}/*        *********************************************************        *                                                       *        *       LCD_L0_SetPixelIndex                            *        *                                                       *        *********************************************************Purpose:  This routine is called by emWin. It writes 1 pixel into the          display.*/void LCD_L0_SetPixelIndex(int x, int y, int ColorIndex) {  SETPIXEL(x, y, ColorIndex);}int  LCDSIM_GetPixelIndex(int x, int y){//?    INT8U ucColor;	ucColor = *((INT8U*)(frameBuffer + y*SCR_XSIZE/2 + x/8*4 + 3 - (x%8)/2));	ucColor = (ucColor >> ((1-(x%2))*4)) & 0x0f;	//return LCD_Color2Index_4(ucColor);	return ucColor;}void  LCDSIM_SetPixelIndex(int x, int y, int c) {  /*  LCD_COLOR color;    int color_data;    color=LCD_Index2Color_4(c);    color_data=color & 0xff;*/	lcd_put_pixel(x, y, c);}void  LCDSIM_SetLUTEntry(U8 Pos, LCD_COLOR color){//? }

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?