Mouse Input: Difference between revisions

From OSDev.wiki
Jump to navigation Jump to search
[unchecked revision][unchecked revision]
Content added Content deleted
No edit summary
m (Fixing the See Also Thread links)
Line 51: Line 51:
==See Also==
==See Also==
===Threads===
===Threads===
* [SANiK's mouse code| Forum:7336]
* [http://www.osdev.org/phpBB2/viewtopic.php?t=10247 SANiK's mouse code]
* [PS2 mouse IRQ| Forum:3888]
* [http://www.osdev.org/phpBB2/viewtopic.php?t=8323 PS2 mouse IRQ]
* [PS2 mouse links| Forum:1143]
* [http://www.osdev.org/phpBB2/viewtopic.php?t=6942 PS2 mouse links]

Revision as of 05:15, 11 September 2007

Template:Convert

PS/2 Mouse Input

The mouse is read just like described on the [Getting Keyboard Input] page, except that any write to the mouse must be preceded by writing 0xD4 to port 0x64, and then writing your byte to port 0x60. For more information, see [1]


inline void mouse_wait(byte a_type)
{
  dword _time_out=100000;
  if(a_type==WAIT_FOR_DATA) {
    while(_time_out--) {
      if((inportb(0x64) & 1)==1)
        return;
    }
    return;
  } else { // WAIT_FOR_SIGNAL
    while(_time_out--) {
      if((inportb(0x64) & 2)==0)
        return;
    }
    return;
  }
}

inline void mouse_write(byte a_write)
{

  mouse_wait(WAIT_FOR_SIGNAL);   //Wait to be able to send a command
  outportb(0x64, 0xD4);          //Tell PS2 we are sending a command to the mouse
  mouse_wait(WAIT_FOR_SIGNAL);
  outportb(0x60, a_write);       //Finally write data byte.
}

byte mouse_read()
{
  mouse_wait(WAIT_FOR_DATA);     //Get's response from mouse
  return inportb(0x60);
}


Initialization

You'll basically have to send a couple of commands to the PS2 controller (not to the mouse itself), so that it enables auxiliary device (command 0xA8), enable interrupts on that device (command 0x20 to read the status, then command 0x60 to write the status back, with bit 1 set).

Once this is done, you can send the "SET_DEFAULTSETTINGS" mouse command using mouseWrite above, then the "ENABLE" command. See SANiK's driver for details.


See Also

Threads