📄 s3c2410kbd.cpp
字号:
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
//
// Use of this source code is subject to the terms of the Microsoft end-user
// license agreement (EULA) under which you licensed this SOFTWARE PRODUCT.
// If you did not accept the terms of the EULA, you are not authorized to use
// this source code. For a copy of the EULA, please see the LICENSE.RTF on your
// install media.
//
#include <windows.h>
#include <ceddk.h>
#include <nkintr.h>
#include <nled.h>
#undef ZONE_INIT
#include <keybddbg.h>
#include <keybddr.h>
#include <keybdpdd.h>
#include <keybdist.h>
#include "s3c2410kbd.hpp"
#include "S2410.h"
#include "oalintr.h"
// Pointer to device control registers
volatile IOPreg *v_pIOPregs;
//volatile S3C2440A_SPI_REG *v_pSPIregs;
static DWORD g_dwSysIntr_Keybd[MAX_HDKEY] = {SYSINTR_EINT1,SYSINTR_EINT2,SYSINTR_EINT3};
DWORD dwIrq_Keybdbuf[]={INTSRC_EINT1,INTSRC_EINT2,INTSRC_EINT3};
// Scan code consts
static const UINT8 scE0Extended = 0xe0;
static const UINT8 scE1Extended = 0xe1;
static const UINT8 scKeyUpMask = 0x80;
UINT32
ScanCodeToVKeyEx(
UINT32 ScanCode,
KEY_STATE_FLAGS KeyStateFlags,
UINT32 VKeyBuf[16],
UINT32 ScanCodeBuf[16],
KEY_STATE_FLAGS KeyStateFlagsBuf[16]
);
// There is really only one physical keyboard supported by the system.
Ps2Keybd *v_pp2k;
extern void ReadRegDWORD( LPCWSTR szKeyName, LPCWSTR szValueName, LPDWORD pdwValue );
void WINAPI KeybdPdd_PowerHandler(BOOL bOff)
{
if (!bOff) {
v_pp2k->KeybdPowerOn();
}
else {
v_pp2k->KeybdPowerOff();
}
return;
}
#define ONEBIT 0x1
#if 0
int putcToKBCTL(UCHAR c)
{
UINT i;
v_pIOPregs->GPBDAT &= ~(ONEBIT << 6); //Set _SS signal to low (Slave Select)
while((v_pSPIregs->SPSTA1 & ONEBIT)==0); // wait while busy
v_pSPIregs->SPTDAT1 = c; // write left justified data
while((v_pSPIregs->SPSTA1 & ONEBIT)==0); // wait while busy
v_pIOPregs->GPBDAT |= (ONEBIT << 6); //Set _SS signal to high (Slave Select)
i = v_pSPIregs->SPRDAT1;
return(i);
}
void getsFromKBCTL(UINT8 *m, int cnt) {
int i, j;
volatile tmp = 1;
for(j = 0; j < 3; j++)
tmp += tmp;
for(j = 0; j < 250 * 30; j++)
tmp += tmp;
for(i = 0; i < cnt; i++) {
m[i] = putcToKBCTL(0xFF);
for(j = 0; j < 400; j++)
tmp+= tmp;
}
}
void putsToKBCTL(UINT8 *m, int cnt)
{
int i, j, x;
volatile tmp = 1;
for(j = 0; j < 3; j++)
x = j;
for(j = 0; j < 3; j++)
tmp += tmp;
for(j = 0; j < 250 * 30; j++)
tmp += tmp;
for(i = 0; i < cnt; i++) {
j = putcToKBCTL(m[i]);
for(j = 0; j < 400; j++)
tmp+= tmp;
for(j = 0; j < 400; j++)
x = j;
}
}
char lrc(UINT8 *buffer, int count)
{
char lrc;
int n;
lrc = buffer[0] ^ buffer[1];
for (n = 2; n < count; n++)
{
lrc ^= buffer[n];
}
if (lrc & 0x80)
lrc ^= 0xC0;
return lrc;
}
int USAR_WriteRegister(int reg, int data)
{
UINT8 cmd_buffer[4];
cmd_buffer[0] = 0x1b; //USAR_PH_WR;
cmd_buffer[1] = (unsigned char)reg;
cmd_buffer[2] = (unsigned char)data;
cmd_buffer[3] = lrc((UINT8 *)cmd_buffer,3);
putsToKBCTL((UINT8 *)cmd_buffer,4);
return TRUE;
}
#endif
BOOL
KeybdDriverInitializeAddresses(
void
)
{
bool RetValue = TRUE;
DWORD dwIOBase;
// DWORD dwSSPBase;
DEBUGMSG(1,(TEXT("++KeybdDriverInitializeAddresses\r\n")));
ReadRegDWORD(TEXT("HARDWARE\\DEVICEMAP\\KEYBD"), _T("IOBase"), &dwIOBase );
if(dwIOBase == 0) {
DEBUGMSG(1, (TEXT("Can't fount registry entry : HARDWARE\\DEVICEMAP\\KEYBD\\IOBase\r\n")));
goto error_return;
}
DEBUGMSG(1, (TEXT("HARDWARE\\DEVICEMAP\\KEYBD\\IOBase:%x\r\n"), dwIOBase));
#if 0
ReadRegDWORD(TEXT("HARDWARE\\DEVICEMAP\\KEYBD"), _T("SSPBase"), &dwSSPBase );
if(dwSSPBase == 0) {
DEBUGMSG(1, (TEXT("Can't fount registry entry : HARDWARE\\DEVICEMAP\\KEYBD\\SSPBase\r\n")));
goto error_return;
}
DEBUGMSG(1, (TEXT("HARDWARE\\DEVICEMAP\\KEYBD\\SSPBase:%x\r\n"), dwSSPBase));
#endif
v_pIOPregs = (volatile IOPreg *)VirtualAlloc(0, sizeof(IOPreg), MEM_RESERVE, PAGE_NOACCESS);
if(v_pIOPregs == NULL) {
DEBUGMSG(1,(TEXT("[KBD] v_pIOPregs : VirtualAlloc failed!\r\n")));
goto error_return;
}
else {
if(!VirtualCopy((PVOID)v_pIOPregs, (PVOID)(dwIOBase), sizeof(IOPreg), PAGE_READWRITE|PAGE_NOCACHE ))
{
DEBUGMSG(1,(TEXT("[KBD] v_pIOPregs : VirtualCopy failed!\r\n")));
goto error_return;
}
}
RETAILMSG(1, (TEXT("[KBD] IOBase 0x%X,v_pIOPregs mapped at %x\r\n"), dwIOBase,v_pIOPregs));
#if 0
v_pSPIregs = (volatile S3C2440A_SPI_REG *)VirtualAlloc(0, sizeof(S3C2440A_SPI_REG), MEM_RESERVE, PAGE_NOACCESS);
if (v_pSPIregs == NULL) {
DEBUGMSG(1, (TEXT("[KBD] v_pSPIregs : VirtualAlloc failed!\r\n")));
goto error_return;
}
else {
if (!VirtualCopy((PVOID)v_pSPIregs, (PVOID)(dwSSPBase), sizeof(S3C2440A_SPI_REG), PAGE_READWRITE | PAGE_NOCACHE))
{
DEBUGMSG(1, (TEXT("[KBD] v_pSPIregs : VirtualCopy failed!\r\n")));
goto error_return;
}
}
DEBUGMSG(1, (TEXT("[KBD] v_pSPIregs mapped at %x\r\n"), v_pSPIregs));
#endif
DEBUGMSG(1,(TEXT("--KeybdDriverInitializeAddresses\r\n")));
return TRUE;
error_return:
if ( v_pIOPregs )
VirtualFree((PVOID)v_pIOPregs, 0, MEM_RELEASE);
// if ( v_pSPIregs )
// VirtualFree((PVOID)v_pSPIregs, 0, MEM_RELEASE);
v_pIOPregs = 0;
// v_pSPIregs = 0;
DEBUGMSG(1,(TEXT("--KeybdDriverInitializeAddresses[FAILED!!!]\r\n")));
return FALSE;
}
#if 0
static UINT KeybdPdd_GetEventEx2(UINT uiPddId, UINT32 rguiScanCode[16], BOOL rgfKeyUp[16])
{
SETFNAME(_T("KeybdPdd_GetEventEx2"));
UINT32 scInProgress = 0;
static UINT32 scPrevious;
BOOL fKeyUp;
UINT8 ui8ScanCode;
UINT cEvents = 0;
DEBUGCHK(rguiScanCode != NULL);
DEBUGCHK(rgfKeyUp != NULL);
getsFromKBCTL(&ui8ScanCode, 1);
DEBUGMSG(ZONE_SCANCODES,
(_T("%s: scan code 0x%08x, code in progress 0x%08x, previous 0x%08x\r\n"),
pszFname, ui8ScanCode, scInProgress, scPrevious));
scInProgress = ui8ScanCode;
if (scInProgress == scPrevious) {
// mdd handles auto-repeat so ignore auto-repeats from keybd
} else {
// Not a repeated key. This is the real thing.
scPrevious = scInProgress;
if (ui8ScanCode & scKeyUpMask) {
fKeyUp = TRUE;
scInProgress &= ~scKeyUpMask;
} else {
fKeyUp = FALSE;
}
rguiScanCode[cEvents] = scInProgress;
rgfKeyUp[cEvents] = fKeyUp;
++cEvents;
}
return cEvents;
}
#endif
void WINAPI KeybdPdd_ToggleKeyNotification(KEY_STATE_FLAGS KeyStateFlags)
{
unsigned int fLights;
DEBUGMSG(1, (TEXT("KeybdPdd_ToggleKeyNotification\r\n")));
fLights = 0;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -