Files
novaos/kernel/arch/io/keyb.c
Nathan Singer af92026a74 Okay wow i forgot to commit a bunch of stuff
I added some work on a keyboard driver here
also changed the emulation system, since bochs was giving me headaches when it came to keyboard input
added some todo stuff.. probably some cleanup, idk
2025-06-03 19:08:45 -04:00

96 lines
1.8 KiB
C

#include <stdbool.h>
#include <stdint.h>
#include <queue.h>
#ifdef __TESTING__
#include <kernel/_kernel.h>
#include <stdio.h>
#endif
#include <kernel/x86/keyb.h>
#include <kernel/x86/io.h>
bool is_shift_down = false;
queue kb_cmd_queue;
// current plan is to create a a multi d array
//
//
// 16 entries each for each scan code... so
// 0x01..0x0F (15)/ this is the top row, so esc - 1..0, etc
// 0x10..0x1F (16) ...
// 0x20..0x2F ...
// these arrays will keep a 0/1 flag to see if these keys are pressed
// as a stort of state machine
// this will also let us tell multiple keys pressed
//
// another more simple version, which i could start with
//
// is do a Single character as currently pressed
// and a bitflag we can mask for leftshift, leftctrl, right shift, right ctrl, alt, etc being pressed down
//
//
//
struct keyboard_state keyb_state;
void init_kb(void)
{
#ifdef __TESTING__
puts("Initializing keyboard driver!");
#endif
init_queue(&kb_cmd_queue);
keyb_state.leds = 0;
queue_kb_command(KEYB_CMD_ENABLE_SCANNING);
queue_kb_command(KEYB_CMD_SET_DEFAULT_PARAMS);
//queue_kb_command(KEYB_CMD_SET_TYPEMATIC);
//queue_kb_command(0x1F);
send_kb_commands();
#ifdef __TESTING__
puts("Initialized keyboard driver!");
#endif
}
void queue_kb_command(uint8_t command)
{enqueue(&kb_cmd_queue, command);}
void send_kb_commands(void)
{
int i;
uint8_t resp, cmd;
while (!queue_is_empty(&kb_cmd_queue)) {
cmd = queue_peek(&kb_cmd_queue);
for (i = 0; i < KEYB_CMD_RETRIES; i++) {
outb(KEYB_PORT, cmd);
io_wait();
resp = inb(KEYB_PORT);
io_wait();
switch(resp) {
case KEYB_RESP_ACK:
break;
case KEYB_RESP_RESEND:
continue;
default:
break;
}
}
dequeue(&kb_cmd_queue);
}
}
kb_key_press_t decode_scancode(uint8_t scancode)
{return (kb_key_press_t) scancode;}