FrostWing
A lightweight raw-control operating system.
Loading...
Searching...
No Matches
keyboard.h File Reference

The PS/2 Keyboard interface code. More...

#include <basics.h>
#include <stdbool.h>
#include <hal.h>
#include <isr.h>
Include dependency graph for keyboard.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define MOD_LCTRL   0b00000001
#define MOD_RCTRL   0b00000010
#define MOD_CTRL   0b00000011
#define MOD_LSHIFT   0b00000100
#define MOD_RSHIFT   0b00001000
#define MOD_SHIFT   0b01001100
#define MOD_LALT   0b00010000
#define MOD_RALT   0b00100000
#define MOD_ALT   0b00110000
#define MOD_CAPSLOCK   0b01000000
#define MOD_NUMLOCK   0b10000000
#define CUR_UP   -1
#define CUR_DOWN   -2
#define CUR_LEFT   -3
#define CUR_RIGHT   -4
#define KB_BUFFER_SIZE   256

Functions

char scancode_to_char (int scancode, bool uppercase)
 Converts the scancode to character.
void keyboard_init ()
 Initalizes the RingBuffer to store the characters.
void process_keyboard (InterruptFrame *frame)
 This is a function that is ran even when the sleep() function is called.
uint8_t getmodifiers ()
 Gets the current modifiers (like lshift, rshift, etc.).
uint8_t getc ()
 Gets the last pressed char.
int getc_nonblock ()
 Non-blocking getc from keyboard buffer.
void keyboard_flush_buffer (void)
 Clears pending keyboard input so stale keypresses are discarded.
int handle_char_from_scancode (uint8_t data)
 Converts the scancode passed to it to ASCII characters.

Detailed Description

The PS/2 Keyboard interface code.

Author
Pradosh (prado.nosp@m.shga.nosp@m.me@gm.nosp@m.ail..nosp@m.com)
Version
0.1
Date
2026-03-20

Definition in file keyboard.h.

Macro Definition Documentation

◆ CUR_DOWN

#define CUR_DOWN   -2

Definition at line 32 of file keyboard.h.

◆ CUR_LEFT

#define CUR_LEFT   -3

Definition at line 33 of file keyboard.h.

◆ CUR_RIGHT

#define CUR_RIGHT   -4

Definition at line 34 of file keyboard.h.

◆ CUR_UP

#define CUR_UP   -1

Definition at line 31 of file keyboard.h.

◆ KB_BUFFER_SIZE

#define KB_BUFFER_SIZE   256

Definition at line 36 of file keyboard.h.

◆ MOD_ALT

#define MOD_ALT   0b00110000

Definition at line 27 of file keyboard.h.

◆ MOD_CAPSLOCK

#define MOD_CAPSLOCK   0b01000000

Definition at line 28 of file keyboard.h.

◆ MOD_CTRL

#define MOD_CTRL   0b00000011

Definition at line 21 of file keyboard.h.

◆ MOD_LALT

#define MOD_LALT   0b00010000

Definition at line 25 of file keyboard.h.

◆ MOD_LCTRL

#define MOD_LCTRL   0b00000001

Definition at line 19 of file keyboard.h.

◆ MOD_LSHIFT

#define MOD_LSHIFT   0b00000100

Definition at line 22 of file keyboard.h.

◆ MOD_NUMLOCK

#define MOD_NUMLOCK   0b10000000

Definition at line 29 of file keyboard.h.

◆ MOD_RALT

#define MOD_RALT   0b00100000

Definition at line 26 of file keyboard.h.

◆ MOD_RCTRL

#define MOD_RCTRL   0b00000010

Definition at line 20 of file keyboard.h.

◆ MOD_RSHIFT

#define MOD_RSHIFT   0b00001000

Definition at line 23 of file keyboard.h.

◆ MOD_SHIFT

#define MOD_SHIFT   0b01001100

Definition at line 24 of file keyboard.h.

Function Documentation

◆ getc()

uint8_t getc ( )

Gets the last pressed char.

Returns
[uint8_t] Last scancode

◆ getc_nonblock()

int getc_nonblock ( )

Non-blocking getc from keyboard buffer.

Returns
int Character if available, 0 if no input

◆ handle_char_from_scancode()

int handle_char_from_scancode ( uint8_t data)

Converts the scancode passed to it to ASCII characters.

Parameters
dataScancode
Returns
int eqivalent of a character.

◆ scancode_to_char()

char scancode_to_char ( int scancode,
bool uppercase )

Converts the scancode to character.

Parameters
scancodeusually inb(0x60);
Returns
[char] Appropriate character to be displayed