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

📄 main.c

📁 tw9910的驱动源码,来自techwell的FAE
💻 C
📖 第 1 页 / 共 5 页
字号:
/*		Prompt				                                                 */
/*===========================================================================*/
void Prompt(void)
{
	Printf("\r\nI2C[%02x]>", (WORD)I2CAddressDeb);
}
/*===========================================================================*/
/*		I2C Edit Read		                                                 */
/*===========================================================================*/
void MonWriteI2C(BYTE addr, BYTE index, BYTE val) 
{
	Printf("\r\nWrite %02xh to [Adrs(%02xh)Index(%02xh)] ", (WORD)val, (WORD)addr, (WORD)index);
	WriteI2C(addr, index, val);
}

void MonWriteI2Cn_(BYTE addr, BYTE *val, BYTE cnt) 
{
	BYTE i;

	Printf("Write ");
	for(i=0; i<cnt; i++) {
		Printf("%02xh ", val[i]);
	}
	Printf("to [Adrs(%02xh)", (WORD)addr);
	if( !WriteI2Cn_(addr, val, cnt) )		//LJY001127
		Puts("---> Fail!! ");	
}
/*===========================================================================*/
/*		I2C Edit Read		                                                 */
/*===========================================================================*/
BYTE MonReadI2C(BYTE addr, BYTE index)
{
	BYTE val;

	val = ReadI2C(addr, index);
	Printf("Read [Adrs:%02xh,%02xh] %02xh", (WORD)addr, (WORD)index, (WORD)val);

	return val;
}

void MonReadI2Cmn(BYTE addr, BYTE *wrdata, BYTE argcnt)
{
	BYTE i, rcnt;

	Printf("Read  [Adrs:%02xh ", (WORD)addr);
	for(i=0; i<argcnt-1; i++)
		Printf(" Index:%02xh ", wrdata[i] );
	Printf("] ");

	rcnt = wrdata[argcnt-1];
	ReadI2Cmn(addr, argcnt-1, rcnt, wrdata);

	for(i=0; i<rcnt; i++)
		Printf("%02xh ", (WORD)wrdata[i]);
}
/*===========================================================================*/
/*		Convert ASCII to Binery                                              */
/*===========================================================================*/
BYTE Asc1Bin(BYTE asc)
{
	if(asc>='0' && asc <='9') return (asc - '0');
	if(asc>='a' && asc <='f') return (asc - 'a' + 0x0a);
	if(asc>='A' && asc <='F') return (asc - 'A' + 0x0a);
}

BYTE Asc2Bin(PDATA_P BYTE *s)
{
	BYTE bin;

	bin = 0;
	while(*s != '\0' && *s !=' ' && *s !='_') {		// add char '_'
		bin = bin<<4;
		bin = bin + Asc1Bin(*s);
		s++;
	}
	return (bin);
}

void I2CDeviceSet( CODE_P BYTE *RegSet)
{
	int	cnt=0;
	BYTE addr, index, val;

	// Output discription
	#ifdef TASKING
	while( *RegSet ) 
		RS_tx( *RegSet++ );
	RegSet++;
	#endif

	while ( *RegSet != 0xFF ) {
		if( cnt==0 ) {
			addr = *RegSet;

			cnt = *(RegSet+1);
			RegSet+=2;
		}
		index = *RegSet;
		val = *(RegSet+1);
		MonWriteI2C(addr, index, val);
//		WriteI2C(addr, index, val);

//		Puts("\r\n");

		RegSet+=2;

		cnt--;
	}

	delay(50);
}

#ifdef REMO_NEC

void IsRemoDataReady(void)
{

	static BYTE AutoWait=0;
	static IDATA BYTE LastDataCode=0xff;
	static IDATA BYTE repeatcnt=0;
	BYTE ret =0 ;

//	Printf("\r\n(Debug)RemoLcnt: %2x, RemoHcnt: %2x, RemoStep: %2x, tm001: %2x", 
//				(WORD)RemoLcnt, (WORD)RemoHcnt, (WORD)RemoStep, (WORD)tm001);

	switch ( RemoDataReady ) {

	case 0: break;	

	case 1:
		#ifdef DEBUG_KEYREMO
		dPrintf("\r\nNEC RemoData = %02x %02x %02x %02x", (WORD)RemoData[0], (WORD)RemoData[1], (WORD)RemoData[2], (WORD)RemoData[3] );
		#endif
		if( (RemoData[0]==REMO_CUSTOM1) && (RemoData[1]==REMO_CUSTOM2 ) && (RemoData[2]+RemoData[3])==0xff ) {
			RemoDataCode = RemoData[2];
			LastDataCode = RemoDataCode;
			AutoWait = 0;
			repeatcnt = 0;
		}
		else {
			RemoDataCode = 0xff;
			LastDataCode = 0xff;

			EnableRemoconInt();		//
		}
		IntFlag = 0;
		break;

	case 2:
		AutoWait++;
		if( AutoWait>=6 ) {
			RemoDataCode = LastDataCode;
			repeatcnt++;
			if( repeatcnt>=5 ) {
				AutoWait = 5;
			}
			else
				AutoWait = 4;
		}
		else {
			EnableRemoconInt();		//
		}
		break;

	}


	if(!IntFlag)
		EnableRemoconInt();		////LJY052902

	#ifdef DEBUG_KEYREMO
	dPrintf("(R-D:%02x)  ", (WORD)RemoDataCode);
	#endif

}


#endif	// REMO_NEC

/*===========================================================================*/
/*		FPGA Write      		                                             */
/*===========================================================================*/
#define FPGA_ADDR	0x5a00
#define FPGA_CNT	42114-2

void FPGAwrite(void)
{
	WORD	i;
	CODE_P BYTE	*ptr;
	
	Printf("\r\nFPGA Write M0=%01d  M1=%01d", (WORD)M0, (WORD)M1 );

	reset = 1;
	CCLK = nCS = nWRITE = BUSY = 1;

	nPGM = 0;
	nPGM = 1;

	// Start up
	nWRITE = 0;
	nCS    = 0;

	#ifdef TASKINGC
	ptr = (CODE_P BYTE *)FPGA_ADDR;
	#elif defined KEILC
	ptr = (BYTE CODE *)FPGA_ADDR;
	#endif

	for(i=0; i<FPGA_CNT; i++) {
		P0 = *ptr++;
		CCLK = 0;
		CCLK = 1;

	}

	// End
	nCS    = 1;
	nWRITE = 1;

	Puts("\r\nFPGA end\n");

	delay(10);
}




/*===========================================================================*/
/*		Help					                                             */
/*===========================================================================*/
void Usage(void)
{
//	Puts("\r\n+-------TW9901/03/05 Evaluation Board--Rev1.00 -------+");
	Printf("\r\n+-------TW9910  Evaluation Board--Rev%d.%02x ------+", (WORD)FWVER/0x100, (WORD)FWVER%0x100);
	Puts("\r\n| W Index Data   Write register                 |");	delay(1);
	Puts("\r\n| X Index D D,,  Write Multiple(<7) bytes       |");	delay(1);
	Puts("\r\n| R Index        Read register                  |");	delay(1);
	Puts("\r\n| D Index Index  Dump registers                 |");	delay(1);
	Puts("\r\n| J Index D D,,  Write Multiple commd           |");	delay(1);
	Puts("\r\n| C Address      Change I2C Address             |");	delay(1);
	Puts("\r\n| I 0|1          Change Input  Comp>YC>         |");	delay(1);
	Puts("\r\n| O              Change Output YUV>RGB>YC       |");	delay(1);
	Puts("\r\n| K 0|1          NTSC/PAL Forcing  	          |");	delay(1);
	Puts("\r\n| < >            Register++,Register--          |");	delay(1);
	Puts("\r\n| /              Repeat previous command        |");	delay(1);
	Puts("\r\n| H,?            Help                           |");	delay(1);
	Puts("\r\n+-----------------------------------------------+");	delay(1);
}


/*===========================================================================*/
/*		Help					                                             */
/*===========================================================================*/
/*void RegisterSummary(void)
{
//	Puts("\r\n+-------TW9901/03/05 Evaluation Board--Rev1.00 -------+");
	Printf("\r\nTW9901/3/5 Register Summary--Rev%d.%02x ", FWVER/0x100, FWVER%0x100);
	Puts("\r\n+--------------------------------------------------------------------------------------------+");
	Puts("\r\n|I(H)|    7     |    6     |    5     |    4     |     3    |    2     |    1     |    0     |");
	Puts("\r\n+--------------------------------------------------------------------------------------------+");
	Puts("\r\n| 00 |                       ID                             |                REV             |");
	Puts("\r\n+--------------------------------------------------------------------------------------------+");
	Puts("\r\n| 01 | VDLOSS   | HLOCK    | SLOCK    | FIELD    | VLOCK    | CCVALID  | MONO     | DET50    |");
	Puts("\r\n+--------------------------------------------------------------------------------------------+");
	Puts("\r\n| 02 |    *     | FC27     |        IFSEL        |         YSEL        | CSEL     | SEL      |");
	Puts("\r\n+--------------------------------------------------------------------------------------------+");
	Puts("\r\n| 03 | MODE     | LEN      |        DVALID       | VSCTL    | OEN      |        TRI_SEL      |");
	Puts("\r\n+--------------------------------------------------------------------------------------------+");
	Puts("\r\n| 04 |    *     |          *          |                        HSDLY                         |");
	Puts("\r\n+--------------------------------------------------------------------------------------------+");
	Puts("\r\n| 05 |LVALID_POL|DVALID_POL|VACTIV_POL|CBFLAG_POL|FIELD_POL |HACTIV_POL|HSYNC_POL |VSYNC_POL |");
	Puts("\r\n+--------------------------------------------------------------------------------------------+");
	Puts("\r\n| 06 | SRESET   | IREF     | VREF     | AGC_EN   | CLKPDN   | Y_PDN    | C_PDN    |    *     |");
	Puts("\r\n+--------------------------------------------------------------------------------------------+");
	Puts("\r\n| 07 |     VDELAY_HI       |      VACTIVE_HI     |      HDELAY_HI      |      HACTIVE_HI     |");
	Puts("\r\n+--------------------------------------------------------------------------------------------+");
	Puts("\r\n| 08 |                                      VDELAY_LO                                        |");
	Puts("\r\n+--------------------------------------------------------------------------------------------+");
	Puts("\r\n| 09 |                                      VACTIVE_LO                                       |");
	Puts("\r\n+--------------------------------------------------------------------------------------------+");
	Puts("\r\n| 0A |                                      HDELAY_LO                                        |");
	Puts("\r\n+--------------------------------------------------------------------------------------------+");
	Puts("\r\n| 0B |                                      HACTIVE_LO                                       |");
	Puts("\r\n+--------------------------------------------------------------------------------------------+");
	Puts("\r\n| 0C | PBW      | DEM      | PALSW    | SET7     | COMB     | HCOMP    | YCOMP    | CCOMP    |");
	Puts("\r\n+--------------------------------------------------------------------------------------------+");
	Puts("\r\n| 0D |                                      VSCALE_LO                                        |");
	Puts("\r\n+--------------------------------------------------------------------------------------------+");
	Puts("\r\n| 0E |                VSCALE_HI                  |                  HSCALE_HI                |");
	Puts("\r\n+--------------------------------------------------------------------------------------------+");
	Puts("\r\n| 0F |                                      HSCALE_LO                                        |");
	Puts("\r\n+--------------------------------------------------------------------------------------------+");
	Puts("\r\n| 10 |                                      BRIGHTNESS                                       |");
	Puts("\r\n+--------------------------------------------------------------------------------------------+");
	Puts("\r\n| 11 |                                      CONTRAST                                         |");
	Puts("\r\n+--------------------------------------------------------------------------------------------+");
	Puts("\r\n| 12 | SCURVE   |    *     |          *          |                 SHARPNESS                 |");
	Puts("\r\n+--------------------------------------------------------------------------------------------+");
	Puts("\r\n| 13 |                                        SAT_U                                          |");
	Puts("\r\n+--------------------------------------------------------------------------------------------+");
	Puts("\r\n| 14 |                                        SAT_V                                          |");
	Puts("\r\n+--------------------------------------------------------------------------------------------+");
	Puts("\r\n| 15 |                                         HUE                                           |");
	Puts("\r\n+--------------------------------------------------------------------------------------------+");
	Puts("\r\n| 16 |                   SHLMT                   |                  SHCOR                    |");
	Puts("\r\n+--------------------------------------------------------------------------------------------+");
	Puts("\r\n| 17 |                     *                     |                     *                     |");
	Puts("\r\n+--------------------------------------------------------------------------------------------+");
	Puts("\r\n| 18 |          *          |        CCOR         |          *          |        BKCOR        |");
	Puts("\r\n+--------------------------------------------------------------------------------------------+");
	Puts("\r\n| 19 | VBI_EN   | VBI_BYT  | VBI_FM   | HA_EN    | CTL656   |             RTSEL              |");
	Puts("\r\n+--------------------------------------------------------------------------------------------+");
	Puts("\r\n| 1A |CCVALID_EN| EDS_EN   | CC_EN    | PARITY   | FF_OVF   | FF_EMP   | CC_EDS   | LO_HI    |");
	Puts("\r\n+--------------------------------------------------------------------------------------------+");
	Puts("\r\n| 1B |                                        CC_DATA                                        |");
	Puts("\r\n+--------------------------------------------------------------------------------------------+");
	Puts("\r\n| 1C | DTSTUS   |            STDNOW              | ATREG    |           STANDARD             |");
	Puts("\r\n+--------------------------------------------------------------------------------------------+");
	Puts("\r\n| 1D | START    | PAL60    | PALCN    | PALM     | NTSC4    | SECAM    | PALB     | NTSC     |");
	Puts("\r\n+--------------------------------------------------------------------------------------------+");
	Puts("\r\n| 1E |                     IN                    |                    OUT                    |");
	Puts("\r\n+--------------------------------------------------------------------------------------------+");
	Puts("\r\n| 1F |                                         TEST                                          |");
	Puts("\r\n+--------------------------------------------------------------------------------------------+");
	Puts("\r\n| 20 |                  CLPEND                   |                  CLPST                    |");
	Puts("\r\n+--------------------------------------------------------------------------------------------+");
	Puts("\r\n| 21 |                  NMGAIN                   |             WPGAIN             |AGCGAIN[8]|");
	Puts("\r\n+--------------------------------------------------------------------------------------------+");
	Puts("\r\n| 22 |                                      AGCGAIN[7:0]                                     |");
	Puts("\r\n+--------------------------------------------------------------------------------------------+");
	Puts("\r\n| 23 |                                         PEAKWT                                        |");
	Puts("\r\n+--------------------------------------------------------------------------------------------+");
	Puts("\r\n| 24 | CLMPLD   |                              CLMPPL                                        |");
	Puts("\r\n+--------------------------------------------------------------------------------------------+");
	Puts("\r\n| 25 | SYNCTD   |                              SYNCT                                         |");
	Puts("\r\n+--------------------------------------------------------------------------------------------+");
	Puts("\r\n| 26 |                  MISSCNT                  |                  HSWIN                    |");
	Puts("\r\n+--------------------------------------------------------------------------------------------+");
	Puts("\r\n| 27 |                                         PCLAMP                                        |");
	Puts("\r\n+--------------------------------------------------------------------------------------------+");
	Puts("\r\n| 28 |        VLCKI        |        VLCKO        | VMODE    | DETV     | AFLD     | VINT     |");
	Puts("\r\n+--------------------------------------------------------------------------------------------+");
	Puts("\r\n| 29 |               BSHT             |                    CCEVENLINE(VSHT)                  |");
	Puts("\r\n+--------------------------------------------------------------------------------------------+");
	Puts("\r\n| 2A |        CKILMAX      |                              CKILMIN                            |");
	Puts("\r\n+--------------------------------------------------------------------------------------------+");
	Puts("\r\n| 2B |                    HTL                    |                    VTL                    |");
	Puts("\r\n+--------------------------------------------------------------------------------------------+");
	Puts("\r\n| 2C |   *      |               YDLY             |                   HSLEN                   |");
	Puts("\r\n+--------------------------------------------------------------------------------------------+");
	Puts("\r\n| 2D | EVCNT    |               HFLT             | TBC_EN   | BYPASS   | SYOUT    | HADV     |");
	Puts("\r\n+--------------------------------------------------------------------------------------------+");
	Puts("\r\n| 2E | VLPF     | PMODE    |        ACCT         |        SPM          |         CBW         |");
	Puts("\r\n+--------------------------------------------------------------------------------------------+");
	Puts("\r\n| 2F | NKILL    | PKILL    | SKILL    | CBAL     | FCS      | LCS      | CCS      | BST      |");
	Puts("\r\n+--------------------------------------------------------------------------------------------+");
	Puts("\r\n| 30 | SF       | PF       | FF       | KF       | CSBAD    | MCVSN    | CSTRIPE  | CTYPE    |");
	Puts("\r\n+--------------------------------------------------------------------------------------------+");
	Puts("\r\n| 31 | CTEST    | YCLEN    | CCLEN    | VCLEN    | GTEST    | PLLTEST  | CKLY     | CKLC     |");
	Puts("\r\n+--------------------------------------------------------------------------------------------+");
	Puts("\r\n| 32 |                                        FILLDATA                                       |");
	Puts("\r\n+--------------------------------------------------------------------------------------------+");
	Puts("\r\n| 33 |        VBILPF       |                             SDID                                |");
	Puts("\r\n+--------------------------------------------------------------------------------------------+");
	Puts("\r\n| 34 |    *     | SYRM     | WSSEN    |                       DID                            |");
	Puts("\r\n+--------------------------------------------------------------------------------------------+");
	Puts("\r\n| 35 | ANCEN    | TOUTHA   | VIPCFG   |                       CCODLINE                       |");
	Puts("\r\n+--------------------------------------------------------------------------------------------+");
	Puts("\r\n| 36 |                                       SLICELEVEL                                      |");
	Puts("\r\n+--------------------------------------------------------------------------------------------+");
	Puts("\r\n| 37 | CRCERR   | WSSFLD   |                             WSS[13:8]                           |");
	Puts("\r\n+--------------------------------------------------------------------------------------------+");
	Puts("\r\n| 38 |                                       WSS[7:0]                                        |");
	Puts("\r\n+--------------------------------------------------------------------------------------------+");
	Puts("\r\n| 39 |    *     |    *     | GAP      | VSTD     | NINTL    | WSSDET   | EDSDET   | CCDET    |");
	Puts("\r\n+--------------------------------------------------------------------------------------------+");
	Puts("\r\n| 3A |                                        HREF                                           |");
	Puts("\r\n+--------------------------------------------------------------------------------------------+");

}
*/

void DetScaleMode(BYTE I2CAddress, BYTE arg1)
{

	if(I2CAddress == TW99I2CAddress && (arg1 == 0x0d || arg1 == 0x0e || arg1 == 0x0f))
		MaskScaleMode = 1;
	else
		MaskScaleMode = 0;

}

/*===========================================================================*/
/*			          Debug Command Service Routine                          */
/*===========================================================================*/
void DebugKeyIn(BYTE ikey)
{
	BYTE i;

	#ifdef TEST_SERCOM
	BYTE buf;
	#endif //TEST_SERCOM

	#ifdef SUPPORT_TELETEXT	
	BYTE j;
	#endif //SUPPORT_TELETEXT	

	bit eol, cerror;
	static bit comment=0;
//	static bit MaskEcho=0;

	//----- if comment, echo back and ignore -----
	if( comment ) {
		if( ikey=='\r' ) 	
			comment = 0;
		else {
			RS_tx(ikey);	// mod0606
			return;
		}
	}
	else if( ikey==';' ) {
		comment = 1;
		RS_tx(ikey);	// mod0606
		return;
	}

	//----- Command Interpret ------------------------------

	if( (ikey=='\r') || (ikey=='/') ) {
		#ifdef TEST_SERCOM
		if(ikey=='\r')
			MaskEcho = 0;
		#endif //TEST_SERCOM
		comment = 0;

		if (ikey == '/') {      // Repeat 
			PutsP(commdbuf);
			commdptr = bptr;
			commdbuf[0]=arg[0];
		}
		commdbuf[commdptr] = '\0';
		bptr = commdptr;
		commdptr = 0;
		argn = 0;
		eol	= 0;
		cerror = 0;

		while(commdbuf[commdptr]==' ' ) commdptr++;		// Cut leading space, add char '_' , mod0606
		if (commdbuf[commdptr]=='\0')  
			eol = 1;			// Exit, if null command
		arg[argn++] = commdbuf[commdptr++];				// Get command

		while( !cerror && !eol ) {
			if( commdbuf[commdptr]!=' ' && commdbuf[commdptr]!='\0') {	// add char '_' , mod0606
				cerror = 1; break;
			}
			while( commdbuf[commdptr]==' ') commdptr++;	// add char '_' //mod0606
			if( commdbuf[commdptr]=='\0' ) {
				eol = 1; break;
			}
			arg[argn++] = Asc2Bin(&commdbuf[commdptr]);
			while( commdbuf[commdptr]!=' ' && commdbuf[commdptr]!='\0') {	// add char '_' //mod0606
				commdptr++;
			}
		}

		if(I2CInitialBlocking){	
			cerror = 0;
			I2CInitialBlocking = 0;
		}

⌨️ 快捷键说明

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