📄 kbd.cpp
字号:
/*
* ------------------------
*
* Jade chip
*
* ------------------------
* File: kbmouse.cpp
* Release: Version 1.0
* ------------------------
*/
#include <windows.h>
#include <ceddk.h>
#include <ddkreg.h>
#include <keybdpdd.h>
#include <laymgr.h>
#include "oalintr.h"
#include "platform.h"
#include "pl050port.hpp"
#include "pl050keybd.hpp"
#include "gpiodrv.h"
static pl050Port *port1 = NULL, *port2 = NULL;
static pl050Keybd *kbdport = NULL;
UINT v_uiPddId;
PFN_KEYBD_EVENT v_pfnKeybdEvent;
//yz_add
HANDLE g_GPIO1Event;
HANDLE g_GPIO2Event;
#define yz_debug 0
DWORD Keybd_GpioIST(PVOID pvParam);
unsigned int KbdISRUpcall(bool timedout, unsigned int scancode);
static KEYBD_PDD GPIOpl050Pdd = {
2,//PS2_AT_PDD,
_T("pl050 GPIO"),
};
BOOL
WINAPI
GPIO_pl050_Entry(
UINT uiPddId,
PFN_KEYBD_EVENT pfnKeybdEvent,
PKEYBD_PDD *ppKeybdPdd
)
{
SETFNAME(_T("PS2_pl050_Entry"));
BOOL fRet = FALSE;
pl050Port *port;
DWORD dwSysIntrKeybd = 0, dwSysIntrMouse = 0;
v_uiPddId = uiPddId;
v_pfnKeybdEvent = pfnKeybdEvent;
RETAILMSG(1, (TEXT("Keybd driver Entry\r\n")));
DEBUGMSG(ZONE_INIT, (_T("%s: Initialize PS/2 ID %u\r\n"), pszFname,
uiPddId));
DEBUGCHK(ppKeybdPdd != NULL);
*ppKeybdPdd = &GPIOpl050Pdd;
if (port1 != NULL)
{
fRet = TRUE;
goto leave;
}
//-----------------------------------------------------
//yz_add for GPIO
{
PGPIO_INFO pGpioHead = NULL;
PHYSICAL_ADDRESS PhysicalAddress;
RETAILMSG (yz_debug, (TEXT("+GIO_Init\r\n")));
// Allocate our control structure.
pGpioHead = (PGPIO_INFO)LocalAlloc(LPTR, sizeof(GPIO_INFO));
// Check that LocalAlloc did stuff ok too.
if ( !pGpioHead ) {
RETAILMSG(yz_debug, (TEXT("Error allocating memory for pGpioHead, GIO_Init failed\r\n")));
return FALSE;
}
// Initially, open list is empty.
// InitializeListHead( &pGpioHead->OpenList );
// InitializeCriticalSection(&(pGpioHead->OpenCS));
pGpioHead->dwAllocatedPinMask = 0;
// Setup the GPIO base register pointers
// Map a virtual memory address to the physical base address
PhysicalAddress.HighPart = 0;
PhysicalAddress.LowPart = GPIO1_BASE;
pGpioHead->pGpio1Regs = (PGPIO_REGS)MmMapIoSpace( PhysicalAddress, sizeof(GPIO_REGS), FALSE);
if(pGpioHead->pGpio1Regs == NULL)
{
RETAILMSG(yz_debug, (TEXT("GIO_Init: Error GPIO1 MmMapIoSpace failed\r\n")));
//GIO_Deinit(pGpioHead);
return FALSE;
}
RETAILMSG(yz_debug, (TEXT("GIO_Init: GPIO1 regs = 0x%X\r\n"), pGpioHead->pGpio1Regs));
PhysicalAddress.HighPart = 0;
PhysicalAddress.LowPart = GPIO2_BASE;
pGpioHead->pGpio2Regs = (PGPIO_REGS)MmMapIoSpace( PhysicalAddress, sizeof(GPIO_REGS), FALSE);
if(pGpioHead->pGpio2Regs == NULL)
{
RETAILMSG(yz_debug, (TEXT("GIO_Init: Error GPIO2 MmMapIoSpace failed\r\n")));
//GIO_Deinit(pGpioHead);
return FALSE;
}
RETAILMSG(yz_debug, (TEXT("GIO_Init: GPIO2 regs = 0x%X\r\n"), pGpioHead->pGpio2Regs));
// Create the interrupt event for the GPIO1 IST
//pGpioHead->hGpio1ISTEvent = CreateEvent(NULL, FALSE, FALSE, NULL);
g_GPIO1Event = CreateEvent(NULL, FALSE, FALSE, NULL);
g_GPIO2Event = CreateEvent(NULL, FALSE, FALSE, NULL);
//if(pGpioHead->hGpio1ISTEvent == NULL)
if(g_GPIO1Event == NULL || g_GPIO2Event == NULL)
{
RETAILMSG(yz_debug, (TEXT("GIO_Init: Error creating GPIO1 IST event\r\n")));
//GIO_Deinit(pGpioHead);
return FALSE;
}
// Enable the interrupts for the GPIO1 subsystem
//InterruptInitialize(SYSINTR_GPIO1, pGpioHead->hGpio1ISTEvent, NULL, 0);
if(!(InterruptInitialize(SYSINTR_KBD, g_GPIO1Event, NULL, 0)))
{
RETAILMSG(yz_debug, (TEXT("GIO_Init: Error cann't initialize interrupt 1!\r\n")));
}
/*
if(!(InterruptInitialize(SYSINTR_GPIO2, g_GPIO2Event, NULL, 0)))
{
RETAILMSG(yz_debug, (TEXT("GIO_Init: Error cann't initialize interrupt 2!\r\n")));
}
*/
// Launch the GPIO1 IST
pGpioHead->hGpio1ISTThread = CreateThread(NULL, 0, Keybd_GpioIST, pGpioHead, 0, NULL );
if(pGpioHead->hGpio1ISTThread == NULL)
{
RETAILMSG(yz_debug, (TEXT("GIO_Init: Error creating GPIO1 IST\r\n")));
//GIO_Deinit(pGpioHead);
return NULL;
}
// Make sure the thread has a higher priority than the driver
CeSetThreadPriority(pGpioHead->hGpio1ISTThread, 200);
}
//------end
RETAILMSG(yz_debug, (TEXT("keybd 3\r\n")));
if (!(port1 = new pl050Port) ||
!(kbdport = new pl050Keybd))
{
RETAILMSG(1, (TEXT("Heap exhausted !\r\n")));
goto dodelete;
}
port1->Initialise();
RETAILMSG(yz_debug, (TEXT("port1->Initialise()!\r\n")));
port = port1;
if (!(kbdport->Initialise(port)))
{
RETAILMSG(1, (TEXT("Could not initialise kbd\r\n")));
goto dodelete;
}
fRet = TRUE;
RETAILMSG(yz_debug, (TEXT("KBD initial END!\r\n")));
dodelete:
if (!fRet)
{
delete port1;
port1 = NULL;
delete port2;
port2 = NULL;
delete kbdport;
kbdport = NULL;
}
leave:
return fRet;
}
//yz_add for GPIO
//key scan code array
//unsigned int key_code[4][4] = {{0x1C, 0x32, 0x21, 0x23}, {0x3a, 0x5a, 0x24, 0x0D}, {0x1f,0x27,1,1}, {1,1,1,1}};
//1-9,0 a-f (1-9,0 ESC, Back, F1-F4)
unsigned int key_code[4][4] = {{0x16, 0x1E, 0x26, 0x25}, {0x2E, 0x36, 0x3D, 0x3E}, {0x46, 0x45, 0x76, 0x66/*0x1C, 0x32*/}, {0x5, 0x6, 0x4, 0xC}/*{0x21, 0x23, 0x24, 0x2B}*/};
// Gpio1ISTThread - This is the GPIO1 IST for the GPIO device driver
//
//extern "C" DWORD yz_Gpio1ISTThread(PVOID pvParam)
DWORD Keybd_GpioIST(PVOID pvParam)
{
PGPIO_INFO pGpioHead = (PGPIO_INFO)pvParam;
DWORD dwEvent;//, dwIntStatus, dwdata, dwdata2;
unsigned char dwIntStatus, dwdata, temp;//dwdata2,
unsigned int yz_key = 0;
BOOL fExit = FALSE;
BOOL yz_keyup = TRUE;
int i;
RETAILMSG (yz_debug, (TEXT("Keybd: GPIO IST thread starting \r\n")));
//enable the interrupt
pGpioHead->pGpio1Regs->GPIODir5 = 0xF0;
pGpioHead->pGpio1Regs->GPIOIS5 = 0x0;
pGpioHead->pGpio1Regs->GPIOIBE5 = 0xFF;
pGpioHead->pGpio1Regs->GPIOIE5 = 0x0F;
pGpioHead->pGpio1Regs->GPIOIC5 = 0xFF;
pGpioHead->pGpio2Regs->GPIODir5 = 0xFF;
//pGpioHead->pGpio2Regs->GPIOIS = 0x0;
//pGpioHead->pGpio2Regs->GPIOIBE = 0xFF;
//pGpioHead->pGpio2Regs->GPIOIE = 0xFF;
pGpioHead->pGpio2Regs->GPIOIC5 = 0xFF;
pGpioHead->pGpio2Regs->Padding1[254] = 0xF0;
pGpioHead->pGpio1Regs->GPIOIC5 = 0xFF;
while(1)
{
dwEvent = WaitForSingleObject(g_GPIO1Event, INFINITE);
//RETAILMSG (yz_debug, (TEXT("GPIO1 IST thread received interrupt event\r\n")));
switch(dwEvent)
{
case WAIT_OBJECT_0:
//just sleep
Sleep(50);
// Fetch the masked interrupt status
dwIntStatus = (unsigned char)(pGpioHead->pGpio1Regs->GPIORIS5 & 0xFF);
dwdata = (unsigned char)(pGpioHead->pGpio1Regs->Padding1[254] & 0xFF);
if((dwdata & 0x0F) == 0x0F && yz_keyup == TRUE)
//if((dwdata & dwIntStatus) == dwIntStatus && yz_keyup == TRUE)
{
Sleep(50);
break;
}
RETAILMSG (yz_debug, (TEXT("GPIO1 IST: PIN %x Interrupt !data: %x \r\n"), dwIntStatus, dwdata));
// Clear all the interrupt bits as we have copied the current status
//pGpioHead->pGpio1Regs->GPIOIC = 0xFF;
if((((dwdata & dwIntStatus)&0x0F) == (dwIntStatus&0x0F)) && ((dwIntStatus&0x0F) != 0))
{
RETAILMSG (yz_debug, (TEXT("up !\r\n")));
if(yz_key == 0x1F)
KbdISRUpcall(false, 0xe0);
KbdISRUpcall(false, 0xF0);
KbdISRUpcall(false, yz_key);
yz_keyup = TRUE;
}
else if(yz_keyup == TRUE)
{
switch((dwIntStatus&0x0F))
{
case 0x01:
for(i = 0; i < 4; i++)
{
temp = 1;
pGpioHead->pGpio2Regs->Padding1[254] = ~(temp << i);
dwdata = (unsigned char)(pGpioHead->pGpio1Regs->Padding1[254] & 0x0F);
if(dwdata != 0x0F)
break;
}
switch(i)
{
case 0x0:
RETAILMSG (yz_debug, (TEXT("a !\r\n")));
KbdISRUpcall(false, key_code[0][0]);
yz_key = key_code[0][0];
yz_keyup = FALSE;
break;
case 0x1:
RETAILMSG (yz_debug, (TEXT("b !\r\n")));
KbdISRUpcall(false, key_code[0][1]);
yz_key = key_code[0][1];
yz_keyup = FALSE;
break;
case 0x2:
RETAILMSG (yz_debug, (TEXT("c !\r\n")));
KbdISRUpcall(false, key_code[0][2]);
yz_key = key_code[0][2];
yz_keyup = FALSE;
break;
case 0x3:
RETAILMSG (yz_debug, (TEXT("d !\r\n")));
KbdISRUpcall(false, key_code[0][3]);
yz_key = key_code[0][3];
yz_keyup = FALSE;
break;
default:
break;
}
break;
case 0x02:
for(i = 0; i < 4; i++)
{
temp = 1;
pGpioHead->pGpio2Regs->Padding1[254] = ~(temp << i);
dwdata = (unsigned char)(pGpioHead->pGpio1Regs->Padding1[254] & 0x0F);
if(dwdata != 0x0F)
break;
}
switch(i)
{
case 0x0:
RETAILMSG (yz_debug, (TEXT("m !\r\n")));
KbdISRUpcall(false, key_code[1][0]);
yz_key = key_code[1][0];
yz_keyup = FALSE;
break;
case 0x1:
RETAILMSG (yz_debug, (TEXT("Enter !\r\n")));
KbdISRUpcall(false, key_code[1][1]);
yz_key = key_code[1][1];
yz_keyup = FALSE;
break;
case 0x2:
RETAILMSG (yz_debug, (TEXT("e !\r\n")));
KbdISRUpcall(false, key_code[1][2]);
yz_key = key_code[1][2];
yz_keyup = FALSE;
break;
case 0x3:
RETAILMSG (yz_debug, (TEXT("Tab !\r\n")));
KbdISRUpcall(false, key_code[1][3]);
yz_key = key_code[1][3];
yz_keyup = FALSE;
break;
default:
break;
}
break;
case 0x4:
for(i = 0; i < 4; i++)
{
temp = 1;
pGpioHead->pGpio2Regs->Padding1[254] = ~(temp << i);
dwdata = (unsigned char)(pGpioHead->pGpio1Regs->Padding1[254] & 0x0F);
if(dwdata != 0x0F)
break;
}
switch(i)
{
case 0x0:
RETAILMSG (yz_debug, (TEXT("Win L !\r\n")));
//KbdISRUpcall(false, 0xe0);
KbdISRUpcall(false, key_code[2][0]);
yz_key = key_code[2][0];
yz_keyup = FALSE;
break;
case 0x1:
RETAILMSG (yz_debug, (TEXT("Win R !\r\n")));
KbdISRUpcall(false, key_code[2][1]);
yz_key = key_code[2][1];
yz_keyup = FALSE;
break;
case 0x2:
RETAILMSG (yz_debug, (TEXT("g !\r\n")));
KbdISRUpcall(false, key_code[2][2]);
yz_key = key_code[2][2];
yz_keyup = FALSE;
break;
case 0x3:
RETAILMSG (yz_debug, (TEXT("h !\r\n")));
KbdISRUpcall(false, key_code[2][3]);
yz_key = key_code[2][3];
yz_keyup = FALSE;
break;
default:
break;
}
break;
case 0x8:
for(i = 0; i < 4; i++)
{
temp = 1;
pGpioHead->pGpio2Regs->Padding1[254] = ~(temp << i);
dwdata = (unsigned char)(pGpioHead->pGpio1Regs->Padding1[254] & 0x0F);
if(dwdata != 0x0F)
break;
}
switch(i)
{
case 0x0:
RETAILMSG (yz_debug, (TEXT("e !\r\n")));
KbdISRUpcall(false, key_code[3][0]);
yz_key = key_code[3][0];
yz_keyup = FALSE;
break;
case 0x1:
RETAILMSG (yz_debug, (TEXT("f !\r\n")));
KbdISRUpcall(false, key_code[3][1]);
yz_key = key_code[3][1];
yz_keyup = FALSE;
break;
case 0x2:
RETAILMSG (yz_debug, (TEXT("g !\r\n")));
KbdISRUpcall(false, key_code[3][2]);
yz_key = key_code[3][2];
yz_keyup = FALSE;
break;
case 0x3:
RETAILMSG (yz_debug, (TEXT("h !\r\n")));
KbdISRUpcall(false, key_code[3][3]);
yz_key = key_code[3][3];
yz_keyup = FALSE;
break;
default:
break;
}
break;
default:
RETAILMSG (1, (TEXT("GPIO Key Error! \r\n")));
break;
}
}
//pGpioHead->pGpio1Regs->GPIOIC = 0xFF;
//InterruptDone(SYSINTR_GPIO1); // Acknowledge the GPIO1 interrupt
break;
default:
break;
}
pGpioHead->pGpio2Regs->Padding1[254] = 0xF0;
pGpioHead->pGpio1Regs->GPIOIC5 = 0xFF;
InterruptDone(SYSINTR_KBD); // Acknowledge the GPIO1 interrupt
}
pGpioHead->fGpio1ISTExit = FALSE; // Signal we have terminated
RETAILMSG (yz_debug, (TEXT("GPIO1 IST thread ERROR\r\n")));
//DEBUGMSG (ZONE_THREAD, (TEXT("GPIO1 IST thread terminating\r\n")));
return 0;
}
/* EOF kbdmouse.cpp */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -