亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關于我們
? 蟲蟲下載站

?? combi.c

?? 這是使用CYPRESS的7C637xx芯片完成USB鼠標的例子。
?? C
?? 第 1 頁 / 共 5 頁
字號:
	{
		if (EP_A0_MODE & SETUP_RECEIVED_MASK)				//if a setup was received,
		{
			DeviceStatus.bAddress &= ~0x80;					//clear the address flag
			HandleSetup();									//and handle it
		}
		else if (EP_A0_MODE & IN_RECEIVED_MASK)				//if an in was received,
		{
			HandleIn();										//handle it
			if (DeviceStatus.bAddress & 0x80)		        //if the address flag was set during the setup
															//phase preceding this IN,
				  USB_DEVICE_A = DeviceStatus.bAddress;		//enable the new address
			DeviceStatus.bAddress &= ~0x80;					//and clear the new address flag
		}
	}
	POPX();
	POPA();
	return;
}


/*
**
** FUNCTION:		USB_A_EP1_ISR
**
** PURPOSE:			Endpoint 1 ISR.  
**
** PARAMETERS:		none
**
** DESCRIPTION:	 
**					this routine is entered upon receiving an endpoint 1 interrupt.	
**					If the ACK bit is sent, indicating that a valid mouse packet was just
**					transmitted to the host, the SIE is set to NAK ins, and the
**					datatoggle bit is flipped for the next transaction.
*/

void USB_A_EP1_ISR(void)
{
	PUSHA();
	if (EP_A1_MODE & ( 1 << ACKNOWLEDGE))
	{
		EP_A1_MODE = USB_MODE_NAK_IN;
		EP_A1_COUNTER ^= DATATOGGLE;
	}
	POPA();
	return;
}


/*
**
** FUNCTION:		TuneWakeup
**
** PURPOSE:			to tune the wakeup ISR  
**
** PARAMETERS:		none
**
** DESCRIPTION:	    The wakeup interrupt period is variable by a factor of 5 due to operating and process
**					conditions.  The period has a prescaler which adjusts the period by a factor of two.
**					This routine is called at regular intervals to tune the wakeup ISR to occur at the
**					rate at which this routine is called, to within a factor of 2.  In other words, if
**					this routine is called every 256 msec, it will tune the wakeup ISR to occur at a rate
**					between 128-256 msec.
**					
**

*/

void TuneWakeup(void)
{
	char temp;
	temp = CLOCK_CONFIGURATION & TWAKEUP_MASK;				//get the current wakeup prescale value
	if ((bWakeupCount > 2) && (temp != TWAKEUP_MAX))			//if more than two wakeup ISRs occurred since
															//the last time this routine was called, and we
															//are not at the maximum prescale value already,
															//increment the prescaler to slow down the ISR interval
		temp += TWAKEUP_2;
	if ((!bWakeupCount) && (temp))							//if no wakeup ISRs occurred, and we are not
															//at the minimum prescale value,
															//decrement the prescaler to speed up the ISR interval
		temp -= TWAKEUP_2;
    CLOCK_CONFIGURATION = PRECISION_USB_CLOCKING | temp;
	bWakeupCount = 0;
}


/*
**
** FUNCTION:		usbmain
**
** PURPOSE:			USB main processing loop 
**
** PARAMETERS:		none
**
** DESCRIPTION:	 
**					main spins in an infinite loop waiting for an event that needs servicing.
**					Main is entered from either the power-on reset or the usb bus reset. Both
**					of these reset routines insures that all USB variables have been initialized
**					prior to calling usbmain.
*/

void usbmain(void)

{
   EI();
   while (1)
    {
		//clear watchdog timer
		RESET_COP();	
		ProcessOptics();											//empty the optics queue
		if (MsecStatus.b1msFlags & ONE_MSEC_FLAG)					//if 1 msec has elapsed
		{
			if (!MsecStatus.b1msCounter)							//every 256 msec tune the wakeup ISR
				TuneWakeup();
			if (DeviceStatus.bConfiguration && 
				(!(MsecStatus.b1msCounter & 3)))					//if we're configured, and if 4 msec has elapsed....
					MouseTask();									//go handle mouse stuff
			if (BusInactive())										//if the bus has gone inactive
			    Suspend();											//suspend us
			MsecStatus.b1msFlags &= ~ONE_MSEC_FLAG;	
		}
	}
}


/*
**
** FUNCTION:		Reinitialize
**
** PURPOSE:			Reinitializes system RAM and USB engine  
**
** PARAMETERS:		none
**
** DESCRIPTION:	 
**					This routine initializes all USB variables to their
**					default states, and resets USB engine controls to their initial values. RAM
**					has been cleared prior to entry.
*/

void UsbReInitialize(void)
{
	DI();														//disable ints
	RESET_COP();												//reset watchdog
    CLOCK_CONFIGURATION = PRECISION_USB_CLOCKING | TWAKEUP_64 ;	//set up precision clocking, /64 wakeup prescaler
																//this will set the initial wakeup time anywhere
																//from 64 - 5*64 msec.  
		OpticsQueue.headP = bOpticsArray;						//initialize queue pointers
	OpticsQueue.tailP = bOpticsArray;
	DeviceStatus.bProtocol = REPORT_PROTOCOL;					//start in report protocol
	USB_STATUS = VREG_ENABLE_MASK | NOT_FORCING;
	PROCESSOR_STATUS &= ~(WATCHDOG_RESET_MASK 					//clear source of reset
		| POWER_ON_RESET_MASK | USB_BUS_RESET_MASK);
	GLOBAL_INTERRUPT = MILLISECOND_ENABLE 						//enable all pertinent interrupts
		| BUS_RESET_ENABLE  | MICROSECOND_ENABLE | WAKEUP_ENABLE;
	USB_DEVICE_A = 0;											//reset device address
	EP_A0_MODE = USB_MODE_DISABLE;								//disable endpoints from responding
	EP_A1_MODE = USB_MODE_DISABLE;
	EP_A2_MODE = USB_MODE_DISABLE;
	ENDPOINT_INTERRUPT = (EPA0_ENABLE | EPA1_ENABLE);			//turn on endpoint interrupts
	return;
}


/*
**
** FUNCTION:		MouseMoved
**
** PURPOSE:			returns a 1 if the mouse's X,Y, or Z counts indicate movement.  
**
** PARAMETERS:		none
**
** DESCRIPTION:		This routine will return a 1 if the accumulated X,Y, or Z counts are nonzero
**					.
**					 
*/

char MouseMoved(void)
{
	if (Mouse.bXcount || Mouse.bYcount)
	         return(1);
	if((DeviceStatus.bProtocol == REPORT_PROTOCOL)		//if Z wheel enabled, nonzero Z count requires a transmission
		&& Mouse.bZcount)
		return(1);
	return(0);
}
     

/*
**
** FUNCTION:		MouseTask
**
** PURPOSE:			Handles mouse data transmission.  
**
** PARAMETERS:		none
**
** DESCRIPTION:		This routine is called every 4 msec from the main loop. It
**					maintains the idle counter, which determines the rate at which mouse packets
**					are sent to the host in the absence of a state change in the mouse itself.
**					It also sends a mouse packet if either of X,Y, or Z counts or the buttons have
**					changed state.
**					 
*/

void MouseTask(void)
{
	Mouse.bChange |= DebounceButtons();				//keep track of button changes
	/*
	** if the idle period is nonzero, and the decremented counter rolls to zero,
	** set the change flag so we will send a packet regardless.
	*/
	if (MouseStatus.bIdlePeriod && !--MouseStatus.bIdleCounter)
	{
		MouseStatus.bIdleCounter = MouseStatus.bIdlePeriod;
		Mouse.bChange = 1;
	}
   	if ((EP_A1_MODE & USB_MODE_MASK) == USB_MODE_NAK_IN)     //we are NAKing, so it's ok to transmit a new package
	{
		Mouse.bChange |= MouseMoved();
		if (Mouse.bChange)										 //ok-transmission definitely required
		{

			ENDPOINT_A1_FIFO[0] = Mouse.bButtons;				 //load mouse data into fifo
			ENDPOINT_A1_FIFO[1] = Mouse.bXcount;
				  Mouse.bXcount = 0;  
			ENDPOINT_A1_FIFO[2] = Mouse.bYcount;
			Mouse.bYcount = 0;
			ENDPOINT_A1_FIFO[3] = Mouse.bZcount;
			Mouse.bZcount = 0;
			if (DeviceStatus.bProtocol == REPORT_PROTOCOL)		  //if report protocol, include z counts in length
				EP_A1_COUNTER = (EP_A1_COUNTER & DATATOGGLE) | 4;
			else
				EP_A1_COUNTER = (EP_A1_COUNTER & DATATOGGLE) | 3; //else omit it

			EP_A1_MODE = USB_MODE_ACK_IN;						  //flip mode to ack the in with the data
			MouseStatus.bIdleCounter = MouseStatus.bIdlePeriod;	  //and reset the idle period.
			Mouse.bChange = 0;								  //clear the flag
		}
	}
}


/*
**
** FUNCTION:		BusInactive
**
** PURPOSE:			Tests for upstream activity  
**
** PARAMETERS:		none
**
** DESCRIPTION:	    This routine should be called every msec from the main loop.
**					it maintains an internal count of the successive samples of the USB status register
**					in which no bus activity was recorded.  When this count exceeds 3 (msec), the
**					routine returns 1, indicating that bus activity has deceased
**					
*/

char BusInactive(void)
{
	if  (!(USB_STATUS & BUS_ACTIVITY_MASK))				//if no bus activity indicated in the status reg,
	    return(++bSuspendCounter == 3);					//return 0 if the counter has elapsed
	USB_STATUS = VREG_ENABLE_MASK;						//reset the flag (always write bit 4 to a 0 in this reg)
	bSuspendCounter = 0;
	return(0);
}


/*
**
** FUNCTION:		Suspend
**
** PURPOSE:			puts the chip into suspend  
**
** PARAMETERS:		none
**
** DESCRIPTION:	 
**					This routine handles the entrance/exit from suspend. If the mouse is configured for
**					remote wakeup, the bus reset, wakeup, and gpio interrupts are enabled.  The optical
**					inputs are sampled once.  The code then enters a loop in which the chip is suspended,
**					and will wake at least as often as the wakeup ISR, but perhaps due to a GPIO or bus
**					reset interrupt. Each time the chip wakes up, the  led drive is reenabled, and the
**					switches and optical inputs are sampled to see if a change occured, and bus activity
**					is monitored. Any of these conditions will cause the firmware to exit the loop.
**
**					if the device is not enabled for remote wakeup, all ports are put into the hi-Z state,
**					only the bus reset interrupt is enabled,and the part is suspended. 
**
**					if the resume was due to bus activity, the firmware returns to the main loop.
**					if the resume was due to mouse movement or a button press, a K state is driven upstream
**					for 14 msec prior to returning to the main loop.
*/

void Suspend(void)
{
	char Optics;
	char temp = 10;
	if (!DeviceStatus.bRemoteWakeup)	
	{
		
		GLOBAL_INTERRUPT = BUS_RESET_ENABLE;				//enable bus reset ISR only
		PORT0_MODE0 = PORT0_MODE0_SUSPEND;																	
		PORT1_MODE0 = PORT1_MODE0_SUSPEND;									
		PORT0_MODE1 = PORT0_MODE1_SUSPEND;																	
		PORT1_MODE1 = PORT1_MODE1_SUSPEND;
		PORT0 = PORT0_SUSPEND;
		PORT1 = PORT1_SUSPEND;
		PROCESSOR_STATUS |= 0x8;							//suspend 
		#asm(nop);
		RESET_COP();
		PORT0_MODE0 = PORT0_MODE0_INIT;						//re-init port modes									
		PORT1_MODE0 = PORT1_MODE0_INIT;
		PORT0_MODE1 = PORT0_MODE1_INIT;									
		PORT1_MODE1 = PORT1_MODE1_INIT;
		PORT0 = PORT0_INIT;
		PORT1 = PORT1_INIT;
	}
	else
	{
		//enable gpio, wakeup, and bus reset ISRs
		GLOBAL_INTERRUPT = BUS_RESET_ENABLE | GPIO_ENABLE | WAKEUP_ENABLE ;
		Optics = OPTICS_PORT;									//sample the optics port
		while (1)
		{														
			PORT0_MODE0 = PORT0_MODE0_RW;						//set ports to remote wakeup configuration																
			PORT1_MODE0 = PORT1_MODE0_RW;									
			PORT0_MODE1 = PORT0_MODE1_RW;																	
			PORT1_MODE1 = PORT1_MODE1_RW;
			PORT0 = PORT0_RW;
			PORT1 = PORT1_RW;
			PROCESSOR_STATUS |= 0x8;							//suspend (wakeup timer will wake us up)
			#asm(nop);
			PORT0_MODE0 = PORT0_MODE0_INIT;						//re-init port modes									
			PORT1_MODE0 = PORT1_MODE0_INIT;
			PORT0_MODE1 = PORT0_MODE1_INIT;									
			PORT1_MODE1 = PORT1_MODE1_INIT;
			PORT0 = PORT0_INIT;
			PORT1 = PORT1_INIT;
			RESET_COP();
			if (USB_STATUS & BUS_ACTIVITY_MASK)					//if wakeup due to bus activity (including bus reset), get out 
																//of this loop
				break;
			if (GetButtons() != Mouse.bButtons)					//if mouse buttons switches different, get out
				break;
			Delay(20);											//wait some more time for optic led to come on
			if ((OPTICS_PORT ^ Optics) & OPTICS_MASK)			//if optics have changed, get out
				break;
		}  
	}
	GLOBAL_INTERRUPT = MILLISECOND_ENABLE 						//reenable all interrupts used in main loop
		| BUS_RESET_ENABLE  | MICROSECOND_ENABLE | WAKEUP_ENABLE;
	temp = MsecStatus.b1msCounter + 5;							//wait 5 msec
	while (temp != MsecStatus.b1msCounter)
	{
		RESET_COP();
 		if (USB_STATUS & BUS_ACTIVITY_MASK)				    //if bus activity is present, get out now
			return;
	}
	USB_STATUS = VREG_ENABLE_MASK | FORCE_J;			    //otherwise force resume upstream for 14 msec
	USB_STATUS = VREG_ENABLE_MASK | FORCE_K;
 	temp = MsecStatus.b1msCounter +	14;						//		
	while (temp != MsecStatus.b1msCounter)
		RESET_COP();
	USB_STATUS = VREG_ENABLE_MASK | NOT_FORCING;		    //switch to nonforcing
	bSuspendCounter = 0;
	return;
}


/*
**
** FUNCTION:		HandleIn
**
** PURPOSE:			Services In packets 
**
** PARAMETERS:		none
**
** DESCRIPTION:	 
**					This routine is entered whenever an IN packet has come in on endpoint 0.
**					it processes the packet.
**					
*/

void HandleIn(void)

{
	//an ACKed IN occurs either in the case of the status phase of a control write,
	//or the data in phase of a control read.  The only thing we are expecting is the
	//data in phase -- there are no control writes to the mouse
	if ((EP_A0_MODE & USB_MODE_MASK) != USB_MODE_NAK_IN_STATUS_OUT )
	{
		SET_EP0_MODE(USB_MODE_STALL_IN_OUT);					//we weren't expecting this!!
		return;
	}
	byte_count = EP_A0_COUNTER;									//unlock the counter register by reading it
	byte_count = 0;												//zero the byte count
	if (XmtBuff.bLength)										//if we've stuff to send,
	    	byte_count = LoadEP0Fifo();			//load it into fifo
			//account for the bytes we will send this pass
	//load up the counter
	EP_A0_COUNTER = (EP_A0_COUNTER & DATATOGGLE) ^ DATATOGGLE;
	EP_A0_COUNTER |= byte_count;
	//and set the ep mode to ack the next IN with the data.
	EP_A0_MODE = USB_MODE_ACK_IN_STATUS_OUT;

}


/*
**
** FUNCTION:		USB_control_read
**
** PURPOSE:			Prepares the SIE for the first IN after a SETUP requesting data
**
** PARAMETERS:		none
**
** DESCRIPTION:	 
**					This routine is called after a SETUP has been received that is requesting
**					a data response from the mouse. Upon entry, XmtBuff has been initialized to
**					point to the data buffer that needs to be tranmsitted.  USB_control_read
**					adjusts the length of the data to be returned if the host requested less
**					data than the actual length of the buffer.  It then loads the FIFO with the
**					first chunck of data and prepares the SIE to ACK with the data.
**					
*/

void USB_control_read(void)

{
	//if the host requested less data than is actually available, use that length instead

	if ((!ENDPOINT_A0_FIFO[USB_wLengthHi]) && (ENDPOINT_A0_FIFO[USB_wLength] < XmtBuff.bLength))
		XmtBuff.bLength = ENDPOINT_A0_FIFO[USB_wLength];
	byte_count = 0;
	if (XmtBuff.bLength)
		byte_count = LoadEP0Fifo();							//data to send. Load FIFO with first chunck
	EP_A0_COUNTER =  DATATOGGLE | byte_count;				//set up counter
	EP_A0_MODE = USB_MODE_ACK_IN_STATUS_OUT;				//and set up SIE to ACK with the data
}


/*
**
** FUNCTION:		LoadEP0Fifo
**
** PURPOSE:			loads EP0 fifo with available data 
**
** PARAMETERS:		bLength -- length of data available to load
**
** DESCRIPTION:	 
**					This routine loads the fifo with data pointed to by XmtBuff.  It
**					returns the length of data actually loaded into the FIFO.
**					
*/

char LoadEP0Fifo(void)
{

	byte_count1 = 0;

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
99久久99精品久久久久久| 日韩理论片网站| 免费久久精品视频| 91精品国产综合久久精品麻豆| 亚洲一区二区三区在线| 欧美日韩精品一二三区| 麻豆国产欧美一区二区三区| 26uuu精品一区二区在线观看| 精品一区二区综合| 中文字幕第一区二区| 91社区在线播放| 五月激情六月综合| 久久久欧美精品sm网站| www.亚洲色图| 婷婷六月综合亚洲| 精品99999| 色综合天天综合色综合av| 天天影视涩香欲综合网| 久久免费的精品国产v∧| 99久久综合国产精品| 日韩精彩视频在线观看| 国产欧美精品一区二区色综合| 91免费在线看| 精品一区免费av| 亚洲精品va在线观看| 日韩欧美你懂的| 99国产麻豆精品| 日本91福利区| 亚洲日本一区二区三区| 欧美一区国产二区| 成人黄色av电影| 三级欧美在线一区| 1024国产精品| 精品久久久久久久人人人人传媒| 成人黄色电影在线 | 欧美成人三级在线| 972aa.com艺术欧美| 久久99国产精品麻豆| 亚洲特级片在线| 欧美一区二区三区在| 波多野洁衣一区| 精品一区二区三区久久久| 国产精品成人网| 久久久久久99久久久精品网站| 欧美性猛交xxxx黑人交| 成人av在线一区二区| 久久成人麻豆午夜电影| 亚洲福利视频一区| 日韩一区在线看| 国产欧美久久久精品影院| 欧美一级在线免费| 欧美日韩dvd在线观看| 99久久免费国产| 成人污污视频在线观看| 久久精品国产免费| 日韩av电影一区| 亚洲1区2区3区4区| 亚洲一区二区三区视频在线播放| 国产欧美日韩卡一| 国产亚洲1区2区3区| 欧美v国产在线一区二区三区| 欧美性色综合网| 色久优优欧美色久优优| 成人福利在线看| 成人午夜在线免费| 国产二区国产一区在线观看| 另类小说色综合网站| 日韩成人午夜精品| 午夜视频在线观看一区二区三区| 亚洲免费在线视频| 亚洲日本在线天堂| 亚洲欧美日韩系列| 亚洲人成影院在线观看| 中文字幕一区二区三区av| 亚洲欧洲日产国码二区| 成人欧美一区二区三区黑人麻豆 | 日韩电影网1区2区| 免费观看久久久4p| 韩国三级中文字幕hd久久精品| 奇米影视一区二区三区| 欧美bbbbb| 国产在线一区观看| 国产一二三精品| 成人99免费视频| 在线欧美一区二区| 欧美日韩日日夜夜| 日韩免费一区二区三区在线播放| 日韩免费看网站| 久久精品欧美一区二区三区不卡| 久久久国产精品不卡| 国产精品麻豆视频| 亚洲综合在线观看视频| 亚洲二区在线观看| 久久精品免费观看| 成人白浆超碰人人人人| 欧美在线免费观看视频| 欧美一区二区视频观看视频| 日韩欧美在线一区二区三区| 久久久激情视频| 伊人夜夜躁av伊人久久| 蜜臀精品一区二区三区在线观看 | ww久久中文字幕| 国产精品美日韩| 亚洲综合久久av| 青娱乐精品视频在线| 国产成人免费av在线| 在线国产电影不卡| 精品嫩草影院久久| 国产精品国产三级国产a| 亚洲午夜电影在线| 国产一区二区不卡| 在线观看精品一区| 久久色中文字幕| 亚洲精品视频在线观看免费| 青青草原综合久久大伊人精品优势 | 日韩一区二区电影网| 中文字幕欧美国产| 亚洲不卡在线观看| 国产69精品久久久久777| 欧美在线观看一二区| 久久综合资源网| 亚洲香肠在线观看| 成人在线视频一区| 日韩视频一区二区在线观看| 最近中文字幕一区二区三区| 久久精品国产网站| 欧美色视频在线观看| 日本一区二区视频在线| 首页亚洲欧美制服丝腿| gogogo免费视频观看亚洲一| 日韩欧美黄色影院| 一级精品视频在线观看宜春院| 韩国女主播成人在线| 69久久夜色精品国产69蝌蚪网| 国产精品美日韩| 国产盗摄一区二区| 欧美一激情一区二区三区| 亚洲男人天堂一区| 国产成人精品免费网站| 91精品国产乱码| 亚洲在线视频网站| 99综合电影在线视频| 久久久久99精品一区| 久久精品国产色蜜蜜麻豆| 欧美日韩精品福利| 亚洲人午夜精品天堂一二香蕉| 国产精品综合一区二区| 日韩一区二区三区av| 亚洲成a人v欧美综合天堂下载| 91香蕉视频黄| 国产精品乱人伦一区二区| 国产成人精品亚洲日本在线桃色 | 欧洲av在线精品| 亚洲视频 欧洲视频| 成人美女视频在线观看| 国产亚洲视频系列| 国精产品一区一区三区mba视频 | 亚洲日本va在线观看| av中文一区二区三区| 中文字幕精品一区二区三区精品| 久久99精品国产麻豆不卡| 日韩视频在线一区二区| 日韩不卡一二三区| 91精品国产欧美日韩| 日韩avvvv在线播放| 欧美性一级生活| 亚洲精品欧美专区| 欧美性受xxxx黑人xyx性爽| 亚洲综合在线第一页| 欧美日韩国产另类一区| 亚洲r级在线视频| 91精品国产综合久久久蜜臀粉嫩 | 国产欧美日韩视频一区二区| 国产精品一二二区| 中文无字幕一区二区三区 | 成人不卡免费av| 一区二区中文字幕在线| 色婷婷亚洲一区二区三区| 一区二区三区**美女毛片| 欧美丝袜第三区| 日韩av午夜在线观看| 2欧美一区二区三区在线观看视频| 激情综合色播五月| 国产欧美日本一区视频| 91在线精品一区二区| 亚洲成人综合在线| 精品福利视频一区二区三区| 国产精品一卡二| 中文字幕制服丝袜成人av| 91国偷自产一区二区三区观看 | 免费成人在线视频观看| 精品电影一区二区| 99精品欧美一区二区三区小说| 亚洲电影欧美电影有声小说| 欧美一区二区三区视频免费播放 | 日韩一区二区免费在线观看| 国产精品一区二区在线播放| 国产精品免费aⅴ片在线观看| 欧美性生活影院| 国产在线视频一区二区三区|