⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 lcd_lc256_.c

📁 水箱自动控制系统
💻 C
📖 第 1 页 / 共 2 页
字号:
/*256色低位在前Bit01234567*/
/*
*************************************************************************************************
Init & display control group
*************************************************************************************************
LCD_L0_Init() Initialize the display.
LCD_L0_ReInit() Reinitialize LCD without erasing the contents.
LCD_L0_Off() Switch LCD off.
LCD_L0_On() Switch LCD on.
*************************************************************************************************
Drawing group
*************************************************************************************************
LCD_L0_DrawBitmap() Universal draw bitmap routine.
LCD_L0_DrawHLine() Draw a horizontal line.
LCD_L0_DrawPixel() Draw a pixel in the current foreground color.
LCD_L0_DrawVLine() Draw a vertical line.
LCD_L0_FillRect() Fill a rectangular area.
LCD_L0_SetPixelIndex() Draw a pixel in a specified color.
LCD_L0_XorPixel() Invert a pixel.
*************************************************************************************************
"Get" group
*************************************************************************************************
LCD_L0_GetPixelIndex() Returs the index of the color of a specific pixel.
*************************************************************************************************
"Set" group
*************************************************************************************************
LCD_L0_SetOrg() Not yet used, reserved for future use (must exist in driver).
*************************************************************************************************
Lookup table group
*************************************************************************************************
LCD_L0_SetLUTEntry() Modifiy a single entry of LUT.
*************************************************************************************************
Misc. group (optional)
*************************************************************************************************
LCD_L0_ControlCache() Lock/unlock/flush LCD cache.
LCD_GetXSize() Return physical X-size of LCD in pixels.
LCD_GetYSize() Return physical Y-size of LCD in pixels.
LCD_GetVXSize() Return virtual X-size of LCD in pixels.
LCD_GetVYSize() Return virtual Y-size of LCD in pixels.
LCD_GetBitsPerPixel() Return the number of bits per pixel.
LCD_GetNumColors() Return the number of available colors.
LCD_GetFixedPalette() Return the fixed palette mode.
*************************************************************************************************/
#include <string.h>             /* for memset */
#include <stddef.h>           /* needed for definition of NULL */
#include "LCD_Private.H"      /* private modul definitions & config */
#include "GUI_Private.H"
#include "GUIDebug.h"
#include "LCD_0.h"            /* Defines for first display */

#include	"..\..\..\ucos_ii\includes.h"  

INT32U aLcdActiveBuffer[LCD_YSIZE][LCD_XSIZE/4];
INT32U aLcdVirtualBuffer[LCD_YSIZE][LCD_XSIZE/4];

#define SCR_XSIZE 	(320)  
#define SCR_YSIZE 	(240)

#define M5D(n) ((n) & 0x1fffff)
#define ARRAY_SIZE_COLOR 	(SCR_XSIZE/1*SCR_YSIZE)
#define HOZVAL			(LCD_XSIZE/4-1)
#define HOZVAL_COLOR		(LCD_XSIZE*3/8-1)
#define LINEVAL			(LCD_YSIZE-1)
#define MVAL			(13)
#define CLKVAL_COLOR 	(10) //60Mhz 
#define MVAL_USED 0
#define LCD_BUF_SIZE (SCR_XSIZE * SCR_YSIZE)

#define INTS(Base)  Base+0,Base+1,Base+2,Base+3,Base+4,Base+5,   \
                    Base+6,Base+7,Base+8,Base+9,Base+10,Base+11, \
                    Base+12,Base+13,Base+14,Base+15

static const LCD_PIXELINDEX aID[] = {
  INTS(0),
  #if LCD_MAX_LOG_COLORS > 0x10
    INTS(0x10),
  #endif
  #if LCD_MAX_LOG_COLORS > 0x20
    INTS(0x20),
    INTS(0x30),
  #endif
  #if LCD_MAX_LOG_COLORS > 0x40
    INTS(0x40),
    INTS(0x50),
    INTS(0x60),
    INTS(0x70),
  #endif
  #if LCD_MAX_LOG_COLORS > 0x80
    INTS(0x80),
    INTS(0x90),
    INTS(0xa0),
    INTS(0xb0),
    INTS(0xc0),
    INTS(0xd0),
    INTS(0xe0),
    INTS(0xf0)
  #endif
};

static int CurPosX;
static U8* pCurPos;

#define LCD_BYTESPERLINE (3*(((LCD_VXSIZE_PHYS)+7)/8))
#define XY2OFF(x,y) (y*LCD_BYTESPERLINE+3*(x>>3))
#define OFF2PTR(Off) &aLcdActiveBuffer[0][Off]
#define GUISWAP(a, b) {a^=b; b^=a; a^=b;}
#ifndef LCD_OPTIMIZE
  #define LCD_OPTIMIZE                (1)
#endif

/*************************************************************************************************
 Init & display control group
 *************************************************************************************************
 LCD_L0_Init() Initialize the display.
 LCD_L0_ReInit() Reinitialize LCD without erasing the contents.
 LCD_L0_Off() Switch LCD off.
 LCD_L0_On() Switch LCD on.
 *************************************************************************************************/

int LCD_L0_Init (void)
{       
	rLCDCON1=(0x0)|(2<<5)|(MVAL_USED<<7)|(0x3<<8)|(0x3<<10)|(CLKVAL_COLOR<<12);
	    // disable,8B_SNGL_SCAN,WDLY=8clk,WLH=8clk,
	rLCDCON2=(LINEVAL)|(HOZVAL_COLOR<<10)|(10<<21);  
	    //LINEBLANK=10 (without any calculation) 
	rLCDSADDR1= (0x3<<27) | ( ((unsigned int)aLcdActiveBuffer>>22)<<21 ) | M5D((unsigned int)aLcdActiveBuffer>>1);
	    // 256-color, LCDBANK, LCDBASEU
	rLCDSADDR2= M5D((((unsigned int)aLcdActiveBuffer+(SCR_XSIZE*LCD_YSIZE))>>1)) | (MVAL<<21);
	rLCDSADDR3= (LCD_XSIZE/2) | ( ((SCR_XSIZE-LCD_XSIZE)/2)<<9 );

	//The following value has to be changed for better display.

	rREDLUT  =0xfdb96420;
	rGREENLUT=0xfdb96420;
	rBLUELUT =0xfb40;

	rDITHMODE=0x0;
	rDP1_2 =0xa5a5;      
	rDP4_7 =0xba5da65;
	rDP3_5 =0xa5a5f;
	rDP2_3 =0xd6b;
	rDP5_7 =0xeb7b5ed;
	rDP3_4 =0x7dbe;
	rDP4_5 =0x7ebdf;
	rDP6_7 =0x7fdfbfe;

	rLCDCON1=(0x1)|(2<<5)|(MVAL_USED<<7)|(0x3<<8)|(0x3<<10)|(CLKVAL_COLOR<<12);
	rPDATB &= 0xffef;
		
	return 0;
}

void LCD_L0_ReInit(void)
{

}

void LCD_L0_On(void)
{

}

void LCD_L0_Off(void)
{

}


/*************************************************************************************************
 Drawing group
 *************************************************************************************************
 LCD_L0_DrawBitmap() Universal draw bitmap routine.
 LCD_L0_DrawHLine() Draw a horizontal line.
 LCD_L0_DrawPixel() Draw a pixel in the current foreground color.
 LCD_L0_DrawVLine() Draw a vertical line.
 LCD_L0_FillRect() Fill a rectangular area.
 LCD_L0_SetPixelIndex() Draw a pixel in a specified color.
 LCD_L0_XorPixel() Invert a pixel.
 *************************************************************************************************/

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 aID for bitmaps without palette */
	if (!pTrans) 
	{
		pTrans = aID;
	}
	/* Use DrawBitLineXBPP */
	for (i=0; i<ysize; i++) 
	{
		switch (BitsPerPixel) 
		{
	    	case 1:
	      		DrawBitLine1BPP(x0, i+y0, pData, Diff, xsize, pTrans);
	      		break;	    	
	      	case 8:
	    		#if (LCD_MAX_LOG_COLORS > 16)
	        	DrawBitLine8BPP(x0, i+y0, pData, xsize, pTrans);
//				#else
//	        	DEBUG_WARN("\nCan not display 8bpp bitmaps, please #define LCD_MAX_LOG_COLORS 256");
	    		#endif
	    }
	    pData += BytesPerLine;
	}
}

void LCD_L0_DrawHLine(int x0, int y,int x1)
{
	if (x0>x1) return;  /* Check if nothing to draw */
	
	if (GUI_Context.DrawMode & LCD_DRAWMODE_XOR) 
	{
		while (x0 <= x1) 
		{
	    	LCD_L0_XorPixel(x0,y);
//	      	XORPIXEL(x0, y);
	      	x0++;
	    }
	}
	else 
	{
		while (x0 <= x1) 
		{
			LCD_L0_DrawPixel(x, y, c)(x0,y,LCD_COLORINDEX);
//	      	SETPIXEL(x0, y, COLOR);
	      	x0++;
	    }
	}	
}

#define LCD_L0_DrawPixel(x, y, c)\
	aLcdActiveBuffer[(y)][(x)/4]=(( aLcdActiveBuffer[(y)][(x)/4] & (~(0x000000ff<<((x)%4)*8)) )\
	| ( (c)<<(((x)%4)*8) ));


void LCD_L0_DrawVLine(int y0,  int y1,int x )
{
	if (GUI_Context.DrawMode & LCD_DRAWMODE_XOR) 
	{
		while (y0 <= y1) 
		{
	    	LCD_L0_XorPixel(x,y0);
//	      	XORPIXEL(x, y0);
	      	y0++;
	    }
	}
	else
	{
		while (y0 <= y1)
		{
	    	LCD_L0_DrawPixel(x,y0,LCD_COLORINDEX);
//	      	SETPIXEL(x, y0, COLOR);
	      	y0++;
	    }
	}
}

void LCD_L0_FillRect(int x0, int y0, int x1, int y1)
{
	for (; y0 <= y1; y0++)
	{
		LCD_L0_DrawHLine(x0,y0, x1);
	}
}


void LCD_L0_SetPixelIndex(int x, int y, int ColorIndex)
{
	LCD_L0_DrawPixel(x,y,ColorIndex);
}

    	
void LCD_L0_XorPixel(int x, int y)
{
	U16 Index = LCD_L0_GetPixelIndex(x,y);
	
	Index = LCD_NUM_COLORS-1-Index;
//	SetPixelPhys(x,y,Index);
	LCD_L0_DrawPixel(x,y,Index);
}


/*************************************************************************************************
 "Get" group
 *************************************************************************************************
 LCD_L0_GetPixelIndex() Returs the index of the color of a specific pixel.
 *************************************************************************************************/

unsigned int LCD_L0_GetPixelIndex(int x, int y)
{
	return ((aLcdActiveBuffer[(y)][(x)/4] >> ((3 - (x % 4)) * 8)) & 0xff);
}


/*************************************************************************************************
 "Set" group
 *************************************************************************************************
 LCD_L0_SetOrg() Not yet used, reserved for future use (must exist in driver).
 *************************************************************************************************/

void LCD_L0_SetOrg(int x, int y)
{
	int Off;
	int i;
 
	if (y>(LCD_VYSIZE_PHYS-LCD_YSIZE_PHYS))
	y = LCD_VYSIZE_PHYS-LCD_YSIZE_PHYS;
	Off = y*LCD_BYTESPERLINE+(x>>3);
    
    for (i=0; i<LCD_BITSPERPIXEL/3; i++)
	{
    	#ifndef WIN32
//      aLcdVirtualBuffer[i][0] = &aLcdActiveBuffer[i][0] +Off;
        aLcdVirtualBuffer[i][0] = aLcdActiveBuffer[i][0] +Off;	//change by lcn
      	#endif
	}
}


/*************************************************************************************************
 Lookup table group
 *************************************************************************************************
 LCD_L0_SetLUTEntry() Modifiy a single entry of LUT.
 *************************************************************************************************/

void LCD_L0_SetLUTEntry  (U8 Pos, LCD_COLOR color)
{

⌨️ 快捷键说明

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