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

📄 lcd.c

📁 基于ARM核的HMS7202
💻 C
字号:

#define  lcdtest
#include "head.h"
//#include "5445.c"
#define  MONO    1
#define  COLOR	 2
#define PmuResetStatusClear  0x1ffu
unsigned long *pPioDmuxctl =(unsigned long *)PioDmuxctl;
extern const unsigned char *bitmap;

typedef struct lcd_reg_setting
{
	unsigned long pll_1;
	unsigned long control;
	unsigned long Timing0;
	unsigned long Timing1;
	unsigned long Timing2;
	unsigned int  x_res;
	unsigned int  y_res;
	unsigned int  bpp;
	unsigned int  mono_color;
}Lcd_reg; 


Lcd_reg lcd_value[]={

	{0xe323,0x018c0014,0x66161E4C,0x0E180CF0,0x013F1C60,320,240,16,COLOR},
//	{0xe323,0x018c0014,0x66161E4C,0x0E180CEF,0x013F1C60,320,240,16,COLOR},
	}; 


void delay_disp(void)
{
	unsigned long i;
	for(i=0; i<0x0000ffff;i++);
}

//---------------------------------------------------------------------------------------------

int Lcd_test(int test_level)	

{

	int i,ret;
	int val, clor_val = 0x3ff, *ptr;
	int box_x1 = 10, box_y1 = 10,box_x2 = 20, box_y2 = 20;
	unsigned int tmp;

	Lcd_reg *plcd_value;

#if defined(STANDALONE) &&  STANDALONE == 2
	test_level = TEST_LEVEL;
#endif

	get_dma_base_size("lcd",&tmp,&LCD_BUFFER_SIZE);	//get lcd dma_base_add and size
	LCDSdramBase = (unsigned short *)tmp;	//lcd dis-fuf
 
	*pLcdDBAR = (unsigned long)__virt2dma(tmp);

   	*pPioDmuxctl &= ~0x1ff;

	plcd_value = &lcd_value[0];

	ser_printf("Lcd_resolution : %d x %d\n",plcd_value->x_res,plcd_value->y_res);
   	ser_printf("Lcd_bpp : %d\n",plcd_value->bpp);

   	*(unsigned *)PmuClkCtl &= (0x0ff);
   	*(unsigned *)PmuClkCtl |= (plcd_value->pll_1);//(0x0ed00); //PLL1 & PLL2  PLL1->42Mhz
   	*(unsigned *)PmuResetStatus =  PmuResetStatusClear;
   	for(i=0; i<0x2000; i++); // delay_disp to alow system to settle

	*pLcdTiming0 = plcd_value->Timing0;
	*pLcdTiming1 = plcd_value->Timing1;
	*pLcdTiming2 = plcd_value->Timing2;

	*pVideoControl = plcd_value->control;

	LCDx_res = plcd_value->x_res;
	LCDy_res = plcd_value->y_res;
	LCDx_bpp_res = (LCDx_res * plcd_value->bpp)/16;


   	*pVideoControl |= 0x000001;    //  Lcd Enable
	for(i = 0; i < 0x12000; i++);
    	*pVideoControl |= 0x400000;    // Lcd Power

	set_LCDpalette256();
	
/********************** test operation *****************************/

	//	Lcd_HZ_disp(50,50,3,"画线调试");


		LCDgenline(1,1, 10, 200, 1, red);
		LCDgenline(50,50, 10, 200, 1, red);
		LCDgenline(120,90, 10, 200, 1, red);
		LCDgenline_h(50, 1, 320, 1, red);

		Lcd_disp_letter(0, 40, red, "Lcd test over");
		ser_printf("\n*** End of LCD Test ***\n\n");

		while(1);
}


/***********************************************************************************1
func: draw vertical line
para: x--line height; y1--start point;y2---end point;
************************************************************************************/
void LCDgenline_v(UINT16T x,UINT16T y1,UINT16T y2,UINT16T width,UINT16T color_val)
{
	int i=0,j=0;
	unsigned short *posy;
	
	if(y1 > y2)
   		swap(&y1,&y2);
   	if(y1>0){
		for(j=width; j>0; j--){
			for(i=y1 ; i<=y2; i++){
				posy = (unsigned short*)(LCDSdramBase + i*LCDx_bpp_res + x);
				*posy = color_val;
			}
		x++;
		}
	}else
		Lcd_disp_letter(0, 80, 0, "input erro");
}

/***********************************************************************************2
func: draw horizontal line
para: y--lint offset; x1--start point;x2---end point;
************************************************************************************/

void LCDgenline_h(UINT16T y1,UINT16T x1,UINT16T x2,UINT16T width,UINT16T color_val)
{
	int i=0,j=0;
//	unsigned char *posx;
	unsigned short *posx;

	if(x1 > x2)
  		swap(&x1,&x2);
  		if(x1>0){
			for(j=width; j>0; j--){
				posx = (unsigned short*)(LCDSdramBase + (y1)*(LCDx_bpp_res) + x1);//
				for(i=x1 ; i<=x2; i++){
					*posx = color_val;
					posx++;
				}
				y1++;
			}
		}else
				Lcd_disp_letter(0, 80, 0, "input error");

}


/******************************************************************************3
func: draw ramp line
para: (x1,y1)--start point;(x2,y2)--end point;
	  dx,dy---ramp rate; P: to judge next height
******************************************************************************/

void LCDgenline(UINT16T usX0, UINT16T usY0, UINT16T usX1, UINT16T usY1, UINT16T ucColor, UINT16T usWidth)
{
	UINT16T usDx;
	UINT16T usDy;
	UINT16T y_sign;
	UINT16T x_sign;
	UINT16T decision;
	UINT16T wCurx, wCury, wNextx, wNexty, wpy, wpx;

	if( usY0 == usY1 )
	{
		LCDgenline_h(usX0, usX1, usY0, ucColor, usWidth);
		return;
	}
	if( usX0 == usX1 )
	{
		LCDgenline_v(usY0, usY1, usX0, ucColor, usWidth);
		return;
	}
	usDx = abs(usX0 - usX1);
	usDy = abs(usY0 - usY1);
	if( ((usDx >= usDy && (usX0 > usX1)) ||
        ((usDy > usDx) && (usY0 > usY1))) )
    {
        swap(&usX1, &usX0);
        swap(&usY1, &usY0);
    }
    y_sign = (usY1 - usY0) / usDy;
    x_sign = (usX1 - usX0) / usDx;

    if( usDx >= usDy )
    {
        for( wCurx = usX0, wCury = usY0, wNextx = usX1,
             wNexty = usY1, decision = (usDx >> 1);
             wCurx <= wNextx; wCurx++, wNextx--, decision += usDy ){
            if( decision >= usDx )
            {
                decision -= usDx;
                wCury += y_sign;
                wNexty -= y_sign;
            }
            for( wpy = wCury - usWidth / 2;
                 wpy <= wCury + usWidth / 2; wpy++ )
            {
               // LCD_PutPixel(wCurx, wpy, ucColor);
               dot_draw(wCurx,wpy,ucColor);
            }

            for( wpy = wNexty - usWidth / 2;
                 wpy <= wNexty + usWidth / 2; wpy++ )
            {
               // LCD_PutPixel(wNextx, wpy, ucColor);
               dot_draw(wNextx,wpy,ucColor);
            }
        }
    }
    else
    {
        for( wCurx = usX0, wCury = usY0, wNextx = usX1,
             wNexty = usY1, decision = (usDy >> 1);
             wCury <= wNexty; wCury++, wNexty--, decision += usDx )
        {
            if( decision >= usDy )
            {
                decision -= usDy;
                wCurx += x_sign;
                wNextx -= x_sign;
            }
            for( wpx = wCurx - usWidth / 2;
                 wpx <= wCurx + usWidth / 2; wpx++ )
            {
                //LCD_PutPixel(wpx, wCury, ucColor);
                dot_draw(wpx,wCury,ucColor);
            }

            for( wpx = wNextx - usWidth / 2;
                 wpx <= wNextx + usWidth / 2; wpx++ )
            {
                //LCD_PutPixel(wpx, wNexty, ucColor);
                dot_draw(wpx,wNexty,ucColor);
            }
        }
    }
}

/***********************************************************************************4
func: draw letter and number
para: (x0,y0)--start point; s---the char string;
************************************************************************************/

void Lcd_disp_letter(UINT16T x0,  UINT16T y0, UINT16T ForeColor, UINT8T *s)
{
	UINT16T i,j,k,x,y,xx;
	UINT8T qm;
	UINT32T ulOffset;
	UINT8T ywbuf[16],temp[2];
	UINT16T *pos;

	for( i = 0; i < strlen((const char*)s); i++ ){
		if( (unsigned char)*(s+i) >= 161 ){
			temp[0] = *(s + i);
			temp[1] = '\0';
			return;
		}
		else
		{
			qm = *(s+i);
			ulOffset = (int)(qm) * 16;
			for( j = 0; j < 16; j ++ ){
				ywbuf[j] = g_ucAscii8x16[ulOffset + j];
            }

            for( y = 0; y < 16; y++ ){
            	for( x = 0; x < 8; x++ ){
                	k = x % 8;
			    	if( ywbuf[y]  & (0x80 >> k) ){
			       		xx = x0 + x + i*8;
						pos = (unsigned short*)(LCDSdramBase + xx + (y + y0)*(LCDx_bpp_res));
						*pos = ForeColor;
			   		}
				}
            }
		}
	}
}

/***********************************************************************************5
func: draw Chinese character
para: (x0,y0)--start point; s---the char string;
************************************************************************************/


/*
void Lcd_HZ_disp(char x0, char y0, int color, char *s)
{
	UINT16T i,j,k,x,y,xx;
	UINT8T qm,wm;
	UINT32T ulOffset;
	UINT8T hzbuf[32],temp[2];
	UINT16T *pos;

	for( i = 0; i < strlen((const char*)s); i++ )
	{
		if( ((char)(*(s+i))) < 161 )
		{
			temp[0] = *(s+i);
			temp[1] = '\0';
			break;
		}
		else
		{
		qm = *(s+i) - 161;
    		wm = *(s + i + 1) - 161;
       		ulOffset = (int)(qm * 94 + wm) * 32;
			for( j = 0; j < 32; j ++ )
            {
            	hzbuf[j] = g_ucHZK16[ulOffset + j];
            }
            for( y = 0; y < 16; y++ )
            {
	        	for( x = 0; x < 16; x++ ) 
	            {
                	k = x % 8;
				   	if( hzbuf[y * 2 + x / 8]  & (0x80 >> k) ){
						xx = x0 + x + i * 8;
						pos = (unsigned short*)( LCDSdramBase + xx + (y + y0)*LCDx_bpp_res );
						*pos = color;
					}
			   	}
           	}
		    i++;
		}
	}
}
*/
/***********************************************************************************6
func: draw letter and number
para: (x1,y1)--start point; (x2,y2)---end point; 
************************************************************************************/

void draw_box(UINT16T x1,UINT16T y1, UINT16T x2,UINT16T y2,UINT16T color_val)
{
	int i=0,j=0;
	unsigned short *posx;

	if(x1 > x2)			//change
  		swap(&x1,&x2);
  	if(y1>y2)
  		swap(&y1,&y2);

  		if(x1>0){
			for(j=y1; j<=y2; j++){
				posx = (unsigned short*)(LCDSdramBase + (y1)*(LCDx_bpp_res) + x1);//
				for(i=x1 ; i<=x2; i++){
					*posx = color_val;
					posx++;
				}
				y1++;
			}
		}else
				Lcd_disp_letter(0, 80, 0, "input error");
}


	
//////////////////////////////////////////////////////////////////

void swap(UINT16T *a,UINT16T *b)
{
	char temp;
	
	temp = *a;
	*a = *b;
	*b = temp;
}

void LCDgenwhite256()
{
	int x, y;
    unsigned short *posy;
	for(y=0 ; y < LCDy_res; y++)
    {
        posy = (unsigned short*)(LCDSdramBase + y*LCDx_bpp_res);
	 	for(x=0;x < LCDx_bpp_res; x++)
	    {
		    *(posy + x) = (unsigned short)white;
  	    }			
    }


    return;
}


/*
void set_LCDpalette256(void)
{
	int i;
	int temp[256];

//	pLcdPalette = &PaletteData;

	for(i=0; i<256; i++)
	{
		temp[i] = ((i&0x1f)<<19) | ((i&0x7e)<<9) | (i&0xf8);
		*(pLcdPalette+i) = temp[i];
	}
	LCDgenwhite256();
}

*/


unsigned PaletteData[] = 
{
	0x00000000,
	0x00080000, 
	0x00100400, 
	0x00180400,
	0x00200800, 
	0x00280800, 
	0x00300C00, 
	0x00380C00,
	0x00401008, 
	0x00481008, 
	0x00501408,
	0x00581408,
	0x00601808, 
	0x00681808, 
	0x00701C08, 
	0x00781C08,
	0x00802010, 
	0x00882010, 
	0x00902410, 
	0x00982410,
	0x00A02810, 
	0x00A82810, 
	0x00B02C10, 
	0x00B82C10,
	0x00C03018, 
	0x00C83018, 
	0x00D03418, 
	0x00D83418,
	0x00E03818, 
	0x00E83818, 
	0x00F03C18, 
	0x00F83C18,
	0x00004020, 
	0x00084020, 
	0x00104420, 
	0x00184420,
	0x00204820, 
	0x00284820, 
	0x00304C20, 
	0x00384C20,
	0x00405028, 
	0x00485028, 
	0x00505428, 
	0x00585428,
	0x00605828, 
	0x00685828, 
	0x00705C28, 
	0x00785C28,
	0x00806030, 
	0x00886030, 
	0x00906430, 
	0x00986430,
	0x00A06830, 
	0x00A86830, 
	0x00B06C30, 
	0x00B86C30,
	0x00C07038, 
	0x00C87038, 
	0x00D07438, 
	0x00D87438,
	0x00E07838, 
	0x00E87838, 
	0x00F07C38, 
	0x00F87C38,
	0x00008040, 
	0x00088040, 
	0x00108440, 
	0x00188440,
	0x00208840, 
	0x00288840, 
	0x00308C40, 
	0x00388C40,
	0x00409048, 
	0x00489048, 
	0x00509448, 
	0x00589448,
	0x00609848, 
	0x00689848, 
	0x00709C48, 
	0x00789C48,
	0x0080A050, 
	0x0088A050, 
	0x0090A450, 
	0x0098A450,
	0x00A0A850, 
	0x00A8A850, 
	0x00B0AC50, 
	0x00B8AC50,
	0x00C0B058, 
	0x00C8B058, 
	0x00D0B458, 
	0x00D8B458,
	0x00E0B858, 
	0x00E8B858, 
	0x00F0BC58, 
	0x00F8BC58,
	0x0000C060, 
	0x0008C060, 
	0x0010C460, 
	0x0018C460,
	0x0020C860, 
	0x0028C860, 
	0x0030CC60, 
	0x0038CC60,
	0x0040D068, 
	0x0048D068, 
	0x0050D468, 
	0x0058D468,
	0x0060D868, 
	0x0068D868, 
	0x0070DC68, 
	0x0078DC68,
	0x0080E070, 
	0x0088E070, 
	0x0090E470, 
	0x0098E470,
	0x00A0E870, 
	0x00A8E870, 
	0x00B0EC70, 
	0x00B8EC70,
	0x00C0F078, 
	0x00C8F078, 
	0x00D0F478, 
	0x00D8F478,
	0x00E0F878, 
	0x00E8F878, 
	0x00F0FC78, 
	0x00F8FC78,
	0x00000080, 
	0x00080080, 
	0x00100480, 
	0x00180480,
	0x00200880, 
	0x00280880, 
	0x00300C80, 
	0x00380C80,
	0x00401088, 
	0x00481088, 
	0x00501488, 
	0x00581488,
	0x00601888, 
	0x00681888, 
	0x00701C88, 
	0x00781C88,
	0x00802090, 
	0x00882090, 
	0x00902490, 
	0x00982490,
	0x00A02890, 
	0x00A82890, 
	0x00B02C90, 
	0x00B82C90,
	0x00C03098, 
	0x00C83098, 
	0x00D03498, 
	0x00D83498,
	0x00E03898, 
	0x00E83898, 
	0x00F03C98, 
	0x00F83C98,
	0x000040A0, 
	0x000840A0, 
	0x001044A0, 
	0x001844A0,
	0x002048A0, 
	0x002848A0, 
	0x00304CA0, 
	0x00384CA0,
	0x004050A8, 
	0x004850A8, 
	0x005054A8, 
	0x005854A8,
	0x006058A8, 
	0x006858A8, 
	0x00705CA8, 
	0x00785CA8,
	0x008060B0, 
	0x008860B0, 
	0x009064B0, 
	0x009864B0,
	0x00A068B0, 
	0x00A868B0, 
	0x00B06CB0, 
	0x00B86CB0,
	0x00C070B8, 
	0x00C870B8, 
	0x00D074B8, 
	0x00D874B8,
	0x00E078B8, 
	0x00E878B8, 
	0x00F07CB8, 
	0x00F87CB8,
	0x000080C0, 
	0x000880C0, 
	0x001084C0, 
	0x001884C0,
	0x002088C0, 
	0x002888C0, 
	0x00308CC0, 
	0x00388CC0,
	0x004090C8, 
	0x004890C8, 
	0x005094C8, 
	0x005894C8,
	0x006098C8, 
	0x006898C8, 
	0x00709CC8, 
	0x00789CC8,
	0x0080A0D0, 
	0x0088A0D0, 
	0x0090A4D0, 
	0x0098A4D0,
	0x00A0A8D0, 
	0x00A8A8D0, 
	0x00B0ACD0, 
	0x00B8ACD0,
	0x00C0B0D8, 
	0x00C8B0D8, 
	0x00D0B4D8, 
	0x00D8B4D8,
	0x00E0B8D8, 
	0x00E8B8D8, 
	0x00F0BCD8, 
	0x00F8BCD8,
	0x0000C0E0, 
	0x0008C0E0, 
	0x0010C4E0, 
	0x0018C4E0,
	0x0020C8E0, 
	0x0028C8E0, 
	0x0030CCE0, 
	0x0038CCE0,
	0x0040D0E8, 
	0x0048D0E8, 
	0x0050D4E8, 
	0x0058D4E8,
	0x0060D8E8, 
	0x0068D8E8, 
	0x0070DCE8, 
	0x0078DCE8,
	0x0080E0F0, 
	0x0088E0F0, 
	0x0090E4F0, 
	0x0098E4F0,
	0x00A0E8F0, 
	0x00A8E8F0, 
	0x00B0ECF0, 
	0x00B8ECF0,
	0x00C0F0F8, 
	0x00C8F0F8, 
	0x00D0F4F8, 
	0x00D8F4F8,
	0x00E0F8F8, 
	0x00E8F8F8, 
	0x00F0FCF8, 
	0x00F8FCF8
};


void set_LCDpalette256(void)
{
    int i,j;
    
    unsigned char tmp,bitset;
    unsigned char tmp_rev;
  

    for (i=0; i < 256; i++)
	{
	      *(pLcdPalette + i) = PaletteData[i];
   		
	}

	LCDgenwhite256();
	for(i=0; i< 0x100;i++)
	{}


}

⌨️ 快捷键说明

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