ps/2 trouble
Posted: Fri Feb 27, 2004 12:00 am
Hi guys,
I'm currently writing a ps/2 mouse driver for the trion project. It uses some low-level procedures that are used by all the high-level ones to interface the hardware:
uchar SendController(uchar command);
uchar ReceiveController();
uchar SendMouse(uchar command);
uchar ReceiveMouse();
These procedures work as expected when I run the kernel from bochs. On real hardware, however, they return (more or less) random rubbish. I suppose that there's some synchronisation problem between the CPU and the ps/2 controller (i.e. I'm not waiting correctly for the mouse/controller to be ready) which doesn't exist when running on an emulator like bochs since the ps/2 controller there answers immediatly.
<C++>
// output_buffer = 1
// input_buffer = 2
// mouse_buffer = 32
uchar Mouse::SendController(uchar command)
{
// Send a command or a command's parameter to the controller
// Wait for the controller to be ready, then send the command
while(Port::ReadByte(0x64) &input_buffer);
Port::WriteByte(0x64, command);
// Wait for the response and return
while(!Port::ReadByte(0x64) &output_buffer);
return Port::ReadByte(0x60);
}
uchar Mouse::ReceiveController()
{
// Used when the controller returns more than 1byte
// Wait for the response and return
while(!Port::ReadByte(0x64) &output_buffer);
return Port::ReadByte(0x60);
}
uchar Mouse::SendMouse(uchar command)
{
// Directly send a command/parameter to the mouse (more comfortable)
// Make sure that neither mouse nor controller are busy
while(Port::ReadByte(0x64) &mouse_buffer);
while(Port::ReadByte(0x64) &input_buffer);
// Send the command
Port::WriteByte(0x64, 0xD4);
Port::WriteByte(0x60, command);
// Wait for the response and return
while(!Port::ReadByte(0x64) &output_buffer);
return Port::ReadByte(0x60);
}
uchar Mouse::ReceiveMouse()
{
// Used when the mouse returns more than 1byte
// Wait for the response and return
while(!Port::ReadByte(0x64) &mouse_buffer);
return Port::ReadByte(0x60);
}
I realy hope that anybody knows where the problem is since there's only very basic information available on how to interface the ps/2 mouse. If somebody knows a good ressource on ps/2 apart from http://govschl.ndsu.nodak.edu/~achapwes ... index.html please let me know.
regards,
gaf (trion: cosmo86)
I'm currently writing a ps/2 mouse driver for the trion project. It uses some low-level procedures that are used by all the high-level ones to interface the hardware:
uchar SendController(uchar command);
uchar ReceiveController();
uchar SendMouse(uchar command);
uchar ReceiveMouse();
These procedures work as expected when I run the kernel from bochs. On real hardware, however, they return (more or less) random rubbish. I suppose that there's some synchronisation problem between the CPU and the ps/2 controller (i.e. I'm not waiting correctly for the mouse/controller to be ready) which doesn't exist when running on an emulator like bochs since the ps/2 controller there answers immediatly.
<C++>
// output_buffer = 1
// input_buffer = 2
// mouse_buffer = 32
uchar Mouse::SendController(uchar command)
{
// Send a command or a command's parameter to the controller
// Wait for the controller to be ready, then send the command
while(Port::ReadByte(0x64) &input_buffer);
Port::WriteByte(0x64, command);
// Wait for the response and return
while(!Port::ReadByte(0x64) &output_buffer);
return Port::ReadByte(0x60);
}
uchar Mouse::ReceiveController()
{
// Used when the controller returns more than 1byte
// Wait for the response and return
while(!Port::ReadByte(0x64) &output_buffer);
return Port::ReadByte(0x60);
}
uchar Mouse::SendMouse(uchar command)
{
// Directly send a command/parameter to the mouse (more comfortable)
// Make sure that neither mouse nor controller are busy
while(Port::ReadByte(0x64) &mouse_buffer);
while(Port::ReadByte(0x64) &input_buffer);
// Send the command
Port::WriteByte(0x64, 0xD4);
Port::WriteByte(0x60, command);
// Wait for the response and return
while(!Port::ReadByte(0x64) &output_buffer);
return Port::ReadByte(0x60);
}
uchar Mouse::ReceiveMouse()
{
// Used when the mouse returns more than 1byte
// Wait for the response and return
while(!Port::ReadByte(0x64) &mouse_buffer);
return Port::ReadByte(0x60);
}
I realy hope that anybody knows where the problem is since there's only very basic information available on how to interface the ps/2 mouse. If somebody knows a good ressource on ps/2 apart from http://govschl.ndsu.nodak.edu/~achapwes ... index.html please let me know.
regards,
gaf (trion: cosmo86)