Page 1 of 1

ps/2 mouse problems

Posted: Sat Nov 10, 2007 8:49 am
by sigler
Hello,

I'm trying to get ps/2 mouse to work.

I've tried all sorts of things, but here's a simple case that doesn't work:

Code: Select all


void wait_for_input()
{
	for(;;)
	{
		if ((inb(0x64) & 2) == 0)
			break;
	}
}

void wait_for_output()
{
	for(;;)
	{
		if (inb(0x64) & 1)
			break;
	}
}

void write_mouse_ack(byte data)
{
	for (;;)
	{

		wait_for_input();
		outb(0x64, 0xD4);	// Write to mouse

		wait_for_input();
		outb(0x60, data);

		wait_for_output();
		byte scancode = inb(0x60);

		if (scancode == 0xFA)
		{
			return;
		}

		printstr("no ack\n");
	}
}

If I then do this:

Code: Select all

	write_mouse_ack(0xF4);	// Enable data reporting

// I know I also might set the control byte to enable mouse and irq, but it is already set correctly

// I have also installed isr for keyboard and mouse

The above line operates correctly, and ack is received from the mouse, but it doesn't have the desired effect. My mouse interrupt is not getting called, and the keyboard interrupt also stops getting called (the keyboard previously worked) It seems like sending any commands to the mouse (with 0xD4) stops the keyboard from sending any keyboard interrupts (in addition to not making the mouse work).

(I also tried disabling mouse data reporting with:

Code: Select all

write_mouse_ack(0xF5)
but it didn't reenable the keyboard

Does anybody have any idea of what I might try next ?

thanks,

--
Sigurd Lerstad

Posted: Sat Nov 10, 2007 11:56 am
by XCHG
I used to have problems with PS/2, with almost similar causes, too. What I do now for initializing the PS/2 mouse is:

Code: Select all

    INVOKE  __PS2MouseDisableMouseInterrupts
    INVOKE  __PS2MouseDisableMouseDevice
    INVOKE  __PS2MouseSendCommandToTheMouseAndGetResult, PS2MOUSE_MOUSECOMMAND_DISABLEDATAREPORTING , 0x00000001
    INVOKE  __PS2MouseSendCommandToTheMouseAndGetResult, PS2MOUSE_MOUSECOMMAND_SETSTREAMMODE        , 0x00000001
    INVOKE  __PS2MouseSendCommandToTheMouseAndGetResult, PS2MOUSE_MOUSECOMMAND_ENABLEDATAREPORTING  , 0x00000001
    INVOKE  __PS2MouseEnableMouseDevice
    INVOKE  __PS2MouseEnableMouseInterrupts
1) Disable interrupts for mouse using the onboard Keyboard Microcontroller.
2) Disable the PS/2 mouse using the Onboard Keyboard Microcontroller Command Byte.
3) Disable data reporting.
4) Set the reporting mode to Stream Mode.
5) Enable Data Reporting.
6) Enable the PS/2 mouse device.
7) Enable interrupts for the Mouse Device.

Posted: Sat Nov 10, 2007 8:36 pm
by bewing
This sounds like a possible EOI problem to me, or something similar.
Of course, there are complications that make me uncertain.
But I am suspecting that the problem is that you are stealing that ACK byte out of the mouse input stream before the IRQ12 is properly handled.

Then the keyboard/mouse locks up, waiting for the OS to acknowledge the receipt of the byte.

I know I have seen threads on this board about keyboards locking up after transmitting just one scancode -- you might search for those, and read some of them to find out what the eventual solution was.

Posted: Sun Nov 11, 2007 5:56 pm
by sigler
Solved, It turns that I DID get a mouse interrupt... (I feel stupid :)

--
Sigurd Lerstad