Mouse Input: Difference between revisions

From OSDev.wiki
Jump to navigation Jump to search
[unchecked revision][unchecked revision]
Content added Content deleted
(Removed conversion tag.)
(added category 'common devices')
Line 51: Line 51:
* [http://www.osdev.org/phpBB2/viewtopic.php?t=8323 PS2 mouse IRQ]
* [http://www.osdev.org/phpBB2/viewtopic.php?t=8323 PS2 mouse IRQ]
* [http://www.osdev.org/phpBB2/viewtopic.php?t=6942 PS2 mouse links]
* [http://www.osdev.org/phpBB2/viewtopic.php?t=6942 PS2 mouse links]

[[Category:Common Devices]]

Revision as of 03:19, 24 October 2007

PS/2 Mouse Input

The mouse is read just like described on the PS2 Keyboard 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