/*************************************************************************
* Nuvoton Electronics Corporation confidential
*
* Copyright (c) 2008 by Nuvoton Electronics Corporation
* All rights reserved
*
* FILENAME
* kpi_test.c
*
* VERSION
* 1.0
*
* DESCRIPTION
* The KPI test program of Nuvoton ARM9 MCU
*
* DATA STRUCTURES
* None
*
* FUNCTIONS
* KPI_BufferTest KPI software buffer test
* KPI_ChangeKPICONF KPI change setting example code
* KPI_Item KPI test menu
* KPI_LPWakeTest KPI low power wake up test
* KPI_Readkey_block KPI block mode test
* KPI_Readkey_nonblock KPI non-block mode test
* KPI_ShowKeyMap Show key may of evaluation board's keypad
* KPI_Test main function of KPI test
* KPI_ThreeKeyTest KPI three key press test
*
* HISTORY
* 06/24/08 Ver 1.0 Created
*
* REMARK
* 1.Please notice that the multi-key function did not support
* that keys in the same column
* 2.Please notice that when encode function enable, the three key
* function key setting must in the different row
****************************************************************************/
/***************************************************************************
HISTORY
2007-01-09
1. KPI_Readkey_block
Add CONTINUOUS_MODE Ioctl command for continuous mode support when
specific 1key or 2key detected.
In this case,
1key: (ROW 1, COL 4)
2key: (ROW 1, COL 4), (ROW 1, COL 5)
***************************************************************************/
#ifdef ECOS
#include "stdio.h"
#include "drv_api.h"
#include "diag.h"
#include "wbtypes.h"
#include "wbio.h"
#else
#include "wblib.h"
#endif
#include "nuc900_reg.h"
#include "nuc900_kpi.h"
#ifdef ECOS
#define Successful 0
#define Fail 1
#define sysprintf diag_printf
#define sysGetChar diag_getc
#endif
//defin by project
#define __WB_EVB__
//#define __WB_POSTAX__
#ifdef __WB_EVB__
#define ESC_ROW 0
#define ESC_COL 1
#endif
#ifdef __WB_POSTAX__
#define ESC_ROW 7
#define ESC_COL 0
#endif
VOID KPI_Test(VOID);
static VOID KPI_Item(VOID);
static VOID KPI_Readkey_block(VOID);
static VOID KPI_Readkey_nonblock(VOID);
static VOID KPI_BufferTest(VOID);
static VOID KPI_ChangeKPICONF(VOID);
static VOID KPI_LPWakeTest(VOID);
static VOID KPI_ThreeKeyTest(VOID);
static VOID KPI_ShowKeyMap(VOID);
/****************************************************************************
* FUNCTION
* KPI_Test
*
* DESCRIPTION
* The KPI test main function
*
* CALLED BY
* various components
*
* INPUTS
* None
*
* OUTPUTS
* None
*
* HISTORY
* NAME DATE REMARKS
* NS21 WTLiu 2005-12-21 Created initial version
*
* REMARK
* None
****************************************************************************/
INT main(VOID)
{
CHAR cUserSelect;
#ifndef ECOS
WB_UART_T my_uart;
/* UART setting */
my_uart.uiFreq = 15000000; /* 15MHZ */
my_uart.uiBaudrate = 115200;
my_uart.uiDataBits = WB_DATA_BITS_8;
my_uart.uiStopBits = WB_STOP_BITS_1;
my_uart.uiParity = WB_PARITY_NONE;
my_uart.uiRxTriggerLevel = LEVEL_1_BYTE;
sysInitializeUART(&my_uart);
#endif
KPI_Init();
do
{
KPI_Item(); // Show menu
cUserSelect = sysGetChar();// Get user select
switch(cUserSelect)
{
//#ifdef ECOS
case '1': KPI_LPWakeTest(); break;
//#endif
case '2': KPI_Readkey_block(); break;
case '3': KPI_Readkey_nonblock(); break;
case '4': KPI_BufferTest(); break;
case '5': KPI_ThreeKeyTest(); break;
default: break;
}
}while(cUserSelect != 27); // Do until user press ESC
sysprintf("Leave program");
return 0;
}
/****************************************************************************
* FUNCTION
* KPI_Item
*
* DESCRIPTION
* The KPI test program menu
*
* CALLED BY
* various components
*
* INPUTS
* None
*
* OUTPUTS
* None
*
* HISTORY
* NAME DATE REMARKS
* NS21 WTLiu 2005-12-21 Created initial version
*
* REMARK
* None
****************************************************************************/
static VOID KPI_Item(VOID)
{
sysprintf("\n\n\n");
sysprintf("+------------------------------------------------------+\n");
sysprintf("| Nuvoton KPI Diagnostic Code |\n");
sysprintf("+------------------------------------------------------+\n");
//#ifdef ECOS
sysprintf("| Power down wake up test - [1] |\n");
//#endif
sysprintf("| KPI block mode test - [2] |\n");
sysprintf("| KPI non-block mode test - [3] |\n");
sysprintf("| KPI buffer test - [4] |\n");
sysprintf("| KPI three key test - [5] |\n");
sysprintf("| Quit - [ESC] |\n");
sysprintf("+------------------------------------------------------+\n");
sysprintf("Please Select : \n");
}
/****************************************************************************
* FUNCTION
* KPI_ThreeKeyTest
*
* DESCRIPTION
* The KPI three press test function
*
* CALLED BY
* various components
*
* INPUTS
* None
*
* OUTPUTS
* None
*
* HISTORY
* NAME DATE REMARKS
* NS21 WTLiu 2005-12-21 Created initial version
*
* REMARK
* None
****************************************************************************/
static VOID KPI_ThreeKeyTest(VOID)
{
INT nStatus;
CHAR cItem;
KPISTATUS_union kpikey;
KPI3KCONF_union kpi3kconf;
kpikey.value = 0;
KPI_Open(PORTI);
KPI_ShowKeyMap();
sysprintf("Setup KPI3KCONF-ENRST\nReset?(y/n)");
cItem = sysGetChar();// Get user key
switch(cItem)
{
case 'y': ENRST = ENRST_ENABLE; break;
case 'Y': ENRST = ENRST_ENABLE; break;
case 'n': ENRST = ENRST_DISABLE; break;
case 'N': ENRST = ENRST_DISABLE; break;
default: ENRST = ENRST_DISABLE; break;
}
#ifdef __WB_EVB__
K30R = 1;
K30C = 0;
K31R = 1;
K31C = 1;
K32R = 1;
K32C = 2;
#endif
#ifdef __WB_POSTAX__
K30R = 3;
K30C = 0;
K31R = 4;
K31C = 1;
K32R = 5;
K32C = 2;
#endif
EN3KY = EN3KY_ENABLE;
nStatus = KPI_Ioctl(SET_KPI3KCONF, 0, kpi3kconf.value);
if(nStatus == kpiInvalidIoctlCommand)
{
sysprintf("KPI ioctl command error!");
return;
}
sysprintf("keypad three key test.\n");
sysprintf("Three key setup:\n Key1 R:%2d C:%2d\n Key2 R:%2d C:%2d\n Key3 R:%2d C:%2d\n",
K30R, K30C, K31R, K31C, K32R, K32C);
if( (cItem == 'y') || (cItem == 'Y') )
{
sysprintf(" Reset: yes\n");
}
else
{
sysprintf(" Reset: no\n");
}
sysprintf("Wait for three key press...(ESC: ROW: %d, COL: %d)\n", ESC_ROW, ESC_COL);
while(1)
{
KPI_Read((PUCHAR)&kpikey, BLOCK_MODE);
if(_1KEY)
{
if(KEY0R == 0 && KEY0C == 1)
{
break;
}
}
if(_3KEY)
{
sysprintf("Three key test OK!!\n\n");
sysprintf("Wait for three key press...(ESC: ROW: %d,COL: %d)\n", ESC_ROW, ESC_COL);
}
}
KPI_Close();
sysprintf("\n\nTest finish\n");
}
/****************************************************************************
* FUNCTION
* KPI_LPWakeTest
*
* DESCRIPTION
* The KPI low power wake up test funct