réplica de
https://github.com/Arnau478/quark.git
synced 2024-11-23 12:58:07 +01:00
PS/2 keyboard driver
This commit is contained in:
pare
e93cf7db3c
commit
08a6ed51bb
S'han modificat 10 arxius amb 89 adicions i 6 eliminacions
51
src/kernel/drivers/keyboard.c
Normal file
51
src/kernel/drivers/keyboard.c
Normal file
|
@ -0,0 +1,51 @@
|
|||
#include "../util/string.h"
|
||||
#include "keyboard.h"
|
||||
#include "../arch/i686/isr.h"
|
||||
#include "../stdio.h"
|
||||
#include "../arch/i686/io.h"
|
||||
#include "../stdio.h"
|
||||
|
||||
static char g_key_buffer[256];
|
||||
|
||||
static const char g_sc_ascii[128] = {
|
||||
'?', '?', '1', '2', '3', '4', '5', '6',
|
||||
'7', '8', '9', '0', '-', '=', '?', '?',
|
||||
'Q', 'W', 'E', 'R', 'T', 'Y', 'U', 'I',
|
||||
'O', 'P', '[', ']', '?', '?', 'A', 'S',
|
||||
'D', 'F', 'G', 'H', 'J', 'K', 'L', ';',
|
||||
'\'', '`', '?', '\\', 'z', 'x', 'c', 'v',
|
||||
'B', 'N', 'M', ',', '.', '/', '?', '?',
|
||||
'?', ' '
|
||||
};
|
||||
|
||||
static void user_input(char *str){
|
||||
printf("In: \"%s\"\n", str);
|
||||
}
|
||||
|
||||
static void keyboard_callback(){
|
||||
uint8_t scancode = i686_inb(0x60);
|
||||
//printf("KEYBOARD (%i)!\n", scancode);
|
||||
if(scancode < 128){ // If it's a "pressed" event, not "released"
|
||||
if(scancode == 0x0E){ // Backspace
|
||||
putc('\b');
|
||||
g_key_buffer[strlen(g_key_buffer)-1] = '\0';
|
||||
}
|
||||
else if(scancode == 0x1C){ // Enter
|
||||
putc('\n');
|
||||
user_input(g_key_buffer);
|
||||
g_key_buffer[0] = '\0';
|
||||
}
|
||||
else{
|
||||
putc(g_sc_ascii[scancode]);
|
||||
|
||||
// strlen() works here because char[] is the same as
|
||||
// char*, and both are null-terminated, so they are
|
||||
// exactly the same
|
||||
g_key_buffer[strlen(g_key_buffer)] = g_sc_ascii[scancode];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void keyboard_initialize(){
|
||||
i686_isr_register_handler(IRQ(1), keyboard_callback);
|
||||
}
|
3
src/kernel/drivers/keyboard.h
Normal file
3
src/kernel/drivers/keyboard.h
Normal file
|
@ -0,0 +1,3 @@
|
|||
#pragma once
|
||||
|
||||
void keyboard_initialize();
|
|
@ -3,7 +3,7 @@
|
|||
#include "../stdio.h"
|
||||
|
||||
static void timer_handler(registers *regs){
|
||||
printf("TICK\n");
|
||||
//printf("TICK\n");
|
||||
}
|
||||
|
||||
void timer_initialize(){
|
||||
|
|
|
@ -50,9 +50,12 @@ int vga_print_char(char c, int x, int y){
|
|||
offset = (y+1)*VGA_WIDTH;
|
||||
}
|
||||
else if(c == '\b'){
|
||||
if(offset != 0){
|
||||
offset--;
|
||||
VGA_MEMORY[offset*2] = ' ';
|
||||
VGA_MEMORY[offset*2+1] = current_color;
|
||||
}
|
||||
}
|
||||
else{
|
||||
VGA_MEMORY[offset*2] = c;
|
||||
VGA_MEMORY[offset*2+1] = current_color;
|
||||
|
@ -115,3 +118,12 @@ void vga_print_string_at(char *str, int x, int y){
|
|||
void vga_print_string(char *str){
|
||||
vga_print_string_at(str, -1, -1);
|
||||
}
|
||||
|
||||
void vga_fill_screen(char c, uint8_t color){
|
||||
for(int y = 0; y < VGA_HEIGHT; y++){
|
||||
for(int x = 0; x < VGA_WIDTH; x++){
|
||||
vga_set_char(x, y, c);
|
||||
vga_set_color(x, y, color);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -53,3 +53,4 @@ int vga_get_cursor();
|
|||
int vga_print_char(char c, int x, int y);
|
||||
void vga_print_string_at(char *str, int x, int y);
|
||||
void vga_print_string(char *str);
|
||||
void vga_fill_screen(char c, uint8_t color);
|
||||
|
|
|
@ -2,13 +2,13 @@
|
|||
#include "stdio.h"
|
||||
#include "hal/hal.h"
|
||||
#include "drivers/timer.h"
|
||||
#include "drivers/keyboard.h"
|
||||
|
||||
void __attribute__((cdecl)) kmain(uint64_t magic, uint64_t addr){
|
||||
hal_initialize();
|
||||
timer_initialize();
|
||||
keyboard_initialize();
|
||||
|
||||
puts("\x1b[33mWARNING\x1b[0m");
|
||||
printf(": amazing %s ahead!\n", "math");
|
||||
printf("%i+%i=%i\n", 1, 1, 2);
|
||||
clear_screen();
|
||||
for(;;);
|
||||
}
|
||||
|
|
|
@ -101,3 +101,8 @@ void printf(char *fmt, ...){
|
|||
else putc(*(fmt++));
|
||||
}
|
||||
}
|
||||
|
||||
void clear_screen(){
|
||||
vga_fill_screen(' ', VGA_COLOR_BG_BLACK | VGA_COLOR_FG_WHITE);
|
||||
vga_set_cursor(0);
|
||||
}
|
||||
|
|
|
@ -3,3 +3,4 @@
|
|||
void puts(char *str);
|
||||
void putc(char c);
|
||||
void printf(char *fmt, ...);
|
||||
void clear_screen();
|
||||
|
|
7
src/kernel/util/string.c
Normal file
7
src/kernel/util/string.c
Normal file
|
@ -0,0 +1,7 @@
|
|||
#include "string.h"
|
||||
|
||||
int strlen(char *s){
|
||||
int len = 0;
|
||||
while(*(s++)) len++;
|
||||
return len;
|
||||
}
|
3
src/kernel/util/string.h
Normal file
3
src/kernel/util/string.h
Normal file
|
@ -0,0 +1,3 @@
|
|||
#pragma once
|
||||
|
||||
int strlen(char *s);
|
Loading…
Referencia en una nova incidència