PS-2 Mouse Interfacing

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
User avatar
XCHG
Member
Member
Posts: 416
Joined: Sat Nov 25, 2006 3:55 am
Location: Wisconsin
Contact:

PS-2 Mouse Interfacing

Post by XCHG »

I am trying to interface with a PS-2 mouse device in this test OS and I was wondering if what I am doing is correct. I would appreciate it if somebody could confirm this:

1. I send command 0x20 to the On-board Keyboard controller at port 0x64.
2. Read the Keyboard controller command byte at port 0x60.
3. Enable Bit#1 in the command byte to enable the PS-2 mouse.
4. I sent command 0x60 to the On-board keyboard controller at port 0x64.
5. I then send the modified byte at the 3rd step to port 0x60 to enable the PS-2 mouse.
6. Send the command 0xF5 to port 0x60 to disable mouse’s streaming mode.
7. I then send the command 0xFF to port 0x60 to reset the mouse.
8. Send the command 0xEA to port 0x60 to enable Streaming Mode.
9. Send the command 0xE9 to port 0x60 to ask the mouse to reports its 3-byte status.

The problem is that the mouse seems to be replying with proper acknowledge messages but the status byte reported at the 9th step returns 3 acknowledge bytes (0xFA). Can anybody help me fix this, please?
pcmattman
Member
Member
Posts: 2566
Joined: Sun Jan 14, 2007 9:15 pm
Libera.chat IRC: miselin
Location: Sydney, Australia (I come from a land down under!)
Contact:

Post by pcmattman »

You have to wait for the mouse to recieve and process the command. If you try to retrieve data before it's ready, you'll get the same data as you read before.
User avatar
XCHG
Member
Member
Posts: 416
Joined: Sat Nov 25, 2006 3:55 am
Location: Wisconsin
Contact:

Post by XCHG »

I wait for approximately half a second (~500 Milliseconds) after sending and before receiving any data. I will post the code here if I can't fix it. Thank you.
pcmattman
Member
Member
Posts: 2566
Joined: Sun Jan 14, 2007 9:15 pm
Libera.chat IRC: miselin
Location: Sydney, Australia (I come from a land down under!)
Contact:

Post by pcmattman »

Just a thought - why don't you just loop while you recieve '0xFA'? Then, when you recieve something else, the loop breaks and you can then get the proper data. Of course, you'd only use this for your testing to find out if the mouse is in fact sending you the packet, but then you could also find out how long to wait.
User avatar
Brendan
Member
Member
Posts: 8561
Joined: Sat Jan 15, 2005 12:00 am
Location: At his keyboard!
Contact:

Post by Brendan »

Hi,
XCHG wrote:I wait for approximately half a second (~500 Milliseconds) after sending and before receiving any data.
For polling, you need to check the keyboard controller's status register before trying to read data from it's 1 byte keyboard buffer. Most online demo code won't show this (either because they use interrupts like sane people, or they aren't very good) - it's worth downloading one (or more) datasheets like this to get better information...

Also note that most keyboard controller datasheets have an output buffer (for data going out of the controller to the computer) and an input buffer (for data going into the controller from the computer). This seems completely around the wrong way to people like us...


Cheers,

Brendan
For all things; perfection is, and will always remain, impossible to achieve in practice. However; by striving for perfection we create things that are as perfect as practically possible. Let the pursuit of perfection be our guide.
Post Reply