LumaOS  v0.1.116
An experimental x86-64 OS
Loading...
Searching...
No Matches
keyboard.c File Reference

Handler and utilities for the keyboard. More...

#include <drivers/keyboard.h>
#include <arch/x86_64/io.h>
#include <arch/x86_64/irq.h>
#include <stdbool.h>
#include "arch/x86_64/pic.h"
Include dependency graph for keyboard.c:

Go to the source code of this file.

Functions

static bool kbd_buf_push (uint8_t b)
 Pushes byte to key buffer.
int kbd_buf_pop (void)
 Pops byte from the keyboard key buffer.
int kbd_getchar (void)
 Waits for a key to be pressed and returns the character.
bool kbd_decode (uint8_t raw, struct key_event *ev)
 Convert a keyboard byte into the correct char.
static void keyboard_handler (struct interrupt_frame *frame)
 Pushes the key code to the key buffer.
void keyboard_init (void)
 Initialize the keyboard driver and register the handler with the IRQ handler.

Variables

static volatile uint8_t kbd_buf [KBD_BUF_SIZE]
 The buffer holding the keys codes.
static volatile uint32_t kbd_head
 next slot to WRITE: only the handler changes this
static volatile uint32_t kbd_tail
 next slot to READ: only the main code changes this
static bool e0_pending
 saw 0xE0, the next byte completes the key
bool shift_down
 Keyboard modifier key status.
bool ctrl_down
bool alt_down
bool caps_on
static const char sc_lower [0x3A]
 The lowercase character conversion table for set 1.
static const char sc_upper [0x3A]
 The uppercase (shifted) character conversion table for set 1.

Detailed Description

Handler and utilities for the keyboard.

Author
Matheus Boscariol
Since
25/11/2026

Definition in file keyboard.c.

Function Documentation

◆ kbd_buf_pop()

int kbd_buf_pop ( void )

Pops byte from the keyboard key buffer.

Returns
Byte from the key buffer (FIFO)

Definition at line 61 of file keyboard.c.

◆ kbd_buf_push()

bool kbd_buf_push ( uint8_t b)
static

Pushes byte to key buffer.

Parameters
bByte to push to buffer
Returns
true if push was successful, false if it failed

Definition at line 53 of file keyboard.c.

◆ kbd_decode()

bool kbd_decode ( uint8_t raw,
struct key_event * ev )

Convert a keyboard byte into the correct char.

Parameters
rawThe raw byte from the keyboard
evThe key event to write to.
Returns
true = decoding successful
false = decoding failed

Definition at line 78 of file keyboard.c.

◆ kbd_getchar()

int kbd_getchar ( void )

Waits for a key to be pressed and returns the character.

Definition at line 68 of file keyboard.c.

Here is the call graph for this function:

◆ keyboard_handler()

void keyboard_handler ( struct interrupt_frame * frame)
static

Pushes the key code to the key buffer.

Parameters
framethe frame status when the interrupt happened

Definition at line 117 of file keyboard.c.

Here is the call graph for this function:

◆ keyboard_init()

void keyboard_init ( void )

Initialize the keyboard driver and register the handler with the IRQ handler.

Definition at line 128 of file keyboard.c.

Here is the call graph for this function:

Variable Documentation

◆ alt_down

bool alt_down

Definition at line 30 of file keyboard.c.

◆ caps_on

bool caps_on

Definition at line 30 of file keyboard.c.

◆ ctrl_down

bool ctrl_down

Definition at line 30 of file keyboard.c.

◆ e0_pending

bool e0_pending
static

saw 0xE0, the next byte completes the key

Definition at line 27 of file keyboard.c.

◆ kbd_buf

volatile uint8_t kbd_buf[KBD_BUF_SIZE]
static

The buffer holding the keys codes.

Definition at line 19 of file keyboard.c.

◆ kbd_head

volatile uint32_t kbd_head
static

next slot to WRITE: only the handler changes this

Definition at line 22 of file keyboard.c.

◆ kbd_tail

volatile uint32_t kbd_tail
static

next slot to READ: only the main code changes this

Definition at line 24 of file keyboard.c.

◆ sc_lower

const char sc_lower[0x3A]
static
Initial value:
= {
0, 27, '1','2','3','4','5','6','7','8','9','0','-','=', '\b', '\t',
'q','w','e','r','t','y','u','i','o','p','[',']','\n', 0, 'a','s',
'd','f','g','h','j','k','l',';','\'','`', 0, '\\','z','x','c','v',
'b','n','m',',','.','/', 0, '*', 0, ' '
}

The lowercase character conversion table for set 1.

Definition at line 33 of file keyboard.c.

◆ sc_upper

const char sc_upper[0x3A]
static
Initial value:
= {
0, 27, '!','@','#','$','%','^','&','*','(',')','_','+', '\b', '\t',
'Q','W','E','R','T','Y','U','I','O','P','{','}','\n', 0, 'A','S',
'D','F','G','H','J','K','L',':','"','~', 0, '|','Z','X','C','V',
'B','N','M','<','>','?', 0, '*', 0, ' '
}

The uppercase (shifted) character conversion table for set 1.

Definition at line 41 of file keyboard.c.

◆ shift_down

bool shift_down

Keyboard modifier key status.

Definition at line 30 of file keyboard.c.