UnnamedOS
ps2.h
1 #ifndef HARDWARE_IO_PS2_H
2 #define HARDWARE_IO_PS2_H
3 
4 #include <interrupts/isr.h>
5 
6 // PS/2 device ports
7 typedef enum {
8  PS2_ANY_PORT, // don't care about the port used
9  PS2_PORT_1, // port 1 is usually the keyboard
10  PS2_PORT_2 // port 2, if supported, is usually the mouse
11 } ps2_port_t;
12 
13 typedef enum { PS2_TIMEOUT_ERR = 1, PS2_INVALID_PORT_ERR } ps2_error_t;
14 
15 typedef union {
16  struct {
17  uint8_t port1_intr : 1; // whether port 1 fires IRQ1
18  uint8_t port2_intr : 1; // whether port 2 fires IRQ12
19  uint8_t system : 1; // set if system passed POST tests
20  uint8_t : 1;
21  uint8_t port1_clock : 1; // whether port 1 clock is disabled
22  uint8_t port2_clock : 1; // whether port 2 clock is disabled
23  uint8_t port1_transl : 1; // whether port 1 translates scancode sets
24  uint8_t : 1;
25  } __attribute__((packed)) bits;
26  uint8_t byte;
27 } ps2_config_t;
28 
29 ps2_config_t ps2_read_config();
30 void ps2_write_config(ps2_config_t config);
31 void ps2_flush();
32 uint8_t ps2_write_device(ps2_port_t port, uint8_t command);
33 uint8_t ps2_read_device(ps2_port_t port, ps2_error_t* err);
34 void ps2_init();
35 void ps2_reboot();
36 
37 #endif