ps2port.cpp
来自「WinCE 3.0 BSP, 包含Inter SA1110, Intel_815」· C++ 代码 · 共 986 行 · 第 1/2 页
CPP
986 行
EnterWrite();
if ( !CommandPut(cmd8042SelfTest) )
{
goto leave;
}
if ( !OutputBufPollRead(&ui8Data) )
{
goto leave;
}
if ( ui8Data != 0x55 )
{
ASSERT(0);
goto leave;
}
bRet = true;
leave:
if ( !bRet )
{
}
LeaveWrite();
return bRet;
}
/*++
Ps2Port::
KeyboardInterfaceTest:
Writes the keyboard interface test command to the 8042 command register
and reads the response.
Returns true if the success response is read.
--*/
bool
Ps2Port::
KeyboardInterfaceTest(
void
)
{
bool bRet = false;
UINT8 ui8Data;
EnterWrite();
if ( !CommandPut(cmd8042KeyboardInterfaceTest) )
{
goto leave;
}
if ( !OutputBufPollRead(&ui8Data) )
{
goto leave;
}
if ( ui8Data != 0x00 )
{
ASSERT(0);
goto leave;
}
bRet = true;
leave:
if ( !bRet )
{
}
LeaveWrite();
return bRet;
}
/*++
Ps2Port::
KeyboardCommandPut:
Writes a command to the keyboard and reads the response.
Returns true if the success response code is read.
--*/
bool
Ps2Port::
KeyboardCommandPut(
UINT8 ui8Cmd
)
{
bool bRet = false;
UINT8 ui8Data;
EnterWrite();
if ( !InputBufPut(ui8Cmd) )
{
goto leave;
}
if ( !OutputBufPollRead(&ui8Data) )
{
goto leave;
}
if ( ui8Data != 0xFA )
{
ASSERT(0);
goto leave;
}
bRet = true;
leave:
LeaveWrite();
return bRet;
}
/*++
Ps2Port::
KeyboardReset:
Sends the keyboard reset command to the keyboard and reads the response.
Returns true if the success response is read.
--*/
bool
Ps2Port::
KeyboardReset(
void
)
{
bool bRet = false;
UINT8 ui8Data;
EnterWrite();
if ( !KeyboardCommandPut(cmdKeybdReset) )
{
goto leave;
}
if ( !OutputBufPollRead(&ui8Data) )
{
goto leave;
}
if ( ui8Data != 0xAA )
{
ASSERT(0);
goto leave;
}
bRet = true;
leave:
if ( !bRet )
{
}
LeaveWrite();
return bRet;
}
/*++
Ps2Port::
KeyboardLights:
Sets the keyboard indicator lights.
--*/
void
Ps2Port::
KeyboardLights(
unsigned int fLights
)
{
EnterWrite();
if ( !KeyboardCommandPut(cmdKeybdLights) )
{
goto leave;
}
if ( !KeyboardCommandPut(fLights) )
{
goto leave;
}
leave:
LeaveWrite();
return;
}
/*++
Ps2Port::
CmdByteModify:
Modifies the command byte of the Ps2Port object and writes the changes to
the 8042 command byte.
--*/
bool
Ps2Port::
CmdByteModify(
UINT8 ui8Set,
UINT8 ui8Clear
)
{
bool bRet = false;
EnterWrite();
m_ui8CmdByte |= ui8Set;
m_ui8CmdByte &= ~ui8Clear;
bRet = true;
LeaveWrite();
return bRet;
}
/*++
Ps2Port::
MouseCommandPut:
Writes a command to the auxiliary device.
--*/
void
Ps2Port::
MouseCommandPut(
UINT8 cmd
)
{
EnterWrite();
CommandPut(cmd8042AuxDeviceWrite);
InputBufPut(cmd);
LeaveWrite();
return;
}
/*++
Ps2Port::
MouseTest:
Tests for a mouse present on the 8042 auxiliary port.
Returns true if a mouse is found.
--*/
bool
Ps2Port::
MouseTest(
void
)
{
bool bRet = false;
UINT8 ui8Data;
EnterWrite();
MouseCommandPut(cmdMouseReadId);
if ( !OutputBufPollRead(&ui8Data) )
{
goto leave;
}
if ( !OutputBufPollRead(&ui8Data) )
{
goto leave;
}
bRet = true;
leave:
if ( !bRet )
{
// RETAILMSG(1,(TEXT("MouseTest fails. Mouse probably not present.\r\n")));
}
LeaveWrite();
return bRet;
}
/*++
Ps2Port::
MouseDataRead:
Reads data from the 8042 output port.
--*/
bool
Ps2Port::
MouseDataRead(
UINT8 *pui8Data
)
{
if ( !AuxOutputBufIsFull() )
{
ERRORMSG(1, (TEXT("MouseDataRead: Mouse data not ready\r\n")));
}
*pui8Data = ui8OutputBufRead();
return true;
}
/*++
Ps2Port::
MouseInterruptEnable:
Enables 8042 auxiliary interrupts.
--*/
bool
Ps2Port::
MouseInterruptEnable(
void
)
{
EnterWrite();
m_ui8CmdByte |= cmdByteEnableAuxInterrupts;
LeaveWrite();
return true;
}
/*++
Ps2Port::
KeybdInterruptEnable:
Enables 8042 keyboard interrupts.
--*/
bool
Ps2Port::
KeybdInterruptEnable(
void
)
{
EnterWrite();
m_ui8CmdByte |= cmdByteEnableKeybdInterrupts;
LeaveWrite();
return true;
}
/*++
Ps2Port::
KeybdDataRead:
Reads data from 8042 output port.
--*/
bool
Ps2Port::
KeybdDataRead(
UINT8 *pui8Data
)
{
if ( !MainOutputBufIsFull() )
{
ERRORMSG(1, (TEXT("KeybdDataRead: Keybd data not ready\r\n")));
}
*pui8Data = ui8OutputBufRead();
return TRUE;
}
/*++
Ps2Port::
Initialize:
Initializes the Ps2Port object.
--*/
bool
Ps2Port::
Initialize(
unsigned int iopBase
)
{
bool bRet = false;
m_iopBase = iopBase;
InitializeCriticalSection(&m_csWrite);
m_cEnterWrites = 0;
m_bMouseFound = FALSE;
// Read the current command byte by sending command and reading the output buffer.
if ( !InputBufPollForEmpty() )
{
goto leave;
}
// Since we are probably booting from DOS, the keyboard controller
// in some initial unknown state. We read the state and disable the
// keyboard interrupts until the keyboard initialized. If we were
// booting from scratch, we should probably go right to the self-test.
// Read the existing command byte from the controller. We
// keep a copy in the instance data and then modify it via CmdByteModify.
CommandWrite(cmd8042ReadModeByte);
OutputBufPollRead(&m_ui8CmdByte);
// Turn on the keyboard interface but turn off keyboard interrupts until ready.
// Enable AT/PS2 to XT translation.
CmdByteModify(cmdByteEnableXTTranslation, cmdByteEnableKeybdInterrupts|cmdByteDisableKeybdInterface);
if ( !SelfTest() )
{
goto leave;
}
if ( MouseTest() )
{
m_bMouseFound = TRUE;
CmdByteModify(0, cmdByteDisableAuxInterface); // Turn on the aux interface
MouseCommandPut(cmdMouseEnable);
}
bRet = true;
leave:
return bRet;
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?