From 16a353054050e40a92a83264d726456eafa97df2 Mon Sep 17 00:00:00 2001 From: Bah Thierno-Souleymane <thiernosouleymane.bah.etu@univ-lille.fr> Date: Sat, 15 May 2021 12:07:15 +0200 Subject: [PATCH] feat(putc function added, write a code ascii in a queue) --- include/keyboard.h | 13 +++++++++++++ src/keyboard.c | 23 +++++++++++++++++++++++ 2 files changed, 36 insertions(+) diff --git a/include/keyboard.h b/include/keyboard.h index 72982bc..4c56ccd 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 8904a99..3463526 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 -- GitLab