PatchworkOS
Loading...
Searching...
No Matches
kbd.c
Go to the documentation of this file.
1#include "kbd.h"
2
3// TODO: Create a system for keymap files
4
5typedef struct
6{
7 char norm;
8 char shift;
10
11typedef struct
12{
14} keymap_t;
15
16static keymap_t keymap = {
17 .map =
18 {
19 [KBD_A] = {.norm = 'a', .shift = 'A'},
20 [KBD_B] = {.norm = 'b', .shift = 'B'},
21 [KBD_C] = {.norm = 'c', .shift = 'C'},
22 [KBD_D] = {.norm = 'd', .shift = 'D'},
23 [KBD_E] = {.norm = 'e', .shift = 'E'},
24 [KBD_F] = {.norm = 'f', .shift = 'F'},
25 [KBD_G] = {.norm = 'g', .shift = 'G'},
26 [KBD_H] = {.norm = 'h', .shift = 'H'},
27 [KBD_I] = {.norm = 'i', .shift = 'I'},
28 [KBD_J] = {.norm = 'j', .shift = 'J'},
29 [KBD_K] = {.norm = 'k', .shift = 'K'},
30 [KBD_L] = {.norm = 'l', .shift = 'L'},
31 [KBD_M] = {.norm = 'm', .shift = 'M'},
32 [KBD_N] = {.norm = 'n', .shift = 'N'},
33 [KBD_O] = {.norm = 'o', .shift = 'O'},
34 [KBD_P] = {.norm = 'p', .shift = 'P'},
35 [KBD_Q] = {.norm = 'q', .shift = 'Q'},
36 [KBD_R] = {.norm = 'r', .shift = 'R'},
37 [KBD_S] = {.norm = 's', .shift = 'S'},
38 [KBD_T] = {.norm = 't', .shift = 'T'},
39 [KBD_U] = {.norm = 'u', .shift = 'U'},
40 [KBD_V] = {.norm = 'v', .shift = 'V'},
41 [KBD_W] = {.norm = 'w', .shift = 'W'},
42 [KBD_X] = {.norm = 'x', .shift = 'X'},
43 [KBD_Y] = {.norm = 'y', .shift = 'Y'},
44 [KBD_Z] = {.norm = 'z', .shift = 'Z'},
45
46 [KBD_1] = {.norm = '1', .shift = '!'},
47 [KBD_2] = {.norm = '2', .shift = '@'},
48 [KBD_3] = {.norm = '3', .shift = '#'},
49 [KBD_4] = {.norm = '4', .shift = '$'},
50 [KBD_5] = {.norm = '5', .shift = '%'},
51 [KBD_6] = {.norm = '6', .shift = '^'},
52 [KBD_7] = {.norm = '7', .shift = '&'},
53 [KBD_8] = {.norm = '8', .shift = '*'},
54 [KBD_9] = {.norm = '9', .shift = '('},
55 [KBD_0] = {.norm = '0', .shift = ')'},
56
57 [KBD_ENTER] = {.norm = '\n', .shift = '\n'},
58 [KBD_ESC] = {.norm = 0x1B, .shift = 0x1B},
59 [KBD_BACKSPACE] = {.norm = 0x08, .shift = 0x08},
60 [KBD_TAB] = {.norm = '\t', .shift = '\t'},
61 [KBD_SPACE] = {.norm = ' ', .shift = ' '},
62 [KBD_MINUS] = {.norm = '-', .shift = '_'},
63 [KBD_EQUAL] = {.norm = '=', .shift = '+'},
64 [KBD_LEFT_BRACE] = {.norm = '[', .shift = '{'},
65 [KBD_RIGHT_BRACE] = {.norm = ']', .shift = '}'},
66 [KBD_BACKSLASH] = {.norm = '\\', .shift = '|'},
67 [KBD_HASHTILDE] = {.norm = '#', .shift = '~'},
68 [KBD_SEMICOLON] = {.norm = ';', .shift = ':'},
69 [KBD_APOSTROPHE] = {.norm = '\'', .shift = '"'},
70 [KBD_GRAVE] = {.norm = '`', .shift = '~'},
71 [KBD_COMMA] = {.norm = ',', .shift = '<'},
72 [KBD_PERIOD] = {.norm = '.', .shift = '>'},
73 [KBD_SLASH] = {.norm = '/', .shift = '?'},
74
75 [KBD_KP_0] = {.norm = '0', .shift = KBD_NONE},
76 [KBD_KP_1] = {.norm = '1', .shift = KBD_NONE},
77 [KBD_KP_2] = {.norm = '2', .shift = KBD_NONE},
78 [KBD_KP_3] = {.norm = '3', .shift = KBD_NONE},
79 [KBD_KP_4] = {.norm = '4', .shift = KBD_NONE},
80 [KBD_KP_5] = {.norm = '5', .shift = KBD_NONE},
81 [KBD_KP_6] = {.norm = '6', .shift = KBD_NONE},
82 [KBD_KP_7] = {.norm = '7', .shift = KBD_NONE},
83 [KBD_KP_8] = {.norm = '8', .shift = KBD_NONE},
84 [KBD_KP_9] = {.norm = '9', .shift = KBD_NONE},
85 [KBD_KP_PERIOD] = {.norm = '.', .shift = KBD_NONE},
86 [KBD_KP_SLASH] = {.norm = '/', .shift = KBD_NONE},
87 [KBD_KP_ASTERISK] = {.norm = '*', .shift = KBD_NONE},
88 [KBD_KP_MINUS] = {.norm = '-', .shift = KBD_NONE},
89 [KBD_KP_PLUS] = {.norm = '+', .shift = KBD_NONE},
90 [KBD_KP_ENTER] = {.norm = '\n', .shift = '\n'},
91 [KBD_KP_EQUAL] = {.norm = '=', .shift = '='},
92 },
93};
94
96{
97 if (code < 0 || code >= UINT8_MAX)
98 {
99 return '\0';
100 }
101 else
102 {
103 return mods & KBD_MOD_SHIFT ? keymap.map[code].shift : keymap.map[code].norm;
104 }
105}
keycode_t
Keyboard keycode type.
Definition kbd.h:27
kbd_mods_t
Keyboard modifiers type.
Definition kbd.h:297
@ KBD_KP_4
Keypad 4.
Definition kbd.h:125
@ KBD_2
Key 2.
Definition kbd.h:60
@ KBD_6
Key 6.
Definition kbd.h:64
@ KBD_1
Key 1.
Definition kbd.h:59
@ KBD_4
Key 4.
Definition kbd.h:62
@ KBD_K
Key K.
Definition kbd.h:42
@ KBD_SPACE
Space key.
Definition kbd.h:74
@ KBD_T
Key T.
Definition kbd.h:51
@ KBD_R
Key R.
Definition kbd.h:49
@ KBD_GRAVE
Grave accent key.
Definition kbd.h:83
@ KBD_PERIOD
Period key.
Definition kbd.h:85
@ KBD_Q
Key Q.
Definition kbd.h:48
@ KBD_MINUS
Minus key.
Definition kbd.h:75
@ KBD_M
Key M.
Definition kbd.h:44
@ KBD_APOSTROPHE
Apostrophe key.
Definition kbd.h:82
@ KBD_3
Key 3.
Definition kbd.h:61
@ KBD_J
Key J.
Definition kbd.h:41
@ KBD_KP_ASTERISK
Keypad Asterisk.
Definition kbd.h:118
@ KBD_BACKSLASH
Backslash key.
Definition kbd.h:79
@ KBD_RIGHT_BRACE
Right brace key.
Definition kbd.h:78
@ KBD_KP_1
Keypad 1.
Definition kbd.h:122
@ KBD_X
Key X.
Definition kbd.h:55
@ KBD_8
Key 8.
Definition kbd.h:66
@ KBD_S
Key S.
Definition kbd.h:50
@ KBD_I
Key I.
Definition kbd.h:40
@ KBD_H
Key H.
Definition kbd.h:39
@ KBD_TAB
Tab key.
Definition kbd.h:73
@ KBD_N
Key N.
Definition kbd.h:45
@ KBD_Z
Key Z.
Definition kbd.h:57
@ KBD_KP_7
Keypad 7.
Definition kbd.h:128
@ KBD_BACKSPACE
Backspace key.
Definition kbd.h:72
@ KBD_HASHTILDE
Hashtilde key.
Definition kbd.h:80
@ KBD_U
Key U.
Definition kbd.h:52
@ KBD_F
Key F.
Definition kbd.h:37
@ KBD_7
Key 7.
Definition kbd.h:65
@ KBD_5
Key 5.
Definition kbd.h:63
@ KBD_KP_9
Keypad 9.
Definition kbd.h:130
@ KBD_0
Key 0.
Definition kbd.h:68
@ KBD_KP_3
Keypad 3.
Definition kbd.h:124
@ KBD_KP_0
Keypad 0.
Definition kbd.h:131
@ KBD_O
Key O.
Definition kbd.h:46
@ KBD_KP_6
Keypad 6.
Definition kbd.h:127
@ KBD_D
Key D.
Definition kbd.h:35
@ KBD_ENTER
Enter key.
Definition kbd.h:70
@ KBD_V
Key V.
Definition kbd.h:53
@ KBD_KP_MINUS
Keypad Minus.
Definition kbd.h:119
@ KBD_W
Key W.
Definition kbd.h:54
@ KBD_EQUAL
Equal key.
Definition kbd.h:76
@ KBD_9
Key 9.
Definition kbd.h:67
@ KBD_KP_SLASH
Keypad Slash.
Definition kbd.h:117
@ KBD_KP_PLUS
Keypad Plus.
Definition kbd.h:120
@ KBD_KP_8
Keypad 8.
Definition kbd.h:129
@ KBD_P
Key P.
Definition kbd.h:47
@ KBD_KP_2
Keypad 2.
Definition kbd.h:123
@ KBD_KP_ENTER
Keypad Enter.
Definition kbd.h:121
@ KBD_KP_EQUAL
Keypad Equal.
Definition kbd.h:137
@ KBD_L
Key L.
Definition kbd.h:43
@ KBD_A
Key A.
Definition kbd.h:32
@ KBD_Y
Key Y.
Definition kbd.h:56
@ KBD_KP_5
Keypad 5.
Definition kbd.h:126
@ KBD_NONE
None.
Definition kbd.h:28
@ KBD_SLASH
Slash key.
Definition kbd.h:86
@ KBD_ESC
Escape key.
Definition kbd.h:71
@ KBD_C
Key C.
Definition kbd.h:34
@ KBD_B
Key B.
Definition kbd.h:33
@ KBD_G
Key G.
Definition kbd.h:38
@ KBD_E
Key E.
Definition kbd.h:36
@ KBD_KP_PERIOD
Keypad Period.
Definition kbd.h:132
@ KBD_COMMA
Comma key.
Definition kbd.h:84
@ KBD_LEFT_BRACE
Left brace key.
Definition kbd.h:77
@ KBD_SEMICOLON
Semicolon key.
Definition kbd.h:81
@ KBD_MOD_SHIFT
Shift modifier.
Definition kbd.h:300
boot_memory_map_t * map
Definition mem.c:19
char kbd_ascii(keycode_t code, kbd_mods_t mods)
Definition kbd.c:95
static keymap_t keymap
Definition kbd.c:16
#define UINT8_MAX
Definition stdint.h:62
Definition kbd.c:6
char shift
Definition kbd.c:8
char norm
Definition kbd.c:7
Definition kbd.c:12
keymap_entry_t map[UINT8_MAX]
Definition kbd.c:13