diff --git a/include/keyboard.h b/include/keyboard.h index 72982bc42028433d6df6678c746433f27026352b..4c56ccd0c1bad889dfe8d505ba3473cfa6734648 100644 --- a/include/keyboard.h +++ b/include/keyboard.h @@ -5,6 +5,7 @@ #define SHIFT_UP 0x2A #define SHIFT_DOWN 0xAA #define NB_KEYS 256 +#define QUEUE_SIZE 8 typedef enum boolean { @@ -20,10 +21,22 @@ typedef struct key_s unsigned char top; } key_t; +typedef struct queue_s +{ + unsigned char first_free; + unsigned char cpt; + char array[QUEUE_SIZE]; +} queue_t; + key_t KEY_MAPPING[NB_KEYS]; +queue_t keyboard_queue; void init_keymapping(); char keyboard_map(unsigned char code); +void init_queue(); + +void putc(char c); + #endif diff --git a/src/keyboard.c b/src/keyboard.c index 8904a99a21a62d367d8e56273f8a62b67441322b..34635267d81e81fc473594c2001c5d2522d16457 100644 --- a/src/keyboard.c +++ b/src/keyboard.c @@ -78,4 +78,27 @@ char keyboard_map(unsigned char code) if (shift_pressed) return KEY_MAPPING[code].top; return KEY_MAPPING[code].bottom; +} + +void init_queue() +{ + keyboard_queue.cpt = 0; + keyboard_queue.first_free = 0; +} + +void putc(unsigned char c) +{ + irq_disable(); + + if (c == NONE) + return; + + if (keyboard_queue.cpt < QUEUE_SIZE) + { + keyboard_queue.cpt++; + keyboard_queue.first_free = (keyboard_queue.first_free + 1) % QUEUE_SIZE; + keyboard_queue.array[keyboard_queue.first_free] = c; + } + + irq_enable(); } \ No newline at end of file