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

📄 kbd_bak.cpp

📁 此压缩包为杰得开发得z228的BSP的源代码,可以实现很多功能,尤其是视频解码有很好的效果.
💻 CPP
📖 第 1 页 / 共 2 页
字号:
	
	//init key stat: UP
	for(i = 0; i < 4; i++)
	{
		for(j = 0; j < 3; j++)
		{
			ScanKeyStat[i][j] = 1;
			CurKeyStat[i][j] = 1;
			key_code[i][j] = key_code1[i][j];
		}	
	}		
	//enable the interrupt	
	pGpioHead->pGpio1Regs->GPIODir5 &= 0xF0;	
	pGpioHead->pGpio1Regs->GPIOIS5 &= 0xF0;	
	pGpioHead->pGpio1Regs->GPIOIBE5 |= 0x0F;	
	pGpioHead->pGpio1Regs->GPIOIE5 |= 0x0F;	
	pGpioHead->pGpio1Regs->GPIOIC5 |= 0x0F;

	
	pGpioHead->pGpio2Regs->GPIODir5 |= 0x07;
	//pGpioHead->pGpio2Regs->GPIOIS5 &= 0xF7;	
	//pGpioHead->pGpio2Regs->GPIOIBE5 &= 0xF7;	
	//pGpioHead->pGpio2Regs->GPIOIEV5 &= 0xF7;
	
	
	
	pGpioHead->pGpio2Regs->Padding1[254] &= 0xF8;	//gpio6_0-2 low
	
	pGpioHead->pGpio1Regs->GPIOIC5 = 0x0F;			//gpio5_0-3 int clear
	
	while(1)
	{
		dwEvent = WaitForSingleObject(g_GPIO1Event, INFINITE);
		RETAILMSG (DBG_KBD, (TEXT("keybd INT 1.2!\r\n")));		
		//just sleep
		Sleep(10);		
		//pGpioHead->pGpio1Regs->GPIOIC5 = 0x0F;
		//InterruptDone(SYSINTR_KBD);	// Acknowledge the GPIO interrupt
		
		keychange = 0;
		// Fetch the raw INT status and the GPIO5 data
		cIntStatus = GET_GPIO5_RIS();
		cdata = GET_GPIO5_DAT();	
		
		RETAILMSG (DBG_KBD, (TEXT("cIntStatus: %x, cdata: %x \r\n"),cIntStatus, cdata));
		
		
		if(cIntStatus == 0)
		{
			RETAILMSG (DBG_KBD, (TEXT("why we get the INT??\r\n")));
			pGpioHead->pGpio1Regs->GPIOIC5 = 0x0F;		
			InterruptDone(SYSINTR_KBD);	// Acknowledge the GPIO interrupt
			continue;	
		}		
		
		//pGpioHead->pGpio1Regs->GPIOIC5 = 0x0F;
		
		//scan the GPIO keybd first
		for(i = 0; i < 4; i++)
		{
			for(j = 0; j < 3; j++)
			{
				//ScanKeyStat[i][j] = 1;				
				ScanKeyStat[i][j] = CurKeyStat[i][j];
			}	
		}		
		for(i = 0; i < 4; i++)
		{
			if(((cIntStatus>>i)&0x01)==0x01)	//which GPIO5_x INT?
			{							
				RETAILMSG (DBG_KBD, (TEXT("GPIO5_%d INT\r\n"), i));				
				for(j = 0; j < 3; j++)
				{										
					pGpioHead->pGpio2Regs->Padding1[254] = (pGpioHead->pGpio2Regs->Padding1[254]&0xF8)|((~(0x01<<j)&0x07));
					cdata2 = GET_GPIO5_DAT();
					//RETAILMSG (1, (TEXT("temp: %x, temph: %x, templ: %x, cdata2: %x\r\n"), temp, temph, templ, cdata2));					
					RETAILMSG (DBG_KBD, (TEXT("cdata2: %x\r\n"), cdata2));					
										
					if((cdata2&(0x01<<i)) == 0x00)	
						ScanKeyStat[i][j] = 0x00;	//0 = down, 1 = up
					else
						ScanKeyStat[i][j] = 0x01;	//0 = down, 1 = up					
				}						
			}
		}					
		
		pGpioHead->pGpio2Regs->Padding1[254] &= 0xF8;	//gpio6_0-2 low
		pGpioHead->pGpio1Regs->GPIOIC5 = 0x0F;
		
		//yz for test
		#if 0
		for(i = 0; i < 3; i++)
		{			
			for(j = 0; j < 3; j++)			
			{	
				RETAILMSG (DBG_KBD, (TEXT("Scan[%d][%d]: %x "),i,j, ScanKeyStat[i][j]));	
			}
		}
		RETAILMSG (DBG_KBD, (TEXT("\r\n")));	
		for(i = 0; i < 3; i++)
		{			
			for(j = 0; j < 3; j++)			
			{	
				RETAILMSG (DBG_KBD, (TEXT("Curr[%d][%d]: %x "),i,j, CurKeyStat[i][j]));	
			}
		}
		RETAILMSG (DBG_KBD, (TEXT("\r\n")));	
		#endif	
						
		//yz_add 1227
		keydown = 0;
		for(i = 0; i < 4; i++)
		{			
			for(j = 0; j < 3; j++)	
			{
				if(CurKeyStat[i][j] == 0 || ScanKeyStat[i][j] == 0)
					keydown++;
			}
		}			
		
		for(i = 0; i < 4; i++)
		{			
			for(j = 0; j < 3; j++)	
			{
				if(ScanKeyStat[i][j] != CurKeyStat[i][j])
				{
					keychange++;
					CurKeyStat[i][j] = ScanKeyStat[i][j];
					if(CurKeyStat[i][j] == 0)	//key down
					{
						RETAILMSG (DBG_KBD, (TEXT("****** key down: %d-%d ******\r\n"),i,j));
						if(i == 0 && j == 2)	//game
						{								
							if(CurKeyStat[1][2] == 0)	//wifi down -> Lock status switch
							{
								keyfunc = 1;
								if(ScreenLocked == 0)
								{
									pGpioHead->pGpio3Regs->GPIOIC5 |= 0x01;	
									pGpioHead->pGpio3Regs->GPIOIE5 &= (~0x01);	
									ScreenLocked = 1;
								}
								else
								{
									pGpioHead->pGpio3Regs->GPIOIC5 |= 0x01;
									pGpioHead->pGpio3Regs->GPIOIE5 |= 0x01;
									ScreenLocked = 0;
								}								
							}							
					  	}
					  	else if(i == 1 && j == 2)	//wifi
					  	{
							if(CurKeyStat[0][2] == 0)	//game down -> Lock status switch
							{
								keyfunc = 1;
								if(ScreenLocked == 0)
								{
									pGpioHead->pGpio3Regs->GPIOIC5 |= 0x01;	
									pGpioHead->pGpio3Regs->GPIOIE5 &= (~0x01);	
									ScreenLocked = 1;
								}
								else
								{
									pGpioHead->pGpio3Regs->GPIOIC5 |= 0x01;
									pGpioHead->pGpio3Regs->GPIOIE5 |= 0x01;
									ScreenLocked = 0;
								}								
							}
					  	}
					  	else
							KbdISRUpcall(false, key_code[i][j]);
					}						
					else	//key up
					{
						RETAILMSG (DBG_KBD, (TEXT("****** key up: %d-%d ******\r\n"),i,j));
						//if(yz_key == 0x1F)
							//KbdISRUpcall(false, 0xe0);																		
						if(i == 0 && j == 2)	//game
						{							
							char ii = 0, jj = 0;
							if(keyfunc == 1)
							{
								if(CurKeyStat[1][2] == 0)
									continue;
								else
								{
									keyfunc = 0;	
									continue;
								}	
							}	
								
							if(keystate == 0)	//Game key
							{								
								SHELLEXECUTEINFO sei;                      
								//LPCTSTR lpVerb;				
								sei.lpVerb=_T("open");                     
								ZeroMemory(&sei, sizeof(sei));             
								sei.cbSize =sizeof(sei);                   
								sei.lpFile=_T("explorer.exe");             
								sei.fMask = SEE_MASK_NOCLOSEPROCESS;       
								sei.lpParameters=_T("\\NandFlash\\MyGame");
								sei.nShow = SW_SHOW;                       
								ShellExecuteEx(&sei);
								//yz_add for key code change 1230
								for(ii = 0; ii < 3; ii++)
									for(jj = 0; jj < 3; jj++)
										key_code[ii][jj] = key_code2[ii][jj];
								keystate = 1;								
							}
							else	//usual key
							{
								//yz_add for key code change 1230
								for(ii = 0; ii < 3; ii++)
									for(jj = 0; jj < 3; jj++)
										key_code[ii][jj] = key_code1[ii][jj];
								
								keystate = 0;
							}
					  	}
					  	else if(i == 1 && j == 2)	//wifi
					  	{
					  		PROCESS_INFORMATION pi;
							if(keyfunc == 1)
							{
								if(CurKeyStat[0][2] == 0)
									continue;
								else
								{
									keyfunc = 0;	
									continue;
								}	
							}					  		
							if(!CreateProcess(L"\\windows\\ds.exe",L".EXE",NULL,NULL,NULL,CREATE_NEW_CONSOLE,NULL,NULL,NULL,&pi))
							RETAILMSG (DBG_KBD, (TEXT("open ds.exe FAIL!\r\n")));
					  	}							
						else
						{	
							KbdISRUpcall(false, 0xF0);
							KbdISRUpcall(false, key_code[i][j]);
						}
					}								
				}				
			}	
			if((CurKeyStat[i][0] == 1)&&(CurKeyStat[i][1] == 1)&&(CurKeyStat[i][2] == 1))
			{
				//pGpioHead->pGpio1Regs->GPIOIC5 = 0x01<<i;
				RETAILMSG (DBG_KBD, (TEXT("GPIO5_%d all up!\r\n"),i));
			}					
		}
		
	
		if(keychange == 0)
			RETAILMSG (DBG_KBD, (TEXT("INT, but no key stat change, Ignore!\r\n")));
		
		//pGpioHead->pGpio1Regs->GPIOIC5 = 0x0F;		
		InterruptDone(SYSINTR_KBD);	// Acknowledge the GPIO interrupt			
	}
	pGpioHead->fGpio1ISTExit = FALSE;	// Signal we have terminated
	RETAILMSG (DBG_KBD, (TEXT("GPIO1 IST thread ERROR\r\n")));
	return 0;
}

/* EOF kbdmouse.cpp */

⌨️ 快捷键说明

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