mirror of
https://github.com/wichtounet/thor-os.git
synced 2025-09-18 09:04:49 -04:00
Rewrite the keyboard driver much more properly
This commit is contained in:
parent
5b300cb7fd
commit
551dd10dc2
@ -3,6 +3,15 @@
|
||||
|
||||
#include "types.hpp"
|
||||
|
||||
namespace keyboard {
|
||||
|
||||
const char KEY_ENTER = 0x1C;
|
||||
const char KEY_BACKSPACE = 0x0E;
|
||||
|
||||
void install_driver();
|
||||
char get_char();
|
||||
char key_to_ascii(uint8_t key);
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
@ -1,6 +1,7 @@
|
||||
#include "memory.hpp"
|
||||
#include "timer.hpp"
|
||||
#include "shell.hpp"
|
||||
#include "keyboard.hpp"
|
||||
|
||||
extern "C" {
|
||||
|
||||
@ -8,6 +9,7 @@ void __attribute__ ((section ("main_section"))) kernel_main(){
|
||||
load_memory_map();
|
||||
init_memory_manager();
|
||||
install_timer();
|
||||
keyboard::install_driver();
|
||||
init_shell();
|
||||
|
||||
return;
|
||||
|
@ -1,4 +1,5 @@
|
||||
#include "keyboard.hpp"
|
||||
#include "kernel_utils.hpp"
|
||||
|
||||
namespace {
|
||||
|
||||
@ -42,8 +43,50 @@ char qwertz[128] =
|
||||
0, /* All other keys are undefined */
|
||||
};
|
||||
|
||||
const uint8_t BUFFER_SIZE = 64;
|
||||
|
||||
char input_buffer[BUFFER_SIZE];
|
||||
volatile uint8_t start;
|
||||
volatile uint8_t count;
|
||||
|
||||
void keyboard_handler(){
|
||||
auto key = static_cast<char>(in_byte(0x60));
|
||||
|
||||
if(count == BUFFER_SIZE){
|
||||
//The buffer is full, we loose the characters
|
||||
} else {
|
||||
auto end = (start + count) % BUFFER_SIZE;
|
||||
input_buffer[end] = key;
|
||||
++count;
|
||||
}
|
||||
}
|
||||
|
||||
char key_to_ascii(uint8_t key){
|
||||
}
|
||||
|
||||
void keyboard::install_driver(){
|
||||
register_irq_handler<1>(keyboard_handler);
|
||||
|
||||
start = 0;
|
||||
count = 0;
|
||||
}
|
||||
|
||||
char keyboard::get_char(){
|
||||
//Wait for the buffer to contains something
|
||||
while(count == 0){
|
||||
__asm__ __volatile__ ("nop");
|
||||
__asm__ __volatile__ ("nop");
|
||||
__asm__ __volatile__ ("nop");
|
||||
__asm__ __volatile__ ("nop");
|
||||
__asm__ __volatile__ ("nop");
|
||||
}
|
||||
|
||||
auto key = input_buffer[start];
|
||||
start = (start + 1) % BUFFER_SIZE;
|
||||
--count;
|
||||
|
||||
return key;
|
||||
}
|
||||
|
||||
char keyboard::key_to_ascii(uint8_t key){
|
||||
return qwertz[key];
|
||||
}
|
||||
|
@ -46,45 +46,44 @@ char current_input[50];
|
||||
|
||||
void exec_command();
|
||||
|
||||
#define KEY_ENTER 0x1C
|
||||
#define KEY_BACKSPACE 0x0E
|
||||
void start_shell(){
|
||||
while(true){
|
||||
auto key = keyboard::get_char();
|
||||
|
||||
void keyboard_handler(){
|
||||
uint8_t key = in_byte(0x60);
|
||||
|
||||
if(key & 0x80){
|
||||
//TODO Handle shift
|
||||
} else {
|
||||
if(key == KEY_ENTER){
|
||||
current_input[current_input_length] = '\0';
|
||||
|
||||
k_print_line();
|
||||
|
||||
exec_command();
|
||||
|
||||
if(get_column() != 0){
|
||||
set_column(0);
|
||||
set_line(get_line() + 1);
|
||||
}
|
||||
|
||||
current_input_length = 0;
|
||||
|
||||
k_print("thor> ");
|
||||
} else if(key == KEY_BACKSPACE){
|
||||
if(current_input_length > 0){
|
||||
set_column(get_column() - 1);
|
||||
k_print(' ');
|
||||
set_column(get_column() - 1);
|
||||
|
||||
--current_input_length;
|
||||
}
|
||||
if(key & 0x80){
|
||||
//TODO Handle shift
|
||||
} else {
|
||||
auto qwertz_key = key_to_ascii(key);
|
||||
if(key == keyboard::KEY_ENTER){
|
||||
current_input[current_input_length] = '\0';
|
||||
|
||||
if(qwertz_key > 0){
|
||||
current_input[current_input_length++] = qwertz_key;
|
||||
k_print(qwertz_key);
|
||||
}
|
||||
k_print_line();
|
||||
|
||||
exec_command();
|
||||
|
||||
if(get_column() != 0){
|
||||
set_column(0);
|
||||
set_line(get_line() + 1);
|
||||
}
|
||||
|
||||
current_input_length = 0;
|
||||
|
||||
k_print("thor> ");
|
||||
} else if(key == keyboard::KEY_BACKSPACE){
|
||||
if(current_input_length > 0){
|
||||
set_column(get_column() - 1);
|
||||
k_print(' ');
|
||||
set_column(get_column() - 1);
|
||||
|
||||
--current_input_length;
|
||||
}
|
||||
} else {
|
||||
auto qwertz_key = keyboard::key_to_ascii(key);
|
||||
|
||||
if(qwertz_key > 0){
|
||||
current_input[current_input_length++] = qwertz_key;
|
||||
k_print(qwertz_key);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -291,5 +290,5 @@ void init_shell(){
|
||||
|
||||
k_print("thor> ");
|
||||
|
||||
register_irq_handler<1>(keyboard_handler);
|
||||
start_shell();
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user