ps2 mice

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
gwall

ps2 mice

Post by gwall »

I wrote a mouse code to get its id works ok under vmware and bochs. they boths return "0" as i want. but it doesn't work under a real pc. it always returns the keyboard's id "83AB". it seems like that my mouse command "0xf2" did Not send to mouse but keyboard. It confused me. I have send "0xD4" to "0x64" before i send "0xf2" to 0x60. my code as below:

Code: Select all

???unsigned char ret_code;
???unsigned char status = 0;
???unsigned char device_id= 0xff;
???unsigned char command_byte = 0xff;

???status = inb(0x64);
???printf("status[after read ret_code] = 0x%x\n", status);

???switch(ret_code){
??????case 1:
?????????printf("clock line stuck low\n");
?????????break;
??????case 2:
?????????printf("clock line stuck high\n");
?????????break;
??????case 3:
?????????printf("data line stuck high\n");
?????????break;
??????case 4:
?????????printf("data line stuck high\n");
?????????break;
???}

???
//stage 5
//????????

???//enable mouse
???command_byte = read_command_byte();
???if(command_byte & (1<<5)){
??????//ps2 mouse is now disable. enable it
??????wait_input_empty();
??????outb(0xa8, 0x64);
???}
???command_byte = read_command_byte();
???if(command_byte &(1<<5))
???{
??????printf("can not open mouse. exit mouse initialization!\n");
??????return;
???}
???
???//get device id???
???wait_input_empty();
???outb(0xd4, 0x64);
???outb(0xf2, 0x60);
???wait_output_full();
???ret_code = inb(0x60);
???printf("get device id command (0xf2) echo = 0x%x\n", ret_code);
???if(0xfa == ret_code){
??????wait_output_full();
??????device_id = inb(0x60);
??????printf("device_id = 0x%x\n", device_id);
??????if(0xab == device_id){
?????????wait_output_full();
?????????ret_code = inb(0x60);
?????????printf("this is keyboard id = 0x%x\n", (ret_code <<8)+device_id);
??????}
???}

???if(0xff == device_id){
??????printf("get device_id error\n");
??????return;
???}

???
???printf("reset mouse.....\n\n");
???wait_input_empty();
???outb(0xd4, 0x64);
???printf("reset command\n");
???outb(0xff, 0x60);
???if(0x0 == device_id){
??????//std ps2 mouse device
??????printf("\noutput\n");
??????wait_output_full();
??????ret_code = inb(0x60);
??????if(0xfa != ret_code){
?????????printf("error echo 0x%x. return \n", ret_code);
?????????return;
??????}
??????printf("1st ret_code = 0x%x\n", ret_code);???
??????wait_output_full();
??????ret_code = inb(0x60);
??????if(0xaa != ret_code){
?????????printf("error echo 0x%x. return \n", ret_code);
?????????return;
??????}
??????printf("2st ret_code = 0x%x\n", ret_code);???
??????wait_output_full();
??????ret_code = inb(0x60);
??????printf("3st ret_code = 0x%x\n", ret_code);???
???}else{
???}

???
???wait_input_empty();
???outb(0xd4, 0x64);
???outb(0xf4, 0x60);
???wait_output_full();
???ret_code = inb(0x60);
???if(0xfa != ret_code){
??????printf("error echo 0x%x. return\n", ret_code);
??????return;
???}
???
???UnmaskIRQ(12);

sorry for my poor english. any help will be appreciate!!
[edit by candy] use the [ code ] tags. [/edit]
octavio

Re:ps2 mice

Post by octavio »

wait_input_empty();
outb(0xd4, 0x64);
wait_input_empty(); required also for port 60h
outb(0xf2, 0x60);

You should also disable the mouse stream mode first ,so the mouse don?t send movement data.
gwall

Re:ps2 mice

Post by gwall »

thanks. it works!! ^_^
Post Reply