下面是一段中断流驱动的一部分,请问是实现什么功能?是几乘几的矩阵键盘吗?还请高手帮忙在后面帮我注释分析下。
本人只剩30积分了,全给了,很不好意思。
********************************************************************************************/
PRIVATE VOID EINT_ConfigInterruptPin(VOID)
{
v_pIOPregs->GPFCON &=~(0x3<<8);
v_pIOPregs->GPFCON |= (0x2<<6);
v_pIOPregs->EXTINT1 &=~(0x7<<12);
v_pIOPregs->EXTINT1 |= (0x2<<12);
v_pIOPregs->GPECON &=~(0x3<<22);//set GPE11 output
v_pIOPregs->GPECON |=(0x1<<22);
v_pIOPregs->GPECON &=~(0x3<<26);//set GPE13 output
v_pIOPregs->GPECON |=(0x1<<26);
v_pIOPregs->GPGCON &=~(0x3<<12);//set GPG6 output
v_pIOPregs->GPGCON |=(0x1<<12);
v_pIOPregs->GPGCON &=~(0x3<<4);//set GPG2 output
v_pIOPregs->GPGCON |=(0x1<<4);
v_pIOPregs->GPEDAT &=~(0x01<<11);//set PGE11 0
v_pIOPregs->GPEDAT &=~(0x01<<13);
v_pIOPregs->GPGDAT &=~(0x01<<2);
v_pIOPregs->GPGDAT &=~(0x01<<6);
}
***********************************************************************************
PRIVATE VOID EINT_ConfigPinDefault( )
{
v_pIOPregs->GPGCON &= ~(0X3<<6); //配置GPG3/EINT11为输入引脚
}
/*PRIVATE VOID EINT_ConfigPinEint(DWORD pinNo )
{
v_pIOPregs->rGPFCON = 0xAA55;
v_pIOPregs->rGPFDAT &= ~(0x0f);
}*/
*******************************************************************************************/
BOOL KEY_Scan(VOID)
{
v_pIOPregs->GPEDAT &=~(0x01<<11);
v_pIOPregs->GPGDAT |=(0x01<<6);
v_pIOPregs->GPEDAT |=(0x01<<13);
v_pIOPregs->GPGDAT |=(0x01<<2);
if (v_pIOPregs->GPGDAT&(1<<3)==0)
{
gReadKeyValue=4;
}
v_pIOPregs->GPEDAT |=(0x01<<11);
v_pIOPregs->GPGDAT &=~(0x01<<6);
v_pIOPregs->GPEDAT |=(0x01<<13);
v_pIOPregs->GPGDAT |=(0x01<<2);
if (v_pIOPregs->GPGDAT&(1<<3) == 0)
{
gReadKeyValue=5;
}
v_pIOPregs->GPEDAT |=(0x01<<11);
v_pIOPregs->GPGDAT |=(0x01<<6);
v_pIOPregs->GPEDAT &=~(0x01<<13);
v_pIOPregs->GPGDAT |=(0x01<<2);
if (v_pIOPregs->GPGDAT&(1<<3) == 0)
{
gReadKeyValue=6;
}
else
{
gReadKeyValue=14;
}
}
*******************************************************************************************/
DWORD EINTKey_IntrThread(PVOID pArg)
{
DWORD ret;
DWORD pressRowNo;
DWORD pressColNo;
// 创建外部中断中断事件
gWaitEvent = CreateEvent(NULL, FALSE, FALSE, NULL);
// 初始化外部按键中断: 注册中断事件, 允许外部中断
if (!(InterruptInitialize(SYSINTR_Key, gWaitEvent, 0, 0)))
{
RETAILMSG(1, (TEXT("ERROR: EINTKey: InterruptInitialize failed.\r\n")));
CloseHandle(gWaitEvent);
return 0;
}
// 外部按键中断线程开始运行
while (1)
{
ret = WaitForSingleObject(gWaitEvent, INFINITE);
if ((ret == WAIT_OBJECT_0 ) && (g_bKillIST == FALSE))
{
if(Key_IsPushed())
{
Sleep(20);
if(Key_IsPushed())
{
EINT_ConfigPinDefault( );
KEY_Scan();
SetEvent(gReadKeyEvent[0]);
RETAILMSG(1,(TEXT(":::The Key PUshed.\r\n")));
}
}
}
else
{
CloseHandle(gWaitEvent);
RETAILMSG(1, (TEXT("::: EINTKey_IntrThread Exit. \r\n")));
return 0;
} //if (ret != WAIT_OBJECT_0) or Error occurs
InterruptDone(SYSINTR_Key); /* 通知内核: 中断处理结束 */
}
return 1;
}
*******************************************************************************************/
DWORD KEY_Read(DWORD Handle, LPVOID pBuffer, DWORD dwNumBytes)
{
DWORD ret;
DWORD waitMillSec;
DWORD *pReadBuffer;
if ((pBuffer == NULL) || (dwNumBytes <= 0))
return 0;
pReadBuffer = MapPtrToProcess(pBuffer, GetCallerProcess());
*pReadBuffer = 0;
/* 根据 等待的时间值调整等待*/
/* if( * (pReadBuffer+1)==0)
{//无限等待
RETAILMSG(1, (TEXT("::: Wait Key Infine. \r\n")));
waitMillSec=INFINITE;
}
else
{
waitMillSec=* (pReadBuffer+1);
}*/
ret = WaitForMultipleObjects(2, gReadKeyEvent, FALSE, waitMillSec);
if (ret == WAIT_OBJECT_0)
{
ResetEvent(gReadKeyEvent[0]);
*pReadBuffer = gReadKeyValue;
return 1;
}
else if (ret == WAIT_OBJECT_0+1)
{
ResetEvent(gReadKeyEvent[1]);
*pReadBuffer = 0;
return 1;
}
return 0;
} // KEY_Read
没有原理图,又没有注释,这样去猜作者意图,很麻烦,很耗时间的。最好能上个原理图咯
呵呵,正在找按键驱动呢,正好有送上门来的,记录一下,明天继续研究:)