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

📄 keypadtest.c

📁 PXA270矩阵键盘测试程序
💻 C
📖 第 1 页 / 共 3 页
字号:
/******************************************************************************
**
**  COPYRIGHT (C) 2002 Intel Corporation.
**
**  This software as well as the software described in it is furnished under
**  license and may only be used or copied in accordance with the terms of the
**  license. The information in this file is furnished for informational use
**  only, is subject to change without notice, and should not be construed as
**  a commitment by Intel Corporation. Intel Corporation assumes no
**  responsibility or liability for any errors or inaccuracies that may appear
**  in this document or any software that may be provided in association with
**  this document.
**  Except as permitted by such license, no part of this document may be
**  reproduced, stored in a retrieval system, or transmitted in any form or by
**  any means without the express written consent of Intel Corporation.
**
**  FILENAME:       KeypadTest.c
**
**  PURPOSE:        This file contains the Bulverde Keypad POST code for 
**                  the Intel(r) XScale(tm) Microarchitecture.
**
**  LAST MODIFIED:  $Modtime: 1/19/04 9:54a $
******************************************************************************/

/*
*******************************************************************************
*   HEADER FILES
*******************************************************************************
*/

#include "string.h"
#include "stdio.h"
#include <stdlib.h>
#include <ctype.h>

#include "systypes.h"
#include "timedelays.h"
#include "dm_errors.h"
#include "xsuart.h"
#include "xsffuart.h"
#include "xsbtuart.h"
#include "xsstuart.h"
#include "uarts.h"
#include "DM_SerialInOut.h"

#include "dm_debug.h"
#include "platform.h"
#include "cotulla.h"
#include "KeypadTest.h"
#include "XsMemCtrl.h"
#include "boardcontrol.h"
#include "xsClkMgr.h"


/*
*******************************************************************************
*   GLOBAL DEFINITIONS
*******************************************************************************
*/


/*
*******************************************************************************
*   LOCAL DEFINITIONS
*******************************************************************************
*/


/*
*******************************************************************************
*    Bulverde MSHC Registers
*******************************************************************************
*/

#define	KPC_REG	    	(*(volatile UINT32 *) 0x41500000)
#define	KPDK_REG		(*(volatile UINT32 *) 0x41500008)
#define	KPREC_REG		(*(volatile UINT32 *) 0x41500010)
#define	KPMK_REG		(*(volatile UINT32 *) 0x41500018)
#define	KPAS_REG		(*(volatile UINT32 *) 0x41500020)
#define	KPASMKP0_REG	(*(volatile UINT32 *) 0x41500028)
#define	KPASMKP1_REG	(*(volatile UINT32 *) 0x41500030)
#define	KPASMKP2_REG	(*(volatile UINT32 *) 0x41500038)
#define	KPASMKP3_REG	(*(volatile UINT32 *) 0x41500040)
#define KPKDI_REG		(*(volatile UINT32 *) 0x41500048)

/*
*******************************************************************************
*    Bulverde Keypad Register Field Macros
*******************************************************************************
*/
#define KEYP_KPC_ASACT            (0x1 <<  29)  // Automatic Scan on Activity
#define KEYP_KPC_MKRN             (0x3 <<  26)  // Number of Keypad Rows, hzh
#define KEYP_KPC_MKCN             (0x2 <<  23)  // Number of Keypad Columns, hzh
#define KEYP_KPC_MI               (0x1 <<  22)  // Matrix interrupt bit
#define KEYP_KPC_IMKP             (0x1 <<  21)  // Ignore Multiple Key Press
#define KEYP_KPC_MS7              (0x1 <<  20)  // Matrix scan line 7
#define KEYP_KPC_MS6              (0x1 <<  19)  // Matrix scan line 6
#define KEYP_KPC_MS5              (0x1 <<  18)  // Matrix scan line 5
#define KEYP_KPC_MS4              (0x1 <<  17)  // Matrix scan line 4
#define KEYP_KPC_MS3              (0x1 <<  16)  // Matrix scan line 3
#define KEYP_KPC_MS2              (0x1 <<  15)  // Matrix scan line 2
#define KEYP_KPC_MS1              (0x1 <<  14)  // Matrix scan line 1
#define KEYP_KPC_MS0              (0x1 <<  13)  // Matrix scan line 0
#define KEYP_KPC_ME               (0x1 <<  12)  // Matrix Keypad Enable
#define KEYP_KPC_MIE			  (0x1 <<  11)  // Matrix Keypad Int Enable
#define KEYP_KPC_DKIN             (0x2 <<   6)  // Direct Key Number -1
#define KEYP_KPC_DI               (0x1 <<   5)  // Direct key interrupt bit
#define KEYP_KPC_REZB             (0x1 <<   4)  // Rotary Encoder Zero Debounce
#define KEYP_KPC_DEE0             (0x1 <<   2)  // Rotary Encoder 0 Enable
#define KEYP_KPC_DE               (0x1 <<   1)  // Direct Keypad Enable
#define KEYP_KPC_DIE			  (0x1 <<   0)  // Direct Keypad Interrupt Enable	
/*
*******************************************************************************
*    Keypad Register Macros
*******************************************************************************
*/



/*
*******************************************************************************
*    Bulverde GPIO Registers used by the Keypad
*******************************************************************************
*/
#define	GPLR0_REG		(*(volatile UINT32 *) 0x40e00000)
#define	GPDR0_REG		(*(volatile UINT32 *) 0x40e0000C)
#define	GPDR2_REG		(*(volatile UINT32 *) 0x40e00014)
#define	GPDR3_REG		(*(volatile UINT32 *) 0x40e0010c)
#define	GAFR0_L_REG		(*(volatile UINT32 *) 0x40e00054)
#define	GAFR2_U_REG		(*(volatile UINT32 *) 0x40e00068)
#define	GAFR3_L_REG		(*(volatile UINT32 *) 0x40e0006c)
#define LED_MASK        (*(volatile UINT32 *) 0x08000040)
#define HEX_LEDS        (*(volatile UINT32 *) 0x08000010)

/*
*******************************************************************************
*    Mainstone Platform Registers for the Keypad
*******************************************************************************
*/

/*
*******************************************************************************
*  Error sub-location codes for ERR_L_KEYPAD location code
*******************************************************************************
*/
#define ERR_S_KEYPAD_INIT               0x01 // HW Initialization
#define ERR_S_KEYPAD_PASS               0x08 // Test Result = PASS
#define ERR_S_KEYPAD_FAIL               0x09 // Test Result = FAIL

/*
*******************************************************************************
*  Return Codes
*******************************************************************************
*/
#define KP_TEST_SUCCESS    0
#define KP_TEST_FAILURE    1

/*
*******************************************************************************
*
* FUNCTION:
*    PostKeyopadTest
*
* DESCRIPTION:
*    Test the Mainstone Keypad.
*
* INPUT PARAMETERS:
*    None.
*
* RETURNS:
*    1 if error, 0 if no error.
*
* GLOBAL EFFECTS:
*    None.
*
* ASSUMPTIONS:
*    None.
*
* CALLS:
*    None.
*
* CALLED BY: 
*    Post main function.
*
* PROTOTYPE:
*    int PostKeypadTest(void);
*
*******************************************************************************
*/
int PostKeypadTest(void)	//modified by hzh
{
#if	0
ErrorT retVal;
int  KeypadTestResult = KP_TEST_SUCCESS;  // Overall Keypad Test Result
int  KeysPressed = 0;                     // Record of keys pressed
int  time;                                // timer
int  scroll_min;                          // min scroll wheel value
int  scroll_max;                          // max scroll wheel value
int  mask;                                // Work register for hex LED masking
char KeyData;                             // Data read from Keypad

    printf(" Testing Keypad\r\n");
	
	// Initialize the Keypad
    PostDisplayProgress(ERR_L_KEYPAD, ERR_S_KEYPAD_INIT, __LINE__);
	KeypadHWSetup();

	// Print Instructions

	printf(" User! Press each key on the keypad in sequence:\r\n");
	printf(" User! 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, E and B\r\n");
	printf(" User! Observe data in hex LED. * displays E, and # displays F.\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 != 0xFFF) & (KeyData != 0x23) & (KeyData != 0x54))
    {    
		KeyData = KeypadGetData();
		LED_MASK = mask;                        // Shut off all hex LEDs
		if((KeyData != 0x54) & (KeyData != 0x0A))
		{
		LED_MASK = mask & ~0x100;				// Turn on least significant hex digit
		HEX_LEDS = KeyData;                     // Display data
		}
		if(KeyData == '1') KeysPressed = KeysPressed | 0x001 ;  // ASCII 1
		if(KeyData == '2') KeysPressed = KeysPressed | 0x002 ;  // ASCII 2
		if(KeyData == '3') KeysPressed = KeysPressed | 0x004 ;  // ASCII 3
		if(KeyData == '4') KeysPressed = KeysPressed | 0x008 ;  // ASCII 4
		if(KeyData == '5') KeysPressed = KeysPressed | 0x010 ;  // ASCII 5
		if(KeyData == '6') KeysPressed = KeysPressed | 0x020 ;  // ASCII 6
		if(KeyData == '7') KeysPressed = KeysPressed | 0x040 ;  // ASCII 7
		if(KeyData == '8') KeysPressed = KeysPressed | 0x080 ;  // ASCII 8
		if(KeyData == '9') KeysPressed = KeysPressed | 0x100 ;  // ASCII 9
		if(KeyData == '0') KeysPressed = KeysPressed | 0x200 ;  // ASCII *
		if(KeyData == 'E') KeysPressed = KeysPressed | 0x400 ;  // ASCII 0
		if(KeyData == 'B') KeysPressed = KeysPressed | 0x800 ;  // ASCII #
	}
    if (KeysPressed != 0xFFF) KeypadTestResult = KP_TEST_FAILURE;
	if (KeyData == 0x54)
	{
        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);
    }
	LED_MASK = mask & ~0xFF00;				// Turn on hex LEDs
    printf(" Testing Scroll Wheel Press\r\n");
    printf(" User! Press and release the scroll wheel.\r\n");
    printf(" User! Start press after you continue.\r\n");
    GetUserResponse(YES);

    time = 200;                              // This will provide about a 10 second timeout

    while (((KPC_REG & KEYP_KPC_DI) != KEYP_KPC_DI) & (time != 0))
    {
    	DM_WaitMs(50);            // Dealy 50 mS as part of timeout loop
		time = time -1;         // Decrement timer
    }

	if (time == 0)
	{
        retVal = ERRORCODEX(ERR_L_KEYPAD, 0x80, 1, ERR_T_TIMEOUT);
   		XllpUtilityOutputError(retVal);
		return (1);
	}

    // Code picks up here when direct key interrupt comes in

	KeyData = KPDK_REG;		// Fetch direct key data
	if(KeyData & 0x4)
    {
    PostDisplayProgress(ERR_L_KEYPAD, ERR_S_KEYPAD_PASS, __LINE__);
    printf(" Success!\r\n");
	}
	else
	{
	printf("Press not detected.\r\n");
    retVal = ERRORCODEX(ERR_L_KEYPAD, 0x80, 1, ERR_T_TIMEOUT);
   	XllpUtilityOutputError(retVal);
	return (1);
	}

	// Scroll wheel press test complete - test for scroll operation
    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;
	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);

#else

	char KeyData = 0;
	
	printf("Now test keypad, press any key to view result, 'S1' to exit.\r\n");
	KeypadHWSetup();
	do {
		KeyData = KeypadGetData();
		if(KeyData!=0xA)
			printf("You enter %c\n", KeyData);
	} while(KeyData!='1');
	return KP_TEST_SUCCESS;
#endif
}
		
// end of PostKeypadTest()

/*
*******************************************************************************
*
* FUNCTION:
*    PostFastTapTest
*
* DESCRIPTION:
*    Test the FastTap Keypad.
*
* INPUT PARAMETERS:
*    None.
*
* RETURNS:
*    1 if error, 0 if no error.
*
* GLOBAL EFFECTS:
*    None.
*
* ASSUMPTIONS:
*    None.
*
* CALLS:
*    None.
*
* CALLED BY: 
*    Post main function.
*
* PROTOTYPE:
*    int PostKeypadTest(void);
*
*******************************************************************************
*/
int PostFastTapTest(void)
{
ErrorT retVal;
int  KeypadTestResult = KP_TEST_SUCCESS;  // Overall Keypad Test Result
int  KeysPressed = 0;                     // Record of keys pressed
//int  time;                                // timer
int  scroll_min;                          // min scroll wheel value
int  scroll_max;                          // max scroll wheel value
int  mask;                                // Work register for hex LED masking
char KeyData;                             // Data read from Keypad
int  last_scroll_val;

    printf(" Testing Keypad\r\n");
	
	// Initialize the Keypad
    PostDisplayProgress(ERR_L_KEYPAD, ERR_S_KEYPAD_INIT, __LINE__);
	FastTapHWSetup();

⌨️ 快捷键说明

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