The manual
ginnOS
The reference: libc, the libraries and the kernel
Loading...
Searching...
No Matches
ps2_mouse.c File Reference
#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.

Macro Definition Documentation

◆ DATA_PORT

#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.

◆ STATUS_PORT

#define STATUS_PORT   0x64

◆ COMMAND_PORT

#define COMMAND_PORT   0x64

◆ STATUS_OUTPUT_FULL

#define STATUS_OUTPUT_FULL   0x01

◆ STATUS_INPUT_FULL

#define STATUS_INPUT_FULL   0x02

◆ STATUS_AUX_DATA

#define STATUS_AUX_DATA   0x20

◆ CTRL_READ_CONFIG

#define CTRL_READ_CONFIG   0x20

◆ CTRL_WRITE_CONFIG

#define CTRL_WRITE_CONFIG   0x60

◆ CTRL_ENABLE_AUX

#define CTRL_ENABLE_AUX   0xA8

◆ CTRL_WRITE_AUX

#define CTRL_WRITE_AUX   0xD4

◆ CONFIG_AUX_IRQ

#define CONFIG_AUX_IRQ   0x02

◆ CONFIG_AUX_DISABLE

#define CONFIG_AUX_DISABLE   0x20

◆ MOUSE_SET_DEFAULTS

#define MOUSE_SET_DEFAULTS   0xF6

◆ MOUSE_ENABLE

#define MOUSE_ENABLE   0xF4

◆ MOUSE_SAMPLE_RATE

#define MOUSE_SAMPLE_RATE   0xF3

◆ MOUSE_GET_ID

#define MOUSE_GET_ID   0xF2

◆ MOUSE_ACK

#define MOUSE_ACK   0xFA

◆ PACKET_ALWAYS_ONE

#define PACKET_ALWAYS_ONE   0x08

◆ PACKET_X_SIGN

#define PACKET_X_SIGN   0x10

◆ PACKET_Y_SIGN

#define PACKET_Y_SIGN   0x20

◆ PACKET_OVERFLOW

#define PACKET_OVERFLOW   0xC0

◆ SPIN_LIMIT

#define SPIN_LIMIT   1000000u

Function Documentation

◆ ps2_mouse_byte()

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).

◆ ps2_mouse_init()

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.

Returns
true if a mouse answered.