Community
cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted
Valued Contributor III
746 Views

ps/2 mouse problem in nios system

Hi there! 

I'm doing 1 small demo : detect the movement and button states from a ps2 mouse in nios system, I use the university IP core. nios build project no error, but when run, the console display nothing. Is the problem in read 3 byte (code c) or the printf function. Have you give me some advice or the code reference (read 3 byte from FIFO). 

Thank!  

the code below : 

# include "altera_up_avalon_ps2.h"# include "altera_up_ps2_mouse.h"# include <alt_types.h># include <stdio.h># include <system.h> 

 

int maxmin(int no, int max, int min) 

if(no>max) {no=max;} 

if(no<min) {no=min;} 

 

return(no); 

 

int main(void) 

{  

alt_up_ps2_dev * ps2_dev; 

ps2_dev = alt_up_ps2_open_dev("/dev/ps2_0");  

alt_up_ps2_init(ps2_dev); 

alt_up_ps2_clear_fifo(ps2_dev); 

 

unsigned char byte1, byte2, byte3, byte1_x, byte1_y; 

alt_u8 X, Y, X1, Y1; 

int pX=320, pY=240, B=0; 

while(1)  

alt_up_ps2_read_data_byte(ps2_dev, &byte1);//read 1 byte 

alt_up_ps2_read_data_byte(ps2_dev, &byte2); 

alt_up_ps2_read_data_byte(ps2_dev, &byte3); 

byte1_x = byte1&0x10; 

byte1_y = byte1&0x30; 

B = (int)byte1&0x07; 

if(byte1_x == 0) 

{ X = byte2; 

pX = pX + X;} 

else  

{ X1 = (~byte2) + 1; 

pX = pX - X1;} 

if(byte1_y == 0) 

{ Y = byte3; 

pY = pY + Y;} 

else  

{ Y1 = (~byte3) + 1; 

pY = pY - Y1;} 

pX=maxmin(pX,639,0); 

pY=maxmin(pY,479,0); 

printf("%d%d\n",pX,pY); 

printf("%d\n",B ) ; 

return 0; 

}
0 Kudos