LumaOS  v0.1.116
An experimental x86-64 OS
Loading...
Searching...
No Matches
keyboard.h
Go to the documentation of this file.
1
9
10#ifndef KERNEL_ARCH_X86_64_KEYBOARD_H
11#define KERNEL_ARCH_X86_64_KEYBOARD_H
12
13#include <stdbool.h>
14#include <arch/x86_64/io.h>
15#include <stdint.h>
16
17#define PS2_DATA 0x60
18#define PS2_STATUS 0x64
19#define PS2_COMMAND 0x64
20
21#define KBD_BUF_SIZE 256
22
24struct key_event {
26 uint8_t scancode;
30 bool pressed;
32 char ascii;
33};
34
35extern bool shift_down, ctrl_down, alt_down, caps_on;
36
40static inline void ps2_wait_write(void) { while (inb(PS2_STATUS) & 0x02) { } }
41
45static inline void ps2_wait_read(void) { while (!(inb(PS2_STATUS) & 0x01)) { } }
46
50void keyboard_init(void);
51
56int kbd_buf_pop(void);
57
65bool kbd_decode(uint8_t raw, struct key_event *ev);
66
70int kbd_getchar(void);
71
72#endif
Provides utilities for IO operations with the hardware.
uint8_t inb(uint16_t port)
Inputs a byte from the specified port.
Definition io.h:31
bool shift_down
Keyboard modifier key status.
Definition keyboard.c:30
int kbd_buf_pop(void)
Pops byte from the keyboard key buffer.
Definition keyboard.c:61
static void ps2_wait_write(void)
Wait until ps/2 input buffer is empty.
Definition keyboard.h:40
bool kbd_decode(uint8_t raw, struct key_event *ev)
Convert a keyboard byte into the correct char.
Definition keyboard.c:78
void keyboard_init(void)
Initialize the keyboard driver and register the handler with the IRQ handler.
Definition keyboard.c:128
int kbd_getchar(void)
Waits for a key to be pressed and returns the character.
Definition keyboard.c:68
static void ps2_wait_read(void)
wait until a byte is waiting
Definition keyboard.h:45
A decoded key event.
Definition keyboard.h:24
bool extended
came after an 0xE0 prefix
Definition keyboard.h:28
uint8_t scancode
the code with bit 7 removed
Definition keyboard.h:26
char ascii
0 if the key has no printable character
Definition keyboard.h:32
bool pressed
true = key down, false = key up
Definition keyboard.h:30