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

📄 lcdslin.c

📁 三星ARM芯片s3c2410基于ucosii
💻 C
📖 第 1 页 / 共 2 页
字号:
/*
*********************************************************************************************************
*                                                uC/GUI
*                        Universal graphic software for embedded applications
*
*                       (c) Copyright 2002, Micrium Inc., Weston, FL
*                       (c) Copyright 2002, SEGGER Microcontroller Systeme GmbH
*
*              礐/GUI is protected by international copyright laws. Knowledge of the
*              source code may not be used to write a similar product. This file may
*              only be used in accordance with a license and should not be redistributed
*              in any way. We appreciate your understanding and fairness.
*
----------------------------------------------------------------------
File        : LCDSLin.C
Purpose     : Driver for LCDs using simple bus interface

Currently supported controllers:

              Toshiba T6963
              Epson SED1330
              Epson SED1335

----------------------------------------------------------------------
Version-Date---Author-Explanation
----------------------------------------------------------------------
2.00g   020319 JE     a) Macro changed to fix NC30-error
2.00f   020204 JE     a) Hardwareinterface routines renamed:
                         ...DATA -> ...A0, ...CMD -> ...A1
2.00e   011112 JE     a) LCD_INIT_CONTROLLER added to be able to
                         execute LCD_X_Init during init
2.00d   010926 JE     a) Support for LCD_SWAP_XY added
2.00c   010706 JE     a) Bugfix in DrawBitLine1BPP
2.00b   010402 RS     a) LCD_GetDevCaps removed from driver
                         (now LCD.c)
2.00a   008026 RS     a) Simulation interface changed
2.00    000525 JE     a) Interface changed
1.02c   000509 JE     a) Simple bus interface changed for SED133x
                      b) Small changes in DrawBitLine1BPP
                      c) Cache initialisation to SED133x added
1.02b   000508 JE     a) Simple bus interface changed for T6963
1.02a   000426 JE     a) Transparent mode in DrawBitLine1BPP changed
                      b) Dummy LCD_L0_SetLUTEntry inserted
1.02    000426 RS     a) Changes for new LCD-driver interface V1.30
1.00a   000410 JE     a) LCD_GetDevCap changed
                      b) LCD_GetpCapFunc deleted
                      c) LCD_DrawBitMap changed
                      d) Definition for aColorIndex changed
1.00    000407 JE     First release
---------------------------LIST OF CONFIG SWITCHES--------------------
The following is a list of additional configuration switches for this
driver. These switches might not be listed in the manual, because
the manual mainly covers the general config switches which are
supported by all drivers.
----------------------------------------------------------------------
define ----------------------Explanation------------------------------
LCD_OPTIMIZE                 Controls the use of optimized routines.
----------------------------------------------------------------------
Known problems or limitations with current version
----------------------------------------------------------------------
none
---------------------------END-OF-HEADER------------------------------
*/

#include <string.h>             /* for memset */
#include <stddef.h>           /* needed for definition of NULL */
#include    <stdlib.h>
#include "LCD_Private.h"      /* private modul definitions & config */
#include "GUI_Private.h"
#include "GUIDebug.h"
#include "LCD_0.h"            /* Defines for first display */
#include "def.h"
#include "2410addr.h"
#include "2410slib.h"
#include "2410lib.h"

#ifndef  LCD_BUSWIDTH
#define  LCD_BUSWIDTH   16
#endif 

#define BKCOLOR LCD_BKCOLORINDEX
#define   COLOR LCD_COLORINDEX



#define MVAL		(13)
#define MVAL_USED 	(0)		//0=each frame   1=rate by MVAL
#define INVVDEN		(1)		//0=normal       1=inverted
#define BSWP		(0)		//Byte swap control
#define HWSWP		(1)		//Half word swap control

#define M5D(n) ((n) & 0x1fffff)	// To get lower 21bits

#define LCD_XSIZE_TFT_640480 	(640)	
#define LCD_YSIZE_TFT_640480 	(480)

//TFT 640480
#define SCR_XSIZE_TFT_640480 	(LCD_XSIZE_TFT_640480*2)
#define SCR_YSIZE_TFT_640480 	(LCD_YSIZE_TFT_640480*2)
//TFT640480
#define HOZVAL_TFT_640480	(LCD_XSIZE_TFT_640480-1)
#define LINEVAL_TFT_640480	(LCD_YSIZE_TFT_640480-1)

U32 (*frameBuffer1BitTft640480)[SCR_XSIZE_TFT_640480/32];
U32 (*frameBuffer8BitTft640480)[SCR_XSIZE_TFT_640480/4];
U32 (*frameBuffer16BitTft640480)[SCR_XSIZE_TFT_640480/2];
U32 (*frameBuffer24BitTft640480)[SCR_XSIZE_TFT_640480];

#define VBPD_640480		((33-1)&0xff)
#define VFPD_640480		((10-1)&0xff)
#define VSPW_640480		((2-1) &0x3f)
#define HBPD_640480		((48-1)&0x7f)
#define HFPD_640480		((16-1)&0xff)
#define HSPW_640480		((96-1)&0xff)

#define CLKVAL_TFT_640480 	(1)
#define LCDFRAMEBUFFER 0x33800000 //_NONCACHE_STARTADDRESS 
//FCLK=180MHz,HCLK=90MHz,VCLK=6.5MHz

static void Lcd_Init(void);
static void Lcd_EnvidOnOff(int onoff);

static void PutPixel(U32 x,U32 y,U32 c);
static void Paint_Bmp(int x0,int y0,int h,int l,unsigned char bmp[]);
static void Glib_FilledRectangle(int x1,int y1,int x2,int y2,int color);
static void Glib_Line(int x1,int y1,int x2,int y2,int color);
static void Lcd_ClearScr(U16 c);
static void Paint_Bmp(int x0,int y0,int h,int l,unsigned char bmp[]);

extern unsigned char xyx_640_480[];	//宽240,高320


volatile static unsigned short LCD_BUFER[SCR_YSIZE_TFT_640480/2][SCR_XSIZE_TFT_640480/2];

/**************************************************************
320×240 16Bpp TFT LCD数据和控制端口初始化
**************************************************************/
static void Lcd_Port_Init(void)
{
    //rGPCUP = 0xffffffff; // Disable Pull-up register
    rGPCUP=0xffffffff; // Disable Pull-up register
    rGPCCON=0xaaaaaaaa; //Initialize VD[7:0],LCDVF[2:0],VM,VFRAME,VLINE,VCLK,LEND 
    rGPDUP=0xffffffff; // Disable Pull-up register
    rGPDCON=0xaaaaaaaa; //Initialize VD[23:8]
}

/**************************************************************
320×240 16Bpp TFT LCD功能模块初始化
**************************************************************/
static void Lcd_Init(void)
{
    frameBuffer16BitTft640480=(U32 (*)[SCR_XSIZE_TFT_640480/2])LCDFRAMEBUFFER;
    
    rLCDCON1=(CLKVAL_TFT_640480<<8)|(MVAL_USED<<7)|(3<<5)|(13<<1)|0;
        // TFT LCD panel,24bpp TFT,ENVID=off
	rLCDCON2=(VBPD_640480<<24)|(LINEVAL_TFT_640480<<14)|(VFPD_640480<<6)|(VSPW_640480);
	rLCDCON3=(HBPD_640480<<19)|(HOZVAL_TFT_640480<<8)|(HFPD_640480);
	rLCDCON4=(MVAL<<8)|(HSPW_640480);
	rLCDCON5=(1<<12)|(1<<9)|(1<<8);	// BPP24:MSB,HSYNC and VSYNC are inverted
	rLCDSADDR1=(((U32)frameBuffer24BitTft640480>>22)<<21)|M5D((U32)frameBuffer24BitTft640480>>1);
	rLCDSADDR2=M5D( ((U32)frameBuffer24BitTft640480+(SCR_XSIZE_TFT_640480*LCD_YSIZE_TFT_640480*2))>>1 );
	rLCDSADDR3=(((SCR_XSIZE_TFT_640480-LCD_XSIZE_TFT_640480)/1)<<11)|(LCD_XSIZE_TFT_640480/1);
	rLCDINTMSK|=(3); // MASK LCD Sub Interrupt
	rLPCSEL&=(~7); // Disable LPC3600
	rTPAL=0; // Disable Temp Palette
}

/**************************************************************
LCD视频和控制信号输出或者停止,1开启视频输出
**************************************************************/
static void Lcd_EnvidOnOff(int onoff)
{
    if(onoff==1)
	rLCDCON1|=1; // ENVID=ON
    else
	rLCDCON1 =rLCDCON1 & 0x3fffe; // ENVID Off
}


  



/**************************************************************
320×240 16Bpp TFT LCD单个象素的显示数据输出
**************************************************************/
static void PutPixel(U32 x,U32 y,U32 c)
{
	if ( (x < SCR_XSIZE_TFT_640480) && (y < SCR_YSIZE_TFT_640480) )
	LCD_BUFER[(y)][(x)] = c;
}

/**************************************************************
320×240 16Bpp TFT LCD全屏填充特定颜色单元或清屏
**************************************************************/
static void Lcd_ClearScr(U16 c)
{
	unsigned int x,y ;
		
    for( y = 0 ; y < SCR_YSIZE_TFT_640480 ; y++ )
    {
    	for( x = 0 ; x < SCR_XSIZE_TFT_640480 ; x++ )
    	{
			LCD_BUFER[y][x] = c;
    	}
    }
}

/**************************************************************
LCD屏幕显示垂直翻转
// LCD display is flipped vertically
// But, think the algorithm by mathematics point.
//   3I2
//   4 I 1
//  --+--   <-8 octants  mathematical cordinate
//   5 I 8
//   6I7
**************************************************************/
static 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;
				}
			}
		}	
	}
}
/**************************************************************
在LCD屏幕上指定坐标点画一个指定大小的图片
**************************************************************/
static void Paint_Bmp(int x0,int y0,int h,int l,unsigned char bmp[])
{
	int x,y;
	U32 c;
	int p = 0;

//本图片显示是正的显示方式
    for( y = 0 ; y < l ; y++ )
    {
    	for( x = 0 ; x < h ; x++ )
    	{
    		c = bmp[p+1] | (bmp[p]<<8) ;

			if ( ( (x0+x) < SCR_XSIZE_TFT_640480) && ( (y0+y) < SCR_YSIZE_TFT_640480) )
			LCD_BUFER[y0+y][x0+x] = c ;

    		p = p + 2 ;
    	}
    }

/*本图片显示是倒过来的,是旋转了180度的显示方式	
    for( y = l ; y > 0 ; y-- )
    {
    	for( x = h ; x > 0 ; x-- )
    	{
    		c = bmp[p+1] | (bmp[p]<<8) ;

			if ( ( (x0+x) < SCR_XSIZE_TFT_240320) && ( (y0+y) < SCR_YSIZE_TFT_240320) )
			LCD_BUFER[y0+y][x0+x] = c ;

    		p = p + 2 ;
    	}
    }
*/
}


/**************************************************************
**************************************************************/
void Lcd_Tft_640X480_Init( void )
{
	#ifdef DEBUG
    	Uart_Printf("\nTest 240*320 TFT LCD !\n");
	#endif	

    Lcd_Port_Init();
    Lcd_Init();
    Lcd_EnvidOnOff(1);		//turn on vedio
	Lcd_ClearScr((U16)0xff0f);		//fill all screen with some color	
    Paint_Bmp( 0,0,320,320, xyx_640_480 ) ;		//paint a bmp
	    Uart_Printf( "\nrGPBCON=0x%x\n", rGPBCON );
    	Uart_Printf( "\trGPBUP=0x%x\n", rGPBUP );
    	Uart_Printf( "rGPCCON=0x%x\n", rGPCCON );
    	Uart_Printf( "\trGPCUP=0x%x\n", rGPCUP );
    	Uart_Printf( "rGPDCON=0x%x\n", rGPDCON );
    	Uart_Printf( "\trGPDUP=0x%x\n", rGPDUP );
    	Uart_Printf( "rGPGCON=0x%x\n", rGPGCON );
    	Uart_Printf( "\trGPGUP=0x%x\n\n", rGPGUP );

    	Uart_Printf( "rLCDCON1=0x%x\n", rLCDCON1 );
    	Uart_Printf( "rLCDCON2=0x%x\n", rLCDCON2 );
    	Uart_Printf( "rLCDCON3=0x%x\n", rLCDCON3 );
    	Uart_Printf( "rLCDCON4=0x%x\n", rLCDCON4 );
    	Uart_Printf( "rLCDCON5=0x%x\n\n", rLCDCON5 );

    	Uart_Printf( "rLCDSADDR1=0x%x\n", rLCDSADDR1 );
    	Uart_Printf( "rLCDSADDR2=0x%x\n", rLCDSADDR2 );
    	Uart_Printf( "rLCDSADDR3=0x%x\n\n", rLCDSADDR3 );
    	
    	Uart_Printf( "rLCDINTMSK=0x%x\n", rLCDINTMSK );
    	Uart_Printf( "rLPCSEL=0x%x\n", rLPCSEL );
    	Uart_Printf( "rTPAL=0x%x\n\n", rTPAL );


}

⌨️ 快捷键说明

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