sortix-mirror/sortix/keyboard.cpp
Jonas 'Sortie' Termansen ead0e1523f Refactored the kernel keyboard API, but kept system calls compatible.
Caps lock now works as caps lock, not as shift lock.

This new design will allow implementing a working tty, such that stdin is
the only way to access the keyboard, instead of the current hacky way of
using a special system call to read from the keyboard.

Added a new system header file <sys/keycodes.h> defining the constants for
every key on the keyboard. This will be used in future APIs.

The main change is to split the keyboard driver into a class that reads
from the keyboard, while another class handles the translation into
printable characters (if possible). This allows a terminal driver based
on logical key presses and printable characters, instead of a terminal
driver based only on unicode-ish codes.
2012-01-22 15:53:50 +01:00

57 lines
1.6 KiB
C++

/******************************************************************************
COPYRIGHT(C) JONAS 'SORTIE' TERMANSEN 2012.
This file is part of Sortix.
Sortix is free software: you can redistribute it and/or modify it under the
terms of the GNU General Public License as published by the Free Software
Foundation, either version 3 of the License, or (at your option) any later
version.
Sortix is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
details.
You should have received a copy of the GNU General Public License along
with Sortix. If not, see <http://www.gnu.org/licenses/>.
keyboard.cpp
An interface to keyboards.
******************************************************************************/
#include "platform.h"
#include "interrupt.h"
#include "syscall.h"
#include "keyboard.h"
#include "kb/ps2.h"
#include "kb/layout/us.h"
#include "kbapiadapter.h"
namespace Sortix
{
KBAPIAdapter* tty;
uint32_t SysReceiveKeystroke()
{
return tty->DequeueKeystroke();
}
void Keyboard::Init()
{
Keyboard* keyboard = new PS2Keyboard(0x60, Interrupt::IRQ1);
if ( !keyboard ) { Panic("Could not allocate PS2 Keyboard driver"); }
KeyboardLayout* kblayout = new KBLayoutUS;
if ( !kblayout ) { Panic("Could not allocate keyboard layout driver"); }
tty = new KBAPIAdapter(keyboard, kblayout);
if ( !tty ) { Panic("Could not allocate a simple terminal"); }
Syscall::Register(SYSCALL_RECEIVE_KEYSTROKE, (void*) SysReceiveKeystroke);
}
}