Mouse Input

From OSDev.wiki
Revision as of 03:22, 7 March 2007 by osdev>Jhawthorn
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

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]

<verbatim>

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);

} </verbatim>


!! 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.

!Todo

  • Basic Packet Format
  • Extended Modes (wheel and five-button mode)
  • Cursor display
  • Anything else...?

Related Threads:

  • [SANiK's mouse code| Forum:7336]
  • [PS2 mouse IRQ| Forum:3888]
  • [PS2 mouse links| Forum:1143]