MonkOS  v0.1
A simple 64-bit operating system (x86_64)
keyboard.c File Reference

Keyboard input routines. More...

#include <core.h>
#include <libc/string.h>
#include <kernel/x86/cpu.h>
#include <kernel/device/keyboard.h>
#include <kernel/interrupt/interrupt.h>

Go to the source code of this file.

Data Structures

struct  kbstate_t
 Keyboard state. More...
 

Macros

#define KB_PORT_DATA   0x60
 Keyboard I/O data port. More...
 
#define MAX_BUFSIZ   32
 Keyboard input buffer size. More...
 
#define BSP   KEY_BACKSPACE
 
#define TAB   KEY_TAB
 
#define ENT   KEY_ENTER
 
#define ESC   KEY_ESCAPE
 
#define CTL   KEY_CTRL
 
#define SHF   KEY_SHIFT
 
#define ALT   KEY_ALT
 
#define PSC   KEY_PRTSCR
 
#define CLK   KEY_CAPSLOCK
 
#define NLK   KEY_NUMLOCK
 
#define SLK   KEY_SCRLOCK
 
#define KIN   KEY_INSERT
 
#define KEN   KEY_END
 
#define KDN   KEY_DOWN
 
#define KPD   KEY_PGDN
 
#define KLT   KEY_LEFT
 
#define KCT   KEY_CENTER
 
#define KRT   KEY_RIGHT
 
#define KHM   KEY_HOME
 
#define KUP   KEY_UP
 
#define KPU   KEY_PGUP
 
#define KDL   KEY_DEL
 
#define KMI   KEY_MINUS
 
#define KPL   KEY_PLUS
 
#define F_1   KEY_F1
 
#define F_2   KEY_F2
 
#define F_3   KEY_F3
 
#define F_4   KEY_F4
 
#define F_5   KEY_F5
 
#define F_6   KEY_F6
 
#define F_7   KEY_F7
 
#define F_8   KEY_F8
 
#define F_9   KEY_F9
 
#define F10   KEY_F10
 
#define F11   KEY_F11
 
#define F12   KEY_F12
 
#define SES   KEY_SCANESC
 
#define INV   KEY_INVALID
 
#define APO   '\''
 
#define BSL   '\\'
 

Functions

static void toggle (uint8_t flag)
 
static void addkey (uint8_t brk, uint8_t meta, uint8_t code, uint8_t ch)
 
static void isr_keyboard (const interrupt_context_t *context)
 
void kb_init ()
 Initialize the keyboard so that it can provide input to the kernel. More...
 
void kb_setlayout (keylayout_t *layout)
 Install a new keyboard layout. More...
 
char kb_getchar ()
 Return the next available character from the keyboard's input buffer. More...
 
bool kb_getkey (key_t *key)
 Return the available next key from the keyboard's input buffer. More...
 
uint8_t kb_meta ()
 Return the current meta-key bit mask. More...
 

Variables

static const keylayout_t ps2_layout
 US English PSC/2 keyboard scan map (default setting) More...
 
static kbstate_t state
 Current keyboard state. More...
 

Detailed Description

Keyboard input routines.

Definition in file keyboard.c.


Data Structure Documentation

struct kbstate

Keyboard state.

Definition at line 108 of file keyboard.c.

Data Fields
keylayout_t layout The installed keyboard layout.
uint8_t meta Mask of meta keys currently pressed.
uint8_t buf_head Index of oldest key in buf.
uint8_t buf_tail Index of next empty slot in buf.
atomic_uchar buf_size Number of keys in the buf.
key_t buf[MAX_BUFSIZ] Buffer holding unconsumed keys.

Macro Definition Documentation

#define KB_PORT_DATA   0x60

Keyboard I/O data port.

Definition at line 17 of file keyboard.c.

Referenced by isr_keyboard().

#define MAX_BUFSIZ   32

Keyboard input buffer size.

Definition at line 20 of file keyboard.c.

Referenced by addkey(), kb_getchar(), and kb_getkey().

#define BSP   KEY_BACKSPACE

Definition at line 23 of file keyboard.c.

#define TAB   KEY_TAB

Definition at line 24 of file keyboard.c.

#define ENT   KEY_ENTER

Definition at line 25 of file keyboard.c.

#define ESC   KEY_ESCAPE

Definition at line 26 of file keyboard.c.

#define CTL   KEY_CTRL

Definition at line 27 of file keyboard.c.

#define SHF   KEY_SHIFT

Definition at line 28 of file keyboard.c.

#define ALT   KEY_ALT

Definition at line 29 of file keyboard.c.

#define PSC   KEY_PRTSCR

Definition at line 30 of file keyboard.c.

#define CLK   KEY_CAPSLOCK

Definition at line 31 of file keyboard.c.

#define NLK   KEY_NUMLOCK

Definition at line 32 of file keyboard.c.

#define SLK   KEY_SCRLOCK

Definition at line 33 of file keyboard.c.

#define KIN   KEY_INSERT

Definition at line 34 of file keyboard.c.

#define KEN   KEY_END

Definition at line 35 of file keyboard.c.

#define KDN   KEY_DOWN

Definition at line 36 of file keyboard.c.

#define KPD   KEY_PGDN

Definition at line 37 of file keyboard.c.

#define KLT   KEY_LEFT

Definition at line 38 of file keyboard.c.

#define KCT   KEY_CENTER

Definition at line 39 of file keyboard.c.

#define KRT   KEY_RIGHT

Definition at line 40 of file keyboard.c.

#define KHM   KEY_HOME

Definition at line 41 of file keyboard.c.

#define KUP   KEY_UP

Definition at line 42 of file keyboard.c.

#define KPU   KEY_PGUP

Definition at line 43 of file keyboard.c.

#define KDL   KEY_DEL

Definition at line 44 of file keyboard.c.

#define KMI   KEY_MINUS

Definition at line 45 of file keyboard.c.

#define KPL   KEY_PLUS

Definition at line 46 of file keyboard.c.

#define F_1   KEY_F1

Definition at line 47 of file keyboard.c.

#define F_2   KEY_F2

Definition at line 48 of file keyboard.c.

#define F_3   KEY_F3

Definition at line 49 of file keyboard.c.

#define F_4   KEY_F4

Definition at line 50 of file keyboard.c.

#define F_5   KEY_F5

Definition at line 51 of file keyboard.c.

#define F_6   KEY_F6

Definition at line 52 of file keyboard.c.

#define F_7   KEY_F7

Definition at line 53 of file keyboard.c.

#define F_8   KEY_F8

Definition at line 54 of file keyboard.c.

#define F_9   KEY_F9

Definition at line 55 of file keyboard.c.

#define F10   KEY_F10

Definition at line 56 of file keyboard.c.

#define F11   KEY_F11

Definition at line 57 of file keyboard.c.

#define F12   KEY_F12

Definition at line 58 of file keyboard.c.

#define SES   KEY_SCANESC

Definition at line 59 of file keyboard.c.

#define INV   KEY_INVALID

Definition at line 60 of file keyboard.c.

#define APO   '\''

Definition at line 61 of file keyboard.c.

#define BSL   '\\'

Definition at line 62 of file keyboard.c.

Function Documentation

static void toggle ( uint8_t  flag)
inlinestatic

Definition at line 124 of file keyboard.c.

Referenced by isr_keyboard().

static void addkey ( uint8_t  brk,
uint8_t  meta,
uint8_t  code,
uint8_t  ch 
)
static

Definition at line 133 of file keyboard.c.

Referenced by isr_keyboard().

static void isr_keyboard ( const interrupt_context_t *  context)
static

Definition at line 164 of file keyboard.c.

Referenced by kb_init().

void kb_init ( )

Initialize the keyboard so that it can provide input to the kernel.

kb_init installs the default US English PS/2 keyboard layout.

Definition at line 268 of file keyboard.c.

Referenced by kmain().

void kb_setlayout ( keylayout_t *  layout)

Install a new keyboard layout.

Parameters
[in]layoutThe keyboard layout to install.

Definition at line 288 of file keyboard.c.

char kb_getchar ( )

Return the next available character from the keyboard's input buffer.

Returns
The ascii value of the next character in the input buffer, or 0 if there are no characters available.

Definition at line 294 of file keyboard.c.

bool kb_getkey ( key_t *  key)

Return the available next key from the keyboard's input buffer.

Parameters
[out]keyThe key record of the next key in the buffer.
Returns
true if there is a key in the buffer, false otherwise.

Definition at line 318 of file keyboard.c.

Referenced by command_run(), and keycode_run().

uint8_t kb_meta ( )

Return the current meta-key bit mask.

Returns
The meta-key bitmask.

Definition at line 340 of file keyboard.c.

Variable Documentation

const keylayout_t ps2_layout
static

US English PSC/2 keyboard scan map (default setting)

Definition at line 65 of file keyboard.c.

Referenced by kb_init().

kbstate_t state
static

Current keyboard state.

Definition at line 121 of file keyboard.c.

Referenced by addkey(), isr_keyboard(), kb_getchar(), kb_getkey(), kb_init(), kb_meta(), kb_setlayout(), and toggle().