The manual
ginnOS
The reference: libc, the libraries and the kernel
Loading...
Searching...
No Matches
keyboard.h File Reference
#include "common/stdint.h"

Go to the source code of this file.

Data Structures

struct  keyboard_event_t
 a single keyboard event returned by keyboard_read_event(). More...

Typedefs

typedef bool(*) keyboard_filter_fn(const keyboard_event_t *event)
 a function that sees every key event before it is buffered (in the keyboard interrupt).

Enumerations

enum  key_state_t { KEY_RELEASED = 0 , KEY_PRESSED = 1 }
 keyboard key state enumeration KEY_RELEASED: the key is not pressed KEY_PRESSED: the key is pressed More...
enum  keyboard_special_key_t {
  KEY_ARROW_UP = 1 , KEY_ARROW_DOWN = 2 , KEY_ARROW_LEFT = 3 , KEY_ARROW_RIGHT = 4 ,
  KEY_HOME = 5 , KEY_END = 6 , KEY_PAGE_UP = 7 , KEY_PAGE_DOWN = 8 ,
  KEY_INSERT = 9 , KEY_DELETE = 10
}
 special key codes for keys that cannot be represented as a plain char. More...
enum  keyboard_event_type_t { KEY_EVENT_CHAR = 0 , KEY_EVENT_SPECIAL = 1 , KEY_EVENT_RAW = 2 }
 event type tag for keyboard_event_t. More...

Functions

void keyboard_initialize (void)
 initialize the keyboard driver and register the keyboard interrupt handler.
void keyboard_handle_scancode (uint8_t scancode)
 decode one byte of PS/2 scan code set 1 (0xE0 starts a two-byte code, bit 7 marks a release).
void keyboard_set_raw_events (bool on)
 report every key press and release as a KEY_EVENT_RAW event (also the modifier keys), and no character or special events, or go back to the normal events.
int keyboard_available (void)
 check if at least one event is available in the event buffer.
char keyboard_getchar (void)
 read the next character from the event buffer without blocking.
int keyboard_read (void)
 read the next character from the event buffer, blocking until one arrives.
int keyboard_read_event (keyboard_event_t *event_out)
 read the next keyboard event from the event buffer without blocking.
bool keyboard_wait_event (keyboard_event_t *event_out)
 read the next keyboard event from the event buffer, blocking until one arrives.
void keyboard_set_filter (keyboard_filter_fn filter)
 set the filter (NULL: none).
void keyboard_flush (void)
 drop every buffered event (input typed but not read yet).
uint32_t keyboard_dropped_count (void)
 return the number of events dropped due to a full buffer since boot.

Typedef Documentation

◆ keyboard_filter_fn

typedef bool(*) keyboard_filter_fn(const keyboard_event_t *event)

a function that sees every key event before it is buffered (in the keyboard interrupt).

it returns true to take the event out of the input: the terminal uses it for Ctrl+C and the other signal keys.

Enumeration Type Documentation

◆ key_state_t

keyboard key state enumeration KEY_RELEASED: the key is not pressed KEY_PRESSED: the key is pressed

Enumerator
KEY_RELEASED 
KEY_PRESSED 

◆ keyboard_special_key_t

special key codes for keys that cannot be represented as a plain char.

produced by 0xE0-prefixed PS/2 scan code sequences.

Enumerator
KEY_ARROW_UP 
KEY_ARROW_DOWN 
KEY_ARROW_LEFT 
KEY_ARROW_RIGHT 
KEY_HOME 
KEY_END 
KEY_PAGE_UP 
KEY_PAGE_DOWN 
KEY_INSERT 
KEY_DELETE 

◆ keyboard_event_type_t

event type tag for keyboard_event_t.

KEY_EVENT_CHAR: the event carries a printable/control character in .character. KEY_EVENT_SPECIAL: the event carries a special key code in .special.

Enumerator
KEY_EVENT_CHAR 
KEY_EVENT_SPECIAL 
KEY_EVENT_RAW 

Function Documentation

◆ keyboard_initialize()

void keyboard_initialize ( void )

initialize the keyboard driver and register the keyboard interrupt handler.

should be called after the IRQ subsystem is initialized.

◆ keyboard_handle_scancode()

void keyboard_handle_scancode ( uint8_t scancode)

decode one byte of PS/2 scan code set 1 (0xE0 starts a two-byte code, bit 7 marks a release).

the PS/2 interrupt calls it, and the USB keyboard driver calls it with codes made from its reports. call with interrupts off.

Parameters
scancodethe byte.

◆ keyboard_set_raw_events()

void keyboard_set_raw_events ( bool on)

report every key press and release as a KEY_EVENT_RAW event (also the modifier keys), and no character or special events, or go back to the normal events.

for games, which need key releases and the positions of the keys rather than characters. the terminal turns this on with the XKEYRAW termios flag.

◆ keyboard_available()

int keyboard_available ( void )

check if at least one event is available in the event buffer.

only a hint: another reader may take the event first, so callers that then read must use a read function that copes with an empty buffer.

Returns
1 if an event is available, 0 otherwise.

◆ keyboard_getchar()

char keyboard_getchar ( void )

read the next character from the event buffer without blocking.

special key events (arrow keys, etc.) are discarded; only KEY_EVENT_CHAR events are returned here. callers that need special keys should use keyboard_read_event() instead.

Returns
the next character, or 0 if no character event is available.

◆ keyboard_read()

int keyboard_read ( void )

read the next character from the event buffer, blocking until one arrives.

special key events are discarded the same way as keyboard_getchar().

Returns
the next character (0-255), or -1 if a signal for the calling process ended the wait.

◆ keyboard_read_event()

int keyboard_read_event ( keyboard_event_t * event_out)

read the next keyboard event from the event buffer without blocking.

Parameters
event_outoutput structure filled with the event type and value.
Returns
1 if an event was read, 0 if the buffer was empty.

◆ keyboard_wait_event()

bool keyboard_wait_event ( keyboard_event_t * event_out)

read the next keyboard event from the event buffer, blocking until one arrives.

the calling process sleeps until the keyboard IRQ wakes it; it does not spin. safe with several readers: each event goes to exactly one of them.

Parameters
event_outoutput structure filled with the event type and value.
Returns
true with an event, false if a signal for the calling process ended the wait.

◆ keyboard_set_filter()

void keyboard_set_filter ( keyboard_filter_fn filter)

set the filter (NULL: none).

◆ keyboard_flush()

void keyboard_flush ( void )

drop every buffered event (input typed but not read yet).

◆ keyboard_dropped_count()

uint32_t keyboard_dropped_count ( void )

return the number of events dropped due to a full buffer since boot.

Returns
total number of dropped events.