📄 keybdpdd.cpp
字号:
//**********************************************************************
//
// Filename: keybdpdd.cpp
//
// Description: Contains keyboard pdd routins.
//
// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
// ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
// THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
// PARTICULAR PURPOSE.
// Copyright(c) Cirrus Logic Corporation 2001, All Rights Reserved
//
//**********************************************************************
//
// 'C" includes
//
//
// 'C++' includes
//
#include <windows.h>
#include <keybddr.h>
#include <nkintr.h>
#include <oalintr.h>
#include <keybdpdd.h>
#include <kbd.h>
/*=============================================================================
> DEFINITIONS LOCAL TO THIS FILE <
-----------------------------------------------------------------------------*/
// Be careful to do pointer arithmetic as chars.
#define REG32(base, id) (*((PVUINT32)(((char*)(base))+(id))))
#define REG16(base, id) (*((PVUINT16)(((char*)(base))+(id))))
#define REG8(base, id) (*((PVUINT8)(((char*)(base))+(id))))
#define USE_REGISTRY 0
static KEY_STATE_FLAGS v_KeyStateToggled;
typedef volatile BYTE *PVBYTE;
typedef volatile DWORD *PVDWORD;
typedef volatile UINT32 *PVUINT32;
typedef volatile UINT16 *PVUINT16;
//
// Debug zones.
//
#define ZONE_INIT DEBUGZONE(0)
#define ZONE_WARN DEBUGZONE(14)
#define ZONE_ERROR DEBUGZONE(15)
extern unsigned long gpKeyMap[8][8];
/*=============================================================================
> PUBLIC DEFINITIONS INTENTED FOR USE BY THE MDD LAYER ONLY<
-----------------------------------------------------------------------------*/
const DWORD gIntrKeyboard = SYSINTR_KEYBOARD;
//****************************************************************************
// KeybdPowerOn
//****************************************************************************
// Power on the keyboard.
//
//
static void KeybdPowerOn( void )
{
DEBUGMSG(ZONE_INIT,(TEXT("KeybdPowerOn")));
GKBD_Enable(TRUE);
//KBD_IRQ_ON(g_pIrqBase);
return;
}
//****************************************************************************
// KeybdPowerOff
//****************************************************************************
// Power off the keyboard
//
//
static void KeybdPowerOff()
{
DEBUGMSG(ZONE_INIT,(TEXT("KeybdPowerOff")));
GKBD_Enable(FALSE);
//KBD_IRQ_OFF(g_pIrqBase);
return;
}
//****************************************************************************
// KeybdPdd_PowerHandler
//****************************************************************************
// @comm This routine runs in kernel context and assumes that interrupts are
// disabled since it monkeys directly with registers. It may not make any
// system calls or cause a reschedule in any way. You can read and write to
// your own memory and that is about it. If you put any subroutines inside
// here, they must also follow this restriction.
//
void WINAPI KeybdPdd_PowerHandler
(
BOOL bOff // @parm TRUE, the system is powering off; FALSE, the system is powering up.
)
{
if (bOff)
KeybdPowerOff();
else
KeybdPowerOn();
return;
}
//****************************************************************************
// KeybdPdd_InitializeDriver
//****************************************************************************
// On entry from the model device driver, the keyboard hardware is
// initialized.
//
//
BOOL WINAPI
KeybdPdd_InitializeDriver
(
PFN_KEYBD_EVENT_CALLBACK pfnKeybdEventCallback // @parm The callback into the input system.
)
{
TCHAR szText[64];
DEBUGMSG(ZONE_INIT,(TEXT("KeybdPdd_InitializeDriver")));
(*pfnKeybdEventCallback)(KEYBD_DEVICE_CONNECT,0);
KeybdPowerOn();
GKBD_SetDebounce(0xfc);
GKBD_SetPreScale(0xfa);
#if 0
DEBUGMSG(ZONE_WARN,(TEXT("----------- REGISTER DUMP AFTER ----------------")));
wsprintf(szText,TEXT(" STARTING ADDRESS VIRTUAL: 0x%08x"),(unsigned long)pReg);
DEBUGMSG(ZONE_WARN,(szText));
wsprintf(szText,TEXT("STARTING ADDRESS PHYSICAL: 0x%08x"),(unsigned long)KBD_BASE);
DEBUGMSG(ZONE_WARN,(szText));
wsprintf(szText,TEXT(" SCANINIT KEY Base + 0x00: 0x%08x"),(unsigned long)*pReg);
DEBUGMSG(ZONE_WARN,(szText));
pReg++;
wsprintf(szText,TEXT(" DIAG KEY Base + 0x04: 0x%08x"),(unsigned long)*pReg);
DEBUGMSG(ZONE_WARN,(szText));
pReg++;
wsprintf(szText,TEXT(" KEY_REG KEY Base + 0x08: 0x%08x"),(unsigned long)*pReg);
DEBUGMSG(ZONE_WARN,(szText));
pReg++;
wsprintf(szText,TEXT(" KEY_TCR KEY Base + 0x10: 0x%08x"),(unsigned long)*pReg);
DEBUGMSG(ZONE_WARN,(szText));
pReg++;
wsprintf(szText,TEXT(" KEY_TISR KEY Base + 0x14: 0x%08x"),(unsigned long)*pReg);
DEBUGMSG(ZONE_WARN,(szText));
pReg++;
wsprintf(szText,TEXT(" KEY_TOCR KEY Base + 0x18: 0x%08x"),(unsigned long)*pReg);
DEBUGMSG(ZONE_WARN,(szText));
pReg++;
#endif
GKBD_GetLastR1();
GKBD_GetLastR2();
GKBD_GetLastC1();
GKBD_GetLastC2();
// initialize the keyboard device
GKBD_Enable(TRUE);
return (TRUE);
}
//****************************************************************************
// KeybdPdd_GetEvent
//****************************************************************************
// Called by the MDD to retrieve keyboard events after SYSINTR_KEYBD is
// signalled.
//
INT WINAPI KeybdPdd_GetEvent
(
UINT32 VirtualKeys[16], // @parm Buffer to put virtual keys which were detected.
KEY_STATE_FLAGS KeyEvents[16] // @parm Buffer to put key state flags.
)
{
unsigned char uiPos=0,uiStatus=KeyStateDownFlag;
TCHAR szText1[64],szText2[64];
unsigned char uiRow1,uiCol1;
unsigned char uiRow2,uiCol2;
GKBD_HandleIrq();
uiRow2=GKBD_GetLastR2();
uiCol2=GKBD_GetLastC2();
uiRow1=GKBD_GetLastR1();
uiCol1=GKBD_GetLastC1();
uiStatus=GKBD_GetLastKeyStatus();
ASSERT(uiRow1 && uiCol1 );
VirtualKeys[uiPos]=gpKeyMap[uiRow1-1][uiCol1-1];
if (uiStatus)
KeyEvents[uiPos]=KeyStateDownFlag;
else
KeyEvents[uiPos]=0;
// first detect if there was two keys pressed at
// the same time
if (uiRow2>0 && uiCol2>0)
{
uiPos++;
VirtualKeys[uiPos]=gpKeyMap[uiRow2-1][uiCol2-1];
if (uiStatus)
KeyEvents[uiPos]=KeyStateDownFlag;
else
KeyEvents[uiPos]=0;
wsprintf(szText2,TEXT(" SECOND KEY: (%d,%d)"),uiRow2,uiCol2);
}
// add the last zero position
uiPos++;
VirtualKeys[uiPos]=0;
KeyEvents[uiPos]=0;
if (GKBD_GetLastKeyStatus())
{
wsprintf(szText1,TEXT(" FIRST KEY DOWN: (%d,%d,%d) %s"),uiRow1,
uiCol1,gpKeyMap[uiRow1-1][uiCol1-1],szText2);
}
else
{
wsprintf(szText1,TEXT(" FIRST KEY UP: (%d,%d,%d) %s"),uiRow1,uiCol1,
gpKeyMap[uiRow1-1][uiCol1-1],szText2);
}
DEBUGMSG(ZONE_WARN,(szText1));
//KBD_IRQ_ON(g_pIrqBase);
return (uiPos);
}
//****************************************************************************
// KeybdPdd_ToggleKeyNotification
//****************************************************************************
// Called when keys are toggled on a keyboard.
//
//
void WINAPI KeybdPdd_ToggleKeyNotification
(
KEY_STATE_FLAGS KeyStateFlags
)
{
/*
v_KeyStateToggled = KeyStateFlags;
*/
return;
}
//****************************************************************************
// KeybdPdd_KeyStateToggled
//****************************************************************************
// Informs Windows that a key has been toggled.
//
//
KEY_STATE_FLAGS WINAPI KeybdPdd_KeyStateToggled(void)
{
return v_KeyStateToggled;
}
//****************************************************************************
// KeybdPdd_DllEntry
//****************************************************************************
// Called by the MDD on Dll state changes.
//
//
BOOL WINAPI KeybdPdd_DllEntry
(
HANDLE hinstDLL, // @parm Standard Dll entry arg.
DWORD Op, // @parm Standard Dll entry arg.
LPVOID lpvReserved // @parm Standard Dll entry arg.
)
{
//
//REVIEW shouldn't allow more than one attachment.
//
if ( Op == DLL_PROCESS_ATTACH )
{
DEBUGREGISTER((HINSTANCE)hinstDLL);
//dpCurSettings.ulZoneMask = ZONE_INIT | ZONE_ERROR;
}
return (TRUE);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -