summaryrefslogtreecommitdiff
path: root/src/kernel/arch/i386/driver/ps2.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/kernel/arch/i386/driver/ps2.c')
-rw-r--r--src/kernel/arch/i386/driver/ps2.c23
1 files changed, 6 insertions, 17 deletions
diff --git a/src/kernel/arch/i386/driver/ps2.c b/src/kernel/arch/i386/driver/ps2.c
index 5121b9e..4b7eae4 100644
--- a/src/kernel/arch/i386/driver/ps2.c
+++ b/src/kernel/arch/i386/driver/ps2.c
@@ -1,31 +1,20 @@
#include <kernel/arch/i386/driver/ps2.h>
#include <kernel/arch/i386/interrupts/irq.h>
+#include <shared/container/ring.h>
#include <shared/mem.h>
#define BACKLOG_CAPACITY 64
-
-static volatile uint8_t backlog[BACKLOG_CAPACITY] = {};
-static volatile size_t backlog_size = 0;
+static volatile uint8_t backlog_buf[BACKLOG_CAPACITY];
+static volatile ring_t backlog = {(void*)backlog_buf, BACKLOG_CAPACITY, 0, 0};
bool ps2_ready(void) {
- return backlog_size > 0;
+ return ring_size((void*)&backlog) > 0;
}
void ps2_recv(uint8_t s) {
- if (backlog_size >= BACKLOG_CAPACITY) return;
- backlog[backlog_size++] = s;
+ ring_put1b((void*)&backlog, s);
}
size_t ps2_read(uint8_t *buf, size_t len) {
- if (backlog_size <= len)
- len = backlog_size;
- backlog_size -= len; /* guaranteed to never be < 0 */
- memcpy(buf, (void*)backlog, len);
-
- /* move rest of buffer back on partial reads */
- // TODO assumes that memcpy()ing into an overlapping buffer is fine, outside spec
- if (backlog_size > 0)
- memcpy((void*)backlog, (void*)backlog + len, backlog_size);
-
- return len;
+ return ring_get((void*)&backlog, buf, len);
}