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

📄 kbd.cpp

📁 此压缩包为杰得开发得z228的BSP的源代码,可以实现很多功能,尤其是视频解码有很好的效果.
💻 CPP
📖 第 1 页 / 共 2 页
字号:
static int game_touch_flag = 0; //当GAME键被按下是SET 为1
static void doConvert(int flag);

DWORD Keybd_GpioIST(PVOID pvParam)
{
	PGPIO_INFO pGpioHead = (PGPIO_INFO)pvParam;
	DWORD	dwEvent;//, dwIntStatus, dwdata, dwdata2;
	unsigned char cIntStatus, cdata, cdata2;//cdata
	unsigned char ScanKeyStat[3][3], CurKeyStat[3][3];
	unsigned int yz_key = 0;
	static char ScreenLocked = 0, ScreenLocked1 = 0;
	static char keystate = 0;
	static char keyfunc = 0;
	BOOL	fExit = FALSE;
	BOOL	yz_keyup = TRUE;
	BOOL	yz_run = FALSE;
	int i,j, keychange, keydown;


    	RETAILMSG (1, (TEXT("Keybd: GPIO IST thread starting 1.0 \r\n")));
	
	//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->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.1!\r\n")));	
		//MessageBox(NULL, _T("305"), _T("driver"), MB_OK);

		
		/*读出是否需要转换的标志*/
		readConvertFlag(&need_key_flag);

		//if(game_touch_flag)
		if(cur_key_flag != need_key_flag) // add by he
		{
			doConvert(need_key_flag);
			cur_key_flag = need_key_flag;
		}

		//just sleep
		Sleep(5);		
		//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();
		
		RETAILMSG (DBG_KBD, (TEXT("cIntStatus: %x\r\n"), cIntStatus));
		
		
		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;	
		}		
		
		
		//scan the GPIO keybd first
		for(i = 0; i < 4; i++)
		{
			for(j = 0; j < 3; j++)
			{
				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));
					Sleep(1);
					cdata = GET_GPIO5_DAT();
					cdata2 = GET_GPIO5_DAT();
					if(cdata != cdata2)
						RETAILMSG (1, (TEXT("cdata: %x, cdata2: %x\r\n"), cdata, 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_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(i == 0 && j == 2)	//game
						{								
							if(keyfunc == 1)
							{
								RETAILMSG (1, (TEXT("keyfunc = 1\r\n")));
								if(CurKeyStat[1][2] == 0)
									continue;
								else
								{
									keyfunc = 0;	
									continue;
								}	
							}	
							
#if 0	//code for keycode change							
							{								
								SHELLEXECUTEINFO sei;                      
								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);
								// set key convert flag
								//setConvertFlag(0);
							}
#endif					

							SetEvent(g_BackLight);	//change BackLight status
							RETAILMSG (1, (TEXT("BKL SetEvent done\r\n")));

  						if(ScreenLocked1 == 0)	//change touchPad Lock status
  						{
  							pGpioHead->pGpio3Regs->GPIOIE5 &= (~0x01);	
  							pGpioHead->pGpio3Regs->GPIOIC5 |= 0x01;									
  							ScreenLocked1 = 1;
  							RETAILMSG (1, (TEXT("TP lock \r\n")));
  						}
  						else
  						{
  							pGpioHead->pGpio3Regs->GPIOIC5 |= 0x01;
  							pGpioHead->pGpio3Regs->GPIOIE5 |= 0x01;
  							ScreenLocked1 = 0;
  							RETAILMSG (1, (TEXT("TP unlock \r\n")));
  						}	

							
					  	}
					  	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;
}



/*
	if flag == 0, key is normal;
	if flag != 0, key is for nes play;
	key_code1 -- actual used; key_code2 --- for nes; key_code3 --- normal
*/
void doConvert(int flag)
{
	if(flag)
	{
		memcpy(key_code, key_code2, sizeof(key_code2));
		//key_code[0][0] = 0x24; key_code[0][1] = 0x23; key_code[0][2] = 0x0; key_code[0][3] = 0x0;    
		//key_code[1][0] = 0x1b; key_code[1][1] = 0x2b; key_code[1][2] = 0x0; key_code[1][3] = 0x0;    
		//key_code[2][0] = 0x0d; key_code[2][1] = 0x66; key_code[2][2] = 0x0; key_code[2][3] = 0x0;    
		//key_code[3][0] = 0x29; key_code[3][1] = 0x33; key_code[3][2] = 0x0; key_code[3][3] = 0x0;    
		//MessageBox(NULL, TEXT("1"),  TEXT("KBD_driver"), MB_OK);
	}
	else
	{
		memcpy(key_code, key_code3, sizeof(key_code3));
		//MessageBox(NULL, TEXT("0"),  TEXT("KBD_driver"), MB_OK);
	}
}

void KeyValueConvert(int flag) /*这个函数暂时还没有办法让应用程序使用*/
{
	//DWORD a;
	//OEMIoControl(6666, 0,0,0,0,&a);
	need_key_flag = flag;

}
/* EOF kbdmouse.cpp */

⌨️ 快捷键说明

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