Keyboard driver now works

!forgot, that the §-sign was not in Codepage 437 (The input is no longer offset while holding the shift button)
+Added modifier key support
This commit is contained in:
Morten Delenk 2015-10-17 17:03:32 +02:00
parent 54691d34e3
commit 39b2261758
6 changed files with 58 additions and 18 deletions

View file

@ -8,6 +8,6 @@ ifeq ($(MODE),debug)
CFLAGS += -g3 -DDEBUG
CPPFLAGS += -g3 -DDEBUG
else
CFLAGS += -O9
CPPFLAGS += -O9
# CFLAGS +=
# CPPFLAGS +=
endif

View file

@ -5,8 +5,8 @@ OBJS = $(addsuffix .o,$(basename $(SRCS)))
CPP = $(PREFIX)g++
CC = $(PREFIX)gcc
ASFLAGS = -m32
CFLAGS = -m32 -Wall -fno-stack-protector -nostdinc -Ic_include/ -ffreestanding -march=native -std=c11 -fno-builtin -Werror -nostdlib
CPPFLAGS = -m32 -Wall -fno-stack-protector -nostdinc -std=c++14 -Iinclude/ -Ic_include/ -fno-rtti -fno-exceptions -ffreestanding -march=native -fno-builtin -Werror -nostdlib -fno-use-cxa-atexit -Wextra -Wno-unused
CFLAGS = -m32 -Wall -fno-stack-protector -nostdinc -Ic_include/ -ffreestanding -march=native -std=c11 -fno-builtin -Werror -nostdlib -g
CPPFLAGS = -m32 -Wall -fno-stack-protector -nostdinc -std=c++14 -Iinclude/ -Ic_include/ -fno-rtti -fno-exceptions -ffreestanding -march=native -fno-builtin -Werror -nostdlib -fno-use-cxa-atexit -Wextra -Wno-unused -g
LDFLAGS = -r -melf_i386

View file

@ -14,6 +14,7 @@ namespace MTGosHAL {
extern Serial debug;
extern Screen out;
extern Screen err;
extern Keyboard in;
extern GDT gdt;
extern IDT idt;
}

View file

@ -1,4 +1,4 @@
#ifndef _KEYBOARD_HPP
#ifndef _KEYBOARD_HPP
#define _KEYBOARD_HPP
#include <stdint.h>
#include <input.hpp>
@ -8,14 +8,15 @@ namespace MTGosHAL {
class Keyboard: public Input {
private:
//This kernel has a buffer of 16 chars
char buf[16];
int len;
auto getChar() -> char;
auto sendCommand(uint8_t command) -> void;
static auto handleIRQ1(struct cpu_state* cpu) -> void;
bool numlock, caps, scrollock;
bool numlock, capslock, scrolllock, response;
public:
auto handleIRQ1(struct cpu_state* cpu) -> void;
Keyboard();
};
}

View file

@ -5,12 +5,12 @@
#define CTRL 2
#define ALT 4
char keymap[8][0x80] = {
"\0\0001234567890\xe1\xa7\b\0qwertzuiop\x81+\n\0asdfghjkl\x94\x84^\0#yxcvbnm,.-\0*\0 \0\0\0\0\0\0\0\0\0\0\0\0\000789-456+1230,<\0\n\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0", // No modifier
"\0\000!\"§$%&/()=?`\b\0QWERTZUIOP\x9A*\n\0ASDFGHJKL\x99\x8e\xF8\0'YXCVBNM;:_\0*\0 \0\0\0\0\0\0\0\0\0\0\0\0\0789-456+1230,>\0\n\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0", // Shift modifier
"\0\0001234567890\xe1\xa7\b\0qwertzuiop\x81+\n\0asdfghjkl\x94\x84^\0#yxcvbnm,.-\0*\0 \0\0\0\0\0\0\0\0\0\0\0\0\0789-456+1230,<\0\0\n\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0", // Control modifier
"\0\000!\"§$%&/()=?`\b\0QWERTZUIOP\x9A*\n\0ASDFGHJKL\x99\x8e\xF8\0'YXCVBNM;:_\0*\0 \0\0\0\0\0\0\0\0\0\0\0\0\0789-456+1230,>\0\0\n\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0", // Control+Shift modifiers
"\0\0001234567890\xe1\xa7\b\0qwertzuiop\x81+\n\0asdfghjkl\x94\x84^\0#yxcvbnm,.-\0*\0 \0\0\0\0\0\0\0\0\0\0\0\0\0789-456+1230,<\0\0\n\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0", // Alt modifier
"\0\000!\"§$%&/()=?`\b\0QWERTZUIOP\x9A*\n\0ASDFGHJKL\x99\x8e\xF8\0'YXCVBNM;:_\0*\0 \0\0\0\0\0\0\0\0\0\0\0\0\0789-456+1230,>\0\0\n\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0", // Alt+Shift modifiers
"\0\0001234567890\xe1\0\b\0qwertzuiop\x81+\n\0asdfghjkl\x94\x84^\0#yxcvbnm,.-\0*\0 \0\0\0\0\0\0\0\0\0\0\0\0\000789-456+1230,<\0\n\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0", // No modifier
"\0\000!\"\0$%&/()=?`\b\0QWERTZUIOP\x9A*\n\0ASDFGHJKL\x99\x8e\xF8\0'YXCVBNM;:_\0*\0 \0\0\0\0\0\0\0\0\0\0\0\0\0789-456+1230,>\0\n\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0", // Shift modifier
"\0\0001234567890\xe1\0\b\0qwertzuiop\x81+\n\0asdfghjkl\x94\x84^\0#yxcvbnm,.-\0*\0 \0\0\0\0\0\0\0\0\0\0\0\0\0789-456+1230,<\0\0\n\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0", // Control modifier
"\0\000!\"\0$%&/()=?`\b\0QWERTZUIOP\x9A*\n\0ASDFGHJKL\x99\x8e\xF8\0'YXCVBNM;:_\0*\0 \0\0\0\0\0\0\0\0\0\0\0\0\0789-456+1230,>\0\0\n\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0", // Control+Shift modifiers
"\0\0001234567890\xe1\0\b\0qwertzuiop\x81+\n\0asdfghjkl\x94\x84^\0#yxcvbnm,.-\0*\0 \0\0\0\0\0\0\0\0\0\0\0\0\0789-456+1230,<\0\0\n\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0", // Alt modifier
"\0\000!\"\0$%&/()=?`\b\0QWERTZUIOP\x9A*\n\0ASDFGHJKL\x99\x8e\xF8\0'YXCVBNM;:_\0*\0 \0\0\0\0\0\0\0\0\0\0\0\0\0789-456+1230,>\0\0\n\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0", // Alt+Shift modifiers
"\0\0001\xFD\x33\xAC\xAB\xAA{[]}\\\xa7\b\0@w\xEErtzui\xEDp\x81~\n\0\x91sdfghjkl\x94^\0#\xAF\xAE\x9Bvbn\xe6,.-\0*\0 \0\0\0\0\0\0\0\0\0\0\0\0\0789-456+1230,|\0\0\n\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0", // Control+Alt modifiers
"\0\000\xAD\"\x9C\x0F%&/(\xF1\xF8\xA8`\b\0\xEAW\xEERT\x9DUIOP\xF8*\n\0\x92SD\xA6GHJ&L\x99\x8e\xF8\0|YXCVBN\xF8;\xF6_\0*\0 \0\0\0\0\0\0\0\0\0\0\0\0\0789-456+1230,|\0\0\n\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0", // Control+Shift modifiers
};

View file

@ -3,6 +3,9 @@
#include <serial.hpp>
#include <keyboard.hpp>
#include <keymap_DE.hpp>
auto handleIRQ(struct cpu_state* cpu) -> void {
return MTGosHAL::in.handleIRQ1(cpu);
}
namespace MTGosHAL {
auto Keyboard::getChar() -> char {
char chr=buf[0];
@ -20,10 +23,20 @@ namespace MTGosHAL {
}
auto Keyboard::handleIRQ1(struct cpu_state* cpu) -> void {
uint8_t keycode=0,scancode=inb(0x60);
if(scancode==0xFA) {
response=false;
return;
} else if(response && scancode == 0xFE) {
sendCommand(0xED);
outb(0x60, (scrolllock) + (numlock<<1) + (capslock<<2));
return;
}
debug << "Keyboard interrupt received.\nGot: 0x" << Base::HEXADECIMAL << (int)scancode;
bool break_code=false;
static bool e0_code=false;
static int e1_code=0;
static uint16_t e1_prev=0;
uint8_t tableID=0;
if((scancode & 0x80 ) && (e1_code || (scancode != 0xE1)) && (e0_code || (scancode != 0xE0))) {
break_code = true;
scancode &= ~0x80;
@ -57,14 +70,39 @@ namespace MTGosHAL {
keydowns[keycode]=false;
else
keydowns[keycode]=true;
//0x2A 0x36 = Shift
if(keydowns[0x2A] || keydowns[0x36])
tableID^=1;
//0x1D = Ctrl
if(keydowns[0x1D])
tableID^=2;
//0x38 = Alt
if(keydowns[0x38])
tableID^=4;
//0x45 = Numlock
if(keycode==0x45)
numlock=!numlock;
//0x3A = CAPS
if(keycode==0x3A)
capslock=!capslock;
//0x46 = Scrolllock
if(keycode==0x46)
scrolllock=!scrolllock;
if(capslock)
tableID^=1;
//Correct the LEDs
sendCommand(0xED);
outb(0x60, (scrolllock) + (numlock<<1) + (capslock<<2));
response=true;
//Convert it into a char
if(!break_code)
out << keymap[0][keycode];
//TODO add checking for shift, and so on
debug << "Keyboard interrupt received.\nGot: 0x" << Base::HEXADECIMAL << (int)scancode << " -> 0x" << (int)keycode << ".\n";
out << keymap[tableID][keycode];
debug << " -> 0x" << (int)keycode << ".\n";
}
Keyboard::Keyboard(): numlock(true), caps(false), scrollock(false) {
if(!idt.request(0x21, (void(*)(struct cpu_state*))&MTGosHAL::Keyboard::handleIRQ1)) {
Keyboard::Keyboard(): numlock(true), capslock(false), scrolllock(false), response(false) {
if(!idt.request(0x21, (void(*)(struct cpu_state*))&handleIRQ)) {
debug << "Could not get an handler for IRQ1 (Keyboard)\n";
return;
}