adds a queue library, work for keyb driver
This commit is contained in:
@ -31,6 +31,7 @@ void exception_handler(unsigned int i)
|
|||||||
//kinfo("Sending EOI instruction to KEYB");
|
//kinfo("Sending EOI instruction to KEYB");
|
||||||
#endif
|
#endif
|
||||||
unsigned char in = inb(0x60);
|
unsigned char in = inb(0x60);
|
||||||
|
|
||||||
char to_print = decode_key_enum(decode_scancode(in));
|
char to_print = decode_key_enum(decode_scancode(in));
|
||||||
if (to_print != '\0')
|
if (to_print != '\0')
|
||||||
printf("%c", to_print);
|
printf("%c", to_print);
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
#include <kernel/x86/keyb.h>
|
#include <kernel/x86/keyb.h>
|
||||||
|
|
||||||
|
@ -3,6 +3,20 @@
|
|||||||
#ifndef ARCH_KEYB_H
|
#ifndef ARCH_KEYB_H
|
||||||
#define ARCH_KEYB_H
|
#define ARCH_KEYB_H
|
||||||
|
|
||||||
|
#define KEYB_DATA_PORT (0x60)
|
||||||
|
#define KEYB_STATUS_PORT (0x64)
|
||||||
|
#define KEYB_COMMAND_PORT (0x64)
|
||||||
|
|
||||||
|
|
||||||
|
#define KEYB_RESP_ERR (0x00)
|
||||||
|
#define KEYB_RESP_SELF_TEST_PASSED (0xAA)
|
||||||
|
#define KEYB_RESP_ECHO (0xEE)
|
||||||
|
#define KEYB_RESP_ACK (0xFA)
|
||||||
|
#define KEYB_RESP_SELF_TEST_FAILED (0xFC)
|
||||||
|
#define KEYB_RESP_SELF_TEST_FAILED_TWO (0xFD)
|
||||||
|
#define KEYB_RESP_RESEND (0xFE)
|
||||||
|
#define KEYB_RESP_ERR_TWO (0xFF)
|
||||||
|
|
||||||
typedef enum {
|
typedef enum {
|
||||||
KEY_ESC = 0x01,
|
KEY_ESC = 0x01,
|
||||||
KEY_1, KEY_2, KEY_3, KEY_4, KEY_5, KEY_6, KEY_7, KEY_8, KEY_9, KEY_0,
|
KEY_1, KEY_2, KEY_3, KEY_4, KEY_5, KEY_6, KEY_7, KEY_8, KEY_9, KEY_0,
|
||||||
@ -58,8 +72,10 @@ typedef enum {
|
|||||||
KEY_F12_R,
|
KEY_F12_R,
|
||||||
} kb_key_press_t;
|
} kb_key_press_t;
|
||||||
|
|
||||||
kb_key_press_t decode_scancode(uint8_t scancode);
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
kb_key_press_t decode_scancode(uint8_t scancode);
|
||||||
char decode_key_enum(kb_key_press_t keycode);
|
char decode_key_enum(kb_key_press_t keycode);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
25
libc/include/queue.h
Normal file
25
libc/include/queue.h
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
|
#ifndef QUEUE_H
|
||||||
|
#define QUEUE_H
|
||||||
|
|
||||||
|
#define MAX_QUEUE_SIZE 100
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
uint8_t items[MAX_QUEUE_SIZE];
|
||||||
|
short front;
|
||||||
|
short rear;
|
||||||
|
} queue;
|
||||||
|
|
||||||
|
void init_queue(queue* q);
|
||||||
|
|
||||||
|
bool queue_is_empty(queue* q);
|
||||||
|
bool queue_is_full(queue* q);
|
||||||
|
|
||||||
|
void enqueue(queue* q, uint8_t val);
|
||||||
|
void dequeue(queue* q);
|
||||||
|
|
||||||
|
uint8_t queue_peek(queue* q);
|
||||||
|
|
||||||
|
|
||||||
|
#endif
|
53
libc/queue/queue.c
Normal file
53
libc/queue/queue.c
Normal file
@ -0,0 +1,53 @@
|
|||||||
|
#ifdef __TESTING__
|
||||||
|
#include <kernel/_kernel.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include <stdint.h>
|
||||||
|
#include <stdbool.h>
|
||||||
|
|
||||||
|
#include <queue.h>
|
||||||
|
|
||||||
|
void init_queue(queue *q)
|
||||||
|
{
|
||||||
|
q->front = -1;
|
||||||
|
q->rear = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool queue_is_empty(queue *q)
|
||||||
|
{return (q->front == q->rear - 1);} ; // TODO: if this returns true, shouldn't we just be re-init-ing because we have the space to take up that used array
|
||||||
|
bool queue_is_full(queue *q)
|
||||||
|
{return (q->rear == MAX_QUEUE_SIZE);} // TODO: this is an error for SURE
|
||||||
|
|
||||||
|
void enqueue(queue *q, uint8_t val)
|
||||||
|
{
|
||||||
|
if (queue_is_full(q)) {
|
||||||
|
#ifdef __TESTING__
|
||||||
|
kwarn("Queue being added to is full!!"); // TODO add a way to print like code lines and addresses to stack trace this
|
||||||
|
#endif
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
q->items[q->rear++] = val;
|
||||||
|
}
|
||||||
|
|
||||||
|
void dequeue(queue* q)
|
||||||
|
{
|
||||||
|
if (queue_is_empty(q)) {
|
||||||
|
#ifdef __TESTING__
|
||||||
|
kwarn("Queue thats already empty is trying to be removed from!!!"); // TODO same as above
|
||||||
|
#endif
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
q->front++;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint8_t peek(queue* q)
|
||||||
|
{
|
||||||
|
if (queue_is_empty(q)) {
|
||||||
|
#ifdef __TESTING__
|
||||||
|
kwarn("Peeking an empty queue!");
|
||||||
|
#endif
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
}
|
||||||
|
return q->items[q->front + 1];
|
||||||
|
}
|
Reference in New Issue
Block a user