PS/2 Mouse irq's not firing/firing once.
Posted: Mon Sep 21, 2020 11:44 pm
This is my first time on the OSDev Forums so excuse the style of the question. This was y question from stackoverflow so the "edits" are not actually edits.
I have written "some" keyboard drivers and I wanted make a little mouse support, maybe a cursor. I read several guides on ps/2 mouse especially on the wiki and copied a bunch of code from Sanik's to start. (viewtopic.php?t=10247)
However I cannot get the mouse to respond. I initialise the mouse and setup irq12 but the output is not consistent. Here is the code.
I call this directly from the kernel after the interrupts are setup. I know for a fact that irq's work because keyboard works. This next code is the mouse handler. I call a printf after I get the mouse_x.
The problem is I get 3 outputs at the initalisation and I don't get any more output when I move the mouse. However, the first time I wrote this code it did work. I got a bunch of values outputted when I moved the mouse but the next time I compiled it without changing any code it stopped working which is funny.
What may the problem be? I am running this on QEmu.
Important edit:
I just kept making little changes and I didnt change anything related to the mouse code however I got the following output
This is the output I got as I moved the mouse. It is very interesting because I didn't change anything at all. The code that didn't work before now works, and it is likely to get broken in the future.
Edit: I think I know the problem. If I were to run the program on qemu and at the moment it runs, click on the qemu screen so I can capture the input; the mouse is detected and some garbage is printed on the screen (that garbage is the unformatted deltaXs). The problem is that if I wait for a moment before clicking the screen I think the mouse is not detected thus it is not emulated as a ps/2 mouse in the qemu therefore it is not initialised. How can I resolve this issue.
Edit: These are the output with printf("%d", mouse_x) they make more sense
These are the deltaX from the mouse which means it works. The problem is with the timing that the mouse is connected to the computer. How can I solve the problem?
So the overall problem is that I need to detect the mouse being plugged into the computer (or QEmu in this case) and initialise the mouse after it is plugged. Is this normal behaviour? How can I solve the issue?
Feel free to request more code. Thank you.
I have written "some" keyboard drivers and I wanted make a little mouse support, maybe a cursor. I read several guides on ps/2 mouse especially on the wiki and copied a bunch of code from Sanik's to start. (viewtopic.php?t=10247)
However I cannot get the mouse to respond. I initialise the mouse and setup irq12 but the output is not consistent. Here is the code.
Code: Select all
void mouse_install()
{
unsigned char _status; //unsigned char
mouse_write(0xFF);
mouse_read();
//Enable the interrupts
mouse_wait(1);
outb(0x64, 0x20);
mouse_wait(0);
_status=inb(0x60);
_status = (_status | 2) ;
mouse_wait(1);
outb(0x64, 0x60);
mouse_wait(1);
outb(0x60, _status);
mouse_read();
//Enable the mouse
mouse_write(0xF4);
mouse_read(); //Acknowledge
}
Code: Select all
void irq12_handler(interrupt_frame_t* frame) //struct regs *a_r (not used but just there)
{
switch(mouse_cycle)
{
case 0:
mouse_byte[0]=inb(0x60);
mouse_cycle++;
break;
case 1:
mouse_byte[1]=inb(0x60);
mouse_cycle++;
break;
case 2:
mouse_byte[2]=inb(0x60);
mouse_x = mouse_byte[1];
mouse_y = mouse_byte[2];
mouse_cycle=0;
break;
}
printf(mouse_x);
default_irq_handler(frame); // <- This is just outb(0x20, 0x20); outb(0xA0, 0x20);
}
What may the problem be? I am running this on QEmu.
Important edit:
I just kept making little changes and I didnt change anything related to the mouse code however I got the following output
This is the output I got as I moved the mouse. It is very interesting because I didn't change anything at all. The code that didn't work before now works, and it is likely to get broken in the future.
Edit: I think I know the problem. If I were to run the program on qemu and at the moment it runs, click on the qemu screen so I can capture the input; the mouse is detected and some garbage is printed on the screen (that garbage is the unformatted deltaXs). The problem is that if I wait for a moment before clicking the screen I think the mouse is not detected thus it is not emulated as a ps/2 mouse in the qemu therefore it is not initialised. How can I resolve this issue.
Edit: These are the output with printf("%d", mouse_x) they make more sense
These are the deltaX from the mouse which means it works. The problem is with the timing that the mouse is connected to the computer. How can I solve the problem?
So the overall problem is that I need to detect the mouse being plugged into the computer (or QEmu in this case) and initialise the mouse after it is plugged. Is this normal behaviour? How can I solve the issue?
Feel free to request more code. Thank you.