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   0x01U
#define MOD_RCTRL   0x02U
#define MOD_CTRL   0x03U
#define MOD_LSHIFT   0x04U
#define MOD_RSHIFT   0x08U
#define MOD_SHIFT   0x4CU
#define MOD_LALT   0x10U
#define MOD_RALT   0x20U
#define MOD_ALT   0x30U
#define MOD_CAPSLOCK   0x40U
#define MOD_NUMLOCK   0x80U
#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 (void)
 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 (void)
 Gets the current modifiers (like lshift, rshift, etc.).
uint8_t getc (void)
 Gets the last pressed char.
int getc_nonblock (void)
 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   0x30U

Definition at line 27 of file keyboard.h.

◆ MOD_CAPSLOCK

#define MOD_CAPSLOCK   0x40U

Definition at line 28 of file keyboard.h.

◆ MOD_CTRL

#define MOD_CTRL   0x03U

Definition at line 21 of file keyboard.h.

◆ MOD_LALT

#define MOD_LALT   0x10U

Definition at line 25 of file keyboard.h.

◆ MOD_LCTRL

#define MOD_LCTRL   0x01U

Definition at line 19 of file keyboard.h.

◆ MOD_LSHIFT

#define MOD_LSHIFT   0x04U

Definition at line 22 of file keyboard.h.

◆ MOD_NUMLOCK

#define MOD_NUMLOCK   0x80U

Definition at line 29 of file keyboard.h.

◆ MOD_RALT

#define MOD_RALT   0x20U

Definition at line 26 of file keyboard.h.

◆ MOD_RCTRL

#define MOD_RCTRL   0x02U

Definition at line 20 of file keyboard.h.

◆ MOD_RSHIFT

#define MOD_RSHIFT   0x08U

Definition at line 23 of file keyboard.h.

◆ MOD_SHIFT

#define MOD_SHIFT   0x4CU

Definition at line 24 of file keyboard.h.

Function Documentation

◆ getc()

uint8_t getc ( void )

Gets the last pressed char.

Returns
[uint8_t] Last scancode

◆ getc_nonblock()

int getc_nonblock ( void )

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