I am writing the code for ps2 mouse.
When i issue the (0xa8) enable aux command my keyboard gets disabled after the mouse irq. I don't get the mouse irq (handler does not run).
Could anybody give me some documentation links to ps2 mouse programming?
Mouse problem (SOLVED)
- salil_bhagurkar
- Member
- Posts: 261
- Joined: Mon Feb 19, 2007 10:40 am
- Location: India
Mouse problem (SOLVED)
Last edited by salil_bhagurkar on Wed Jul 18, 2007 11:59 am, edited 1 time in total.
- salil_bhagurkar
- Member
- Posts: 261
- Joined: Mon Feb 19, 2007 10:40 am
- Location: India
Such lazy people will never write decent program.
http://www.osdev.org/phpBB2/viewtopic.php?t=14125
http://www.osdev.org/phpBB2/viewtopic.php?t=13568
http://www.osdev.org/phpBB2/viewtopic.php?t=13257
http://www.osdev.org/phpBB2/viewtopic.php?t=13204
http://www.osdev.org/phpBB2/viewtopic.php?t=13058
http://www.osdev.org/phpBB2/viewtopic.php?t=13087
http://cutemouse.sourceforge.net/index.html
and that was only 1st page of the search results
maybe forum needs some FAQ
http://www.osdev.org/phpBB2/viewtopic.php?t=14125
http://www.osdev.org/phpBB2/viewtopic.php?t=13568
http://www.osdev.org/phpBB2/viewtopic.php?t=13257
http://www.osdev.org/phpBB2/viewtopic.php?t=13204
http://www.osdev.org/phpBB2/viewtopic.php?t=13058
http://www.osdev.org/phpBB2/viewtopic.php?t=13087
http://cutemouse.sourceforge.net/index.html
and that was only 1st page of the search results
maybe forum needs some FAQ
- salil_bhagurkar
- Member
- Posts: 261
- Joined: Mon Feb 19, 2007 10:40 am
- Location: India
sorry
for the code you can search www.google.com/codesearch & www.koders.com
and look sources of the SolarOS http://www.oby.ro/
look "OS Construction" forum here http://board.flatassembler.net/
http://bos.asmhackers.net/docs/mouse/
sources here have install_mouse function & mention aux device in comments
I think you need to enable both IRQ1 & IRQ12 thru kbd ports like digo_rp suggested
edited: docs:
http://www.nondot.org/sabre/os/articles ... ceDevices/
http://www.osdever.net/cottontail/#Mouse
http://en.wikipedia.org/wiki/Computer_mouse
http://www.computer-engineering.org/ps2mouse/ - good link but it doesn't work for me at the moment, never trust internet, always save
there is pdf called "active PS/2 multiplexing"
for the code you can search www.google.com/codesearch & www.koders.com
and look sources of the SolarOS http://www.oby.ro/
look "OS Construction" forum here http://board.flatassembler.net/
http://bos.asmhackers.net/docs/mouse/
sources here have install_mouse function & mention aux device in comments
I think you need to enable both IRQ1 & IRQ12 thru kbd ports like digo_rp suggested
edited: docs:
http://www.nondot.org/sabre/os/articles ... ceDevices/
http://www.osdever.net/cottontail/#Mouse
http://en.wikipedia.org/wiki/Computer_mouse
http://www.computer-engineering.org/ps2mouse/ - good link but it doesn't work for me at the moment, never trust internet, always save
there is pdf called "active PS/2 multiplexing"
- salil_bhagurkar
- Member
- Posts: 261
- Joined: Mon Feb 19, 2007 10:40 am
- Location: India
Okay i used the code of mystran from the forums...
Here it is:
I have not initiated the keyboard IRQ. I am in a while loop and i am checking for the mouse irq by moving the mouse (and clicking also). But i don't get any IRQ.
Here it is:
Code: Select all
void MouseIRQ()
{
//LocalData.status = GetByte();
//LocalData.xcoord = GetByte();
//LocalData.ycoord = GetByte();
printdev("\nMouse irq");
// readable = 1;
}
int KBD_wait_write() {
unsigned int timeout = 100000;
unsigned char c;
while(--timeout) {
c = inb(0x64);
if(!(c & 2)) {
return 0;
}
}
return -1;
}
int KBD_write(unsigned char byte) {
if(!KBD_wait_write()) {
outb(0x60, byte);
return 0;
}
else return -1;
}
int KBD_write_cmd(unsigned char byte) {
if(!KBD_wait_write()) {
outb(0x64, byte);
return 0;
}
else return -1;
}
int KBD_write_aux(unsigned char byte) {
if(KBD_write_cmd(0xD4) || KBD_write(byte)) return -1;
else return 0;
}
// return unsigned char if success, -1 if fails
int KBD_read() {
unsigned int timeout = 100000;
unsigned char c;
while(--timeout) {
c = inb(0x64);
if(c & 1) {
c = inb(0x60);
return (unsigned) c;
}
}
return -1;
}
int KBD_wait_ack() {
unsigned int timeout = 100000;
while(--timeout) {
unsigned char c = KBD_read();
if(c == 0xFA) return 0; // got ack, we're happy
if(!c) {
// if we get 0, spend some time and retry
int i;
for(i = 0; i < 1000; i++) outb(0x80,0x80);
continue;
} else {
printdev("console_input: 0x%2x while expecting ACK\n", c);
return -1;
}
}
return -1;
}
// init the mouse
static int console_mouse_imps2;
int InitMouse()
{
if(KBD_write_cmd(0xA9) || KBD_read() != 0x00) {
printdev("PS/2 mouse interface test failed.\n");
return -1;
}
// enable PS/2 mouse
KBD_write_cmd(0xA8);
{
// fetch command word
if(KBD_write_cmd(0x20)) return -1;
int cb = KBD_read();
if(cb < 0) return -1;
// set bit1 (aux interrupt),
// store the resulting new command word
if(KBD_write_cmd(0x60)) return -1;
if(KBD_write(cb |= 0x2)) return -1; // <-- only need to set aux-int bit <--
}
// Send set defaults
if(KBD_write_aux(0xF6) || KBD_wait_ack()) return -1;
// Enable data reporting
if(KBD_write_aux(0xF4) || KBD_wait_ack()) return -1;
request_irq(12,MouseIRQ);
enable_irq(12);
while(1);
}
- salil_bhagurkar
- Member
- Posts: 261
- Joined: Mon Feb 19, 2007 10:40 am
- Location: India
Ok the problem is solved...
The code was giving only one IRQ on IRQ12
The change that i made was:
1.Added an EOI -- outb(0x20,0x20) I dont't know why for the first pic...found it on the forum. So now u send EOI to both pics
2.Added EnableKeyboard and DisableKeyboard in the IRQ handler...
Both mouse and kbd are successfully working...
The code was giving only one IRQ on IRQ12
The change that i made was:
1.Added an EOI -- outb(0x20,0x20) I dont't know why for the first pic...found it on the forum. So now u send EOI to both pics
2.Added EnableKeyboard and DisableKeyboard in the IRQ handler...
Both mouse and kbd are successfully working...