|
ginnOS
The reference: libc, the libraries and the kernel
|
PS/2 keyboard driver implementation. More...
#include "keyboard.h"#include "keyboard_layout.h"#include "keyboard_ioctl.h"#include "kernel/errno.h"#include "kernel/usermode/uaccess.h"#include "kernel/vfs/poll.h"#include "kernel/input/input.h"#include "drivers/mouse/ps2_mouse.h"#include "kernel/signal/signal.h"#include "arch/arch.h"#include "kernel/irq/irq.h"#include "kernel/device/device.h"#include "kernel/process/process.h"#include "kernel/scheduler/scheduler.h"#include "kernel/sync/spinlock.h"#include "kernel/sync/wait_queue.h"#include "arch/x86/cpu/io.h"#include "common/stdint.h"#include "common/string.h"#include "common/memory.h"Macros | |
| #define | KEYBOARD_BUFFER_SIZE 128 |
| #define | EXT_RIGHT_ALT 0x38 |
| #define | EXT_RIGHT_CTRL 0x1D |
| #define | SCANCODE_EXTENDED_PREFIX 0xE0 |
Enumerations | |
| enum | keyboard_scancode_t { SCANCODE_LEFT_SHIFT = 0x2A , SCANCODE_RIGHT_SHIFT = 0x36 , SCANCODE_CAPS_LOCK = 0x3A , SCANCODE_LEFT_CTRL = 0x1D , SCANCODE_LEFT_ALT = 0x38 } |
Functions | |
| 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. | |
| 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). | |
| int | keyboard_available (void) |
| check if at least one event is available in the event buffer. | |
| 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. | |
| 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. | |
| 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. | |
| void | keyboard_initialize (void) |
| initialize the keyboard driver and register the keyboard interrupt handler. | |
PS/2 keyboard driver implementation.
This file implements a PS/2 keyboard driver that handles keyboard interrupts, processes scan codes, and provides an interface for reading keyboard events. It supports modifier keys (Shift, Ctrl, Alt, AltGr) and special keys (arrows, home, end, etc.) and maintains a circular buffer of keyboard events.
| #define KEYBOARD_BUFFER_SIZE 128 |
| #define EXT_RIGHT_ALT 0x38 |
| #define EXT_RIGHT_CTRL 0x1D |
| #define SCANCODE_EXTENDED_PREFIX 0xE0 |
| enum keyboard_scancode_t |
| 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.
| 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.
| scancode | the byte. |
| 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.
| int keyboard_read_event | ( | keyboard_event_t * | event_out | ) |
read the next keyboard event from the event buffer without blocking.
| event_out | output structure filled with the event type and value. |
| 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.
| event_out | output structure filled with the event type and value. |
| 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.
| 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().
| 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.
| void keyboard_initialize | ( | void | ) |
initialize the keyboard driver and register the keyboard interrupt handler.
should be called after the IRQ subsystem is initialized.