1.原理图
2.代码
#include <windows.h> #include <types.h> #include <ceddk.h> #include <memory.h> #include <nkintr.h> #include <pegdpar.h> #include <ddkreg.h> #include <Winuser.h> #include "matrixkey.h" #include "Oal_timer.h" #include "at91_pio.h" // Controller includes #include "at91sam9263_gpio.h" #include "AT91SAM9263_oal_intr.h" #include "atmel_oal_ioctl.h" static HANDLE m_hMute; static BYTE Virtualkey0=VK_NUMPAD0; static HANDLE m_hevInterrupt0; static HANDLE gintThread0; static DWORD g_dwSysIntrToIrq0 = SYSINTR_UNDEFINED; static BYTE Virtualkey1=VK_NUMPAD0; static HANDLE m_hevInterrupt1; static HANDLE gintThread1; static DWORD g_dwSysIntrToIrq1 = SYSINTR_UNDEFINED; static BYTE Virtualkey2=VK_NUMPAD0; static HANDLE m_hevInterrupt2; static HANDLE gintThread2; static DWORD g_dwSysIntrToIrq2 = SYSINTR_UNDEFINED; static BYTE Virtualkey3=VK_NUMPAD0; static HANDLE m_hevInterrupt3; static HANDLE gintThread3; static DWORD g_dwSysIntrToIrq3 = SYSINTR_UNDEFINED; static BYTE Virtualkey4=VK_NUMPAD0; static HANDLE m_hevInterrupt4; static HANDLE gintThread4; static DWORD g_dwSysIntrToIrq4 = SYSINTR_UNDEFINED; static BYTE Virtualkey5=VK_NUMPAD0; static HANDLE m_hevInterrupt5; static HANDLE gintThread5; static DWORD g_dwSysIntrToIrq5 = SYSINTR_UNDEFINED; //////////////////////////////////////// static BYTE int9keyup=0; static void loopn(UINT32 wCount) { volatile unsigned int i, k,j=0; for (k=0; k<wCount; k++) for(i=0;i < 100; i++) { j++; } //400n } static DWORD KeyPadLock() { DWORD dwStatus; dwStatus = WaitForSingleObject(m_hMute, INFINITE); if(dwStatus == WAIT_OBJECT_0) { dwStatus = ERROR_SUCCESS; } else { dwStatus = GetLastError(); } return dwStatus; } static DWORD KeyPadUnLock() { DWORD dwStatus = ERROR_SUCCESS; BOOL fOk; fOk = ReleaseMutex(m_hMute); if(!fOk) { dwStatus = GetLastError(); } return dwStatus; } // 中断脚输入为低则返回TRUE,否则返回FALSE static BOOL IsIntPortLow(unsigned IrqNumber) { int result; result=pio_get_value(IrqNumber); if(result) return FALSE; else return TRUE; } // 中断脚输入是否稳定,稳定则返回TRUE,否则返回FALSE static BOOL IsIntPortStable(unsigned IrqNumber) { int i; int pre,now; KeyPadLock(); pre=pio_get_value(IrqNumber); for(i=0;i<3;i++) { Sleep(3); now=pio_get_value(IrqNumber); if(pre!=now) { KeyPadUnLock(); return FALSE; } } KeyPadUnLock(); return TRUE; } //所有输出管脚输出高电平 void alloutpinhigh(void) { pio_set_value(AT91C_PIN_PB(22), 1); pio_set_value(AT91C_PIN_PB(23), 1); pio_set_value(AT91C_PIN_PB(24), 1); pio_set_value(AT91C_PIN_PB(25), 1); pio_set_value(AT91C_PIN_PB(26), 1); pio_set_value(AT91C_PIN_PB(27), 1); } //所有输出管脚输出低电平 void alloutpinlow(void) { pio_set_value(AT91C_PIN_PB(22), 0); pio_set_value(AT91C_PIN_PB(23), 0); pio_set_value(AT91C_PIN_PB(24), 0); pio_set_value(AT91C_PIN_PB(25), 0); pio_set_value(AT91C_PIN_PB(26), 0); pio_set_value(AT91C_PIN_PB(27), 0); } #define ENTRY_POWEROFF 0x2 #define ENTRY_NULL 0x0 #define poweroff_counter 1300 #define wait_cnt 100 INT WINAPI Int0_Thread(void) { DWORD result; BYTE i; static int count=0; while(1) { result=WaitForSingleObject(m_hevInterrupt0, INFINITE); switch(result) { case WAIT_OBJECT_0: const struct pio_desc hw_pio[] = { {"INT0", AT91C_PIN_PB(6), 0, PIO_PULLUP, PIO_INPUT}, NULL, }; pio_setup(hw_pio, sizeof(hw_pio)/sizeof(struct pio_desc)); // 消除按键抖动 if(!IsIntPortStable(AT91C_PIN_PB(6))) { InterruptDone(g_dwSysIntrToIrq0); break; } // 中断输入是高电平,说明按键弹起 if(pio_get_value(AT91C_PIN_PB(6))) { keybd_event(Virtualkey0,0, KEYEVENTF_EXTENDEDKEY|KEYEVENTF_KEYUP, 0); RETAILMSG(1,(TEXT("Virtualkey0=%d up/r/n"),Virtualkey0)); } // 否则,轮询输出低电平, else { // 输出管脚全部输出高 alloutpinhigh(); for(i=0;i<6;i++) { pio_set_value(AT91C_PIN_PB(22)+i, 0); Sleep(3); while(!pio_get_value(AT91C_PIN_PB(6)) ) { Sleep(10); //按键为A,B,C,D,E,F.0x41,0x42,0x43,0x44,0x45,0x46. Virtualkey0=0x41+i; if(count==0) { Virtualkey0=0x41+i; keybd_event(Virtualkey0 ,0, KEYEVENTF_EXTENDEDKEY|0, 0); RETAILMSG(1,(TEXT("Virtualkey0=%d down/r/n"),Virtualkey0)); count++; } } count=0; pio_set_value(AT91C_PIN_PB(22)+i, 1); } alloutpinlow(); } InterruptDone(g_dwSysIntrToIrq0); break; } } } INT WINAPI Int1_Thread(void) { DWORD result; BYTE i; static int count=0; while(1) { result=WaitForSingleObject(m_hevInterrupt1, INFINITE); switch(result) { case WAIT_OBJECT_0: const struct pio_desc hw_pio[] = { {"INT0", AT91C_PIN_PB(7), 0, PIO_PULLUP, PIO_INPUT}, NULL, }; pio_setup(hw_pio, sizeof(hw_pio)/sizeof(struct pio_desc)); // 消除按键抖动 if(!IsIntPortStable(AT91C_PIN_PB(7))) { InterruptDone(g_dwSysIntrToIrq1); break; } // 中断输入是高电平,说明按键弹起 if(pio_get_value(AT91C_PIN_PB(7))) { keybd_event(Virtualkey1,0, KEYEVENTF_EXTENDEDKEY|KEYEVENTF_KEYUP, 0); RETAILMSG(1,(TEXT("Virtualkey0=%d up/r/n"),Virtualkey1)); } // 否则,轮询输出低电平, else { // 输出管脚全部输出高 alloutpinhigh(); for(i=0;i<6;i++) { pio_set_value(AT91C_PIN_PB(22)+i, 0); Sleep(3); while(!pio_get_value(AT91C_PIN_PB(7)) ) { if(count==0) { Sleep(10); //按键为G,H,I,J,K,L.0x47,0x48,0x49,0x4A,0x4B,0x4C. Virtualkey1=0x47+i; keybd_event(Virtualkey1 ,0, KEYEVENTF_EXTENDEDKEY|0, 0); RETAILMSG(1,(TEXT("Virtualkey0=%d down/r/n"),Virtualkey1)); count++; } } count=0; pio_set_value(AT91C_PIN_PB(22)+i, 1); } alloutpinlow(); } InterruptDone(g_dwSysIntrToIrq1); break; } } } INT WINAPI Int2_Thread(void) { DWORD result; BYTE i; static int count=0; while(1) { result=WaitForSingleObject(m_hevInterrupt2, INFINITE); switch(result) { case WAIT_OBJECT_0: const struct pio_desc hw_pio[] = { {"INT0", AT91C_PIN_PB(11), 0, PIO_PULLUP, PIO_INPUT}, NULL, }; pio_setup(hw_pio, sizeof(hw_pio)/sizeof(struct pio_desc)); // 消除按键抖动 if(!IsIntPortStable(AT91C_PIN_PB(11))) { InterruptDone(g_dwSysIntrToIrq2); break; } // 中断输入是高电平,说明按键弹起 if(pio_get_value(AT91C_PIN_PB(11))) { keybd_event(Virtualkey2,0, KEYEVENTF_EXTENDEDKEY|KEYEVENTF_KEYUP, 0); RETAILMSG(1,(TEXT("Virtualkey0=%d up/r/n"),Virtualkey2)); } // 否则,轮询输出低电平, else { // 输出管脚全部输出高 alloutpinhigh(); for(i=0;i<6;i++) { pio_set_value(AT91C_PIN_PB(22)+i, 0); Sleep(3); while(!pio_get_value(AT91C_PIN_PB(11)) ) { if(count==0) { Sleep(10); //按键为M,N,O,P,Q,R.0x4D,0x4E,0x4F,0x50,0x51,0x52. Virtualkey2=0x4D+i; keybd_event(Virtualkey2 ,0, KEYEVENTF_EXTENDEDKEY|0, 0); RETAILMSG(1,(TEXT("Virtualkey0=%d down/r/n"),Virtualkey2)); count++; } } count=0; pio_set_value(AT91C_PIN_PB(22)+i, 1); } alloutpinlow(); } InterruptDone(g_dwSysIntrToIrq2); break; } } } INT WINAPI Int3_Thread(void) { DWORD result; BYTE i; static int count=0; while(1) { result=WaitForSingleObject(m_hevInterrupt3, INFINITE); switch(result) { case WAIT_OBJECT_0: const struct pio_desc hw_pio[] = { {"INT0", AT91C_PIN_PB(19), 0, PIO_PULLUP, PIO_INPUT}, NULL, }; pio_setup(hw_pio, sizeof(hw_pio)/sizeof(struct pio_desc)); // 消除按键抖动 if(!IsIntPortStable(AT91C_PIN_PB(19))) { InterruptDone(g_dwSysIntrToIrq3); break; } // 中断输入是高电平,说明按键弹起 if(pio_get_value(AT91C_PIN_PB(19))) { keybd_event(Virtualkey3,0, KEYEVENTF_EXTENDEDKEY|KEYEVENTF_KEYUP, 0); RETAILMSG(1,(TEXT("Virtualkey0=%d up/r/n"),Virtualkey3)); } // 否则,轮询输出低电平, else { // 输出管脚全部输出高 alloutpinhigh(); for(i=0;i<6;i++) { pio_set_value(AT91C_PIN_PB(22)+i, 0); Sleep(3); while(!pio_get_value(AT91C_PIN_PB(19)) ) { if(count==0) { Sleep(10); //按键为S,T,U,V,W,X.0x53,0x54,0x55,0x56,0x57,0x58. Virtualkey3=0x53+i; keybd_event(Virtualkey3 ,0, KEYEVENTF_EXTENDEDKEY|0, 0); RETAILMSG(1,(TEXT("Virtualkey0=%d down/r/n"),Virtualkey3)); count++; } } count=0; pio_set_value(AT91C_PIN_PB(22)+i, 1); } alloutpinlow(); } InterruptDone(g_dwSysIntrToIrq3); break; } } } INT WINAPI Int4_Thread(void) { DWORD result; BYTE i; static int count=0; while(1) { result=WaitForSingleObject(m_hevInterrupt4, INFINITE); switch(result) { case WAIT_OBJECT_0: const struct pio_desc hw_pio[] = { {"INT0", AT91C_PIN_PB(20), 0, PIO_PULLUP, PIO_INPUT}, NULL, }; pio_setup(hw_pio, sizeof(hw_pio)/sizeof(struct pio_desc)); // 消除按键抖动 if(!IsIntPortStable(AT91C_PIN_PB(20))) { InterruptDone(g_dwSysIntrToIrq4); break; } // 中断输入是高电平,说明按键弹起 if(pio_get_value(AT91C_PIN_PB(20))) { keybd_event(Virtualkey4,0, KEYEVENTF_EXTENDEDKEY|KEYEVENTF_KEYUP, 0); RETAILMSG(1,(TEXT("Virtualkey0=%d up/r/n"),Virtualkey4)); } // 否则,轮询输出低电平, else { // 输出管脚全部输出高 alloutpinhigh(); for(i=0;i<6;i++) { pio_set_value(AT91C_PIN_PB(22)+i, 0); Sleep(3); while(!pio_get_value(AT91C_PIN_PB(20)) ) { if(count==0) { Sleep(10); //按键为Y,Z.0x59,0x5A. //按键为0,1,2,3.0x30,0x31,0x32,0x33. if(i<2) Virtualkey4=0x59+i; else Virtualkey4=0x30+i-2; keybd_event(Virtualkey4 ,0, KEYEVENTF_EXTENDEDKEY|0, 0); RETAILMSG(1,(TEXT("Virtualkey0=%d down/r/n"),Virtualkey4)); count++; } } count=0; pio_set_value(AT91C_PIN_PB(22)+i, 1); } alloutpinlow(); } InterruptDone(g_dwSysIntrToIrq4); break; } } } INT WINAPI Int5_Thread(void) { DWORD result; BYTE i; static int count=0; while(1) { result=WaitForSingleObject(m_hevInterrupt5, INFINITE); switch(result) { case WAIT_OBJECT_0: const struct pio_desc hw_pio[] = { {"INT0", AT91C_PIN_PB(21), 0, PIO_PULLUP, PIO_INPUT}, NULL, }; pio_setup(hw_pio, sizeof(hw_pio)/sizeof(struct pio_desc)); // 消除按键抖动 if(!IsIntPortStable(AT91C_PIN_PB(21))) { InterruptDone(g_dwSysIntrToIrq5); break; } // 中断输入是高电平,说明按键弹起 if(pio_get_value(AT91C_PIN_PB(21))) { keybd_event(Virtualkey5,0, KEYEVENTF_EXTENDEDKEY|KEYEVENTF_KEYUP, 0); RETAILMSG(1,(TEXT("Virtualkey0=%d up/r/n"),Virtualkey5)); } // 否则,轮询输出低电平, else { // 输出管脚全部输出高 alloutpinhigh(); for(i=0;i<6;i++) { pio_set_value(AT91C_PIN_PB(22)+i, 0); Sleep(3); while(!pio_get_value(AT91C_PIN_PB(21)) ) { if(count==0) { Sleep(10); //按键为4,5,6,7,8,9.0x34,0x35,0x36,0x37,0x38,0x39. Virtualkey5=0x34+i; keybd_event(Virtualkey5 ,0, KEYEVENTF_EXTENDEDKEY|0, 0); RETAILMSG(1,(TEXT("Virtualkey0=%d down/r/n"),Virtualkey5)); count++; } } count=0; pio_set_value(AT91C_PIN_PB(22)+i, 1); } alloutpinlow(); } InterruptDone(g_dwSysIntrToIrq5); break; } } } BOOL APIENTRY DllMain( HANDLE hModule,DWORD ul_reason_for_call,LPVOID lpReserved ) { switch (ul_reason_for_call) { case DLL_PROCESS_ATTACH: RETAILMSG(1,(TEXT("KEY Process Attach/r/n"))); break; case DLL_PROCESS_DETACH: RETAILMSG(1,(TEXT("KEY Process Detach/r/n"))); break; } return TRUE; } DWORD KEY_Init(LPCTSTR pContext,LPCVOID lpBusContext) { DWORD dwPhyIntr0; // 默认情况下矩阵键盘的4个行输出低电平,5个中断打开接收按键输入 // 输出管脚 const struct pio_desc hw_pio1[] = { {"OUT0", AT91C_PIN_PB(22), 0, PIO_PULLUP, PIO_OUTPUT}, {"OUT1", AT91C_PIN_PB(23), 0, PIO_PULLUP, PIO_OUTPUT}, {"OUT2", AT91C_PIN_PB(24), 0, PIO_PULLUP, PIO_OUTPUT}, {"OUT3", AT91C_PIN_PB(25), 0, PIO_PULLUP, PIO_OUTPUT}, {"OUT4", AT91C_PIN_PB(26), 0, PIO_PULLUP, PIO_OUTPUT}, {"OUT5", AT91C_PIN_PB(27), 0, PIO_PULLUP, PIO_OUTPUT}, NULL, }; // 中断管脚 /* const struct pio_desc hw_pio2[] = { {"IN0", AT91C_PIN_PB(6), 0, PIO_PULLUP, PIO_INPUT}, {"IN1", AT91C_PIN_PB(7), 0, PIO_PULLUP, PIO_INPUT}, {"IN2", AT91C_PIN_PB(11), 0, PIO_PULLUP, PIO_INPUT}, {"IN3", AT91C_PIN_PB(19), 0, PIO_PULLUP, PIO_INPUT}, {"IN4", AT91C_PIN_PB(20), 0, PIO_PULLUP, PIO_INPUT}, {"IN5", AT91C_PIN_PB(21), 0, PIO_PULLUP, PIO_INPUT}, NULL, }; */ pio_setup(hw_pio1, sizeof(hw_pio1)/sizeof(struct pio_desc)); //pio_setup(hw_pio2, sizeof(hw_pio2)/sizeof(struct pio_desc)); pio_set_value(AT91C_PIN_PB(22), 0); pio_set_value(AT91C_PIN_PB(23), 0); pio_set_value(AT91C_PIN_PB(24), 0); pio_set_value(AT91C_PIN_PB(25), 0); pio_set_value(AT91C_PIN_PB(26), 0); pio_set_value(AT91C_PIN_PB(27), 0); RETAILMSG(1,(TEXT("+KEY_Init/r/n"))); m_hMute = CreateMutex ( NULL, // No security descriptor FALSE, // Mutex object not owned TEXT("MatrixKeyboardMutex")); // Object name if(!m_hMute) { RETAILMSG(DEBUGCOMOUTPUT, (_T("ERROR::Matrixkeybord CreateMutex failed/r/n"))); } // 中断0 dwPhyIntr0 = (LOGINTR_BASE_PIOB + 6); m_hevInterrupt0 = CreateEvent(NULL,FALSE,FALSE,NULL); if (!KernelIoControl(IOCTL_HAL_REQUEST_SYSINTR, &dwPhyIntr0, sizeof(DWORD), &g_dwSysIntrToIrq0, sizeof(DWORD), NULL)) { RETAILMSG(1, (TEXT("ERROR: Failed to request the SDCARD detect sysintr/r/n"))); g_dwSysIntrToIrq0 = SYSINTR_UNDEFINED; return FALSE; } if (!InterruptInitialize(g_dwSysIntrToIrq0, m_hevInterrupt0, 0, 0)) { RETAILMSG(1 ,(TEXT("ERROR:Cannot initialize the SDCARD detect interrupt ! /r/n"))); } gintThread0 = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE) Int0_Thread, NULL, 0, NULL); if ( gintThread0 == NULL ) { RETAILMSG(1, (TEXT("Fatal Error! Failed to create MMC card detect thread./r/n"))); return (FALSE); } // 中断1 dwPhyIntr0 = (LOGINTR_BASE_PIOB + 7); m_hevInterrupt1 = CreateEvent(NULL,FALSE,FALSE,NULL); if (!KernelIoControl(IOCTL_HAL_REQUEST_SYSINTR, &dwPhyIntr0, sizeof(DWORD), &g_dwSysIntrToIrq1, sizeof(DWORD), NULL)) { RETAILMSG(1, (TEXT("ERROR: Failed to request the SDCARD detect sysintr/r/n"))); g_dwSysIntrToIrq1 = SYSINTR_UNDEFINED; return FALSE; } if (!InterruptInitialize(g_dwSysIntrToIrq1, m_hevInterrupt1, 0, 0)) { RETAILMSG(1 ,(TEXT("ERROR:Cannot initialize the SDCARD detect interrupt ! /r/n"))); } gintThread1 = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE) Int1_Thread, NULL, 0, NULL); if ( gintThread1 == NULL ) { RETAILMSG(1, (TEXT("Fatal Error! Failed to create MMC card detect thread./r/n"))); return (FALSE); } // 中断2 dwPhyIntr0 = (LOGINTR_BASE_PIOB + 11); m_hevInterrupt2 = CreateEvent(NULL,FALSE,FALSE,NULL); if (!KernelIoControl(IOCTL_HAL_REQUEST_SYSINTR, &dwPhyIntr0, sizeof(DWORD), &g_dwSysIntrToIrq2, sizeof(DWORD), NULL)) { RETAILMSG(1, (TEXT("ERROR: Failed to request the SDCARD detect sysintr/r/n"))); g_dwSysIntrToIrq2 = SYSINTR_UNDEFINED; return FALSE; } if (!InterruptInitialize(g_dwSysIntrToIrq2, m_hevInterrupt2, 0, 0)) { RETAILMSG(1 ,(TEXT("ERROR:Cannot initialize the SDCARD detect interrupt ! /r/n"))); } gintThread2 = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE) Int2_Thread, NULL, 0, NULL); if ( gintThread2 == NULL ) { RETAILMSG(1, (TEXT("Fatal Error! Failed to create MMC card detect thread./r/n"))); return (FALSE); } // 中断3 dwPhyIntr0 = (LOGINTR_BASE_PIOB + 19); m_hevInterrupt3 = CreateEvent(NULL,FALSE,FALSE,NULL); if (!KernelIoControl(IOCTL_HAL_REQUEST_SYSINTR, &dwPhyIntr0, sizeof(DWORD), &g_dwSysIntrToIrq3, sizeof(DWORD), NULL)) { RETAILMSG(1, (TEXT("ERROR: Failed to request the SDCARD detect sysintr/r/n"))); g_dwSysIntrToIrq3 = SYSINTR_UNDEFINED; return FALSE; } if (!InterruptInitialize(g_dwSysIntrToIrq3, m_hevInterrupt3, 0, 0)) { RETAILMSG(1 ,(TEXT("ERROR:Cannot initialize the SDCARD detect interrupt ! /r/n"))); } gintThread3 = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE) Int3_Thread, NULL, 0, NULL); if ( gintThread3 == NULL ) { RETAILMSG(1, (TEXT("Fatal Error! Failed to create MMC card detect thread./r/n"))); return (FALSE); } // 中断4 dwPhyIntr0 = (LOGINTR_BASE_PIOB + 20); m_hevInterrupt4 = CreateEvent(NULL,FALSE,FALSE,NULL); if (!KernelIoControl(IOCTL_HAL_REQUEST_SYSINTR, &dwPhyIntr0, sizeof(DWORD), &g_dwSysIntrToIrq4, sizeof(DWORD), NULL)) { RETAILMSG(1, (TEXT("ERROR: Failed to request the SDCARD detect sysintr/r/n"))); g_dwSysIntrToIrq4 = SYSINTR_UNDEFINED; return FALSE; } if (!InterruptInitialize(g_dwSysIntrToIrq4, m_hevInterrupt4, 0, 0)) { RETAILMSG(1 ,(TEXT("ERROR:Cannot initialize the SDCARD detect interrupt ! /r/n"))); } gintThread4 = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE) Int4_Thread, NULL, 0, NULL); if ( gintThread4 == NULL ) { RETAILMSG(1, (TEXT("Fatal Error! Failed to create MMC card detect thread./r/n"))); return (FALSE); } // 中断5 dwPhyIntr0 = (LOGINTR_BASE_PIOB + 21); m_hevInterrupt5 = CreateEvent(NULL,FALSE,FALSE,NULL); if (!KernelIoControl(IOCTL_HAL_REQUEST_SYSINTR, &dwPhyIntr0, sizeof(DWORD), &g_dwSysIntrToIrq5, sizeof(DWORD), NULL)) { RETAILMSG(1, (TEXT("ERROR: Failed to request the SDCARD detect sysintr/r/n"))); g_dwSysIntrToIrq5 = SYSINTR_UNDEFINED; return FALSE; } if (!InterruptInitialize(g_dwSysIntrToIrq5, m_hevInterrupt5, 0, 0)) { RETAILMSG(1 ,(TEXT("ERROR:Cannot initialize the SDCARD detect interrupt ! /r/n"))); } gintThread5 = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE) Int5_Thread, NULL, 0, NULL); if ( gintThread5== NULL ) { RETAILMSG(1, (TEXT("Fatal Error! Failed to create MMC card detect thread./r/n"))); return (FALSE); } RETAILMSG(1,(TEXT("-KEY_Init/r/n"))); return(TRUE); } BOOL KEY_Deinit(LPCTSTR hDeviceContext) { CloseHandle(m_hMute); CloseHandle(m_hevInterrupt0); CloseHandle(gintThread0); CloseHandle(m_hevInterrupt1); CloseHandle(gintThread1); return TRUE; } DWORD KEY_Open(LPCTSTR hDeviceContext,DWORD AccessCode,DWORD ShareMode) { return (DWORD)hDeviceContext; } DWORD KEY_Close(LPCTSTR pOpenContext) { return TRUE; } DWORD KEY_Write(LPCTSTR pOpenContext,LPCVOID pBuffer,DWORD Count) { return -1; } DWORD KEY_Read(LPCTSTR pOpenContext,LPCVOID pBuffer,DWORD Count) { return -1; } BOOL KEY_IOControl(LPCTSTR pOpenContext,DWORD dwCode,PBYTE pBufIn,DWORD dwLenIn,PBYTE pBufOut,DWORD dwLenOut,DWORD pdwActualOut) { return 0; } DWORD KEY_Seek(LPCTSTR pOpenContext,LPCVOID pBuffer,DWORD Count) { return -1; }
3.sources文件
RELEASETYPE=PLATFORM
TARGETNAME=MATRIXKEY
TARGETTYPE=DYNLINK
DLLENTRY=DllMain
SOURCES= /
matrixkey.cpp /
TARGETLIBS= /
$(_COMMONSDKROOT)/lib/$(_CPUINDPATH)/coredll.lib /
SOURCELIBS= /
$(_TARGETPLATROOT)/lib/$(_CPUDEPPATH)/gpio.lib /
INCLUDES= $(_TARGETPLATROOT)/SRC/inc;$(_COMMONOAKROOT)/inc;$(INCLUDES)
4.注册表
[HKEY_LOCAL_MACHINE/Drivers/BuiltIn/matrixkey]
"Prefix"="KEY"
"Index"=dword:1
"Dll"="MATRIXKEY.dll"
"Order"=dword:12
5.platform.bib文件加入:
IF BSP_MATRIX
MATRIXKEY.dll $(_FLATRELEASEDIR)/MATRIXKEY.dll NK SHK
ENDIF BSP_MATRIX
6.platform.reg文件加入
; -----------------------------------------------------------------------------
IF BSP_MATRIX
#include "$(_TARGETPLATROOT)/SRC/DRIVERS/MATRIXKEY/MATRIXKEY.reg"
ENDIF BSP_MATRIX
; -----------------------------------------------------------------------------
7注意:这里我做的按键是A-Z以及0-9共36个按键。
; -----------------------------------------------------------------------------
QQ:229425962
Phone:15820435302
Email:[email protected]
; -----------------------------------------------------------------------------