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

📄 graphic.c

📁 ADC图形图像例子
💻 C
字号:

#include "graphic.h"
#include "register.h"
#include "io.h"
#include "uart.h"

/**********************************************************************
	Name : Vid_EndCommand
	Desc : this function assigns the command is valid
**********************************************************************/
void Vid_EndCommand( void )
{		
	static U32 i=0;
	i++;
	_vgCurCommandNum = (_vgCurCommandNum+1)&MAX_COMMAND_MASK;

	while( Vid_ReadReg( 1 ) == _vgCurCommandNum )
	{
		UartPrintfCh1("%08x,%08x(%d)\n",Vid_ReadReg( 1 ), _vgCurCommandNum, i);
	}
	
	Vid_WriteReg( 0, (U16)_vgCurCommandNum );
}


void InitRenderingEngine()
{
	//***********************************************
	//	Rendering Engine initialize
	//***********************************************
	// Cancel2D
	Vid_WriteReg( 0, 0 );
	Vid_WriteReg( 0x06 ,VIDREG6_CANCEL2D );

	// clear flip count
	Vid_WriteReg( 0x13,	0 );

	// FMEM	type
	Vid_WriteReg( 0x08 , VIDREG8_FMEM64	); // initial backbuffer address: 0x4400000

	// Run2D , Dithering mode ,	Render target
	Vid_WriteReg( 0x06 ,VIDREG6_RUN2D|VIDREG6_DITHER4x4|VIDREG8_RENDER_BACK );
}


vgBOOL	vgSetScreenMode( DGSCREENMODE smode	)
{
//OSC
	U32	ModeParam[][15] = {
	
	// 1	320x240 noninterlace
	{0x0000, 0x008b, 0x213b, 319, 0x0000, 0x3809, 0x000e,
	240-1,	0x05c6,	0x09f9,	0x0021,	0x0000,	0x4001,	320, 240},
	
	// 2	360x240 noninterlace
	{0x0000, 0x008b, 0x2121, 359, 0x0000, 0x3809, 0x000e,
	240-1,	0x05c6,	0x09f9,	0x0021,	0x0000,	0x4001,	360, 240},
	
	// 3	640x480 noninterlace
	{0x0000, 0x0091, 0x2c5f, 645-1, 12, 0, 30,
	480-1,((0x01<<10)|(800/2-1)), ((0x01<<11)|((525-9)*2-1)), 45, 0,0x4001,	640, 480}
	};

	long i;
	U32	*SelectedModeParam;
	U32	*CRT_reg = (U32*)REG_CRTMOD;

	switch( smode )
	{
	case DGSCREENMODE_320x240:	SelectedModeParam =	ModeParam[0]; break;
	case DGSCREENMODE_360x240:	SelectedModeParam =	ModeParam[1]; break;
	case DGSCREENMODE_640x480:	SelectedModeParam =	ModeParam[2]; break;
	default: ;
	return vgFALSE;
	}

	Vid_WaitEmptyCommandQueue();
	
	for( i=0; i<13;	i++	)
	{
		if(	i!=5 )
			CRT_reg[i] = SelectedModeParam[i];
	}
	
	_vgScreen_width	= (S32)SelectedModeParam[13];
	_vgScreen_height = (S32)SelectedModeParam[14];
	vgSetClipWindow( 0,	0, _vgScreen_width,_vgScreen_height );

	{
		long clearw, clearh;
		if( _vgScreen_width<=512 )	clearw = 512;
		else						clearw = 1024;
		clearh = _vgScreen_height + 2;
		vgClearFMEM(0,0,clearw,clearh);
		vgASyncFlip();
		vgClearFMEM(0,0,clearw,clearh);
		vgASyncFlip();
		Vid_WaitEmptyCommandQueue();
	}

	return vgTRUE;
}


/**********************************************************************
	Name : Vid_WaitEmptyCommandQueue
	Desc : 
**********************************************************************/
void Vid_WaitEmptyCommandQueue( void )
{		
	while( Vid_ReadReg( 1 ) != _vgCurCommandNum );
}


/**********************************************************************
	vgSetClipWindow
	Desc: set clipping area	in screen coordinate
**********************************************************************/
S32	_vgClip_x0;
S32	_vgClip_y0;
S32	_vgClip_x1;
S32	_vgClip_y1;
void	vgSetClipWindow( S32 x,	S32	y, S32 dx, S32 dy )
{
	_vgClip_x0 = x;
	_vgClip_y0 = y;
	_vgClip_x1 = x + dx	- 1;
	_vgClip_y1 = y + dy	- 1;
}


void vgClearFMEM( long x, long y, long w, long h )
{	
	/* command write
	****************************************************/
	Vid_WriteCmd( 0x00, (U16)(0x10 | 0x0100 | 0x1000) );
	Vid_WriteCmd( 0x01, (U16)x );
	Vid_WriteCmd( 0x02, (U16)y );
	Vid_WriteCmd( 0x03, (U16)(x+w-1) );
	Vid_WriteCmd( 0x04, (U16)(y+h-1) );
	Vid_WriteCmd( 0x15, 0 );
	Vid_WriteCmd( 0x16, 0 );
	Vid_EndCommand();

	Vid_WriteCmd( 0x00, 0x1000 );
	Vid_WriteCmd( 0x15, (U16)((U16)_vgSDK_ShadeColor & 0xffff) );
	Vid_WriteCmd( 0x16, (U16)((U16)(_vgSDK_ShadeColor>>16) & 0xffff) );
	Vid_EndCommand();
}


/**********************************************************************
	vgSetShadeColor
	Desc: Set Shade Color
**********************************************************************/
void	vgSetShadeColor( U8 r, U8 g, U8 b )
{
	U32 write_data = 0;
	write_data = (((U32)r)<<16) | (((U32)g)<<8) | ((U32)b) ;
	
	Vid_WriteCmd( 0x00, 0x1000 );
	Vid_WriteCmd( 0x15, (U16)((U16)write_data & 0xffff) );
	Vid_WriteCmd( 0x16, (U16)((U16)(write_data>>16) & 0xffff) );
	Vid_EndCommand();
	
	_vgSDK_ShadeColor = write_data;
}


void vgASyncFlip( void )
{
	
	while(vgNumberOfFlip());
	
	Vid_WriteCmd(0x00,0x0000);
	Vid_EndCommand();
	Vid_WriteCmd(0x00,0x0000);
	Vid_EndCommand();

	*(unsigned short*)0x030000a6 = 0; // reset flip count
	*(unsigned short*)0x030000a6 = 1; // increase flip count
	Vid_WriteCmd( 0x00,	0x0080 );
	Vid_EndCommand();	
}


U32	 vgNumberOfFlip( void )
{
	return 	Vid_ReadReg( 0x13 );
}


void vgFlip( void )
{
	int i;
	volatile U16* front_buffer;

	while(vgNumberOfFlip());

	*(unsigned short*)0x030000a6 = 0; // reset flip count
	*(unsigned short*)0x030000a6 = 1; // increase flip count
	Vid_WriteCmd( 0x00,	0x0001 );
	Vid_EndCommand();

	if(*(U16*)(0x300008e) & 1)
		front_buffer = (U16*)0x4400000;
	else
		front_buffer = (U16*)0x4000000;
		
	if(_vgScreen_width < 512)
	{
		for(i=0;i<4;i++)
			front_buffer[(512*_vgScreen_height) + i] = front_buffer[i];
	}
	else
	{
		for(i=0;i<4;i++)
			front_buffer[(1024*_vgScreen_height) + i] = front_buffer[i];
	}

}


void vgClearScreen( U8 r, U8 g, U8 b )
{
	U32 write_data = 0;
	write_data = (((U32)r)<<16) | (((U32)g)<<8) | ((U32)b) ;
	
	/* command write
	****************************************************/
	Vid_WriteCmd( 0x00, (U16)(0x10 | 0x0100 | 0x1000) );
	Vid_WriteCmd( 0x01, (U16)0 );
	Vid_WriteCmd( 0x02, (U16)0 );
	Vid_WriteCmd( 0x03, (U16)(_vgScreen_width-1) );
	Vid_WriteCmd( 0x04, (U16)(_vgScreen_height-1) );
	Vid_WriteCmd( 0x15, (U16)((U16)write_data & 0xffff) );
	Vid_WriteCmd( 0x16, (U16)((U16)(write_data>>16) & 0xffff) );
	Vid_EndCommand();

	Vid_WriteCmd( 0x00, 0x1000 );
	Vid_WriteCmd( 0x15, (U16)((U16)_vgSDK_ShadeColor & 0xffff) );
	Vid_WriteCmd( 0x16, (U16)((U16)(_vgSDK_ShadeColor>>16) & 0xffff) );
	Vid_EndCommand();	
}


void DrawColorBar(void)
{	
	int i;
	
	for(i=0; i<8; i++)
	{
		Vid_WriteCmd( 0x00, 0x1110 );
		Vid_WriteCmd( 0x01, i*80 );
		Vid_WriteCmd( 0x02, 0 );
		Vid_WriteCmd( 0x03, (i+1)*80-1 );
		Vid_WriteCmd( 0x04, 480-1 );
		switch(i)
		{
			case 0:	// White	(255,255,255)
				Vid_WriteCmd( 0x15, (U16)((0xff<<8) | 0xFF ) );
				Vid_WriteCmd( 0x16, (U16)0xFF );
				break;
			case 1:	// Yellow	(255,255,0)
				Vid_WriteCmd( 0x15, (U16)((0xff<<8) | 0x00 ));
				Vid_WriteCmd( 0x16, (U16)0xFF );
				break;
			case 2:	// Cyan		(0,255,255)
				Vid_WriteCmd( 0x15, (U16)((0xff<<8) | 0xFF ));
				Vid_WriteCmd( 0x16, (U16)0x00 );
				break;
			case 3:	// Green	(0,255,0)
				Vid_WriteCmd( 0x15, (U16)((0xff<<8) | 0x00));
				Vid_WriteCmd( 0x16, (U16)0x00 );
				break;
			case 4:	// Purple	(255,0,255)
				Vid_WriteCmd( 0x15, (U16)0xFF );
				Vid_WriteCmd( 0x16, (U16)0xFF );
				break;
			case 5:	// Red		(255,0,0)
				Vid_WriteCmd( 0x15, (U16)0x00 );
				Vid_WriteCmd( 0x16, (U16)0xFF );
				break;
			case 6:	// Blue		(0,0,255)
				Vid_WriteCmd( 0x15, (U16)0xFF );
				Vid_WriteCmd( 0x16, (U16)0x00 );
				break;
			case 7:	// Black	(0,0,0)
				Vid_WriteCmd( 0x15, (U16)0x00 );
				Vid_WriteCmd( 0x16, (U16)0x00 );
				break;
		}	
		Vid_EndCommand();
	}
}

/**********************************************************************
	vgSetDrawMode
	Desc: set draw mode 
**********************************************************************/
void	vgSetDrawMode( U32 dmode )
{
	_vg_current_drawmode = dmode;

	_vg_write_mode = 0;
	if( dmode & DGDRAWMODE_ALPHA )			_vg_write_mode |= 0x02;
	if( dmode & DGDRAWMODE_SHADE )			_vg_write_mode |= 0x10;
	if( dmode & DGDRAWMODE_TEXTURE )		_vg_write_mode |= 0x08;
	if( dmode & DGDRAWMODE_TRANSPARENCY )	_vg_write_mode |= 0x04;
	if( dmode & DGDRAWMODE_NOREPEAT )		_vg_write_mode |= 0x20;
}

⌨️ 快捷键说明

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