⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ps2port.cpp

📁 三星2410的BSP开发包
💻 CPP
📖 第 1 页 / 共 2 页
字号:

	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 != response8042Ack )
		{
		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);
	
	//ui8Data should contain response8042Ack   
	if ( !OutputBufPollRead(&ui8Data) )
		{
		goto leave;
		}

	//ui8Data should contain mouse ID
	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::
SetModeIntelliMouse:

Set mouse to IntelliMouse mode.  If an IntelliMouse is present:
	1. mouse ID becomes response8042IntelliMouseId
	2. the motion report format changes 
If IntelliMouse not present the mouse ID and motion report format remain at the default values

--*/
void
Ps2Port::
SetModeIntelliMouse(
	void
	)
{
	EnterWrite();

	// IntelliMouse(R) is uniquely identified by issuing the specific series of Set Report Rate commands:
	// 200Hz (0xC8), then 100Hz (0x64), then 80Hz (0x50).  The Set Report Rate commands are valid and we 
	// therefore have to set the report rate back to the default 100Hz (this is done be MouseId() ).
	MouseCommandPut(cmdMouseSetReportRate);
	MouseCommandPut(0xC8);
	MouseCommandPut(cmdMouseSetReportRate);
	MouseCommandPut(0x64);
	MouseCommandPut(cmdMouseSetReportRate);
	MouseCommandPut(0x50);
	
	LeaveWrite();
}	


UINT8
Ps2Port::
MouseId(
	void
	)
{
	UINT8	ui8MouseId;
	
	EnterWrite();
	
	MouseCommandPut(cmdMouseReadId);
	OutputBufPollRead(&ui8MouseId);
	ASSERT(ui8MouseId == response8042Ack);
	
	OutputBufPollRead(&ui8MouseId);

	// Set the report rate back to the default 100Hz
	MouseCommandPut(cmdMouseSetReportRate);
	MouseCommandPut(0x64);

	LeaveWrite();
	return ui8MouseId;
}


/*++

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;
	gdwIoBase = m_iopBase;		// for power handling
	InitializeCriticalSection(&m_csWrite);
	m_cEnterWrites = 0;

	m_bMouseFound = FALSE;
	m_bIntelliMouseFound = 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;
		
		// Read mouse ID to determine if IntelliMouse is present.
		SetModeIntelliMouse();
		if( response8042IntelliMouseId == MouseId() )
			{
			m_bIntelliMouseFound = true;
			}         
		
		CmdByteModify(0, cmdByteDisableAuxInterface);	//	Turn on the aux interface
		MouseCommandPut(cmdMouseEnable);
		}

	bRet = true;

leave:
	return bRet;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -