1
0
mirror of https://gitlab.os-k.eu/os-k-team/os-k.git synced 2023-08-25 14:03:10 +02:00
os-k/kaleid/kernel/io/keyb.c

144 lines
4.3 KiB
C
Raw Normal View History

//----------------------------------------------------------------------------//
// GNU GPL OS/K //
// //
2019-05-07 18:35:46 +02:00
// Desc: Basic Keyboard Driver //
// //
// //
// Copyright © 2018-2019 The OS/K Team //
// //
// This file is part of OS/K. //
// //
// OS/K 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 //
// any later version. //
// //
// OS/K 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 OS/K. If not, see <https://www.gnu.org/licenses/>. //
//----------------------------------------------------------------------------//
2019-04-24 21:08:44 +02:00
#include <kernel/base.h>
#include <kernel/iomisc.h>
2019-04-24 22:40:12 +02:00
#include <extras/buf.h>
2019-04-24 11:40:14 +02:00
2019-04-24 22:40:12 +02:00
char ScanCodes[100] = { 0 };
2019-04-24 11:40:14 +02:00
2019-04-24 22:40:12 +02:00
void KeybPrint(char code)
{
if (code) {
2019-05-07 23:16:56 +02:00
bputc(BStdIn, ScanCodes[(int)code]);
2019-05-07 22:32:17 +02:00
bputc(BStdOut, ScanCodes[(int)code]);
2019-04-29 23:51:25 +02:00
//bprintf(BStdOut, "%x ", code);
BStdOut->flusher(BStdOut);
2019-04-24 22:40:12 +02:00
}
}
void ScanCodesInit(void)
{
ScanCodes[0x02] = '1';
ScanCodes[0x03] = '2';
ScanCodes[0x04] = '3';
ScanCodes[0x05] = '4';
ScanCodes[0x06] = '5';
ScanCodes[0x07] = '6';
ScanCodes[0x08] = '7';
ScanCodes[0x09] = '8';
ScanCodes[0x0A] = '9';
ScanCodes[0x0B] = '0';
2019-04-29 23:51:25 +02:00
ScanCodes[0x0C] = ' ';
ScanCodes[0x0D] = '+';
2019-05-07 22:32:17 +02:00
ScanCodes[0x0E] = 0x8;
ScanCodes[0x0F] = '\t';
2019-04-24 22:40:12 +02:00
ScanCodes[0x10] = 'a';
ScanCodes[0x11] = 'z';
ScanCodes[0x12] = 'e';
ScanCodes[0x13] = 'r';
ScanCodes[0x14] = 't';
ScanCodes[0x15] = 'y';
ScanCodes[0x16] = 'u';
ScanCodes[0x17] = 'i';
ScanCodes[0x18] = 'o';
ScanCodes[0x19] = 'p';
2019-04-29 23:51:25 +02:00
ScanCodes[0x1A] = '^';
ScanCodes[0x1B] = '$';
2019-04-24 22:40:12 +02:00
ScanCodes[0x1E] = 'q';
ScanCodes[0x1F] = 's';
ScanCodes[0x20] = 'd';
ScanCodes[0x21] = 'f';
ScanCodes[0x22] = 'g';
ScanCodes[0x23] = 'h';
ScanCodes[0x24] = 'j';
ScanCodes[0x25] = 'k';
ScanCodes[0x26] = 'l';
2019-04-29 23:51:25 +02:00
ScanCodes[0x27] = 'm';
ScanCodes[0x28] = 'u';
ScanCodes[0x29] = '*';
2019-04-24 22:40:12 +02:00
ScanCodes[0x2C] = 'w';
ScanCodes[0x2D] = 'x';
ScanCodes[0x2E] = 'c';
ScanCodes[0x2F] = 'v';
ScanCodes[0x30] = 'b';
ScanCodes[0x31] = 'n';
2019-04-29 23:51:25 +02:00
ScanCodes[0x32] = ',';
ScanCodes[0x33] = ';';
ScanCodes[0x34] = ':';
ScanCodes[0x35] = '!';
2019-04-24 11:55:15 +02:00
2019-04-24 22:40:12 +02:00
ScanCodes[0x1C] = '\n';
ScanCodes[0x39] = ' ';
}
2019-04-27 00:04:27 +02:00
void KeybHandler(ISRFrame_t *regs)
2019-04-24 11:55:15 +02:00
{
2019-04-24 21:08:44 +02:00
char status;
char code = 0;
2019-04-24 11:55:15 +02:00
// write EOI
2019-04-24 18:14:23 +02:00
IoWriteByteOnPort(0x20, 0x20);
2019-04-24 11:55:15 +02:00
2019-04-24 21:08:44 +02:00
status = IoReadByteFromPort(0x64);
2019-04-24 11:55:15 +02:00
if (status & 0x01) {
2019-04-24 21:08:44 +02:00
code = IoReadByteFromPort(0x60);
2019-04-24 11:55:15 +02:00
2019-04-24 21:08:44 +02:00
if(code < 0) code = 0;
2019-04-24 11:55:15 +02:00
}
2019-04-24 22:40:12 +02:00
KeybPrint((int)code);
2019-04-24 23:00:12 +02:00
IoSendEOItoPIC(0x21);
2019-04-24 11:55:15 +02:00
}
2019-04-27 00:04:27 +02:00
2019-05-07 22:32:17 +02:00
void IoCreateInputBuffer(void)
{
error_t rc;
rc = BOpenPureBuf(&BStdIn, BS_RDWR, 4 * KB);
if (rc) KeStartPanic("Couldn't create BStdIn");
BEnableLineBuffering(BStdIn);
}
2019-04-27 00:04:27 +02:00
void IoEnableKeyb(void)
{
ulong flags = KePauseIRQs();
2019-05-07 22:32:17 +02:00
2019-05-06 22:04:22 +02:00
IdtRegisterIsr(KeybHandler, 0x21);
2019-04-27 00:04:27 +02:00
char readedInterruptConfig = IoReadByteFromPort(0x21);
IoWriteByteOnPort(0x21, 0xFD & readedInterruptConfig);
2019-05-07 22:32:17 +02:00
2019-04-27 00:04:27 +02:00
KeRestoreIRQs(flags);
2019-05-07 22:32:17 +02:00
2019-04-27 00:04:27 +02:00
IoEnableNMI();
ScanCodesInit();
2019-05-07 22:32:17 +02:00
IoCreateInputBuffer();
2019-04-27 00:04:27 +02:00
}