|
ginnOS
The reference: libc, the libraries and the kernel
|
#include "ps2_mouse.h"#include "arch/x86/cpu/io.h"#include "kernel/input/input.h"#include "kernel/irq/irq.h"#include "kernel/klog/klog.h"Macros | |
| #define | DATA_PORT 0x60 |
| the PS/2 mouse driver (the i8042 aux port; the IntelliMouse wheel extension). | |
| #define | STATUS_PORT 0x64 |
| #define | COMMAND_PORT 0x64 |
| #define | STATUS_OUTPUT_FULL 0x01 |
| #define | STATUS_INPUT_FULL 0x02 |
| #define | STATUS_AUX_DATA 0x20 |
| #define | CTRL_READ_CONFIG 0x20 |
| #define | CTRL_WRITE_CONFIG 0x60 |
| #define | CTRL_ENABLE_AUX 0xA8 |
| #define | CTRL_WRITE_AUX 0xD4 |
| #define | CONFIG_AUX_IRQ 0x02 |
| #define | CONFIG_AUX_DISABLE 0x20 |
| #define | MOUSE_SET_DEFAULTS 0xF6 |
| #define | MOUSE_ENABLE 0xF4 |
| #define | MOUSE_SAMPLE_RATE 0xF3 |
| #define | MOUSE_GET_ID 0xF2 |
| #define | MOUSE_ACK 0xFA |
| #define | PACKET_ALWAYS_ONE 0x08 |
| #define | PACKET_X_SIGN 0x10 |
| #define | PACKET_Y_SIGN 0x20 |
| #define | PACKET_OVERFLOW 0xC0 |
| #define | SPIN_LIMIT 1000000u |
Functions | |
| void | ps2_mouse_byte (uint8_t byte) |
| one byte from the mouse. | |
| bool | ps2_mouse_init (void) |
| find and turn on a PS/2 mouse. | |
| #define DATA_PORT 0x60 |
the PS/2 mouse driver (the i8042 aux port; the IntelliMouse wheel extension).
setup: turn on the aux port and its interrupt in the controller's configuration byte, reset the mouse to its defaults, ask for the wheel with the sample rate sequence 200, 100, 80 (a wheel mouse then reports id 3 and sends 4-byte packets), and turn on data reporting.
a packet: byte 0 has the buttons (bits 0 to 2), a bit that is always 1 (bit 3), and the sign bits of x and y (bits 4 and 5); bytes 1 and 2 are the movement; byte 3 is the wheel. y and the wheel count up when the mouse moves away from the user, so both change sign for /dev/input.
| #define STATUS_PORT 0x64 |
| #define COMMAND_PORT 0x64 |
| #define STATUS_OUTPUT_FULL 0x01 |
| #define STATUS_INPUT_FULL 0x02 |
| #define STATUS_AUX_DATA 0x20 |
| #define CTRL_READ_CONFIG 0x20 |
| #define CTRL_WRITE_CONFIG 0x60 |
| #define CTRL_ENABLE_AUX 0xA8 |
| #define CTRL_WRITE_AUX 0xD4 |
| #define CONFIG_AUX_IRQ 0x02 |
| #define CONFIG_AUX_DISABLE 0x20 |
| #define MOUSE_SET_DEFAULTS 0xF6 |
| #define MOUSE_ENABLE 0xF4 |
| #define MOUSE_SAMPLE_RATE 0xF3 |
| #define MOUSE_GET_ID 0xF2 |
| #define MOUSE_ACK 0xFA |
| #define PACKET_ALWAYS_ONE 0x08 |
| #define PACKET_X_SIGN 0x10 |
| #define PACKET_Y_SIGN 0x20 |
| #define PACKET_OVERFLOW 0xC0 |
| #define SPIN_LIMIT 1000000u |
| void ps2_mouse_byte | ( | uint8_t | byte | ) |
one byte from the mouse.
the keyboard interrupt hands over a mouse byte it finds in the data port (the i8042 status says which device sent it).
| bool ps2_mouse_init | ( | void | ) |
find and turn on a PS/2 mouse.
call with interrupts off, after the keyboard driver and the interrupt controllers are set up.