9 #define PS2MOUSE_SAMPLES 0x64 // Samples in second - 0x50 for 80, 0x64 for 100, 0xC8 for 200
10 #define PS2MOUSE_RESOLUTION 2
12 #define PS2MOUSE_TIMEOUT 500000
13 #define PS2MOUSE_ACK 0xFA
14 #define PS2MOUSE_PORT 0x60
15 #define PS2MOUSE_CTRL 0x64
16 #define PS2MOUSE_COMMAND 0xD4
17 #define PS2MOUSE_COMMAND_RESET 0xFF
18 #define PS2MOUSE COMMAND_GET_MOUSE_ID 0xF2
19 #define PS2MOUSE_COMMAND_ENABLE_PACKETS 0xF4
20 #define PS2MOUSE_COMMAND_SET_SAMPLES 0xF3
21 #define PS2MOUSE_COMMAND_SET_RESOLUTION 0xE8
22 #define PS2MOUSE_RESET_ACK 0xAA
23 #define PS2MOUSE_IRQ 12
27 static int cursor_state
;
29 bool ps2mouse_reset ();
30 void ps2mouse_command_write (unsigned char command
);
31 void ps2mouse_write (unsigned char command
);
32 unsigned char ps2mouse_read ();
34 /* ps2mouse_reset - reset mouse */
40 for (timeout
= 0; timeout
< PS2MOUSE_TIMEOUT
; timeout
++)
42 if((inb (PS2MOUSE_CTRL
) && 0x02) == 0x02)
47 outb (PS2MOUSE_CTRL
, PS2MOUSE_COMMAND
);
48 outb (PS2MOUSE_PORT
, PS2MOUSE_COMMAND_RESET
);
50 for (timeout
= 0; timeout
< PS2MOUSE_TIMEOUT
; timeout
++)
52 int read
= ps2mouse_read ();
53 if (read
== PS2MOUSE_RESET_ACK
)
65 /* ps2mouse_command_write - send a command to mouse */
67 unsigned int ps2mouse_command_write(unsigned char command
)
71 for (timeout
= 0; timeout
< PS2MOUSE_TIMEOUT
; timeout
++)
73 if((inb (PS2MOUSE_CTRL
) && 0x02) == 0x02)
78 outb (PS2MOUSE_CTRL
, PS2MOUSE_COMMAND
);
79 outb (PS2MOUSE_PORT
, command
);
81 for (timeout
= 0; timeout
< PS2MOUSE_TIMEOUT
; timeout
++)
83 int read
= ps2mouse_read ();
84 if (read
== PS2MOUSE_ACK
)
96 /* ps2mouse_write - send a command to mouse */
98 unsigned int ps2mouse_command_write(unsigned char command
)
102 for (timeout
= 0; timeout
< PS2MOUSE_TIMEOUT
; timeout
++)
104 if((inb (PS2MOUSE_CTRL
) && 0x02) == 0x02)
109 outb (PS2MOUSE_PORT
, command
);
111 for (timeout
= 0; timeout
< PS2MOUSE_TIMEOUT
; timeout
++)
113 int read
= ps2mouse_read ();
114 if (read
== PS2MOUSE_ACK
)
126 /* ps2mouse_read - read a value from mouse */
128 unsigned char ps2mouse_read()
132 for (timeout
= 0; timeout
< PS2MOUSE_TIMEOUT
; timeout
++)
134 if ((inb (PS2MOUSE_CTRL
) && 0x01) != 0x01)
135 return inb (PS2MOUSE_PORT
);
142 void ps2mouse_handler (struct regs
*r
)
144 kprintf("handler ()\n");
146 /* while (inb(0x64) == 0x02) // Wait until on port 0x64 isn´t 02h
152 while (inb(0x64) == 0x01) // Wait until on port 0x64 isn´t 01h
155 char b1 = inb (0x60);
157 while (inb(0x64) == 0x01) // Wait until on port 0x64 isn´t 01h
160 char b2 = inb (0x60);
162 while (inb(0x64) == 0x01) // Wait until on port 0x64 isn´t 01h
167 if ((b1 & (1 << 6)) == 0)
170 cursor_x += (int) (char) ((b1 << 6) | (b2 & 0x3f));
171 cursor_y += (int) (char) (((b1 << 4) & 0xc0) | (b3 & 0x3f));
185 cursor_state = (b1 >> 4) & 3;*/
188 unsigned ps2mouse_init ()
190 unsigned char status_byte
= 0xD8;
191 unsigned char mouse_id
;
193 if(ps2mouse_reset () == -1)
196 mouse_id
= ps2mouse_read ();
198 ps2mouse_command_write (PS2MOUSE_COMMAND_SET_SAMPLES
);
199 ps2mouse_write (PS2MOUSE_SAMPLES
);
201 ps2mouse_command_write (PS2MOUSE_COMMAND_SET_RESOLUTION
);
202 ps2mouse_write (PS2MOUSE_RESOLUTION
);
204 kprintf ("ps2mouse -> ID: %d \n", mouse_id
);
208 irq_install_handler(PS2MOUSE_IRQ
, ps2mouse_handler
);
215 void ps2mouse_get_status (int *x
, int *y
, int *state
)
219 *state
= cursor_state
;
222 bool ps2mouse_acthandler (unsigned act
, char *block
, unsigned block_len
)
227 return ps2mouse_init ();