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

📄 keypadtest.c

📁 PXA270矩阵键盘测试程序
💻 C
📖 第 1 页 / 共 3 页
字号:

	// Print Instructions

    printf(" User! Press each key on the keypad in sequence:\r\n");
    printf(" User! A, H, O, V, /, Back, Send, Up, Soft1, Soft2, Home \r\n");
	printf(" User! Observe data in hex LED: \r\n");
	printf(" User! H displays 1, O = 0, V = 2, / = 3, Back = 4, Send = 5, Up = 6\r\n");
	printf(" User! Soft1 displays 7, Soft2 = 8, Home = 9\r\n");

    printf(" User! Begin pressing after you continue.\r\n");
    GetUserResponse(YES);
	mask = LED_MASK;		// Obtain the present state of the LED mask
	mask = mask | 0xFF00;   // Blank out the hex LEDs
	LED_MASK = mask;

		
    while ((KeysPressed != 0x7FF) & (KeyData != 0x23) & (KeyData != 0x7E))
    {    
		KeyData = FastTapGetData();
		LED_MASK = mask;                        // Shut off all hex LEDs
		if((KeyData != 0x7E) & (KeyData != 0x0A))
		{
		LED_MASK = mask & ~0x100;				// Turn on least significant hex digit
		//HEX_LEDS = KeyData;                     // Display data
		}
		if(KeyData == KEY_A) 
			{
				KeysPressed = KeysPressed | 0x001 ;  
				HEX_LEDS = 0xA;
			}
		if(KeyData == KEY_H) 
			{
				KeysPressed = KeysPressed | 0x002 ;  
				HEX_LEDS = 0x1;
			}
		if(KeyData == KEY_O) 
			{
				KeysPressed = KeysPressed | 0x004 ;  
				HEX_LEDS = 0x0;
			}
		if(KeyData == KEY_V) 
			{
				KeysPressed = KeysPressed | 0x008 ;  
				HEX_LEDS = 0x2;
			}
		if(KeyData == KEY_FS) 
			{
				KeysPressed = KeysPressed | 0x010 ;  
				HEX_LEDS = 0x3;
			}
		if(KeyData == KEY_BACK)
			{				 
				KeysPressed = KeysPressed | 0x020 ;  
				HEX_LEDS = 0x4;
			}
		if(KeyData == KEY_SND) 
			{
				KeysPressed = KeysPressed | 0x040 ;  
				HEX_LEDS = 0x5;
			}
		if(KeyData == KEY_UP) 
			{
				KeysPressed = KeysPressed | 0x080 ;  
				HEX_LEDS = 0x6;
			}
		if(KeyData == KEY_SF1) 
			{
				KeysPressed = KeysPressed | 0x100 ;  
				HEX_LEDS = 0x7;
			}
		if(KeyData == KEY_SF2) 
			{
				KeysPressed = KeysPressed | 0x200 ;  
				HEX_LEDS = 0x8;
			}
	
		if(KeyData == KEY_HOME) 
			{
				KeysPressed = KeysPressed | 0x400 ;  
				HEX_LEDS = 0x9;
			}
    }
    
    DM_WaitMs(2000);

    if (KeysPressed != 0x7FF) KeypadTestResult = KP_TEST_FAILURE;
	if (KeyData == 0x7E)
	{
        retVal = ERRORCODEX(ERR_L_KEYPAD, 0x80, 1, ERR_T_TIMEOUT);
   		XllpUtilityOutputError(retVal);
		return (1);
	}
    if (KeypadTestResult == KP_TEST_SUCCESS)
    {
        PostDisplayProgress(ERR_L_KEYPAD, ERR_S_KEYPAD_PASS, __LINE__);
    	printf(" Success!\r\n");
    }
    else
    {
        retVal = ERRORCODEX(ERR_L_KEYPAD, 0x80, 1, ERR_T_WRONG_VALUE);
   		XllpUtilityOutputError(retVal);
    }

    
	

    printf(" Testing Scroll Wheel Rotation\r\n");
    printf(" User! Rotate the scroll wheel.\r\n");
    printf(" User! Start press after you continue.\r\n");
    GetUserResponse(YES);

    scroll_min = 0x7f;
	scroll_max = 0x7f;
	while((scroll_min > 0x5F) & (scroll_max < 0x9F))  // Stay in test loop until min/max values have been reached
	{
	KeyData = KPREC_REG;
    if (POSTRunState() & VS_DEBUG_ON)
    {
    	if (last_scroll_val != KeyData)
        {
        	printf("Scroll data = %x\r\n",KeyData);
            last_scroll_val = KeyData;
        }
    }
    
	KeyData = KeyData & 0xFF;   // Clear out any extraneous bits
	if(KeyData < scroll_min) scroll_min = KeyData;
    if(KeyData > scroll_max) scroll_max = KeyData;
	}
    PostDisplayProgress(ERR_L_KEYPAD, ERR_S_KEYPAD_PASS, __LINE__);
    printf(" Success!\r\n");
	return (KeypadTestResult);
	}
		
// end of PostKeypadTest()

/*
*******************************************************************************
*
* FUNCTION:
*    KeypadGetData
*
* DESCRIPTION:
*    translate a keypress into a key
*
* INPUT PARAMETERS:
*    None.
*
* RETURNS:
*    None.
*
* GLOBAL EFFECTS:
*    None.
*
* ASSUMPTIONS:
*    None.
*
* CALLS:
*    None.
*
* CALLED BY:
*    Keypad test main function.
*
* PROTOTYPE:
*    char KeypadGetData(void);
*
*******************************************************************************
*/
char KeypadGetData(void)	//modified by hzh
{
char KeyData;             // Character from Keypad
unsigned int KPData0;     // Register data
unsigned int KPData1;     // Register data
unsigned int KPPress;     // Keypad press count
int timer;                // Loop coutner/timer (for test timeout)
unsigned int kpc;

    KeyData = 0x30;                           // Inital setting = ASCII ?
    timer = 200;                              // This will provide about a 10 second timeout

	kpc = KPC_REG;
    while (!(kpc & (KEYP_KPC_MI | KEYP_KPC_DI)) && (timer != 0) && !(~GPLR0_REG & 0x2))
    {
    	DM_WaitMs(50);            // Dealy 50 mS as part of timeout loop
		timer = timer -1;         // Decrement timer
		kpc = KPC_REG;
    }

	if (timer == 0)
	{
		KeyData = 0x54;     // ASCII "T" for Time out
		return (KeyData);
	}

    // Code picks up here if a key is pressed
    DM_WaitMs(50);   // Dealy 50 mS for data to settle

 	if(~GPLR0_REG & 0x2)
	{    DM_WaitMs(50);   // Dealy 50 mS for data to settle
    	return '1';
	}

    if(kpc & KEYP_KPC_DI)
    {
    	UINT32 val = KPDK_REG;
    	

    	if(val & (1UL<<31))
    	{
    		if(val & (1<<0))
   			return '2';
    		if(val & (1<<1))
    			return '3';
    		if(val & (1<<2))
    			return '4';
    	}
    }

    KPData0 = KPAS_REG;
    KPData1 = (KPData0 & 0xF0) >> 4;           // Extract Row data and right justify
	KPPress = (KPData0 & 0x7C000000) >> 26;    // Extract key press count and right justify
	KPData0 = KPData0 & 0xF;                   // Isolate Column Data
//	printf("KPData0 = %08x\r\n", KPData0);
//	printf("Key Count = %08x\r\n", KPPress);
    KeyData = 0xA;
    if (KPPress == 1)                         // Decode only if 1 keypress has been detected
	{
    	switch (KPData0)
		{
	    case 0:
			if(KPData1 == 0) KeyData = '8';
			if(KPData1 == 1) KeyData = '7';
			if(KPData1 == 2) KeyData = '6';
			if(KPData1 == 3) KeyData = '5';
			break;

	    case 1:
			if(KPData1 == 0) KeyData = 'C';
			if(KPData1 == 1) KeyData = 'B';
			if(KPData1 == 2) KeyData = 'A';
			if(KPData1 == 3) KeyData = '9';
			break;

		case 2:
			if(KPData1 == 0) KeyData = '0';
			if(KPData1 == 1) KeyData = 'F';
			if(KPData1 == 2) KeyData = 'E';
			if(KPData1 == 3) KeyData = 'D';
			break;
		}
	}
	return (KeyData);

}// End of KeypadGetPress()

char PostGetKeypad(void)	//hzh
{
char KeyData;             // Character from Keypad
unsigned int KPData0;     // Register data
unsigned int KPData1;     // Register data
unsigned int KPPress;     // Keypad press count
unsigned int kpc;

	kpc = KPC_REG;
    if (!(kpc & (KEYP_KPC_MI | KEYP_KPC_DI)) && !(~GPLR0_REG & 0x2))
		return 0;

	if(~GPLR0_REG & 0x2)
	{   DM_WaitMs(200);   // Dealy 50 mS for data to settle
    	return '1';
    }
		
    if(kpc & KEYP_KPC_DI)
    {
    	UINT32 val = KPDK_REG;
    	
    	if(val & (1UL<<31))
    	{
    		if(val & (1<<0))
    			return '2';
    		if(val & (1<<1))
    			return '3';
    		if(val & (1<<2))
    			return '4';
    	}
    }

    KPData0 = KPAS_REG;
    KPData1 = (KPData0 & 0xF0) >> 4;           // Extract Row data and right justify
	KPPress = (KPData0 & 0x7C000000) >> 26;    // Extract key press count and right justify
	KPData0 = KPData0 & 0xF;                   // Isolate Column Data
//	printf("KPData0 = %08x\r\n", KPData0);
//	printf("Key Count = %08x\r\n", KPPress);
    KeyData = 0;
    if (KPPress == 1)                         // Decode only if 1 keypress has been detected
	{
    	switch (KPData0)
		{
	    case 0:
			if(KPData1 == 0) KeyData = '8';//0x1b;
			if(KPData1 == 1) KeyData = '7';
			if(KPData1 == 2) KeyData = '6';
			if(KPData1 == 3) KeyData = '5';
			break;

	    case 1:
			if(KPData1 == 0) KeyData = 'C';//0x08;
			if(KPData1 == 1) KeyData = 'B';
			if(KPData1 == 2) KeyData = 'A';
			if(KPData1 == 3) KeyData = '9';
			break;

		case 2:
			if(KPData1 == 0) KeyData = '0';//0x0d;
			if(KPData1 == 1) KeyData = 'F';
			if(KPData1 == 2) KeyData = 'E';
			if(KPData1 == 3) KeyData = 'D';
			break;
		}
	}
	return (KeyData);
}
/*
*******************************************************************************
*
* FUNCTION:
*    FastTapGetData
*
* DESCRIPTION:
*    translate a keypress into a key
*
* INPUT PARAMETERS:
*    None.
*
* RETURNS:
*    None.
*
* GLOBAL EFFECTS:
*    None.
*
* ASSUMPTIONS:
*    None.
*
* CALLS:
*    None.
*
* CALLED BY:
*    Keypad test main function.
*
* PROTOTYPE:
*    char FastTapGetData(void);
*
*******************************************************************************
*/
/*

		C0		C1		C2		C3		C4		C5		C6
R0		A		B		C		D		E		F		SEND
			1		!		2		?		3		[]
R1		G		H		I		J		K		L		END
			4		$		5		&		6		[]
R2		M		N		O		P		Q		R		SOFT1
			7		:		8		;		9		[]
R3		S		T		U		V		W		X		SOFT2
			*		'		0		,		#		[]
R4		.		@		Y		Z		/		\		[]
			TAB		(		DEL		)		ENTER	[]
R5		HOME	SHIFT	SPACE	SPACE	CTRL	BACK	[]
			[]		[]		[]		[]		[]		[]	
R6		UP		DOWN	LEFT	RIGHT	ACTION	[]		[]

*/

char FastTapGetData(void)
{
char KeyData;             // Character from Keypad
unsigned int KPData0;     // Register data
unsigned int KPData1;     // Register data
unsigned int KPPress;     // Keypad press count
int timer;                // Loop coutner/timer (for test timeout)

⌨️ 快捷键说明

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