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

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

?? combi.c

?? USB/PS2鼠標驅動
?? C
?? 第 1 頁 / 共 5 頁
字號:
void ResetScaling(void);
char GetByte ( void);
void ProcessCommand(char p);
void SendMouseData(void);
void Put(char p);
void PutMsgBuff(void);
void SendMouseData(void);
void ps2main(void);
void PutNextByte(void);
void ReInitialize(void);
void ResetInterval(void);
void Ps2MouseTask(void);


/*
**
** FUNCTION:		ClearRam
**
** PURPOSE:			Clears all RAM except data and program stacks.  
**
** PARAMETERS:		none
**
** DESCRIPTION:		Written in assembler so that only X and A are used ( no variables
**					that might be cleared as a result of this function executing)
**
*/

void ClearRam(void)
{
    #asm 
    mov     X,REGISTER_SIZE - 1
    mov     A,0
lp:
    mov     [X + REGISTER_START],A
    dec     X
    jnc     lp
    #endasm
    return;
    }


/*
**
** FUNCTION:		IsUsbInterface
**
** PURPOSE:			Determines whether a USB or PS/2 host is connected upstream.  
**
** PARAMETERS:		none
**
** DESCRIPTION:		This function performs the following algorithm:

					1) Wake up and delay 50mS. Initialize the PS2 BAT delay counter.

					2) For a period of 2mS, poll the SCLK and SDATA lines every 10uS.
					   If we get 4 samples in a row with non-zero data on either line, 
					   detect PS2. If the 2mS expires, go to (3).

					3) Enable USB pull up resistor and delay 500uS. 
					   Poll the SCLK and SDATA lines indefinitely 
					   until a non-zero condition exists on either line. 
					   During this polling period, we begin to count down the PS2 BAT delay.  
					   If SCLK(D+) is sampled high, detect PS2. If SDATA(D-) 
					   is sampled high, go to (4).

					4) Disable the USB connect resistor and Delay 100uS.  
						if D+ and D- are both 0, detect  USB, else detect PS2.
*/

char 	IsUsbInterface(void)
{

	char temp;
	char samples = 4;
     bBatDelay = (500 - 50);								//initialize BAT delay to 500 msec
	temp = MsecStatus.b1msCounter+50;					    //wait 50 msec
  														    
	while (temp != MsecStatus.b1msCounter)
		RESET_COP();
	temp = MsecStatus.b1msCounter+2;
	while (temp != MsecStatus.b1msCounter)					//for 2 msec, sample clock and data
	{
		if ((PORT2 & (PS2_CLOCK_BIT | PS2_DATA_BIT)) && (!--samples))
				return(0);									//4  consecutive samples of either clock or data high, it's ps2
		samples = 4;					
	}

	USB_STATUS = (VREG_ENABLE_MASK | FORCE_NEG_OPEN_POS_OPEN);//enable USB pullup 
	Delay(250);												//and delay 250 usec
	while (1)												//wait forever
	{
		RESET_COP();
		if (MsecStatus.b1msFlags & ONE_MSEC_FLAG)
		{
			if (bBatDelay)									//if a msec expires, decrease bat delay
				bBatDelay--;
			MsecStatus.b1msFlags &= ~ONE_MSEC_FLAG;
		}
		if (PORT2 & PS2_CLOCK_BIT)							
			return(0);										//clock bit high it's ps2
		if (PORT2 & PS2_DATA_BIT)							//data bit high, quit the loop
			break;
	}
	USB_STATUS = FORCE_NEG_OPEN_POS_OPEN;					//disable USB pullup 
    Delay(100);  
	return(!(PORT2 & (PS2_CLOCK_BIT | PS2_DATA_BIT)));		//if both clock and data go low, it's usb
}


/*
**
** FUNCTION:		MY_RESET_ISR
**
** PURPOSE:			Reset ISR, vectored to during power-up or watchdog reset.  
**
** PARAMETERS:		none
**
** DESCRIPTION:		This function performs the following initialization:
**					
**					1)disables interrupts;
**					2)resets the watchdog;
**					3)initializes data stack pointer;
**					4)clears ram;
**					5)initializes port I/O;
*					6)enables 1msec interrupt;
**					7)jumps to main loop
**					
**
*/

void MY_RESET_ISR(void)
{
    DI();											//disable ints
	RESET_COP();									//reset watchdog

	/*
	** use assembler to initialize data stack
	*/
#asm (mov A,RAM_START + STACK_SIZE-1)			        
#asm (swap A,dsp)
      ClearRam();
	USB_STATUS = FORCE_NEG_OPEN_POS_OPEN;						//drive D+,D- to Hi-Z
	PORT0_MODE1 = PORT0_MODE1_INIT;								//set up port modes
	PORT0_MODE0 = PORT0_MODE0_INIT;								//
	PORT1_MODE0 = PORT1_MODE0_INIT ;							//
	PORT1_MODE1 = PORT1_MODE1_INIT;								//
	PORT0 = PORT0_INIT;											//set up initial values
	PORT1 = PORT1_INIT;											//
	PORT0IE = PORT0_INIT;										//set up for GPIO interrupts on switch inputs
	PORT1IE = PORT1_INIT;										//
	PORT0IP = ~PORT0_INIT;										//set up for negative edges interrupts switch inputs
	PORT1IP = ~PORT1_INIT;
	GLOBAL_INTERRUPT = MILLISECOND_ENABLE; 						//enable all pertinent interrupts
	EI();
    #asm (jmp main)
 }


/*
**
** FUNCTION:		main
**
** PURPOSE:			determines interface (usb or ps2) and dispatches to appropriate code.  
**
** PARAMETERS:		none
**
** DESCRIPTION:		
**					
**
*/

 void main(void)
 {
    if (IsUsbInterface())								//if it is USB
    {
          UsbReInitialize();							//initialize USB variables
          usbmain();									//and go to usbmain
	}
	ps2main();											//else straight to ps2
}


/*
**
** FUNCTION:		ProcessOptics
**
** PURPOSE:			Extracts optics data from the queue, and accumulates X,Y, and Z counts
**					based on the state data of each quadrature pair.
** PARAMETERS:		none
**
** DESCRIPTION:		This routine is called from the main loop to process the optical data that has
**					accumulated during successive 128 usec interrupts. For each byte in the optics queue,
**					it extracts the X,Y,and Z state data, and uses the state data from the previous sample
**					to increment/decrement/hold the corresponding count data.	
**					
**
*/

void ProcessOptics(void)
{   
	char temp;
    char temp1;
      if (OpticsQueue.bLen > 16)								//somehow the queue overflowed
      {
		  DI();													//this should never happen, but if so
		  OpticsQueue.headP =									//reset the queue pointers and quit
		  OpticsQueue.tailP = bOpticsArray;
		  OpticsQueue.bLen = 0;
		  EI();
		  return;
      }
	while (OpticsQueue.bLen)
	{
		temp = GET_X_OPTICS(*OpticsQueue.tailP);				//get X quadrature inputs into [1:0]
		temp1 = temp;											//save temporarily
		temp |= Optics.bXstate;									//or in with previous state 
		Optics.bXstate = temp1 << 2;							//shift X inputs into [3:2] and save for next pass
		temp1 = Mouse.bXcount;
		Mouse.bXcount += quad_table[temp];						//use quadrature lookup to inc/dec xcount
		if ((unsigned char) Mouse.bXcount == 0x80)								//if overflow in either direction
			Mouse.bXcount = temp1;								//restore old count
																
		temp = GET_Y_OPTICS(*OpticsQueue.tailP);				//repeat for Y.....
		temp1 = temp;
		temp |= Optics.bYstate;
		Optics.bYstate = temp1 << 2;
		temp1 = Mouse.bYcount;
		Mouse.bYcount -= quad_table[temp];						//note, y counts need to be negated for proper direction
		if ((unsigned char) Mouse.bYcount == 0x80)
			Mouse.bYcount = temp1;

		temp = GET_Z_OPTICS(*OpticsQueue.tailP);				//repeat for Z....
		temp1 = temp;
		temp |= Optics.bZstate;
		Optics.bZstate = temp1 << 2;
		temp1 = Mouse.bZcount;
		Mouse.bZcount += z_quad_table[temp];
		if ((unsigned char) Mouse.bZcount == 0x80)
			Mouse.bZcount = temp1;

		*OpticsQueue.tailP++;									//manage queue pointers
 		if (OpticsQueue.tailP == &bOpticsArray[16])				//wrap them if necessary
			OpticsQueue.tailP = bOpticsArray;
		OpticsQueue.bLen--;
	}
}


/*
**
** FUNCTION:		MICROSECONDx128_ISR
**
** PURPOSE:			128 usec ISR.  
**
** PARAMETERS:		none
**
** DESCRIPTION:		
**					This ISR samples the mouse optics and places the sample in a queue for
**					later processing by the main loop. This is done to minimize the execution time
**					of this ISR, which can interrupt during the time ps/2 bits are being clocked
**					to the host.  The timing of the ps/2 clocking is critical (20 us margin),
**					so the corresponding execution time of this ISR must be kept to less than 20 us.
**					
**
*/

void MICROSECONDx128_ISR(void)
{
	PUSHA();
	PUSHX();
	*OpticsQueue.headP++ = OPTICS_PORT;							//sample optical data
	OpticsQueue.bLen++;											//manage queue pointers and length
	if (OpticsQueue.headP == &bOpticsArray[16])					//wrap pointers if necessary
		OpticsQueue.headP = bOpticsArray;
	POPX();
	POPA();
}


/*
**
** FUNCTION:		MILLISECOND_ISR
**
** PURPOSE:			1 msec ISR.  
**
** PARAMETERS:		none
**
** DESCRIPTION:		
**					This ISR maintains the 1msec counter variable,
**					and sets a flag indicating a 1msec interrupt has occurred. The main loop uses
**					these variables for timing purposes.
*/

void MILLISECOND_ISR(void)
{
    PUSHA();										//save A
    RESET_COP();
	MsecStatus.b1msFlags |= ONE_MSEC_FLAG;			//set flag for main loop
	MsecStatus.b1msCounter++;					    //increment 1msec counter
    POPA();
	return;
}


/*
**
** FUNCTION:		DebounceButtons
**
** PURPOSE:			Debounces the mouse switch inputs  
**
** PARAMETERS:		none
**
** DESCRIPTION:	 
**					This routine should be called at regular intervals from the main loop
**					to debounce the mouse switch inputs.  It maintains a count of the number
**					of successive identical samples of the switch inputs, and returns a 1
**					if the switch inputs have changed have been stable for the debounce interval.
*/

char GetButtons(void)
{
	char bButtons = 0;


	if (LEFT_SWITCH_ASSERTED)						//format an internal copy of the switches
		bButtons |= BIT0;							//this happens to be the USB format!
	if (RIGHT_SWITCH_ASSERTED)
		bButtons |= BIT1;
	/*
	** if Zwheel is enabled in either USB or PS2 mode, report the middle switch
	*/
	if ((MouseParms.bZmouse || DeviceStatus.bProtocol) && (MIDDLE_SWITCH_ASSERTED))
		bButtons |= BIT2;
	return(bButtons);
}

char DebounceButtons(void)
{
    char bButtons;
	bButtons = GetButtons();
 	if (bButtons == bLastButtons)				    //if same as last sample
	{
		  if (bDebounceCount && !--bDebounceCount)  //and debounce interval just expired
		  {
			  Mouse.bButtons = bLastButtons;			//record new buttons
			  return(1);							//and flag that a button change occurred
		  }
		  return(0);								//else no change yet occurred
	}
	bLastButtons = bButtons;						//buttons aren't stable, reset debounce count
	bDebounceCount = DEBOUNCE_COUNT;				//
	return(0);
}


/*
**
** FUNCTION:		USB_BUS_RESET_ISR
**
** PURPOSE:			Bus Reset ISR, vectored to during USB bus reset.  
**
** PARAMETERS:		none
**
** DESCRIPTION:		This function performs the following initialization:
**					
**					1)disables interrupts;
**					2)resets the watchdog;
**					3)initialized data stack pointer and program stack pointer;
**					4 clears ram;
**					5)makes a call to initialize system variables;
**					6)enables device to respond at address 0;
**					7)jumps to main loop
**					
**
*/

void USB_BUS_RESET_ISR(void)
{

    DI();
	RESET_COP();						//tickle watchdog
										//initialize stacks using assembler
#asm (mov A,RAM_START + STACK_SIZE-1)			        
#asm (swap A,dsp)
#asm (mov A,0)
#asm (mov psp,a)
	ClearRam();
	UsbReInitialize();						//reinitialize all system variables

	USB_DEVICE_A = 0x80;  // enable endpoint zero response at address 0
	EP_A0_MODE = USB_MODE_STALL_IN_OUT;
										//and make the leap to the main loop
#asm(jmp usbmain)							
}


/*
**
** FUNCTION:		WAKEUP_ISR
**
** PURPOSE:			ISR for wakeup interrupt.  
**
** PARAMETERS:		none
**
** DESCRIPTION:		The wakeup ISR increments a global counter which is used to "tune" the
**					frequency of the occurrence of the ISR itself (See routine TuneWakeup).
**
*/

void WAKEUP_ISR(void)
{
	bWakeupCount++;
}


/*
**
** FUNCTION:		GPIO_ISR
**
** PURPOSE:			ISR for wakeup interrupt. does nothing except returns  
**
** PARAMETERS:		none
**
** DESCRIPTION:	
**
*/

void GPIO_ISR(void)
{
	
}


/*
**
** FUNCTION:		USB_A_EP0_ISR
**
** PURPOSE:			Endpoint 0 Interrupt Service Routine.  
**
** PARAMETERS:		none
**
** DESCRIPTION:	 
**					this routine is entered upon receiving an endpoint 0 interrupt.
**					EP0 interrupts occur during the Setup, data , and status phases of a
**					setup transaction.  This ISR dispatches the proper routine to handle
**					one of these phases. The interrupt will remain active until the
**					phase in question is completely handled.
*/

void USB_A_EP0_ISR(void)
{
	PUSHA();												//save A and X,they'll get wasted
	PUSHX();
	if (EP_A0_MODE & (1 << ACKNOWLEDGE))					//if this packet was acknowledged,
	{
		if (EP_A0_MODE & SETUP_RECEIVED_MASK)				//if a setup was received,
		{
			DeviceStatus.bAddress &= ~0x80;					//clear the address flag
			HandleSetup();									//and handle it

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
99在线精品观看| 欧美在线综合视频| 色吧成人激情小说| 欧美一区二区二区| 亚洲精品乱码久久久久久| 国产一区免费电影| 69精品人人人人| 亚洲宅男天堂在线观看无病毒| 韩国午夜理伦三级不卡影院| 欧美视频三区在线播放| 国产精品国产自产拍在线| 国产一区二区不卡| 日韩欧美视频一区| 日韩专区一卡二卡| 欧美日韩国产a| 亚洲成人一二三| 欧美在线free| 亚洲蜜臀av乱码久久精品蜜桃| 国产成人综合网| 久久综合久久综合亚洲| 久久精品国产99| 日韩免费高清av| 老司机免费视频一区二区三区| 欧美日韩成人一区二区| 亚洲国产精品自拍| 欧美日韩亚洲丝袜制服| 亚洲图片自拍偷拍| 欧美日韩在线三级| 首页国产丝袜综合| 欧美一级艳片视频免费观看| 日韩主播视频在线| 日韩视频永久免费| 国产一区二区在线视频| 国产午夜亚洲精品午夜鲁丝片| 寂寞少妇一区二区三区| 精品国产三级电影在线观看| 久久爱www久久做| 久久视频一区二区| 成人一区二区三区视频| 中文字幕制服丝袜成人av | 国产午夜精品理论片a级大结局| 精品一区二区综合| 国产亚洲美州欧州综合国| 岛国精品一区二区| 依依成人精品视频| 91精品国产乱| 国产成人在线网站| 一区二区三区日韩精品视频| 欧美色图在线观看| 国产在线国偷精品产拍免费yy| 久久精品网站免费观看| 91在线观看免费视频| 亚洲一级片在线观看| 精品国产电影一区二区 | 肉肉av福利一精品导航| 日韩欧美一区二区三区在线| 国模少妇一区二区三区| 国产精品美女久久久久久| 91成人免费网站| 日韩电影一区二区三区四区| 久久久噜噜噜久噜久久综合| 色成人在线视频| 国产在线播放一区二区三区| 亚洲欧洲一区二区三区| 在线播放国产精品二区一二区四区| 美女国产一区二区三区| 国产精品国产三级国产aⅴ中文| 欧美日韩久久一区| 国产成人午夜精品影院观看视频| 一区二区三区国产精品| 欧美xxxx老人做受| 欧美午夜理伦三级在线观看| 国产一区二区三区av电影| 亚洲综合在线免费观看| 精品99一区二区| 欧美熟乱第一页| 粉嫩av一区二区三区粉嫩| 日韩和的一区二区| 亚洲日韩欧美一区二区在线| 日韩一区二区在线观看| 一本久道久久综合中文字幕| 精品一区二区三区不卡| 亚洲国产精品一区二区久久恐怖片| 久久嫩草精品久久久久| 欧美另类z0zxhd电影| 色综合天天综合狠狠| 国产主播一区二区三区| 天堂影院一区二区| 亚洲一区二区在线视频| 最新热久久免费视频| 国产日韩av一区| 久久网这里都是精品| 日韩一区二区三免费高清| 在线免费av一区| 91精品91久久久中77777| 懂色中文一区二区在线播放| 精品一区二区三区影院在线午夜 | 老司机精品视频线观看86| 亚洲永久免费视频| 亚洲三级免费电影| 亚洲免费在线看| 最新不卡av在线| 亚洲丝袜精品丝袜在线| 国产精品乱码一区二区三区软件 | 在线日韩一区二区| 色综合久久综合网欧美综合网| 国产精品一区二区无线| 狠狠狠色丁香婷婷综合激情 | 色综合天天综合色综合av| 高清在线成人网| 国产成人亚洲综合色影视 | 免费三级欧美电影| 日韩精品三区四区| 奇米影视一区二区三区| 麻豆成人av在线| 激情久久五月天| 国产精品自拍一区| 成人一区二区三区| 91一区一区三区| 在线免费精品视频| 在线成人免费观看| 精品99999| 中文字幕精品在线不卡| 日韩一区在线看| 亚洲国产视频a| 奇米精品一区二区三区四区| 久久97超碰国产精品超碰| 国产剧情在线观看一区二区| 国产伦精品一区二区三区在线观看| 欧美日韩亚洲另类| 3d成人h动漫网站入口| www久久久久| 亚洲欧美一区二区在线观看| 亚洲精品菠萝久久久久久久| 午夜成人在线视频| 国内外成人在线| 色偷偷成人一区二区三区91| 欧美四级电影在线观看| 26uuu国产在线精品一区二区| 国产性做久久久久久| 亚洲免费在线播放| 麻豆91小视频| 成人av在线播放网站| 欧美日韩一级二级| 国产欧美中文在线| 午夜精品久久久久久| 国产精品小仙女| 欧美日韩国产在线观看| 国产免费观看久久| 亚洲福利一区二区三区| 国产精品性做久久久久久| 色8久久精品久久久久久蜜| 日韩亚洲欧美综合| 中文字幕在线免费不卡| 免费高清在线一区| 成人午夜免费av| 欧美精品日日鲁夜夜添| 国产精品久久福利| 美女性感视频久久| 欧美视频自拍偷拍| 日本一区二区在线不卡| 日韩av网站在线观看| 91同城在线观看| 国产视频一区二区在线| 日韩精品久久理论片| 99久久久精品免费观看国产蜜| 91精品国产综合久久久久久漫画| 中文字幕一区二区在线观看| 久久精品国产99久久6| 色婷婷精品久久二区二区蜜臂av | 欧美日韩高清一区二区不卡| 国产精品网站一区| 捆绑调教一区二区三区| 在线观看精品一区| 国产精品久久久久婷婷 | 日日夜夜一区二区| 色综合网站在线| 中文字幕精品三区| 国产精品自在在线| 欧美v亚洲v综合ⅴ国产v| 亚洲h动漫在线| 欧美色图一区二区三区| 亚洲激情一二三区| 色哟哟欧美精品| 亚洲欧洲精品一区二区三区 | 国产在线精品一区在线观看麻豆| 在线亚洲一区二区| 亚洲欧美偷拍三级| 99久久久国产精品| 国产精品视频观看| 国产aⅴ综合色| 中文字幕第一区二区| 成人av中文字幕| 亚洲欧洲成人精品av97| av不卡在线播放| 亚洲日本在线a| 欧美性色黄大片手机版| 亚洲无线码一区二区三区| 欧美三级欧美一级| 天天影视网天天综合色在线播放|