Espresso 0.0.0e
This commit is contained in:
@ -5,94 +5,18 @@
|
||||
|
||||
|
||||
/*
|
||||
PS/2 Controller IO Ports
|
||||
PS/2 Controller IO Ports
|
||||
|
||||
The PS/2 Controller itself uses 2 IO ports (IO ports 0x60 and 0x64). Like many IO ports, reads and writes may access different internal registers.
|
||||
The PS/2 Controller itself uses 2 IO ports (IO ports 0x60 and 0x64). Like many IO ports, reads and writes may access different internal registers.
|
||||
|
||||
Historical note: The PC-XT PPI had used port 0x61 to reset the keyboard interrupt request signal (among other unrelated functions). Port 0x61 has no keyboard related functions on AT and PS/2 compatibles.
|
||||
IO Port Access Type Purpose
|
||||
0x60 Read/Write Data Port
|
||||
0x64 Read Status Register
|
||||
0x64 Write Command Register
|
||||
Historical note: The PC-XT PPI had used port 0x61 to reset the keyboard interrupt request signal (among other unrelated functions). Port 0x61 has no keyboard related functions on AT and PS/2 compatibles.
|
||||
IO Port Access Type Purpose
|
||||
0x60 Read/Write Data Port
|
||||
0x64 Read Status Register
|
||||
0x64 Write Command Register
|
||||
*/
|
||||
|
||||
#define PS2_DATA_PORT 0x60
|
||||
#define PS2_STATUS_PORT 0x64
|
||||
|
||||
#define KEYBOARD_IRQ 33
|
||||
|
||||
/*extern void register_interrupt_handler(int irq, void (*handler)(void));*/
|
||||
|
||||
static const char scancode_map[128] = {
|
||||
0, 27, '1','2','3','4','5','6','7','8','9','0','-','=','\b', /* Backspace */
|
||||
'\t', /* Tab */
|
||||
'q','w','e','r','t','y','u','i','o','p','[',']','\n', /* Enter */
|
||||
0, /* Control */
|
||||
'a','s','d','f','g','h','j','k','l',';','\'','`',
|
||||
0, /* Left shift */
|
||||
'\\','z','x','c','v','b','n','m',',','.','/',
|
||||
0, /* Right shift */
|
||||
'*',
|
||||
0, /* Alt */
|
||||
' ', /* Spacebar */
|
||||
0, /* Caps lock */
|
||||
/* The rest are function and control keys */
|
||||
};
|
||||
|
||||
static bool shift_pressed = false;
|
||||
|
||||
void keyboard_handler(isr_stack_t* regs)
|
||||
{
|
||||
(void)regs; /* Only here to dismiss the "Unused parameter" warnings */
|
||||
printd("PS/2 Keyboard handler fired!\n");
|
||||
|
||||
uint8_t scancode = inb(PS2_DATA_PORT);
|
||||
|
||||
/* Handle shift press/release */
|
||||
if (scancode == 0x2A || scancode == 0x36)
|
||||
{
|
||||
shift_pressed = true;
|
||||
return;
|
||||
}
|
||||
else if (scancode == 0xAA || scancode == 0xB6)
|
||||
{
|
||||
shift_pressed = false;
|
||||
return;
|
||||
}
|
||||
|
||||
if (scancode & 0x80)
|
||||
{
|
||||
/* Key release event, ignore for now */
|
||||
}
|
||||
else
|
||||
{
|
||||
char c = scancode_map[scancode];
|
||||
if (shift_pressed && c >= 'a' && c <= 'z')
|
||||
{
|
||||
c -= 32; /* Convert to uppercase */
|
||||
}
|
||||
|
||||
if (c)
|
||||
{
|
||||
/* Do something with the keypress (e.g., print or buffer) */
|
||||
printf("Char: %c", c);
|
||||
}
|
||||
}
|
||||
|
||||
outb(0x20, 0x20); /* Acknowledge PIC */
|
||||
}
|
||||
|
||||
void test_handler(isr_stack_t* r) {
|
||||
printf("IRQ1 fired!\n");
|
||||
}
|
||||
|
||||
|
||||
void keyboard_init(void)
|
||||
{
|
||||
outb(0x21, inb(0x21) & ~0x02);
|
||||
|
||||
register_interrupt_handler(KEYBOARD_IRQ, test_handler);
|
||||
|
||||
/* Enable keyboard (controller-specific, often optional if already working) */
|
||||
//outb(0x64, 0xAE);
|
||||
}
|
||||
|
Reference in New Issue
Block a user