Mouse problem (SOLVED)

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
User avatar
salil_bhagurkar
Member
Member
Posts: 261
Joined: Mon Feb 19, 2007 10:40 am
Location: India

Mouse problem (SOLVED)

Post by salil_bhagurkar »

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?
Last edited by salil_bhagurkar on Wed Jul 18, 2007 11:59 am, edited 1 time in total.
digo_rp
Member
Member
Posts: 233
Joined: Sun Jun 05, 2005 11:00 pm

Post by digo_rp »

you have to enable IRQ12 in kbc

mouse_wait(1);
outb_p(0x64, 0x20);

mouse_wait(0);
_status=(inb_p(0x60) | 2);

mouse_wait(1);
outb_p(0x64, 0x60);

mouse_wait(1);
outb_p(0x60, _status);
User avatar
salil_bhagurkar
Member
Member
Posts: 261
Joined: Mon Feb 19, 2007 10:40 am
Location: India

Post by salil_bhagurkar »

Could you please tell give me more detail code and links documentation?
User avatar
salil_bhagurkar
Member
Member
Posts: 261
Joined: Mon Feb 19, 2007 10:40 am
Location: India

Post by salil_bhagurkar »

Oh i forgot that we can search the forum!... I am not lazy... I have made several attempts to write mouse code... Besides, when i have noting to do other than osdev all day how can i be lazy?
exkor
Member
Member
Posts: 111
Joined: Wed May 23, 2007 9:38 pm

Post by exkor »

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"
User avatar
salil_bhagurkar
Member
Member
Posts: 261
Joined: Mon Feb 19, 2007 10:40 am
Location: India

Post by salil_bhagurkar »

Okay i used the code of mystran from the forums...
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);
} 
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.
User avatar
salil_bhagurkar
Member
Member
Posts: 261
Joined: Mon Feb 19, 2007 10:40 am
Location: India

Post by salil_bhagurkar »

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...
Post Reply