Mouse Button Driver

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.
Locked
Yashas
Member
Member
Posts: 45
Joined: Sun Feb 05, 2012 5:19 am
Location: India
Contact:

Mouse Button Driver

Post by Yashas »

I have not tested on real hardware.I have not tested because my test bed had got spoilt and is under repair.Test in a emulator ,also inform me if it dose not work or works.

FRIST TEST IT IN A EMULATOR,PLZ

You need to have a functions inport,outport and wait.
=======================================================
Add this to your file were the you store variables

static unsigned char mouse_no = 0;
static char mousebyte[3];

=======================================================
#include<base.h>//Few variables and more
#include<hardware.h>//My IO is here


void load_mouse()
{
outportb(0x64,0xA8);
outportb(0x64,0x20);
unsigned char stbyt;
stbyt = (inportb(0x60) | 2);
outportb(0x64, 0x60);
outportb(0x60, stbyt);
outportb(0x64, 0xD4);
outportb(0x60,0xF6);
inportb(0x60);
outportb(0x64, 0xD4);
outportb(0x60,0xF4);
inportb(0x60);
}
void mouse_handler(struct regstrs * reg)
{
if (mouse_no == 3)
{
mouse_no = 0;
mousebyte[mouse_no++] = inportb(0x60);

if (mousebyte[0] & 0x4)
mouse_round_button();//Same thing as below but for the middle button.

if (mousebyte[0] & 0x2)
mouse_right();//Replace with you function to do if right button is clicked.

if (mousebyte[0] & 0x1)
mouse_left();//Same thing as above but for left
}
}
void init_mouse ()
{
load_mouse();
wait(2);//Give some time for the mouse
install_irq_to_system(12, mouse_handler);//This must be your IRQ function which installs IRQ's
}

=================================================================
Call init_mouse in your main.

i will be thankful to for a few correction's

Also can anybody tell how to get the x and y of the mouse.
User avatar
brain
Member
Member
Posts: 234
Joined: Thu Nov 05, 2009 5:04 pm
Location: UK
Contact:

Re: Mouse Button Driver

Post by brain »

You should probably put

Code: Select all

 tags around your example, makes it easier to read - looking good though, hope you figure out how to do coordinates/movement...
Yashas
Member
Member
Posts: 45
Joined: Sun Feb 05, 2012 5:19 am
Location: India
Contact:

Re: Mouse Button Driver

Post by Yashas »

Do you mean comments?


This driver is not easy, i got a datasheet of a PS/2 Mouse and prepared it.But i didnot understand about the x and y that sheet.

You will not get it anywhere on the web.The code.
I justed , a glitch.
I tested it 10 times, 5 times worked other 5 failed.I dint even change a bit of the code.
User avatar
brain
Member
Member
Posts: 234
Joined: Thu Nov 05, 2009 5:04 pm
Location: UK
Contact:

Re: Mouse Button Driver

Post by brain »

Can you post a link to the datasheet so that others can help easier and maybe develop their own drivers?
Yashas
Member
Member
Posts: 45
Joined: Sun Feb 05, 2012 5:19 am
Location: India
Contact:

Re: Mouse Button Driver

Post by Yashas »

http://www.datasheetarchive.com/

I got here, i dono which one,I typed mouse microcontroller PS/2 in the search, i downloaded few from there.
Yashas
Member
Member
Posts: 45
Joined: Sun Feb 05, 2012 5:19 am
Location: India
Contact:

Re: Mouse Button Driver

Post by Yashas »

The mouse's are active only sometimes.Can anyone make a function for checking the mouse and keyboard weather it is ready to take in command or not.
User avatar
bluemoon
Member
Member
Posts: 1761
Joined: Wed Dec 01, 2010 3:41 am
Location: Hong Kong

Re: Mouse Button Driver

Post by bluemoon »

Yashas wrote:The mouse's are active only sometimes.Can anyone make a function for checking the mouse and keyboard weather it is ready to take in command or not.
Pooling is not a good idea. What's wrong with IRQ?
By the way, check here Mouse_Input.
Yashas
Member
Member
Posts: 45
Joined: Sun Feb 05, 2012 5:19 am
Location: India
Contact:

Re: Mouse Button Driver

Post by Yashas »

I ment that your function of installing irq might be different from my function.

And also by the way thank you.I am trying the y-delta and the x-delta.
Locked