diff options
author | Benji Dial <benji6283@gmail.com> | 2021-02-19 22:24:08 -0500 |
---|---|---|
committer | Benji Dial <benji6283@gmail.com> | 2021-02-19 22:24:08 -0500 |
commit | eae7442610215e55ea350c65aab4ab3869111014 (patch) | |
tree | 601aa476e52a5e3bb3b352df7e781d3aa11c090b /src/kernel/kbd.c | |
parent | cba9eec34b205c760f16f7171b58bfc906723b72 (diff) | |
download | portland-os-eae7442610215e55ea350c65aab4ab3869111014.tar.gz |
kernel settings file
Diffstat (limited to 'src/kernel/kbd.c')
-rw-r--r-- | src/kernel/kbd.c | 25 |
1 files changed, 21 insertions, 4 deletions
diff --git a/src/kernel/kbd.c b/src/kernel/kbd.c index c09684d..96d2069 100644 --- a/src/kernel/kbd.c +++ b/src/kernel/kbd.c @@ -1,14 +1,16 @@ #include <stdint.h> +#include "settings.h" #include "window.h" #include "drive.h" #include "panic.h" #include "pmap.h" #include "util.h" #include "kbd.h" +#include "log.h" -#define SCANTAB_DIR "sys/scantabs" -#define LAYOUT_HARDCODE_TMP "qwerty" +#define SCANTAB_DIR "sys/scantabs/" +#define SCANTAB_DIR_LEN 13 enum { PS2_CMD = 0x64, @@ -45,14 +47,29 @@ enum { ST_SKIP }; +#define LAYOUT_NAME_MAX_LEN 31 +static char scantab_path[SCANTAB_DIR_LEN + LAYOUT_NAME_MAX_LEN + 5] = SCANTAB_DIR; + void init_kbd() { outb(PS2_CMD, PS2C_READ_CONFIG); uint8_t config = inb(PS2_DATA); outb(PS2_CMD, PS2C_WRITE_CONFIG); outb(PS2_DATA, config | PS2G_XT_COMPAT); - //TODO: get layout from some config file - file_id_t stf = drives->get_file(drives, SCANTAB_DIR "/" LAYOUT_HARDCODE_TMP ".sct"); + uint32_t layout_len; + if (!try_get_sz_setting("kbd-layout", scantab_path + SCANTAB_DIR_LEN, LAYOUT_NAME_MAX_LEN, &layout_len)) + PANIC("keyboard layout not found in settings file."); + if (layout_len == LAYOUT_NAME_MAX_LEN) + logf(LOG_WARN, "keyboard layout name potentially cropped."); + scantab_path[SCANTAB_DIR_LEN + layout_len] = '.'; + scantab_path[SCANTAB_DIR_LEN + layout_len + 1] = 's'; + scantab_path[SCANTAB_DIR_LEN + layout_len + 2] = 'c'; + scantab_path[SCANTAB_DIR_LEN + layout_len + 3] = 't'; + scantab_path[SCANTAB_DIR_LEN + layout_len + 4] = '\0'; + logf(LOG_INFO, "Using scantab file at \"%s\".", scantab_path); + file_id_t stf = drives->get_file(drives, scantab_path); + if (!stf) + PANIC("could not load scantab file."); fmcpy(&n_scantabs, drives, stf, 0, 4); scantabs = allocate_kernel_pages((sizeof(struct scantab_info) * n_scantabs - 1) / 4096 + 1); |