Store device structs in a dynamic list

This commit is contained in:
2025-10-03 22:25:16 +02:00
parent c0178a1405
commit 57ba9ff126
10 changed files with 44 additions and 24 deletions

View File

@ -7,7 +7,8 @@
typedef int32_t (*DevFn)(uint8_t *buffer, size_t len, void *extra);
typedef struct {
typedef struct Dev {
struct Dev *next;
DevFn fns[DEV_FNS_MAX];
} Dev;

View File

@ -6,6 +6,8 @@
#include "dev.h"
#include "errors.h"
#include "dlmalloc/malloc.h"
#include "util/util.h"
#include "syscall/devctl.h"
Dev PS2KBDEV;
Ps2KbFastBuf PS2KB_BUF;
@ -32,4 +34,5 @@ void ps2kbdev_init(void) {
uint8_t *buf = dlmalloc(bufsz);
rbuf_init(&PS2KB_BUF.rbuf, buf, bufsz);
PS2KB_BUF.init = true;
LL_APPEND(DEVS, &PS2KBDEV);
}

View File

@ -5,6 +5,8 @@
#include "termdev.h"
#include "dev.h"
#include "errors.h"
#include "util/util.h"
#include "syscall/devctl.h"
Dev TERMDEV;
@ -16,4 +18,5 @@ int32_t termdev_putch(uint8_t *buffer, size_t len, void *extra) {
void termdev_init(void) {
hal_memset(&TERMDEV, 0, sizeof(TERMDEV));
TERMDEV.fns[0] = &termdev_putch;
LL_APPEND(DEVS, &TERMDEV);
}